![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
combine-stream
Advanced tools
Combine multiple duplex streams into just one.
combine-stream lets you treat a few streams as just one, in a parallel fashion. When you combine a bunch of streams, you write to it as if it was one, and read from it as if it was one, but you are simultaneously writing to all the streams and getting the output from all the streams.
Error events are also aggregated from all the streams and forwarded up through the combining stream for you to listen to in one place.
Code:
var stream = require("stream");
var CombineStream = require("combine-stream");
var streamA = new stream.PassThrough({objectMode: true}),
streamB = new stream.PassThrough({objectMode: true}),
streamC = new stream.PassThrough({objectMode: true});
var combine = new CombineStream([streamA, streamB, streamC]);
combine.on("data", console.log);
combine.write("hello");
combine.end();
Output:
hello
hello
hello
Available via npm:
$ npm install combine-stream
Or via git:
$ git clone git://github.com/deoxxa/combine-stream.git node_modules/combine-stream
NOTE:
Currently this is relying on my fork of readable-stream. Hopefully my patch gets merged and I can remove the hardcoded github dependency.
constructor
Creates a new combine-stream.
new CombineStream(options);
var combine = new CombineStream({
logSize: 100,
recordDuplicates: true,
comparator: functon compare(a, b) {
return a === b;
},
});
Arguments
TransformStream
options, the parameters described below. If this argument is an array, it will
be wrapped in {streams: ...}
.options
Also see example.js.
var stream = require("stream");
var CombineStream = require("combine-stream");
var delayed = function delayed(n) {
var s = new stream.Transform({objectMode: true});
s._transform = function _transform(input, encoding, done) {
var self = this;
return setTimeout(function() {
self.push(input + " " + n);
return done();
}, n);
};
s._flush = function _flush(done) {
console.log("ending!", n);
setTimeout(done, n);
};
return s;
};
var combine = new CombineStream();
var streamA = delayed(100),
streamB = delayed(500);
var combine = new CombineStream([streamA, streamB]);
combine.on("data", console.log);
combine.on("error", console.log);
combine.write("hello 1");
combine.write("hello 2");
combine.write("hello 3");
combine.end(function() {
console.log("everything finished");
});
Output:
hello 1 100
hello 1 500
hello 2 100
hello 2 500
hello 3 100
hello 3 500
ending! 100
ending! 500
everything finished
3-clause BSD. A copy is included with the source.
FAQs
Combine multiple duplex streams into just one
The npm package combine-stream receives a total of 3 weekly downloads. As such, combine-stream popularity was classified as not popular.
We found that combine-stream demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.