Skip to content

Commit

Permalink
implement _serializeKey and _serializeValue
Browse files Browse the repository at this point in the history
With undefined behavior for nullish targets (range options and
seek targets). Previously, nullish range options were ignored and
seek(null) and seek(undefined) would throw an error. Now they
translate to String(null) and String(undefined).

This change makes it explicit that leveldown only supports buffers
and strings. Nullish targets do have a meaning in the ecosystem;
that meaning should be given at a higher level like encoding-down.

In other words, it isn't leveldown's concern anymore.
  • Loading branch information
vweevers committed Sep 23, 2018
1 parent 82cdd77 commit 1e363aa
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions leveldown.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ LevelDOWN.prototype._close = function (callback) {
this.binding.close(callback)
}

LevelDOWN.prototype._serializeKey = function (key) {
return Buffer.isBuffer(key) ? key : String(key)
}

LevelDOWN.prototype._serializeValue = function (value) {
return Buffer.isBuffer(value) ? value : String(value)
}

LevelDOWN.prototype._put = function (key, value, options, callback) {
this.binding.put(key, value, options, callback)
}
Expand Down
2 changes: 1 addition & 1 deletion test/iterator-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const lexi = require('lexicographic-integer')
const util = require('util')

make('iterator#seek throws if target is empty', function (db, t, done) {
var targets = [null, undefined, '', Buffer.alloc(0), []]
var targets = ['', Buffer.alloc(0), []]
var pending = targets.length

targets.forEach(function (target) {
Expand Down

0 comments on commit 1e363aa

Please sign in to comment.