Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

stream-connect

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

stream-connect

Connects an arbitrary number of streams into a single, combined stream

  • 1.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
137K
decreased by-8.45%
Maintainers
1
Weekly downloads
 
Created
Source

view on npm npm module downloads Build Status Coverage Status Dependency Status js-standard-style

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)

// data piped into the connected stream is transparently passed through all four internal streams
// then output into process.stdout. Errors in any of the internal streams are emitted
// by the connected stream.
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) {}) // catches data from streamOne via streamTwo
stream.on('error', function (err) {}) // catches errors only from streamTwo
stream.end('test') // is written to streamTwo

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) {}) // catches data from streamOne via streamTwo
stream.on('error', function (err) {}) // catches errors from both streamOne and streamTwo
stream.end('test') // is written to streamOne

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

ParamTypeDescription
...streamsDuplexOne or more streams to connect.

© 2015 Lloyd Brookes <75pound@gmail.com>. Documented by jsdoc-to-markdown.

Keywords

FAQs

Package last updated on 04 Jan 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc