merge-readable
npm install merge-readableMerge multiple readable streams into one.
```
npm install merge-readable
`js
const merge = require('merge-streams')
const { Readable } = require('streamx')
const merged = merge(Readable.from(['hello', 'world']), Readable.from(['foo', 'bar']))
merged.on('data', console.log)
// hello
// world
// foo
// bar
`
#### const output = merge(source1, source2, ..., [map])
Merges multiple readable streams into a single readable stream.
- source1, source2, ... - Readable streams to mergemap
- - Optional function to transform each chunk: (data) => transformedData
Returns a Readable stream that emits data from all sources. The output stream ends when all source streams have ended. If any source stream errors or closes prematurely, all streams are destroyed.
You can also pass an array of streams:
`js`
const merged = merge([stream1, stream2, stream3])
`js
const merged = merge(Readable.from(['hello', 'world']), Readable.from(['foo', 'bar']), (data) =>
data.toUpperCase()
)
merged.on('data', console.log)
// HELLO
// WORLD
// FOO
// BAR
`
`js
const { pipeline, Transform } = require('streamx')
const output = pipeline(
merge(stream1, stream2),
new Transform({
transform(data, cb) {
cb(null, processData(data))
}
})
)
``
Apache-2.0