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

Commit

Permalink
multihashes may be followed by sub-path strings (#495)
Browse files Browse the repository at this point in the history
  • Loading branch information
James Halliday authored and daviddias committed Dec 25, 2016
1 parent bb1c292 commit c9df6c3
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/clean-multihash.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ const bs58 = require('bs58')
const isIPFS = require('is-ipfs')

module.exports = function (multihash) {
if (!isIPFS.multihash(multihash)) {
throw new Error('not valid multihash')
}
if (Buffer.isBuffer(multihash)) {
return bs58.encode(multihash)
multihash = bs58.encode(multihash)
}
if (typeof multihash !== 'string') {
throw new Error('unexpected multihash type: ' + typeof multihash)
}
if (!isIPFS.multihash(multihash.split('/')[0])) {
throw new Error('not valid multihash')
}
return multihash
}
Expand Down

0 comments on commit c9df6c3

Please sign in to comment.