[Pkg-javascript-commits] [node-leveldown] 44/492: fix ReadStream bug -- encoding options not passed
Andrew Kelley
andrewrk-guest at moszumanska.debian.org
Sun Jul 6 17:13:43 UTC 2014
This is an automated email from the git hooks/post-receive script.
andrewrk-guest pushed a commit to annotated tag rocksdb-0.10.1
in repository node-leveldown.
commit b9f98ad7291329406ea2f9006dcee69c6a1a842a
Author: Rod Vagg <rod at vagg.org>
Date: Wed Sep 12 21:41:48 2012 +1000
fix ReadStream bug -- encoding options not passed
---
lib/levelup.js | 3 +--
test/read-stream-test.js | 36 +++++++++++++++++++++++++++++++++---
test/write-stream-test.js | 32 ++++++++++++++++++++++++++++++--
3 files changed, 64 insertions(+), 7 deletions(-)
diff --git a/lib/levelup.js b/lib/levelup.js
index ff067ad..d053a97 100644
--- a/lib/levelup.js
+++ b/lib/levelup.js
@@ -206,8 +206,7 @@ LevelUP.prototype = {
}
, readStream: function (options) {
- if (typeof options != 'object')
- options = {}
+ options = extend({}, extend(this._options, typeof options == 'object' ? options : {}))
return readStream.create(
options
, this
diff --git a/test/read-stream-test.js b/test/read-stream-test.js
index 7de2d69..af7fe1a 100644
--- a/test/read-stream-test.js
+++ b/test/read-stream-test.js
@@ -22,13 +22,14 @@ buster.testCase('ReadStream', {
})
}
- this.verify = function (rs, done) {
+ this.verify = function (rs, done, data) {
+ if (!data) data = this.sourceData // can pass alternative data array for verification
assert.isFalse(rs.writable)
assert.isFalse(rs.readable)
assert.equals(this.readySpy.callCount, 1, 'ReadStream emitted single "ready" event')
assert.equals(this.endSpy.callCount, 1, 'ReadStream emitted single "end" event')
- assert.equals(this.dataSpy.callCount, this.sourceData.length, 'ReadStream emitted correct number of "data" events')
- this.sourceData.forEach(function (d, i) {
+ assert.equals(this.dataSpy.callCount, data.length, 'ReadStream emitted correct number of "data" events')
+ data.forEach(function (d, i) {
var call = this.dataSpy.getCall(i)
if (call) {
//console.log('call', i, ':', call.args[0].key, '=', call.args[0].value, '(expected', d.key, '=', d.value, ')')
@@ -404,4 +405,33 @@ buster.testCase('ReadStream', {
}.bind(this))
}.bind(this))
}
+
+ , 'test json encoding': function (done) {
+ var options = { createIfMissing: true, errorIfExists: true, keyEncoding: 'utf8', valueEncoding: 'json' }
+ , data = [
+ { type: 'put', key: 'aa', value: { a: 'complex', obj: 100 } }
+ , { type: 'put', key: 'ab', value: { b: 'foo', bar: [ 1, 2, 3 ] } }
+ , { type: 'put', key: 'ac', value: { c: 'w00t', d: { e: [ 0, 10, 20, 30 ], f: 1, g: 'wow' } } }
+ , { type: 'put', key: 'ba', value: { a: 'complex', obj: 100 } }
+ , { type: 'put', key: 'bb', value: { b: 'foo', bar: [ 1, 2, 3 ] } }
+ , { type: 'put', key: 'bc', value: { c: 'w00t', d: { e: [ 0, 10, 20, 30 ], f: 1, g: 'wow' } } }
+ , { type: 'put', key: 'ca', value: { a: 'complex', obj: 100 } }
+ , { type: 'put', key: 'cb', value: { b: 'foo', bar: [ 1, 2, 3 ] } }
+ , { type: 'put', key: 'cc', value: { c: 'w00t', d: { e: [ 0, 10, 20, 30 ], f: 1, g: 'wow' } } }
+ ]
+
+ this.openTestDatabase(options, function (db) {
+ db.batch(data.slice(), function (err) {
+ refute(err)
+
+ var rs = db.readStream()
+ assert.isFalse(rs.writable)
+ assert.isTrue(rs.readable)
+ rs.on('ready', this.readySpy)
+ rs.on('data' , this.dataSpy)
+ rs.on('end' , this.endSpy)
+ rs.on('close', this.verify.bind(this, rs, done, data))
+ }.bind(this))
+ }.bind(this))
+ }
})
\ No newline at end of file
diff --git a/test/write-stream-test.js b/test/write-stream-test.js
index b51efa8..4fffb6a 100644
--- a/test/write-stream-test.js
+++ b/test/write-stream-test.js
@@ -21,11 +21,12 @@ buster.testCase('WriteStream', {
})
}
- this.verify = function (ws, db, done) {
+ this.verify = function (ws, db, done, data) {
+ if (!data) data = this.sourceData // can pass alternative data array for verification
assert.isFalse(ws.writable)
assert.isFalse(ws.readable)
async.forEach(
- this.sourceData
+ data
, function (data, callback) {
db.get(data.key, function (err, value) {
refute(err)
@@ -135,4 +136,31 @@ buster.testCase('WriteStream', {
ws.once('ready', ws.destroy)
}.bind(this))
}
+
+ , '=>test json encoding': function (done) {
+ var options = { createIfMissing: true, errorIfExists: true, keyEncoding: 'utf8', valueEncoding: 'json' }
+ , data = [
+ { type: 'put', key: 'aa', value: { a: 'complex', obj: 100 } }
+ , { type: 'put', key: 'ab', value: { b: 'foo', bar: [ 1, 2, 3 ] } }
+ , { type: 'put', key: 'ac', value: { c: 'w00t', d: { e: [ 0, 10, 20, 30 ], f: 1, g: 'wow' } } }
+ , { type: 'put', key: 'ba', value: { a: 'complex', obj: 100 } }
+ , { type: 'put', key: 'bb', value: { b: 'foo', bar: [ 1, 2, 3 ] } }
+ , { type: 'put', key: 'bc', value: { c: 'w00t', d: { e: [ 0, 10, 20, 30 ], f: 1, g: 'wow' } } }
+ , { type: 'put', key: 'ca', value: { a: 'complex', obj: 100 } }
+ , { type: 'put', key: 'cb', value: { b: 'foo', bar: [ 1, 2, 3 ] } }
+ , { type: 'put', key: 'cc', value: { c: 'w00t', d: { e: [ 0, 10, 20, 30 ], f: 1, g: 'wow' } } }
+ ]
+
+ this.openTestDatabase(options, function (db) {
+ var ws = db.writeStream()
+ ws.on('error', function (err) {
+ refute(err)
+ })
+ ws.on('close', this.verify.bind(this, ws, db, done, data))
+ data.forEach(function (d) {
+ ws.write(d)
+ })
+ ws.once('ready', ws.end) // end after it's ready, nextTick makes this work OK
+ }.bind(this))
+ }
})
\ No newline at end of file
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-leveldown.git
More information about the Pkg-javascript-commits
mailing list