node package manager

Introducing npm Enterprise add-ons. Integrate third-party dev tools into npm…


read randomly from leveldb

level-random - read randomly

The level-random Node.js module implements a Transform stream to read values for random keys in an LevelUP instance.

var levelup = require('levelup')
var lr = require('level-random')
levelup('/tmp/level-random.db', function (er, db) {
    { type: 'put', key: 'a', value: 'hey\n' }
  , { type: 'put', key: 'b', value: 'you\n' }
  ], function (er) {
    var values = lr({ db: db })

Object passed to Transform stream constructor.

  • db The mandatory LevelUP instance
  • errorIfNotFound Emit error if key is not found Boolean=false
  • fillCache Fill LevelDB's LRU-cache Boolean=false

level-random exports a sole function that returns a Transform stream which transforms keys to values.

var lr = require('level-random')

At large, of course, we leverage the lexicographical sort order of LevelDB keys (to stream ranges), occasionally though we encounter the oddball use case which requires to read randomly from the store. To read a bunch of unsorted values for random keys this module might be useful.

With npm do:

$ npm install level-random

MIT License