Suckle

0.0.1 • Public • Published

Suckle

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)

mux.pipe(process.stdout).write('asdf\n')

process.stdin.resume()
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 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! /*
})

zipper.pipe(mux)
fileStream.pipe(zipper)

Readme

Keywords

none

Package Sidebar

Install

npm i Suckle

Weekly Downloads

1

Version

0.0.1

License

none

Last publish

Collaborators

  • Weltschmerz