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

fix: Promisify .block (get, put, rm, stat) #1085

Merged
merged 1 commit into from
Nov 17, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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