You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

append-batch

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

append-batch

append stuff to a log. It's important that we can reason about the order, so do not perform parallel writes.

0.0.2
latest
Source
npm
Version published
Weekly downloads
13K
-26.49%
Maintainers
1
Weekly downloads
 
Created
Source

append-batch

append stuff to a log. It's important that we can reason about the order, so do not perform parallel writes.

To use this, pass in a function that processes a single batch.

Example

an batch append on top of leveldb, using timestamps as keys.

var Append = require('append-batch')
var timestamp = require('monotonic-timestamp')
var db = level(path...) //example with leveldb.

var append = Append(function (batch, cb) {
  var ops = []

  function add (value) {
    opts.push({key: Date.now(), value: value, type: 'put'}
  }
  batch.forEach(function (value) {
    if(Array.isArray(value) value.forEach(add)
    else add(value)
  })

  db.batch(opts, cb)
})

//append a single value
append({foo: 'bar'}, function (err) {
  //the value is definitely written by now
})

api

Append(writeBatch(values, cb)) => append(value, cb)

create an append function. writeBatch is a function that takes an array of values or arrays of values (which represents a batch operation)

License

MIT

FAQs

Package last updated on 14 Oct 2017

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