Skip to content

Close event fired prematurely in node@14 and node@16 #37

@jteagles

Description

@jteagles

Other user reported it here.
https://stackoverflow.com/questions/63524117/fs-createreadstream-with-pipe-fires-close-event-twice

My code + fix by switching to another zip library (node-stream-zip)
https://github.com/sreenaths/mock-ats/pull/4/files

  zipFiles.upload.forEach(function (file){
    var unzipDir = file.path + "_dir/";

    fs.createReadStream(file.path).
    pipe(unzip.Extract({ path: unzipDir }).
      on('close', function() {
        fs.readdir(unzipDir, function(err, files){
          if (err) throw err;
          files.forEach(function(file){
              var json = JSON.parse(fs.readFileSync(unzipDir + file, 'utf8'));
              extractData(data, json);
          });

          completeCount++;

          if(completeCount == zipFiles.upload.length) {
            callback(data);
          }
        });
      })
    );

extra close event is triggered with files being [] for the first event and correctly populated for the second close event.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions