File tree Expand file tree Collapse file tree 4 files changed +7
-15
lines changed Expand file tree Collapse file tree 4 files changed +7
-15
lines changed Original file line number Diff line number Diff line change 55
55
"sinon" : " ^9.0.1"
56
56
},
57
57
"dependencies" : {
58
- "base32.js" : " ~0.1.0" ,
59
58
"bignumber.js" : " ^9.0.0" ,
60
59
"buffer" : " ^5.5.0" ,
61
60
"bytes" : " ^3.1.0" ,
72
71
"ipld-block" : " ^0.9.1" ,
73
72
"just-safe-get" : " ^2.0.0" ,
74
73
"just-safe-set" : " ^2.1.0" ,
75
- "lodash.has " : " ^4.5.2 " ,
74
+ "multibase " : " ^0.7.0 " ,
76
75
"p-queue" : " ^6.0.0" ,
77
76
"proper-lockfile" : " ^4.0.0" ,
78
77
"sort-keys" : " ^4.0.0"
Original file line number Diff line number Diff line change 1
1
'use strict'
2
2
3
- const { Buffer } = require ( 'buffer' )
4
- const base32 = require ( 'base32.js' )
5
3
const { Key } = require ( 'interface-datastore' )
6
4
const CID = require ( 'cids' )
5
+ const multibase = require ( 'multibase' )
7
6
8
7
/**
9
8
* Transform a cid to the appropriate datastore key.
@@ -12,8 +11,7 @@ const CID = require('cids')
12
11
* @returns {Key }
13
12
*/
14
13
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 )
17
15
}
18
16
19
17
/**
@@ -23,8 +21,5 @@ exports.cidToKey = cid => {
23
21
* @returns {CID }
24
22
*/
25
23
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 ) ) )
30
25
}
Original file line number Diff line number Diff line change @@ -5,7 +5,6 @@ const Key = require('interface-datastore').Key
5
5
const { default : Queue } = require ( 'p-queue' )
6
6
const _get = require ( 'just-safe-get' )
7
7
const _set = require ( 'just-safe-set' )
8
- const _has = require ( 'lodash.has' )
9
8
const errcode = require ( 'err-code' )
10
9
const errors = require ( './errors' )
11
10
@@ -28,7 +27,7 @@ module.exports = (store) => {
28
27
29
28
const encodedValue = await store . get ( configKey )
30
29
const config = JSON . parse ( encodedValue . toString ( ) )
31
- if ( key !== undefined && ! _has ( config , key ) ) {
30
+ if ( key !== undefined && _get ( config , key ) === undefined ) {
32
31
throw new errors . NotFoundError ( `Key ${ key } does not exist in config` )
33
32
}
34
33
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ const _ = require('lodash')
13
13
const multihashing = require ( 'multihashing-async' )
14
14
const Key = require ( 'interface-datastore' ) . Key
15
15
const tempDir = require ( 'ipfs-utils/src/temp-dir' )
16
- const base32 = require ( 'base32.js ' )
16
+ const multibase = require ( 'multibase ' )
17
17
const IPFSRepo = require ( '../' )
18
18
19
19
module . exports = ( repo ) => {
@@ -214,8 +214,7 @@ module.exports = (repo) => {
214
214
const data = Buffer . from ( `TEST${ Date . now ( ) } ` )
215
215
const hash = await multihashing ( data , 'sha2-256' )
216
216
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 )
219
218
220
219
otherRepo = new IPFSRepo ( tempDir ( ) , {
221
220
storageBackends : {
You can’t perform that action at this time.
0 commit comments