What is stream-combiner?
The stream-combiner npm package is used to combine multiple Node.js streams (readable or writable) into a single stream. This is particularly useful for managing stream pipelines and handling data transformations in a more organized and readable manner.
What are stream-combiner's main functionalities?
Stream Pipeline Creation
This code sample demonstrates how to create a stream pipeline using stream-combiner. It combines stdin, a decryption stream, a gzip compression stream, and stdout into a single stream pipeline. Errors in any part of the stream are handled by logging to the console.
const { combine } = require('stream-combiner');
const zlib = require('zlib');
const crypto = require('crypto');
const combinedStream = combine(
process.stdin,
crypto.createDecipher('aes192', 'a_secret'),
zlib.createGzip(),
process.stdout
);
combinedStream.on('error', console.error);
Other packages similar to stream-combiner
pump
Pump is a small node module that pipes streams together and destroys all of them if one of them closes. Compared to stream-combiner, pump provides a similar functionality but with a focus on properly cleaning up the streams to avoid memory leaks, which is not explicitly handled by stream-combiner.
multistream
Multistream allows you to combine multiple streams into a single readable stream. It differs from stream-combiner in that it focuses more on sequential rather than parallel stream combination, making it suitable for scenarios where streams need to be processed one after another.
stream-combiner
Combine (stream1,...,streamN)
Turn a pipeline into a single stream. Combine
returns a stream that writes to the first stream
and reads from the last stream.
Listening for 'error' will recieve errors from all streams inside the pipe.
var Combine = require('stream-combiner')
var es = require('event-stream')
Combine(
process.openStdin(),
es.split(),
es.map(function (data, callback) {
var repr = util.inspect(JSON.parse(data))
callback(null, repr)
}),
process.stdout
)
Can also be called with an array:
var combinedStream = Combine([
stream1,
stream2,
]);
Or to combine gulp plugins:
function coffeePipe() {
return Combine(
coffeescript(),
coffeelint.reporter('fail').on('error', function(){
gutil.beep()
gulp.run('lint')
})
}
gulp.src().pipe(coffeePipe());
License
MIT