Combine multiple duplex streams into just one
Combine multiple duplex streams into just one.
combine-stream lets you treat a few streams as just one, in a parallel fashion. When you combine a bunch of streams, you write to it as if it was one, and read from it as if it was one, but you are simultaneously writing to all the streams and getting the output from all the streams.
Error events are also aggregated from all the streams and forwarded up through the combining stream for you to listen to in one place.
var stream = require"stream";var CombineStream = require"combine-stream";var streamA = objectMode: truestreamB = objectMode: truestreamC = objectMode: true;var combine = streamA streamB streamC;combineon"data" console.log;combinewrite"hello";combineend;
Available via npm:
$ npm install combine-stream
Or via git:
$ git clone git://github.com/deoxxa/combine-stream.git node_modules/combine-stream
Currently this is relying on my fork of readable-stream. Hopefully my patch gets merged and I can remove the hardcoded github dependency.
Creates a new combine-stream.
var combine =logSize: 100recordDuplicates: truecomparator: functon comparea breturn a === b;;
- options - an object containing, as well as the regular
TransformStreamoptions, the parameters described below. If this argument is an array, it will be wrapped in
- streams - an array of streams to add at instantiation time.
- bubbleErrors - a boolean value specifying whether to bubble errors up from the wrapped streams.
Also see example.js.
var stream = require"stream";var CombineStream = require"combine-stream";var delayed =var s = objectMode: true;s_transform =var self = this;return setTimeoutselfpushinput + " " + n;return done;n;;s_flush =console.log"ending!" n;setTimeoutdone n;;return s;;var combine = ;var streamA = delayed100streamB = delayed500;var combine = streamA streamB;combineon"data" console.log;combineon"error" console.log;combinewrite"hello 1";combinewrite"hello 2";combinewrite"hello 3";combineendconsole.log"everything finished";;
hello 1 100hello 1 500hello 2 100hello 2 500hello 3 100hello 3 500ending! 100ending! 500everything finished
3-clause BSD. A copy is included with the source.