stream-connect
Similar to .pipe
except .pipe
returns the last stream in a pipeline. stream-connect returns a stream which writes to the first stream in the pipeline and reads from the last.
Synopsis
const connect = require('stream-connect')
const fs = require('fs')
const connected = connect(stream1, stream2, stream3, stream4)
process.stdin
.pipe(connected)
.on('error', console.error)
.pipe(process.stdout)
More detail
Consider this .pipe
example.
function getExampleStream () {
...
return streamOne.pipe(streamTwo)
}
const stream = getExampleStream()
stream.on('data', function (chunk) {})
stream.on('error', function (err) {})
stream.end('test')
If you write to the output it will be written to streamTwo
, whereas you probably wanted to write to the start of the pipeline and read from the end. Fixed by stream-connect:
const connect = require('stream-connect')
function getExampleStream () {
...
return connect(streamOne, streamTwo)
}
const stream = getExampleStream()
stream.on('data', function (chunk) {})
stream.on('error', function (err) {})
stream.end('test')
Any errors emitted in streamOne
or streamTwo
are propagated to the output stream.
stream-connect
Example
const connect = require('stream-connect')
connect(...streams) ⇒ Duplex
⏏
Connect streams.
Kind: Exported function
Param | Type | Description |
---|
...streams | Duplex | One or more streams to connect. |
© 2015 Lloyd Brookes <75pound@gmail.com>. Documented by jsdoc-to-markdown.