Tuesday, 18 April 2017

fs.createReadStream not always hits the close event

I have the following piece of code in a Node JS script

fs.createReadStream(zipFile).pipe(unzip.Extract({ path: outputPath }))
.on('close', function () {

    fs.exists(zipFile, function (exists) {
        if (exists) {
            fs.unlink(zipFile);
        }
    });

    resolve('Files unziped');
})
.on('error', function (res) {

    reject('Error encountered when unziping files');
});

However, not always hits the .on('close'...) event. I've tested the exact same file several times and only 20% of the times it unzip it. The rest of the times it does nothing...

Is it something that I am doing wrong?



via user3587624

No comments:

Post a Comment