rocket.chat.mqtt
Version:
It's a MQTT Server, using redis to scale horizontally.
87 lines (62 loc) • 2.78 kB
Markdown
[]: https://img.shields.io/travis/feross/multistream/master.svg
[]: https://travis-ci.org/feross/multistream
[]: https://img.shields.io/npm/v/multistream.svg
[]: https://npmjs.org/package/multistream
[]: https://img.shields.io/npm/dm/multistream.svg
[]: https://npmjs.org/package/multistream
[]: https://img.shields.io/badge/code_style-standard-brightgreen.svg
[]: https://standardjs.com
[](https://saucelabs.com/u/multistream)

Simple, robust streams2 version of [combined-stream](https://www.npmjs.org/package/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](http://webtorrent.io), specifically [create-torrent](https://github.com/feross/create-torrent).
```
npm install multistream
```
Use `multistream` like this:
```js
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')
]
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:
```js
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
```
Alternatively, streams may be created by an asynchronous "factory" function:
```js
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)
}
MultiStream(factory).pipe(process.stdout) // => 123
```
- [Feross Aboukhadijeh](http://feross.org)
- [Mathias Buus](https://github.com/mafintosh/)
- [Yuri Astrakhan](https://github.com/nyurik/)
MIT. Copyright (c) [Feross Aboukhadijeh](http://feross.org).