Giter VIP home page Giter VIP logo

stream-multiplexer's Introduction

stream-multiplexer

Pipe one stream in, many streams out. Goes as slow as the slowest writer.

THE PROBLEM

If you are trying to pipe to a very fast stream, and also to a very slow stream, then every time the fast stream emits drain, it'll try to write another chunk.

Most of the time, you'd prefer that the reader goes no faster than the slowest writer can accomodate.

In Node v0.10, this is how it works. However, in Node v0.8 and before, any 'drain' event from any writer would cause the reader to emit more data.

Compounding the issue, in v0.8, writable streams usually emitted 'drain' after any flushed write(), even if it was immediately flushed, and already returned true!

In Node v0.10, this module simply exports the stream.PassThrough module. In Node v0.8 and before, it exports a streams1 style stream that behaves properly when piped to multiple differing-speed destinations.

If you know that your program will only be run in Node v0.10 and above, don't bother with this module.

USAGE

var SM = require('stream-multiplexer');
var sm = new SM;
var myStream = fs.createReadStream('some-file');

myStream.pipe(sm);
sm.pipe(fastWriter);
sm.pipe(slowWriter);

stream-multiplexer's People

Contributors

isaacs avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.