Skip to content

Instantly share code, notes, and snippets.

@RangerMauve
Created January 19, 2015 22:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RangerMauve/3628bed7a25cd79a6394 to your computer and use it in GitHub Desktop.
Save RangerMauve/3628bed7a25cd79a6394 to your computer and use it in GitHub Desktop.
Facade duplex streams
//https://www.npmjs.com/package/duplexer
var duplexer = require("duplexer");
var through = require("through2");
function boostrap(fn){
var input = noop(); // Just passes data through
var output = noop(); // Just passed data through;
input.once("data",function(chunk, encoding, cb){
fn(chunk, encoding, function(err,stream){
if(err) return cb(err);
input.pipe(stream).pipe(output); // Wire the input and output to the new stream
});
});
return duplexer(input, output);
}
function noop(){
return through(function(chunk,encoding,cb){
return cb(null, chunk);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment