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.
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
extra close event is triggered with files being [] for the first event and correctly populated for the second close event.