@@ -4,12 +4,11 @@ const utils = require('./utils')
44
55function HyperdbReadTransform ( db , basename , options ) {
66 if ( ! ( this instanceof HyperdbReadTransform ) ) {
7- return new HyperdbReadTransform ( db , options )
7+ return new HyperdbReadTransform ( db , basename , options )
88 }
99 var opts = options || { }
1010 this . db = db
1111 this . _prefixes = { _ : basename }
12- this . _finished = false
1312 this . _count = 0
1413 this . _filter = opts . filter
1514 this . _offset = opts . offset || 0
@@ -25,13 +24,6 @@ function HyperdbReadTransform (db, basename, options) {
2524inherits ( HyperdbReadTransform , Transform )
2625
2726HyperdbReadTransform . prototype . _transform = function transform ( nodes , encoding , done ) {
28- if ( this . _finished ) return done ( )
29- if ( this . _limit && this . _count >= this . _limit ) {
30- this . push ( null )
31- this . _sources . forEach ( source => source . destroy ( ) )
32- this . _finished = true
33- return
34- }
3527 var value = nodes [ 0 ] . value && JSON . parse ( nodes [ 0 ] . value . toString ( ) )
3628 if ( value === null ) return done ( )
3729 value = Object . assign ( value , utils . decodeKey ( nodes [ 0 ] . key , this . _prefixes ) )
@@ -40,8 +32,16 @@ HyperdbReadTransform.prototype._transform = function transform (nodes, encoding,
4032 this . push ( value )
4133 }
4234 this . _count ++
35+ if ( this . _limit && this . _count >= this . _limit ) {
36+ this . end ( )
37+ }
4338 }
4439 done ( )
4540}
4641
42+ HyperdbReadTransform . prototype . _flush = function ( done ) {
43+ this . _sources . forEach ( source => source . destroy ( ) )
44+ done ( )
45+ }
46+
4747module . exports = HyperdbReadTransform
0 commit comments