simple-stream

utility functions for simple streams

#Simple Stream

Useful stream sources, transforms and sinks for Simple Streams.

##Documentation ###Sources

###Transforms

###Sinks

##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)

##Transforms

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

var mapStream = stream.map(someNumberStream, function(erreach) {
  return each * 2
})
 
// pipe the stream to an array: 
stream.toArray(mapStream, function(errres) {
  console.log(res)
})

var mapStream = stream.map(someNumberStream, function(erreachcb) {
  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(erreach) {
  return (each % 2) == 0
})

var evenNumbersStream = stream.filter(someNumberStream, function(erreachcb) {
  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 
console.log(bufferedStream.bufferFillRatio())
 
// change the buffer size later 
bufferedStream.setBufferSize(100)

##Sinks

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

stream.toArray(someStream)(function(errarray) {
  console.log(array)
})

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

var writeStream = fs.createWriteStream('output.txt')
stream.toWritableStream(stream, writeStream, 'utf8')(function() {
  console.log('done')
})

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

stream.forEach(someStream, function(errdata) {
  console.log(data)
})(function() {
  console.log('end')
})

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(errdatacb) {
  console.log(data)
  setTimeout(cb, 100)
}(function() {
  console.log('end')
})

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