JSPM

stream-forward

2.0.1
    • ESM via JSPM
    • ES Module Entrypoint
    • Export Map
    • Keywords
    • License
    • Repository URL
    • TypeScript Types
    • README
    • Created
    • Published
    • Downloads 20
    • Score
      100M100P100Q61851F
    • License MIT

    Forward stream events.

    Package Exports

    • stream-forward

    This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (stream-forward) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

    Readme

    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');
    
    streamForward(request('http://yahoo.com'))
      .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) {
      return streamForward(request(reqOpts))
        .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
    Default: All events will be emitted.

    Event names to watch and re-emit on attached streams.

    options.excludeEvents

    Type: Array
    Default: []

    Event names to ignore from stream.