read-write-stream
Base stream class for RW stream
Last updated 3 years ago by raynos .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ gnpm install read-write-stream 
SYNC missed versions from official npm registry.

read-write-stream

Base stream class for through RW stream

Example through

var through = require("read-write-stream")
    , transform = through(function write(chunk, queue) {
        queue.push(chunk * chunk)
    }).stream
    , to = require("write-stream").toArray
    , from = require("read-stream").fromArray

from([1,2,3]).pipe(transform).pipe(to([], function end(list) {
    console.log(list); // [1, 4, 9]
}))

Example duplex

var axon = require("axon")
    , pub = axon.socket("push")
    , sub = axon.socket("pull")
    , duplex = require("read-write-stream")
    , from = require("read-stream").fromArray
    , to = require("write-stream").toArray

// Writable end of duplex
var queue = duplex(function write(chunk) {
    pub.send(chunk)
}, function end() {
    pub.send("__GOODBYE__")
    setTimeout(pub.close.bind(pub), 1000)
})

// Readable end of duplex
sub.on("message", function (chunk) {
    chunk = chunk.toString()
    if (chunk === "__GOODBYE__") {
        queue.end()
        sub.close()
    } else {
        queue.push(chunk)
    }
})

// Open underlying writable data source
pub.bind(3000, function () {
    // Open underlying readable data source
    sub.connect(3000, function () {
        // flow data from array
        from(["foo", "bar", "baz"])
            // into duplex
            .pipe(queue.stream)
            // into array
            .pipe(to([], function (list) {
                console.log("list from sub", list)
            }))
    })
})

Installation

npm install read-write-stream

Contributors

  • Raynos

MIT Licenced

Current Tags

  • 0.1.8                                ...           latest (3 years ago)

9 Versions

  • 0.1.8                                ...           3 years ago
  • 0.1.7                                ...           11 years ago
  • 0.1.6                                ...           12 years ago
  • 0.1.5                                ...           12 years ago
  • 0.1.4                                ...           12 years ago
  • 0.1.3                                ...           12 years ago
  • 0.1.2                                ...           12 years ago
  • 0.1.1                                ...           12 years ago
  • 0.1.0                                ...           12 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (3)
Dev Dependencies (2)

Copyright 2013 - present © cnpmjs.org | Home |