[ann] pump - pipe streams together and destroy all them if one of the closes / emits an error

423 views
Skip to first unread message

Mathias Buus Madsen

unread,
Aug 14, 2013, 5:55:31 PM8/14/13
to nod...@googlegroups.com
Usually when I pipe streams I want to destroy the source if the destination closes.
Since pipe does not do that I kept repeating this

source
.on('close', dest.destroy.bind(dest))
.on('error', dest.destroy.bind(dest))
.pipe(dest)
.on('close', source.destroy.bind(source))
.on('error', source.destroy.bind(source))

I decided to do a small module that does this for me. It is called pump


Using pump you can do the above like so

var pump = require('pump');
pump(source, transform1, transform2, ..., dest, function(err) {
console.log('pipe finished', err);
});

It works with both 0.8 and 0.10 streams.

Jan Maybach

unread,
May 22, 2015, 1:09:13 PM5/22/15
to nod...@googlegroups.com, mathi...@gmail.com
Why do you have to bind it?

Regards,
Ian
Reply all
Reply to author
Forward
0 new messages