JSPM

dynamic-duplex

1.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 6
  • Score
    100M100P100Q33407F
  • License ISC

Dynamically wires up readable streams based on data it receives.

Package Exports

  • dynamic-duplex

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 (dynamic-duplex) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

dynamic-duplex

Dynamically wires up a duplex stream based on the data it receives.

build status

Installation

This module is installed via npm:

$ npm install dynamic-duplex

Testing

This module can be tested by running:

$ npm run test

Example Usage

var Readable = require('stream').Readable;
var streamify = require('stream-array');
var dynamicDuplex = require('dynamic-duplex');

var input = new Readable({objectMode: true});

var streams = {
    a: streamify([1,2,3,4]),
    b: streamify([5,6,7,8])
};
input.pipe(dynamicDuplex(function(letter, en, cb) {
    cb(null, streams[letter]);
})).pipe(through(function(chunk, end, cb) {
    console.log(chunk);

    if (chunk === 2) {
        // force a switch to stream b
        input.push('b');
    }

    cb();
}));

// To get the ball rolling
input.push('a');

// Expected output from this code is:
// 1 2 5 6 7 8