🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

datawriter

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

datawriter

cache and write

1.0.1
latest
Source
npm
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

DataWriter

If you need to write something in very high frequency and you want to reduce system load or network connections, this is the best utility for you.

Install

npm i --save datawriter

API

new DataWriter(maxBufferSize, maxCacheAge, batchWriteFunction, errorHandler);
  • maxBufferSize is the max data rows cached in DataWriter. If the cached data rows grows bigger than this value, an batch write call will be triggered.

  • maxCacheAge a max cache time in milliseconds. Once a write() command is called, a batch write call will be triggered after this time delay.

  • batchWriteFunction the function you provide to do a batch writing operation.

  • errorHandler the global error handler.

dataWriteInstance.write(...args);

The write command call. args will be treated as a data row. So you can pass any parameters. Please notice the write command will not trigger any error. The error occured in the batchWriteFunction, will be caught by the errorHandler function.

Example

const DataWriter = require('datawriter');
const fs = require('fs');

let writer = new DataWriter(10, 1000, async arr => {
	console.log('batch write', arr.length, 'rows');
	fs.appendFileSync('a.log', arr.map(params => JSON.stringify(params)).join('\n') + '\n');
}, function(err) {
	console.log('onError', err);
});


writer.write(1);
writer.write('a');
writer.write(1, 2, 3);
writer.write({a: 'A'}, 'nice', [1, 2, 4]);

/*
a.log content will be:

[1]
["a"]
[1,2,3]
[{"a":"A"},"nice",[1,2,4]]

*/

Keywords

write

FAQs

Package last updated on 08 Sep 2018

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