suckle

Stream multiplexer, with callback ability

npm install suckle
6 downloads in the last day
49 downloads in the last week
192 downloads in the last month

Suckle

npm install suckle

Suckle is a stream multiplexer for node. Give it one readable stream, and it pipes to multiple writable streams.

var suckle = require('suckle')

var mux = suckle.createStream();

mux.pipe(process.stdout, process.stdout, process.stdout)
mux.pipe(process.stdout, process.stdout);
mux.pipe(process.stdout);

process.stdin.pipe(mux)

The main problem Suckle solves is when you need a callback, to return the piped data. As a case study, say you have a static file server. Ideally, you would like to pipe node's file readStream to gzip, and then to the client. Fine. But what if you also need to cache that gzipped data in an object, for subsequent requests? With Suckle you can!


var fs   = require('fs')
var zlib = require('zlib')
var http = require('http')

var Suckle = require('suckle')

http.createserver(function(req, res) {

    var mux = new Suckle;

    mux.pipe(res);

    mux.onComplete(function(data, length) {
      /* Here's your gzipped data */
    });

    fs.createReadStream('somefile.jpg')
    .pipe(zlib.createGzip())
    .pipe(mux);

}).listen(8080)

Suckle is used internally by Lactate

npm loves you