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

Commit c9df6c3

Browse files
James Hallidaydaviddias
authored andcommitted
multihashes may be followed by sub-path strings (#495)
1 parent bb1c292 commit c9df6c3

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/clean-multihash.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@ const bs58 = require('bs58')
44
const isIPFS = require('is-ipfs')
55

66
module.exports = function (multihash) {
7-
if (!isIPFS.multihash(multihash)) {
8-
throw new Error('not valid multihash')
9-
}
107
if (Buffer.isBuffer(multihash)) {
11-
return bs58.encode(multihash)
8+
multihash = bs58.encode(multihash)
9+
}
10+
if (typeof multihash !== 'string') {
11+
throw new Error('unexpected multihash type: ' + typeof multihash)
12+
}
13+
if (!isIPFS.multihash(multihash.split('/')[0])) {
14+
throw new Error('not valid multihash')
1215
}
1316
return multihash
1417
}

0 commit comments

Comments
 (0)