Nerds Pledge Magnanimously
    Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

    streammergepublic

    StreamMerge

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

    NPM version Build Status Dependency Status devDependency Status Coverage Status

     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.

    API

    StreamMerge([options], [stream1, stream2, ... streamN])

    options

    options.objectMode

    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.

    options.*

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

    streamN

    Type: Stream

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

    StreamMerge.add(stream1, [stream2, ... streamN])

    Append streams given in argument to the merge.

    StreamMerge.done([stream1, stream2, ... streamN])

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

    Stats

    NPM NPM

    Contributing

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

    install

    npm i streammerge

    Downloadsweekly downloads

    3

    version

    0.0.1

    license

    none

    repository

    githubgithub

    last publish

    collaborators

    • avatar