1.1.0 • Published 11 years ago

stream-cb v1.1.0

Weekly downloads
39
License
-
Repository
github
Last release
11 years ago

===============================================================================

streamCb

Switch between node's two most popular interfaces, streams and (err, result) callbacks.

streamCb = require('stream-cb')

streamCb(?, opt)

if ? is a stream, call .toCb(?, opt) if ? is a function, call .toStream(?, opt) Otherwise throw an error.

streamCb.toStream(cb, encoding)

return a writable stream that calls cb(null, results) if it's ended or with an error if error occurs.

streamCb.toCb(stream, noend)

return a callback that writes to the stream when it's called (null, data), or emits an error if one is provided.

If noend then don't end the stream when the returned callback is called.

Why?

Because you want to make a streams lib and a cb lib work together, or you want to provide a flexible api for your users.

:: function (opts, cb) { var awesome = new crazyStream // Do cool streams stuff here

if (cb) return awesome.pipe(streamCb.toStream(cb))
return awesome

}

1.1.0

11 years ago

1.0.0

11 years ago

0.1.0

11 years ago

0.0.8

11 years ago

0.0.5

11 years ago

0.0.4

11 years ago

0.0.3

11 years ago

0.0.2

11 years ago

0.0.1

11 years ago