utility functions for simple streams

#Simple Stream

Useful stream sources, transforms and sinks for Simple Streams.

##Documentation ###Sources




Creates an stream from an array.

var arrayStream = stream.fromArray(numbers)

Creates an stream from a Readable Stream.

var readStream = fs.createReadStream('input.txt', {encoding: 'utf8'})
var streamStream = stream.fromReadableStream(readStream)


Create an stream that applies a map function to transform each value of the source stream.

var mapStream =, function(each) {
  return each * 2
// pipe the stream to an array: 
stream.toArray(mapStream)(function(errres) {

var mapStream =, function(eachcb) {
  cb(null, each * 2)

Create an stream that filters the values of the source stream using a filter function.

var evenNumbersStream = stream.filter(someNumberStream, function(each) {
  return (each % 2) == 0

var evenNumbersStream = stream.filter(someNumberStream, function(eachcb) {
  cb(null, (each % 2) == 0)

Creates an stream that only streames over the specified range.

range is specified as {from: startIndex, to: endIndex} where from and to are both inclusive.

var rangeStream = stream.range(stream, {from: 10, to: 19})

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.

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.buffer(someStream, 10)
// inspect buffer size 
// change the buffer size later 


Reads the source stream and writes the results to an array.

stream.toArray(someStream)(function(errarray) {

Reads the source stream and writes the result to a Writable Stream.

var writeStream = fs.createWriteStream('output.txt')
stream.toWritableStream(stream, writeStream, 'utf8')(function(err) {

Reads the source stream and invokes fn for each value of the stream.

stream.forEach(someStream, function(data) {
})(function(err) {

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.forEachAsync(someStream, function(datacb) {
  setTimeout(cb, 100)
}(function(err) {

##Contributors This project was created by Mirko Kiefer (@mirkokiefer).