Home

Awesome

cursor

level stream cursor

NPM version Build Status Dependency Status Coverage Status

install

npm install [--save/--save-dev] level-cursor

api

var cursor = require('level-cursor');

each

readStream

var stream = db.readStream()

stream.on('error', function (e) {
  throw e
})

stream.pipe(cursor.each(function (key, value, data) {
  assert.notEqual(value, undefined)
  assert.notEqual(key, undefined)
  assert.notEqual(value, null)
  assert.notEqual(key, null)
  
  assert.equal(value, data[key])  
}, function () {
  // end
}))
var stream = db.readStream()

cursor(stream).each(function (key, value, data) {
  assert.notEqual(value, undefined)
  assert.notEqual(key, undefined)
  assert.notEqual(value, null)
  assert.notEqual(key, null)
  
  assert.equal(value, data[key]) 
}, function (e) {
  assert.equal(e, null || undefined)
  // end
})

valueStream

var stream = db.valueStream()

stream.on('error', function (e) {
  throw e
})

stream.pipe(cursor.each(function (value) {
  assert.notEqual(value, undefined)
  assert.notEqual(value, null)
}, function () {
  // end
}))
var stream = db.valueStream()

cursor(stream).each(function (value) {
  assert.notEqual(value, undefined)
  assert.notEqual(value, null)
}, function (e) {
  assert.equal(e, null || undefined)
  // end
})

keyStream

var stream = db.keyStream()

stream.on('error', function (e) {
  throw e
})

stream.pipe(cursor.each(function (key) {
  assert.notEqual(key, undefined)
  assert.notEqual(key, null)
}, function () {
  // end
}))
var stream = db.keyStream()

cursor(stream).each(function (key) {
  assert.notEqual(key, undefined)
  assert.notEqual(key, null)
}, function (e) {
  assert.equal(e, null || undefined)
  // end
})

all

readStream

var stream = db.readStream()

stream.on('error', function (e) {
  throw e
})

stream.pipe(cursor.all(function (keys, values, data) {
  assert.notEqual(values, undefined)
  assert.notEqual(keys, undefined)
  assert.notEqual(values, null)
  assert.notEqual(keys, null)
  
  assert.equal(Object.keys(data).length, keys.length)
}))
var stream = db.readStream()

cursor(stream).all(function (e, keys, values, data) {
  assert.equal(e, null || undefined)

  assert.notEqual(values, undefined)
  assert.notEqual(keys, undefined)
  assert.notEqual(values, null)
  assert.notEqual(keys, null)
  
  assert.equal(Object.keys(data).length, keys.length)
})

valueStream

var stream = db.valueStream()

stream.on('error', function (e) {
  throw e
})

stream.pipe(cursor.all(function (values) {
  assert.notEqual(values, undefined)
  assert.notEqual(values, null)
}))
var stream = db.valueStream()

cursor(stream).all(function (e, values) {
  assert.equal(e, null || undefined)

  assert.notEqual(values, undefined)
  assert.notEqual(values, null)
})

keyStream

var stream = db.keyStream()

stream.on('error', function (e) {
  throw e
})

stream.pipe(cursor.all(function (keys) {
  assert.notEqual(keys, undefined)
  assert.notEqual(keys, null)
}))
var stream = db.keyStream()

cursor(stream).all(function (e, keys) {
  assert.equal(e, null || undefined)

  assert.notEqual(keys, undefined)
  assert.notEqual(keys, null)
})

piping

db.readStream().pipe(cursor.each()).pipe(otherdb.writeStream())
cursor(db.readStream()).each().pipe(otherdb.writeStream())
db.readStream().pipe(cursor.all()).pipe(otherdb.writeStream())
cursor(db.readStream()).all().pipe(otherdb.writeStream())

license

MIT