stream-util2
Various stream utilities.
Installation
npm install stream-util2
API
transform(transform, [flush])
Returns a transform stream in object mode.
-
transform
implements_transform
. Arguments:chunk
,callback
. -
flush
implements_flush
.
readable(read)
Returns a readable stream in object mode.
-
read
implements_read
.
writable(write)
Returns a writable stream in object mode.
-
write
implements_write
. Arguments:chunk
,callback
.
buffer()
Returns a transform stream that buffers chunks of <Buffer>
type and emits concatenated buffer down the stream.
toString()
Returns a transform stream that calls chunk.toString()
for each chunk.
consoleLog()
Returns a transform stream that calls console.log(chunk)
for each chunk.
readArray(array)
Returns a readable stream that reads the array and emits each item down the stream.
pushArray(array)
Returns a transform stream that pushes each chunk to array
.
bufferArray()
Returns a transform stream that buffers chunks to an array and emits it down the stream.
writeVoid()
Returns a writable stream that does nothing.
readFunction(options, fn)
Returns a readable stream that generates data from periodic function fn
.
Options:
-
T
- function period in milliseconds. Default is1000
.
fn
arguments:
-
dt
- delta time since beginning of current period. -
T
- period.
writePromise([options])
Returns instance of PromiseWriteStream
, a writable stream that conforms to Promise
. It buffers data and resolves the promise right before emitting the finish
event.
Options:
PromiseWriteStream
PromiseWriteStream
is a writable stream that conforms to Promise
. Internal buffer and promise can be retrieved using writablePromise.buffer
and writablePromise.promise
, respectively.
License
ISC