node-stream-lib
A library with stream utilities for node.js
How to install
npm install -s stream-lib
How to use
In general
var streamLib = ; // your streamlib module like:// new streamLib.Random.Alphanumeric();
Please take also a look into the JSDoc
Buffer
Buffers a stream in memory with a duplex stream. You are able to save the content in memory if the destination works slower then the source. You are able to close the destination earlier.
You can also use it in object mode, when you set the first paramerter to true;
var streamLib = ; // You need some source and destination streamsvar fs = ; var sourceStream = fs;var destinationStream = fs; // You need the buffer streamvar objectMode = false; // This is optionalvar bufferStream = objectMode: objectMode; sourceStream ;
Concat
Concat multiple streams in given order.
var streamLib = ; // You need some source and destination streamsvar fs = ; var firstStream = fs;var secondStream = fs;var thirdStream = fs;var destinationStream = fs; // You need the concat streamvar concatStream = ; firstStream ;secondStream ;thirdStream ; concatStream;
Delay
Delay the flow of a stream.
There are a lot of other pipes. Please take a look in API-doc
var streamLib = ; // You need some source and destination streamsvar fs = ; var sourceStream = fs;var destinationStream = fs; // You need the buffer streamvar delay = 500; // Delay in milli-seconds (Zero makes it just asynchronous)var objectMode = false; // This is optionalvar delayStream = objectMode: objectMode; sourceStream ;
Event
An event stream works like a normal event emitter but works with streams.
You are also able to augment an existing event emitter with the eventStream.
var streamLib = ; // Create an event stream var eventStream = ; // For sending and getting EventseventStream; eventStream; var EventEmitter = EventEmitter; // anotherEventStream var anotherEventStream = ; anotherEventStream; eventStr;
Unit
Create a unit of different pipes.
var streamLib = ; // Create an unit var unit = ; // Create streams for the unit var hexDecoder = ;var toUpperCaseStream = ; // Combine to an unit HexEncoder ; unit;unit; // Now the unit create an upper case hex string
Sequence
Streams a never ending recorded sequence.
var streamLib = ; // Create an sequence var sequence = ; sequence;sequence;sequence;sequence;sequence;sequence; sequence; // Outputs 1 2 4 8 16 1 2 4 8 16 1 2 4 8 16 1 2 4 8 16 1 2 4 8 16 1 2 4 8 16 1 2 4 8 16 1 2 4 8 16 ...
Measure
Makes measures on a stream
var streamLib = ; // Create a measure var measure = ; // Create some asynchronous pipes var firstPipe = ;var secondPipe = ;var thirdPipe = ; measuremeasureInlet ; measuremeasureInlet;measuremeasureInlet;measuremeasureInlet;measuremeasureInlet;measuremeasureInlet;measuremeasureInlet; measure;