multistream

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

Github星跟踪图

multistream travis npm downloads javascript style guide

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

Sauce Test Status

cat

Simple, robust streams3 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.

install

npm install multistream

usage

Use multistream like this:

var MultiStream = require('multistream')
var fs = require('fs')

var streams = [
  fs.createReadStream(__dirname + '/numbers/1.txt'),
  fs.createReadStream(__dirname + '/numbers/2.txt'),
  fs.createReadStream(__dirname + '/numbers/3.txt')
]

new MultiStream(streams).pipe(process.stdout) // => 123

You can also create an object-mode stream with MultiStream.obj(streams).

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')
  }
]

new MultiStream(streams).pipe(process.stdout) // => 123

Alternatively, streams may be created by an asynchronous "factory" function:

var count = 0
function factory (cb) {
  if (count > 3) return cb(null, null)
  count++
  setTimeout(function () {
    cb(null, fs.createReadStream(__dirname + '/numbers/' + count + '.txt'))
  }, 100)
}

new MultiStream(factory).pipe(process.stdout) // => 123

contributors

license

MIT. Copyright (c) Feross Aboukhadijeh.

主要指标

概览
名称与所有者feross/multistream
主编程语言JavaScript
编程语言JavaScript (语言数: 1)
平台
许可证MIT License
所有者活动
创建于2014-07-06 16:42:02
推送于2021-09-09 04:03:16
最后一次提交2021-02-04 11:15:19
发布数26
最新版本名称v4.1.0 (发布于 2021-02-04 11:15:19)
第一版名称v1.0.0 (发布于 2014-07-06 16:43:11)
用户参与
星数293
关注者数7
派生数25
提交数139
已启用问题?
问题数17
打开的问题数3
拉请求数27
打开的拉请求数1
关闭的拉请求数14
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?