Skip to content
This repository was archived by the owner on Mar 23, 2023. It is now read-only.

Commit a5d7378

Browse files
jacobheundaviddias
authored andcommitted
fix: update binary encoding for levelup 2
License: MIT Signed-off-by: Jacob Heun <[email protected]>
1 parent 670ede4 commit a5d7378

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"homepage": "https://github.com/ipfs/js-datastore-level#readme",
4242
"dependencies": {
4343
"datastore-core": "~0.4.0",
44+
"encoding-down": "^5.0.2",
4445
"interface-datastore": "~0.4.1",
4546
"level-js": "github:timkuijsten/level.js#idbunwrapper",
4647
"leveldown": "^3.0.2",

src/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const levelup = require('levelup')
99
const asyncFilter = require('interface-datastore').utils.asyncFilter
1010
const asyncSort = require('interface-datastore').utils.asyncSort
1111
const Key = require('interface-datastore').Key
12+
const encode = require('encoding-down')
1213

1314
/**
1415
* A datastore backed by leveldb.
@@ -35,10 +36,9 @@ class LevelDatastore {
3536
}
3637

3738
this.db = levelup(
38-
database(path),
39+
encode(database(path), { valueEncoding: 'binary' }),
3940
Object.assign({}, opts, {
40-
compression: false, // same default as go
41-
valueEncoding: 'binary'
41+
compression: false // same default as go
4242
}),
4343
(err) => {
4444
// Prevent an uncaught exception error on duplicate locks

test/index.spec.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,14 @@ describe('LevelDatastore', () => {
1818

1919
levelStore.open((err) => {
2020
expect(err).to.not.exist()
21-
expect(levelStore.db.db instanceof LevelDown).to.equal(true)
21+
expect(levelStore.db.db.db instanceof LevelDown).to.equal(true)
2222
expect(levelStore.db.options).to.include({
2323
createIfMissing: true,
2424
errorIfExists: false
2525
})
26+
expect(levelStore.db.db.codec.opts).to.include({
27+
valueEncoding: 'binary'
28+
})
2629
done()
2730
})
2831
})
@@ -36,7 +39,7 @@ describe('LevelDatastore', () => {
3639

3740
levelStore.open((err) => {
3841
expect(err).to.not.exist()
39-
expect(levelStore.db.db instanceof memdown).to.equal(true)
42+
expect(levelStore.db.db.db instanceof memdown).to.equal(true)
4043
expect(levelStore.db.options).to.include({
4144
createIfMissing: true,
4245
errorIfExists: true

0 commit comments

Comments
 (0)