Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

buffered-sink

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

buffered-sink

A general purpose buffer class that can buffer custom objects need to be sent to a sink.

  • 0.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

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 = require('buffered-sink');

var jsonFileSink = new BufferedSink( {
    maxSize: 5,
    writeItems: function(items, cb){
        var existing;
        try {
            existing = JSON.parse( fs.readFileSync( outFile, 'utf-8' ) );
        } catch(e){
            existing = [];
        }
        var total = existing.concat( items );
        fs.writeFile( outFile, JSON.stringify(total, null, ' '), 'utf-8', cb );
    }
});

jsonFileSink.$write({ title: 'first'}, cb ); // No real write. data is stored in memmoy
jsonFileSink.$write({ title: 'second'}, cb ); // No real write. data is stored in memmoy
jsonFileSink.$write({ title: 'third'}, cb ); // No real write. data is stored in memmoy
jsonFileSink.$write({ title: 'fourth'}, cb ); // No real write. data is stored in memmoy
jsonFileSink.$write({ title: 'fifth'}, cb ); // 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.

FAQs

Package last updated on 06 Dec 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc