Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jteagles opened this issue Aug 19, 2021 · 0 comments
Open

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

jteagles opened this issue Aug 19, 2021 · 0 comments

Comments

@jteagles
Copy link

jteagles commented Aug 19, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant