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.
Super Quickstart
Code:
var stream = require("stream");var CombineStream = require("combine-stream");var streamA = new stream.PassThrough({objectMode: true}), streamB = new stream.PassThrough({objectMode: true}), streamC = new stream.PassThrough({objectMode: true});var combine = new CombineStream([streamA, streamB, streamC]);combine.on("data", console.log);combine.write("hello");combine.end();
Currently this is relying on my fork of readable-stream.
Hopefully my patch gets merged and I can remove the hardcoded github dependency.
API
constructor
Creates a new combine-stream.
new CombineStream(options);
var combine = new CombineStream({ logSize: 100, recordDuplicates: true, comparator: functon compare(a, b) { return a === b; },});
Arguments
options - an object containing, as well as the regular TransformStream
options, the parameters described below. If this argument is an array, it will
be wrapped in {streams: ...}.
options
streams - an array of streams to add at instantiation time.
bubbleErrors - a boolean value specifying whether to bubble errors up from
the wrapped streams.