node package manager
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

stream-pass

stream-pass

Manable multiple streams and their ends easily.

It uses through and concat-stream to pipe and produce results to callback.

Examples

Using child_process.spawn :

var streamPass = require('stream-pass'), child_process = require('child_process');
 
var pass = streamPass(function(results) {
  console.log('stdout was: '+results.stdout.toString());
  console.log('2nd line of stderr was: '+results.stderr.toString().split(/\n/)[1]);
}, ['stderr', 'stdout']);
 
var child = child_process.spawn('wget', ['-O', '-', 'http://httpbin.org/user-agent']);
 
pass.passStream('stdout', child.stdout);
pass.passStream('stderr', child.stderr);
 
// stdout was: { 
//   "user-agent": "Wget/1.15 (linux-gnu)" 
// } 
// 
// 2nd line of stderr was: Resolving httpbin.org (httpbin.org)... 54.175.219.8 

You can also pipe the streams :

var streamPass = require('stream-pass');
var pass = streamPass(function(results) { ... }, ['myStream']);
pass.passStream('myStream', myStreamObject);
pass.getStream('myStream').pipe(process.stdout);

Or add some :

var streamPass = require('stream-pass');
var pass = streamPass(function(results) { /* do something with results.myStream */ });
pass.addStream('myStream');
pass.passStream('myStream', myStreamObject);

To do

  • anyStream.pipe(pass.getStream('myStream')) brokes the callback
  • passStream() without addStream() before