Last active
December 25, 2015 17:19
-
-
Save soldair/7012676 to your computer and use it in GitHub Desktop.
wrap a pipe chain in an exposed through stream
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var through = require('through') | |
module.exports = function(chain){ | |
chain = chain(); | |
var s = through(function(data){ | |
if(!chain.write(data)) this.pause(); | |
}); | |
chain.on('drain',function(){ | |
s.resume(); | |
}) | |
chain.on('data',function(data){ | |
s.emit('data',data) | |
}); | |
chain.on('end',function(){ | |
s.end(); | |
}); | |
return s; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment