node package manager
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »



Suckle is a stream multiplexer for node. You pass it as many writable streams as you want, and it exposes a simple chainable API for treating it as if it were only one. Also, if enabled, you can wedge a callback for when the stream ends. This callback is supplied the accumulated data.

var Suckle = require('suckle')
var mux = new Suckle(process.stdout)

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 Suckle = require('suckle')
var fileStream = fs.createReadStream('somefile.jpg')
var zipper = zlib.createGzip()
var mux = new Suckle(true, process.stdout)
mux.oncomplete(function(data) {
    /* You can do anything! Anything! /*