streams2

Wrap a 0.8 stream into a streams2 stream

npm install streams2
1 downloads in the last day
5 downloads in the last week
23 downloads in the last month

streams2

gi

Example

var fs = require("fs")
    , read = fs.createReadStream
    , write = fs.createWriteStream
    , wrap = require("streams2")

var stream = wrap(write("/tmp/noise"))

stream.end("some data")
stream.on("finish", function () {
    // finished writing
})

var stream = wrap(read("/tmp/noise"))

consume(stream, function (chunk) {
    // some data
})

function consume(stream, consumer) {
    flow()

    stream.on("readable", flow)

    function flow() {
        var chunk = stream.read()
        while (chunk !== null) {
            consumer(chunk)
            chunk = stream.read()
        }
    }
}

Installation

npm install streams2

Contributors

  • Raynos

MIT Licenced

npm loves you