through-stream

0.0.2 • Public • Published

through-stream

Base stream class for through RW stream

Example

// The buffer is shared among the stream and is an array
var through = require("through-stream")
    , stream = through(function write(chunk, buffer) {
        buffer.push(chunk)
        // Handle writing the chunk
    }, function read(bytes, buffer) {
        // Handle reading the bytes
        return buffer.shift()
    }, function end() {
        // Stream has ended
    })

// Do stuff with stream

The write / read / end functions are optional and default to

function write(data, buffer) {
    buffer.push(data)
}

function read(bytes, buffer) {
    return buffer.shift()
}

function end() {
    this.emit('end')
}

If you would like to overwrite just the end logic then do

through(through.write, through.read, function customEnd() {
    ...
})

Installation

npm install through-stream

Contributors

  • Raynos

MIT Licenced

Readme

Keywords

none

Package Sidebar

Install

npm i through-stream

Weekly Downloads

1

Version

0.0.2

License

none

Last publish

Collaborators

  • raynos