Skip to content

Commit f955829

Browse files
committed
fix: reduce size
1 parent a929ddf commit f955829

File tree

4 files changed

+7
-15
lines changed

4 files changed

+7
-15
lines changed

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555
"sinon": "^9.0.1"
5656
},
5757
"dependencies": {
58-
"base32.js": "~0.1.0",
5958
"bignumber.js": "^9.0.0",
6059
"buffer": "^5.5.0",
6160
"bytes": "^3.1.0",
@@ -72,7 +71,7 @@
7271
"ipld-block": "^0.9.1",
7372
"just-safe-get": "^2.0.0",
7473
"just-safe-set": "^2.1.0",
75-
"lodash.has": "^4.5.2",
74+
"multibase": "^0.7.0",
7675
"p-queue": "^6.0.0",
7776
"proper-lockfile": "^4.0.0",
7877
"sort-keys": "^4.0.0"

src/blockstore-utils.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
'use strict'
22

3-
const { Buffer } = require('buffer')
4-
const base32 = require('base32.js')
53
const { Key } = require('interface-datastore')
64
const CID = require('cids')
5+
const multibase = require('multibase')
76

87
/**
98
* Transform a cid to the appropriate datastore key.
@@ -12,8 +11,7 @@ const CID = require('cids')
1211
* @returns {Key}
1312
*/
1413
exports.cidToKey = cid => {
15-
const enc = new base32.Encoder()
16-
return new Key('/' + enc.write(cid.buffer).finalize(), false)
14+
return new Key('/' + multibase.encode('base32', cid.buffer).toString().slice(1), false)
1715
}
1816

1917
/**
@@ -23,8 +21,5 @@ exports.cidToKey = cid => {
2321
* @returns {CID}
2422
*/
2523
exports.keyToCid = key => {
26-
// Block key is of the form /<base32 encoded string>
27-
const decoder = new base32.Decoder()
28-
const buff = decoder.write(key.toString().slice(1)).finalize()
29-
return new CID(Buffer.from(buff))
24+
return new CID(multibase.decode('b' + key.toString().slice(1)))
3025
}

src/config.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ const Key = require('interface-datastore').Key
55
const { default: Queue } = require('p-queue')
66
const _get = require('just-safe-get')
77
const _set = require('just-safe-set')
8-
const _has = require('lodash.has')
98
const errcode = require('err-code')
109
const errors = require('./errors')
1110

@@ -28,7 +27,7 @@ module.exports = (store) => {
2827

2928
const encodedValue = await store.get(configKey)
3029
const config = JSON.parse(encodedValue.toString())
31-
if (key !== undefined && !_has(config, key)) {
30+
if (key !== undefined && _get(config, key) === undefined) {
3231
throw new errors.NotFoundError(`Key ${key} does not exist in config`)
3332
}
3433

test/blockstore-test.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const _ = require('lodash')
1313
const multihashing = require('multihashing-async')
1414
const Key = require('interface-datastore').Key
1515
const tempDir = require('ipfs-utils/src/temp-dir')
16-
const base32 = require('base32.js')
16+
const multibase = require('multibase')
1717
const IPFSRepo = require('../')
1818

1919
module.exports = (repo) => {
@@ -214,8 +214,7 @@ module.exports = (repo) => {
214214
const data = Buffer.from(`TEST${Date.now()}`)
215215
const hash = await multihashing(data, 'sha2-256')
216216
const cid = new CID(hash)
217-
const enc = new base32.Encoder()
218-
const key = new Key('/' + enc.write(cid.buffer).finalize(), false)
217+
const key = new Key('/' + multibase.encode('base32', cid.buffer).toString().slice(1), false)
219218

220219
otherRepo = new IPFSRepo(tempDir(), {
221220
storageBackends: {

0 commit comments

Comments
 (0)