Simple Stream
Useful stream sources, transforms and sinks for Simple Streams.
Documentation
Sources
Transforms
Sinks
Sources ### fromArray(array) -> stream Creates an stream from an array.
### fromReadableStream(readableStream) -> stream Creates an stream from a [Readable Stream](http://nodejs.org/api/stream.html#stream_class_stream_readable).var arrayStream = stream
var readStream = fsvar streamStream = stream
Transforms ### map(stream, mapFn) -> stream Create an stream that applies a map function to transform each value of the source stream.
### mapAsync(stream, mapFn) -> streamvar mapStream = stream// pipe the stream to an array:stream {console}
Create an stream that filters the values of the source stream using a filter function.var mapStream = stream
filter(stream, filterFn) -> stream
### filterAsync(stream, filterFn) -> streamvar evenNumbersStream = stream
### range(stream, range) -> stream Creates an stream that only streames over the specified range.var evenNumbersStream = stream
range
is specified as {from: startIndex, to: endIndex}
where from
and to
are both inclusive.
### buffer(stream, bufferSize) -> stream Creates an stream with an internal buffer that is always filled until `bufferSize`. The buffer can abviously only grow if the buffer stream is read slower than the underlying stream source can return data.var rangeStream = stream
The current buffer fill ratio can be inspected at any time using bufferFillRatio()
which returns a number between 0..1.
The buffer size can be changed using setBufferSize(bufferSize)
.
var bufferedStream = stream// inspect buffer sizeconsole// change the buffer size laterbufferedStream
Sinks ### toArray(stream) -> continuable Reads the source stream and writes the results to an array.
### toWritableStream(stream, writeStream, encoding) -> continuable Reads the source stream and writes the result to a [Writable Stream](http://nodejs.org/api/stream.html#stream_class_stream_writable).stream {console}
### forEach(stream, fn) -> continuable Reads the source stream and invokes `fn` for each value of the stream.var writeStream = fsstream {console}
### forEachAsync(stream, fn) -> continuable Reads the source stream and invokes `fn` for each value of the stream. Only once the callback is invoked the next value is read from the source stream.stream{console}
stream
Contributors
This project was created by Mirko Kiefer (@mirkokiefer).