multistream

A stream that emits multiple other streams one after another (streams2)

multistream

Simple, robust streams2 version of combined-stream. Allows you to combine multiple streams into a single stream. When the first stream ends, the next one starts, and so on, until all streams are consumed.

This module is used by WebTorrent, specifically create-torrent.

npm install multistream

Use multistream like this:

var MultiStream = require('multistream')
var concat = require('concat-stream')
var fs = require('fs')
 
var streams = [
  fs.createReadStream(__dirname + '/numbers/1.txt'),
  fs.createReadStream(__dirname + '/numbers/2.txt'),
  fs.createReadStream(__dirname + '/numbers/3.txt')
]
 
MultiStream(streams).pipe(process.stdout) // => 123 

To lazily create the streams, wrap them in a function:

var streams = [
  fs.createReadStream(__dirname + '/numbers/1.txt'),
  function () { // will be executed when the stream is active 
    return fs.createReadStream(__dirname + '/numbers/2.txt')
  },
  function () { // same 
    return fs.createReadStream(__dirname + '/numbers/3.txt')
  }
]
 
MultiStream(streams).pipe(process.stdout) // => 123 

MIT. Copyright (c) Feross Aboukhadijeh.