Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
},
"browser": "browser.js",
"dependencies": {
"level-js": "^4.0.0",
"level-js": "^5.0.0",
"level-packager": "^5.0.0",
"leveldown": "^5.0.0",
"opencollective-postinstall": "^2.0.0"
Expand Down
37 changes: 27 additions & 10 deletions test-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ test('level put', function (t) {
})
})

test('level binary value', function (t) {
t.plan(9)
test('level Buffer value', function (t) {
t.plan(5)

var db = factory({ valueEncoding: 'binary' })
var buf = Buffer.from('00ff', 'hex')
Expand All @@ -49,15 +49,32 @@ test('level binary value', function (t) {
t.ok(Buffer.isBuffer(value), 'is a buffer')
t.same(value, buf)

db.get('binary', { valueEncoding: 'id' }, function (err, value) {
t.ifError(err, 'no get error')
t.notOk(Buffer.isBuffer(value), 'is not a buffer')
t.ok(value instanceof Uint8Array, 'is a Uint8Array')
t.same(Buffer.from(value), buf)
db.close(function (err) {
t.ifError(err, 'no close error')
})
})
})
})

test('level Buffer key', function (t) {
var db = factory({ keyEncoding: 'binary' })
var key = Buffer.from('00ff', 'hex')

db.close(function (err) {
t.ifError(err, 'no close error')
})
if (!db.supports.bufferKeys) {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's magic 😄

t.pass('Environment does not support buffer keys')
return t.end()
}

db.put(key, 'value', function (err) {
t.ifError(err, 'no put error')

db.get(key, function (err, value) {
t.ifError(err, 'no get error')
t.is(value, 'value')

db.close(function (err) {
t.ifError(err, 'no close error')
t.end()
})
})
})
Expand Down