Skip to content
This repository has been archived by the owner on Dec 2, 2024. It is now read-only.

Commit

Permalink
add read-stream examples
Browse files Browse the repository at this point in the history
  • Loading branch information
mafintosh committed Apr 25, 2015
1 parent d8c3dbd commit b45e4a7
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
19 changes: 19 additions & 0 deletions example/bulk-insert.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
var level = require('../');
var db = level(__dirname + '/data', { encoding: 'json' });

db.on('leader', function () {
console.log('i am the leader now')
})

var tick = 0

function loop () {
db.put('hello-' + tick, {hello: 'world-' + tick}, function () {
console.log('inserted %d values', tick)
if (tick === 10000) process.exit()
tick++
loop()
})
}

loop()
19 changes: 19 additions & 0 deletions example/read-stream.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
var level = require('../');
var db = level(__dirname + '/data', { encoding: 'json' });

db.on('leader', function () {
console.log('i am the leader now')
})

var rs = db.createReadStream()
var tick = 0

rs.on('end', function () {
console.log('(end)')
process.exit()
})

setInterval(function () {
var next = rs.read()
if (next) console.log(next)
}, 250);

0 comments on commit b45e4a7

Please sign in to comment.