I'm trying to use the unzipper node module to extract and process a number of files (exact number is unknown). However, I can't seem to figure out how to know when all the files are processed. So far, my code looks like this:
s3.getObject(params).createReadStream()
.pipe(unzipper.Parse())
.on('entry', async (entry) => {
var fileName = entry.path;
if (fileName.match(someRegex)) {
await processEntry(entry);
console.log("Uploaded");
} else {
entry.autodrain();
console.log("Drained");
}
});
I'm trying to figure out how to know that unzipper has gone through all the files (i.e., no more entry
events are forthcoming) and all the entry
handlers have finished so that I know I've finished processing all the files I care about.
I've tried experimenting with the close
and finish
events but when I have, they both trigger before console.log("Uploaded");
has printed, so that doesn't seem right.
Help?
Directly from the docs:
The parser emits
finish
anderror
events like any other stream. The parser additionally provides a promise wrapper around those two events to allow easy folding into existing Promise-based structures.Example:
fs.createReadStream('path/to/archive.zip') .pipe(unzipper.Parse()) .on('entry', entry => entry.autodrain()) .promise() .then( () => console.log('done'), e => console.log('error',e));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With