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 - npm Package Compare versions

Comparing version 0.2.1 to 0.2.2

47

lib/stream-connect.js

@@ -5,24 +5,23 @@ 'use strict'

/**
Create a pipeline of connected streams.
Connect two streams returning a single duplex stream. Use over `.pipe()` when you want to write to the source stream yet read from the destination.
@module stream-connect
@example
> streamConnect = require("stream-connect")
> PassThrough = require("stream").PassThrough
const connect = require('stream-connect')
> pass1 = PassThrough()
> pass1.setEncoding("utf8")
> pass1.on("data", console.log.bind(console, "pass1"))
function streamsOneAndTwo () {
const streamOne = getStreamOneSomehow()
const streamTwo = getStreamTwoSomehow()
> pass2 = PassThrough()
> pass2.setEncoding("utf8")
> pass2.on("data", console.log.bind(console, "pass2"))
// We want to return streams one and two pre-connected. We can't return
// `streamOne.pipe(streamTwo)` as this returns streamTwo while the calling code
// wants to write to streamOne yet receive the output from streamTwo.
// So, return a new stream which is streams one and two connected:
const streamsOneAndTwo = connect(streamOne(), streamTwo())
}
> pass1.write("testing")
pass1 testing
> connected = streamConnect(pass1, pass2)
> connected.write("testing")
pass1 testing
pass2 testing
// main.js is piped through the pre-connected streamOne and streamTwo, then stdout
fs.createReadStream('main.js')
.pipe(streamsOneAndTwo())
.pipe(process.stdout)
*/

@@ -32,7 +31,7 @@ module.exports = connect

/**
Connects two duplex streams together.
Connects two streams together.
@param {external:Duplex} - source stream
@param {external:Duplex} - dest stream, to be connected to
@return {external:Transform}
@return {external:Duplex}
@alias module:stream-connect

@@ -52,6 +51,10 @@ */

})
two.on('readable', function () {
var chunk = this.read()
/* use flowing rather than paused mode, for node 0.10 compatibility. */
two.on('data', function (chunk) {
connected.push(chunk)
})
two.on('end', function () {
connected.push(null)
})

@@ -69,8 +72,4 @@ one.on('error', function (err) {

/**
@external Transform
@see https://nodejs.org/api/stream.html#stream_class_stream_transform
*/
/**
@external Duplex
@see https://nodejs.org/api/stream.html#stream_class_stream_duplex
*/
{
"name": "stream-connect",
"author": "Lloyd Brookes <75pound@gmail.com>",
"version": "0.2.1",
"version": "0.2.2",
"description": "Create a pipeline of connected streams",

@@ -6,0 +6,0 @@ "repository": "https://github.com/75lb/stream-connect.git",

@@ -9,28 +9,27 @@ [![view on npm](http://img.shields.io/npm/v/stream-connect.svg)](https://www.npmjs.org/package/stream-connect)

## stream-connect
Create a pipeline of connected streams.
Connect two streams returning a single duplex stream. Use over `.pipe()` when you want to write to the source stream yet read from the destination.
**Example**
```js
> streamConnect = require("stream-connect")
> PassThrough = require("stream").PassThrough
const connect = require('stream-connect')
> pass1 = PassThrough()
> pass1.setEncoding("utf8")
> pass1.on("data", console.log.bind(console, "pass1"))
function streamsOneAndTwo () {
const streamOne = getStreamOneSomehow()
const streamTwo = getStreamTwoSomehow()
> pass2 = PassThrough()
> pass2.setEncoding("utf8")
> pass2.on("data", console.log.bind(console, "pass2"))
// We want to return streams one and two pre-connected. We can't return
// `streamOne.pipe(streamTwo)` as this returns streamTwo while the calling code
// wants to write to streamOne yet receive the output from streamTwo.
// So, return a new stream which is streams one and two connected:
const streamsOneAndTwo = connect(streamOne(), streamTwo())
}
> pass1.write("testing")
pass1 testing
> connected = streamConnect(pass1, pass2)
> connected.write("testing")
pass1 testing
pass2 testing
// main.js is piped through the pre-connected streamOne and streamTwo, then stdout
fs.createReadStream('main.js')
.pipe(streamsOneAndTwo())
.pipe(process.stdout)
```
<a name="exp_module_stream-connect--connect"></a>
### connect(one, two) ⇒ <code>[Transform](https://nodejs.org/api/stream.html#stream_class_stream_transform)</code> ⏏
Connects two duplex streams together.
### connect(one, two) ⇒ <code>[Duplex](https://nodejs.org/api/stream.html#stream_class_stream_duplex)</code> ⏏
Connects two streams together.

@@ -37,0 +36,0 @@ **Kind**: Exported function

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