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

Commit 4611a77

Browse files
committed
Move cleanMultihash into a module.
1 parent c238f43 commit 4611a77

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

src/api/cat.js

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
'use strict'
22

3-
const bs58 = require('bs58')
4-
const isIPFS = require('is-ipfs')
53
const promisify = require('promisify-es6')
4+
const cleanMultihash = require('../clean-multihash')
65

76
module.exports = (send) => {
87
const cat = promisify((multihash, callback) => {
@@ -15,13 +14,3 @@ module.exports = (send) => {
1514
})
1615
return cat
1716
}
18-
19-
function cleanMultihash (multihash) {
20-
if (!isIPFS.multihash(multihash)) {
21-
throw new Error('not valid multihash')
22-
}
23-
if (Buffer.isBuffer(multihash)) {
24-
return bs58.encode(multihash)
25-
}
26-
return multihash
27-
}

src/clean-multihash.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
'use strict'
2+
3+
const bs58 = require('bs58')
4+
const isIPFS = require('is-ipfs')
5+
6+
module.exports = function (multihash) {
7+
if (!isIPFS.multihash(multihash)) {
8+
throw new Error('not valid multihash')
9+
}
10+
if (Buffer.isBuffer(multihash)) {
11+
return bs58.encode(multihash)
12+
}
13+
return multihash
14+
}
15+

0 commit comments

Comments
 (0)