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

Commit

Permalink
refactor out the pull-stream version of read-stream,
Browse files Browse the repository at this point in the history
  • Loading branch information
dominictarr committed Jun 22, 2014
1 parent ad38ad3 commit b25d0cc
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 20 deletions.
25 changes: 25 additions & 0 deletions pull.js
@@ -0,0 +1,25 @@


var pull = require('pull-stream')
// Currently this uses pull streams,
// and not levelup's readstream, but in theory
// I should be able pretty much just drop that in.

module.exports = function pullReadStream (options, makeData) {
var stream = pull.defer()

stream.setIterator = function (iterator) {
stream.resolve(function (end, cb) {
if(!end) iterator.next(function (err, key, value) {
if(err) return cb(err)
if(key === undefined || value === undefined)
return cb(true)
cb(null, makeData(key, value))
})
else
iterator.end(cb)
})
}

return stream
}
22 changes: 2 additions & 20 deletions test/level.js
Expand Up @@ -9,30 +9,12 @@ var shell = require('../shell') //the shell surrounds the nut
var codec = require('levelup/lib/codec')
var bytewise = require('bytewise')
var concat = require('../codec')
var pullReadStream = require('../pull')

function create (precodec, db) {

//convert pull stream to iterators
function pullIterator (iterator) {
var stream = pull.defer()

stream.setIterator = function (iterator) {
stream.resolve(function (end, cb) {
if(!end) iterator.next(function (err, key, value) {
if(err) return cb(err)
if(key === undefined || value === undefined)
return cb(true)
cb(null, {key: key, value: value})
})
else
iterator.end(cb)
})
}

return stream
}

return shell ( nut ( db || mock(), precodec, codec ), [], pullIterator )
return shell ( nut ( db || mock(), precodec, codec ), [], pullReadStream)
}

function prehookPut (db) {
Expand Down

0 comments on commit b25d0cc

Please sign in to comment.