npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

combine-stream

v0.0.4

Published

Combine multiple duplex streams into just one

Downloads

937

Readme

combine-stream build status

Combine multiple duplex streams into just one.

Overview

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.

Super Quickstart

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

Installation

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.

API

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

  • options - an object containing, as well as the regular TransformStream options, the parameters described below. If this argument is an array, it will be wrapped in {streams: ...}.

options

  • streams - an array of streams to add at instantiation time.
  • bubbleErrors - a boolean value specifying whether to bubble errors up from the wrapped streams.

Example

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

License

3-clause BSD. A copy is included with the source.

Contact