Buffered-Sink
A general purpose Nodejs class that can be used to write data to any data sinks, with buffering. It's working is similar to underscore.js 's after() funnction. But it take care of some other situations too.
Usage
var BufferedSink = ; var jsonFileSink = maxSize: 5 { var existing; try existing = JSON; catche existing = ; var total = existing; fs; }; jsonFileSink; // No real write. data is stored in memmoyjsonFileSink; // No real write. data is stored in memmoyjsonFileSink; // No real write. data is stored in memmoyjsonFileSink; // No real write. data is stored in memmoyjsonFileSink; // real write occurs. calls writeItems funnction provided in constructor internally.
Documentation
Class BufferedSink
Constructor : new BufferedSink( opts );
opts.maxSize
: {Integer} maximum size of internal buffer.opts.writeItems
: {funnction( items, callback )} A function that does real writing.
Methods
$writeItems( items, cb )
Writes an array of items.
$write( items, cb )
Writes a single item.
flush( cb )
Do real writing and empty the buffer.
Internal variable that holds state
cache: Array
Used to store items. Used as a buffer store.
tempCache: Array
Used to store items at the moment when real writing is taking place. To be precise, if this.isWriting == true.
isWriting: Boolean
A flag that used to indicate whether real writing is taking place or not.