Skip to content

Commit e11f0e3

Browse files
authored
chore: update deps (#26)
* chore: update deps * chore: update hamt sharding dep * fix: remove importer dep * test: test on node 12 * chore: move importer to dev deps
1 parent 036a514 commit e11f0e3

File tree

3 files changed

+33
-12
lines changed

3 files changed

+33
-12
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ stages:
66
- cov
77

88
node_js:
9-
- '10'
9+
- '12'
1010

1111
os:
1212
- linux

package.json

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,19 @@
4747
"ipld": "^0.25.0",
4848
"ipld-dag-pb": "^0.18.0",
4949
"ipld-in-memory": "^3.0.0",
50-
"multicodec": "~0.5.1",
51-
"multihashes": "~0.4.14",
52-
"nyc": "^14.0.0",
53-
"sinon": "^7.1.0"
50+
"ipfs-unixfs-importer": "^0.42.0",
51+
"multicodec": "^1.0.0",
52+
"multihashes": "^0.4.14",
53+
"nyc": "^15.0.0",
54+
"sinon": "^8.0.4"
5455
},
5556
"dependencies": {
5657
"async-iterator-last": "^1.0.0",
57-
"cids": "~0.7.1",
58+
"cids": "^0.7.1",
5859
"err-code": "^2.0.0",
59-
"hamt-sharding": "~0.0.2",
60-
"ipfs-unixfs": "^0.2.0",
61-
"ipfs-unixfs-importer": "~0.40.0"
60+
"hamt-sharding": "^1.0.0",
61+
"ipfs-unixfs": "^0.3.0",
62+
"multihashing-async": "^0.8.0"
6263
},
6364
"contributors": [
6465
"Alan Shaw <[email protected]>",

src/utils/find-cid-in-shard.js

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

33
const Bucket = require('hamt-sharding/src/bucket')
4-
const DirSharded = require('ipfs-unixfs-importer/src/dir-sharded')
4+
const multihashing = require('multihashing-async')
5+
6+
// FIXME: this is copy/pasted from ipfs-unixfs-importer/src/dir-sharded.js
7+
const hashFn = async function (value) {
8+
const hash = await multihashing(Buffer.from(value, 'utf8'), 'murmur3-128')
9+
10+
// Multihashing inserts preamble of 2 bytes. Remove it.
11+
// Also, murmur3 outputs 128 bit but, accidently, IPFS Go's
12+
// implementation only uses the first 64, so we must do the same
13+
// for parity..
14+
const justHash = hash.slice(2, 10)
15+
const length = justHash.length
16+
const result = Buffer.alloc(length)
17+
// TODO: invert buffer because that's how Go impl does it
18+
for (let i = 0; i < length; i++) {
19+
result[length - i - 1] = justHash[i]
20+
}
21+
22+
return result
23+
}
24+
hashFn.code = 0x22 // TODO: get this from multihashing-async?
525

626
const addLinksToHamtBucket = (links, bucket, rootBucket) => {
727
return Promise.all(
@@ -10,7 +30,7 @@ const addLinksToHamtBucket = (links, bucket, rootBucket) => {
1030
const pos = parseInt(link.Name, 16)
1131

1232
return bucket._putObjectAt(pos, new Bucket({
13-
hashFn: DirSharded.hashFn
33+
hashFn
1434
}, bucket, pos))
1535
}
1636

@@ -46,7 +66,7 @@ const findShardCid = async (node, name, ipld, context) => {
4666
if (!context) {
4767
context = {
4868
rootBucket: new Bucket({
49-
hashFn: DirSharded.hashFn
69+
hashFn
5070
}),
5171
hamtDepth: 1
5272
}

0 commit comments

Comments
 (0)