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

stream-forward

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

stream-forward

Forward stream events.

  • 3.0.0
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

stream-forward

Forward events to the next stream in the pipeline.

Use

$ npm install --save stream-forward
var streamForward = require('stream-forward');

Example

var streamForward = require('stream-forward');
var request = require('request');

var opts = {
  events: ['response']
};

streamForward(request('http://yahoo.com'), opts)
  .pipe(process.stdout)
  .on('response', function (response) {
    // `response` from the request stream.
  });

Note: don't neglect proper event handling on the individual parts of your stream.

This is just a convenience when you have to manually listen and re-emit events across a middleman/spy pipe. Consider the following example:

var fs = require('fs');

function getRequestStream(reqOpts) {
  var opts = {
    events: ['complete']
  };

  return streamForward(request(reqOpts), opts)
    .pipe(fs.createWriteStream('./request-cache'));
}

getRequestStream('http://yahoo.com')
  .on('complete', function () {
    // Without `stream-forward`, this couldn't emit.
  });

stream = streamForward(stream, [options]);

stream

Type: Stream

The source stream to spy on. This is returned from the function to allow chaining.

options

Optional. Configuration options.

options.continuous

Type: Boolean
Default: false

If true, when a new stream is attached to stream, it will receive the events emitted by the original.

Disabled (default)
var sourceStream = request('http://yahoo.com');
var through = require('through2');

streamForward(sourceStream)
  .pipe(through())
  .on('complete', function () {
    // Called.
  })
  .pipe(through())
  .on('complete', function () {
    // Not called.
  });
Enabled
var sourceStream = request('http://yahoo.com');
var through = require('through2');

streamForward(sourceStream, { continuous: true })
  .pipe(through())
  .on('complete', function () {
    // Called.
  })
  .pipe(through())
  .on('complete', function () {
    // Called.
  });
options.events

Type: Array

Event names to re-emit on attached streams.

Keywords

FAQs

Package last updated on 19 Aug 2015

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