Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit a478c0d

Browse files
committed
refactor(CR)
1 parent 44dba6c commit a478c0d

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

src/core/ipfs/block.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ const multihash = require('multihashes')
66
module.exports = function block (self) {
77
return {
88
get: (hash, callback) => {
9-
if (typeof hash === 'string') {
10-
hash = multihash.fromB58String(hash)
11-
}
9+
hash = cleanHash(hash)
10+
1211
self._blockS.getBlock(hash, callback)
1312
},
1413
put: (block, callback) => {
@@ -24,16 +23,11 @@ module.exports = function block (self) {
2423
})
2524
},
2625
del: (hash, callback) => {
27-
if (typeof hash === 'string') {
28-
hash = multihash.fromB58String(hash)
29-
}
30-
26+
hash = cleanHash(hash)
3127
self._blockS.deleteBlock(hash, callback)
3228
},
3329
stat: (hash, callback) => {
34-
if (typeof hash === 'string') {
35-
hash = multihash.fromB58String(hash)
36-
}
30+
hash = cleanHash(hash)
3731

3832
self._blockS.getBlock(hash, (err, block) => {
3933
if (err) {
@@ -47,3 +41,10 @@ module.exports = function block (self) {
4741
}
4842
}
4943
}
44+
45+
function cleanHash (hash) {
46+
if (typeof hash === 'string') {
47+
return multihash.fromB58String(hash)
48+
}
49+
return hash
50+
}

0 commit comments

Comments
 (0)