Socket
Book a DemoInstallSign in
Socket

streams2

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

streams2

Wrap a 0.8 stream into a streams2 stream

latest
Source
npmnpm
Version
0.1.1
Version published
Maintainers
1
Created
Source

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

FAQs

Package last updated on 21 Nov 2012

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts