combining
Combine streams in a pipeline.
Behaviors:
- Piping to it pipes to its first stream.
- Piping from it pipes from its last stream.
- adding 'close' event listener will add it to its first stream
- adding listeners: end, finish, data, readable will add it to its last stream
- adding other listeners, including error, will be added to all its streams
- error events emitted on any of its streams are automatically forwarded and emitted on it
Install
npm install --save combining
Usage
// get the modulevar buildCombine = // build the combine function for usevar combine = // no options provided // some input stream where you'd have data coming fromvar input = // some output stream where you'd like to send resultsvar output = // create some sample streams to combinevar stream1 = var stream2 = var stream3 = // combine the three streams togethervar combo = // Or,// provide an array of streams:var combo = // Or,// provide streams and arrays of streams// because it'll be flattened into a single array.var combo = // now use the combined streams as if they were one streaminput // adds end listener to the first stream:combo // adds finish listener to the last stream:combo // adds custom listeners to all streams in the `combo`:combo // Note:// We could have pipe'd each one to the next ourselves.// But, I've found I'm rarely the one controlling all parts involved.// This shows how things work together. In development, I find it's// helpful to create a single stream combined from other streams to// supply to some library or function to use.//// Also, I'm aware of the module `stream-combiner`. I wasn't able to add event// listeners to it and have them added on the internal streams I knew to be// combined in a stream I had. My implementation allows that.