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.
Installation
This module is installed via npm:
$ npm install dynamic-duplexTesting
This module can be tested by running:
$ npm run testExample 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