Skip to content

Commit

Permalink
Fix encoding options (#37)
Browse files Browse the repository at this point in the history
* add failing test for keyEncoding and valueEncoding

* fix failing test for keyEncoding/valueEncoding options

* add sanity test for encoding defaults

* OPTS not needed

* const -> var (should not mix these)
  • Loading branch information
ralphtheninja authored Oct 12, 2017
1 parent 9de3fd3 commit 5c619b8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion level-packager.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function packager (leveldown) {
if (typeof options !== 'object' || options === null)
options = {}

return levelup(encode(leveldown(location)), options, callback)
return levelup(encode(leveldown(location), options), options, callback)
}

[ 'destroy', 'repair' ].forEach(function (m) {
Expand Down
20 changes: 20 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,26 @@ module.exports = function (test, level, options) {
})
})

test('options.keyEncoding and options.valueEncoding are passed on to encoding-down', function (t) {
var db = level(location, { keyEncoding: 'json', valueEncoding: 'json' })
db.on('ready', function () {
var codec = db.db.codec
t.equal(codec.opts.keyEncoding, 'json', 'keyEncoding correct')
t.equal(codec.opts.valueEncoding, 'json', 'valueEncoding correct')
db.close(t.end.bind(t))
})
})

test('encoding options default to utf8', function (t) {
var db = level(location)
db.on('ready', function () {
var codec = db.db.codec
t.equal(codec.opts.keyEncoding, 'utf8', 'keyEncoding correct')
t.equal(codec.opts.valueEncoding, 'utf8', 'valueEncoding correct')
db.close(t.end.bind(t))
})
})

if (!options.skipRepairTest) {
test('test repair', function (t) {
t.plan(1)
Expand Down

0 comments on commit 5c619b8

Please sign in to comment.