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

Commit

Permalink
refactor(CR)
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddias committed Aug 25, 2016
1 parent 44dba6c commit a478c0d
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/core/ipfs/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ const multihash = require('multihashes')
module.exports = function block (self) {
return {
get: (hash, callback) => {
if (typeof hash === 'string') {
hash = multihash.fromB58String(hash)
}
hash = cleanHash(hash)

self._blockS.getBlock(hash, callback)
},
put: (block, callback) => {
Expand All @@ -24,16 +23,11 @@ module.exports = function block (self) {
})
},
del: (hash, callback) => {
if (typeof hash === 'string') {
hash = multihash.fromB58String(hash)
}

hash = cleanHash(hash)
self._blockS.deleteBlock(hash, callback)
},
stat: (hash, callback) => {
if (typeof hash === 'string') {
hash = multihash.fromB58String(hash)
}
hash = cleanHash(hash)

self._blockS.getBlock(hash, (err, block) => {
if (err) {
Expand All @@ -47,3 +41,10 @@ module.exports = function block (self) {
}
}
}

function cleanHash (hash) {
if (typeof hash === 'string') {
return multihash.fromB58String(hash)
}
return hash
}

0 comments on commit a478c0d

Please sign in to comment.