For example, I have this:
var r = fs.createReadStream('file.txt');
var z = zlib.createGzip();
var w = fs.createWriteStream('file.txt.gz');
r.pipe(z).pipe(w);
I want to do something after r.pipe(z).pipe(w) finishes. I tried something like this:
var r = A.pipe(B);
r.on('end', function () { ... });
but it doesn't work for a pipe chain. How can I make it work?
You're looking for the finish
event. From the docs:
When the end() method has been called, and all data has been flushed to the underlying system, this event is emitted.
When the source stream emits an end
, it calls end()
on the destination, which in your case, is B
. So you can do:
var r = A.pipe(B);
r.on('finish', function () { ... });
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