streammerge

Merge given streams once they are readable ensuring their content integrity.

StreamMerge

StreamMerge pipe the given streams one by one once they are readable and preserve their content integrity.

## Usage Install the npm module:

npm install streammerge --save

Then, in your scripts:

var streammerge = require('streammerge');
 
streammerge(
  Fs.createReadStream('input.txt'),
  Fs.createReadStream('input2.txt'),
  Fs.createReadStream('input3.txt')
).pipe(process.stdout);

StreamMerge also accept functions returning streams, the above can be written like this, doing system calls only when piping:

var streammerge = require('streammerge');
 
streammerge(
  Fs.createReadStream.bind(null, 'input.txt'),
  Fs.createReadStream.bind(null, 'input2.txt'),
  Fs.createReadStream.bind(null, 'input3.txt')
).pipe(process.stdout);

Object-oriented traditionnal API offers more flexibility:

var StreamMerge = require('streammerge');
 
var mergeStream = new StreamMerge();
mergeStream.add(
  Fs.createReadStream('input.txt'),
  Fs.createReadStream('input2.txt'),
  Fs.createReadStream('input3.txt')
);
mergeStream.done();
 
mergeStream.pipe(process.stdout);

You can also chain StreamMerge methods like that:

var StreamMerge = require('streammerge');
 
new StreamMerge()
  .add(Fs.createReadStream('input.txt'))
  .add(Fs.createReadStream('input2.txt'))
  .add(Fs.createReadStream('input3.txt'))
  .done()
  .pipe(process.stdout);

You can add new streams at any moment until you call the done() method. So the created stream will not fire the end event until done() call.

Type: Boolean Default value: false

Use if piped in streams are in object mode. In this case, the merge stream will also be in the object mode.

StreamMerge inherits of Stream.Readable, the options are passed to the parent constructor so you can use it's options too.

Type: Stream

Append streams given in argument to the merge and ends when each streams are consumed.

Append streams given in argument to the merge.

Append streams given in argument to the merge and ends when each streams are consumed.

Feel free to pull your code if you agree with publishing it under the MIT license.