Created
January 19, 2015 22:26
-
-
Save RangerMauve/3628bed7a25cd79a6394 to your computer and use it in GitHub Desktop.
Facade duplex streams
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
//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