streamize
stream helper for NodeJs
Installation
This is a Node.js module available through the npm registry.
Before installing, download and install Node.js. Node.js 6 or higher is required.
Installation is done using the
npm install
command:
$ npm install streamize
Documentation
Readable
Description: create a readable stream
streamize.Readable(read, [options])
- read is a function that take a callback function as argument.
- options is an optional object argument passed to the node stream: see node readable stream documentation
return a readable stream
sample
var streamize = ;var myArray = '1' '2' '3' '4' '5';// create a readable stream from myArrayvar readable = streamize;
the read function passed in argument is called each time a new chunk is required. the callback takes 2 arguments:
- error
When error is defined and not null, the stream returned emit the error and chunk is ignored.
- chunk
When chunk is a Buffer, Uint8Array or string, the chunk of data will be added to the internal queue for users of the stream to consume. Passing chunk as null signals the end of the stream (EOF), after which no more data can be written.
As read function is called in the stream context, every internal function could be called from this
.
var readable = streamize;
Writable
Description: create a writable stream
streamize.Writable(write, [options])
- write is a function that take the chunk to be written and a callback function as arguments.
- options is an optional object argument passed to the node stream: see node writable stream documentation
sample
var streamize = ;var newArray = ;// create a writable stream that push chunk in newArrayvar writable = streamize;
the write function is called each time a chunk should be written. chunk | | The chunk to be written. Will always be a buffer unless the decodeStrings option was set to false or the stream is operating in object mode. callback Call this function (optionally with an error argument) when processing is complete for the supplied chunk.
Duplex
Description: create a duplex stream
streamize.Duplex(read, write, [options])
- read is a function that take a callback function as argument.see Readable read function
- write is a function that take the chunk to be written and a callback function as arguments.see Writable write function
- options is an optional object argument passed to the node stream: see node duplex stream documentation
sample
var streamize = ;var myArray = '1' '2' '3' '4' '5';var newArray = ;// create a duplex stream that read myArray and write in newArrayvar duplex = streamize;
Transform
Description: create a transform stream
streamize.Transform(transform, [options])
- transform is a function that take the chunk to be transform and a callback function as arguments.
- options is an optional object argument passed to the node stream: see node transform stream documentation
sample
var streamize = ;// create a transform stream that duplicate all chunksvar transform = streamize;
the transform function is called each time a chunk should be transform. chunk | | The chunk to be written. Will always be a buffer unless the decodeStrings option was set to false or the stream is operating in object mode. callback A callback function (optionally with an error argument and data) to be called after the supplied chunk has been processed.
As transform function is called in the stream context, every internal function could be called from this
.
Object mode
streamize.obj.Readable(read, [options])
streamize.obj.Writable(write, [options])
streamize.obj.Duplex(read, write, [options])
streamize.obj.Transform(transform, [options])
do the same but return a stream in object mode.