buffed
Acts as a stream to send a buffer, gather a buffer, or both.
Install
npm install --save buffed
Usage
Show:
- using it as a source (a Readable with buffer content)
- using it as a sink (a Writable collecting buffer chunks)
- as both a source and a sink at once
- getting its class
- resetting an instance with a new buffer (to use as a source)
- resetting an instance with
pipe(buffer)
(to use as a source)
// reused in examples below.var buffer = // NOTE: everywhere you see `buffer` as an arg to// methods, including the constructor,// you could provide an array of buffers instead. // Piping out: Buffed as a source // 1a. create instance with buffer to pipe outvar buffed = buffer // 1b. pipe buffer to another streambuffed // 2a. get buffed function to use to create instancesvar Buffed = // 2b. create an instance with a buffer and pipe it to another stream // or:Buffed // Piping in: Buffed as a sink // 3a. get buffed function to create an instancevar Buffed = // 3b. create a source buffedvar sink = // combine 3a and 3b:var sink = // 3c. use event to get full buffer from sinksink // 3d. pipe stream to buffedanotherStream // Both source and sink // 4a. get instance from function (like 1a)var buffed = buffer // 4b. use event to get full buffer from itbuffed // 4c. pipe to another stream and then back to itselfbuffed // Separate instances for source and sink // 5a. get function to create instancesvar buffed = // 5b. create a sourcevar source = // 5c. create a sinkvar sink = // 5d. use event to get full buffer from sinksink // 5e. pipe source thru another stream to sinksource // the Buffed class is also exported as a subproperty // 6a. get classvar Buffed = Buffed // 6b. create an instance as a source (has a buffer) (can be a sink, too)var source = buffer // 6c. create an instance as a sink (no buffer)var sink = // Reset buffed instance with new buffer // 7a. create a buffed instancevar buffed = buffer // 7b. use event to continue when it's done:buffed // 7c. use buffedbuffed // ES6 version: const source = bufferconst sink = source sink