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

Commit

Permalink
fix: promisify .block (get, put, rm, stat) (#1085)
Browse files Browse the repository at this point in the history
  • Loading branch information
haadcode authored and daviddias committed Nov 17, 2017
1 parent 9b385ae commit cafa52b
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/core/components/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@ const multihash = require('multihashes')
const multihashing = require('multihashing-async')
const CID = require('cids')
const waterfall = require('async/waterfall')
const promisify = require('promisify-es6')

module.exports = function block (self) {
return {
get: (cid, callback) => {
get: promisify((cid, callback) => {
cid = cleanCid(cid)
self._blockService.get(cid, callback)
},
put: (block, options, callback) => {
}),
put: promisify((block, options, callback) => {
callback = callback || function noop () {}

if (typeof options === 'function') {
callback = options
options = {}
Expand Down Expand Up @@ -52,12 +55,12 @@ module.exports = function block (self) {
cb(null, block)
})
], callback)
},
rm: (cid, callback) => {
}),
rm: promisify((cid, callback) => {
cid = cleanCid(cid)
self._blockService.delete(cid, callback)
},
stat: (cid, callback) => {
}),
stat: promisify((cid, callback) => {
cid = cleanCid(cid)

self._blockService.get(cid, (err, block) => {
Expand All @@ -69,7 +72,7 @@ module.exports = function block (self) {
size: block.data.length
})
})
}
})
}
}

Expand Down

0 comments on commit cafa52b

Please sign in to comment.