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

Commit

Permalink
fix: remove node buffers (#39)
Browse files Browse the repository at this point in the history
This module didn't have a lot of buffer use in the first place,
but we remove any references to buffers in favour of Uint8Arrays.

When querying, values come back as Buffers which are Uint8Arrays so
the conversion was unnecessary.

BREAKING CHANGE: remove node buffers in favour of Uint8Arrays
  • Loading branch information
achingbrain committed Jul 29, 2020
1 parent 62e8aca commit 19fe886
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 8 deletions.
10 changes: 10 additions & 0 deletions .aegir.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'use strict'

module.exports = {
webpack: {
node: {
// this is needed until level stops using node buffers in browser code
Buffer: true
}
}
}
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@
},
"homepage": "https://github.com/ipfs/js-datastore-level#readme",
"dependencies": {
"datastore-core": "^1.1.0",
"interface-datastore": "^1.0.2",
"datastore-core": "^2.0.0",
"interface-datastore": "^2.0.0",
"level": "^5.0.1"
},
"devDependencies": {
"aegir": "^22.0.0",
"aegir": "^25.0.0",
"chai": "^4.2.0",
"cids": "^0.8.0",
"cids": "^0.8.3",
"dirty-chai": "^2.0.1",
"level-mem": "^5.0.1",
"rimraf": "^3.0.0"
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class LevelDatastore extends Adapter {
it = map(it, ({ key, value }) => {
const res = { key: new Key(key, false) }
if (values) {
res.value = Buffer.from(value)
res.value = value
}
return res
})
Expand Down
4 changes: 2 additions & 2 deletions test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ chai.use(require('dirty-chai'))
const expect = chai.expect
const levelmem = require('level-mem')
const level = require('level')
const os = require('os')
const LevelStore = require('../src')
const { utils } = require('interface-datastore')

describe('LevelDatastore', () => {
describe('initialization', () => {
Expand Down Expand Up @@ -43,7 +43,7 @@ describe('LevelDatastore', () => {
;[levelmem, level].forEach(database => {
describe(`interface-datastore ${database.name}`, () => {
require('interface-datastore/src/tests')({
setup: () => new LevelStore(`${os.tmpdir()}/datastore-level-test-${Math.random()}`, { db: database }),
setup: () => new LevelStore(utils.tmpdir(), { db: database }),
teardown () {}
})
})
Expand Down
2 changes: 1 addition & 1 deletion test/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ describe('LevelDatastore', () => {
const cids = []

for await (const e of store.query({})) {
cids.push(new CID(1, 'dag-cbor', e.key.toBuffer()))
cids.push(new CID(1, 'dag-cbor', e.key.uint8Array()))
}

expect(cids[0].version).to.be.eql(0)
Expand Down

0 comments on commit 19fe886

Please sign in to comment.