merge-readable
v1.1.0
Published
merge-readable
Readme
merge-readable
Merge multiple readable streams into one.
npm install merge-readableUsage
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
// barAPI
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:
const merged = merge([stream1, stream2, stream3])With map function
const merged = merge(Readable.from(['hello', 'world']), Readable.from(['foo', 'bar']), (data) =>
data.toUpperCase()
)
merged.on('data', console.log)
// HELLO
// WORLD
// FOO
// BARWith pipeline
const { pipeline, Transform } = require('streamx')
const output = pipeline(
merge(stream1, stream2),
new Transform({
transform(data, cb) {
cb(null, processData(data))
}
})
)License
Apache-2.0
