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

Commit cafa52b

Browse files
haadcodedaviddias
authored andcommitted
fix: promisify .block (get, put, rm, stat) (#1085)
1 parent 9b385ae commit cafa52b

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/core/components/block.js

+11-8
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,17 @@ const multihash = require('multihashes')
55
const multihashing = require('multihashing-async')
66
const CID = require('cids')
77
const waterfall = require('async/waterfall')
8+
const promisify = require('promisify-es6')
89

910
module.exports = function block (self) {
1011
return {
11-
get: (cid, callback) => {
12+
get: promisify((cid, callback) => {
1213
cid = cleanCid(cid)
1314
self._blockService.get(cid, callback)
14-
},
15-
put: (block, options, callback) => {
15+
}),
16+
put: promisify((block, options, callback) => {
17+
callback = callback || function noop () {}
18+
1619
if (typeof options === 'function') {
1720
callback = options
1821
options = {}
@@ -52,12 +55,12 @@ module.exports = function block (self) {
5255
cb(null, block)
5356
})
5457
], callback)
55-
},
56-
rm: (cid, callback) => {
58+
}),
59+
rm: promisify((cid, callback) => {
5760
cid = cleanCid(cid)
5861
self._blockService.delete(cid, callback)
59-
},
60-
stat: (cid, callback) => {
62+
}),
63+
stat: promisify((cid, callback) => {
6164
cid = cleanCid(cid)
6265

6366
self._blockService.get(cid, (err, block) => {
@@ -69,7 +72,7 @@ module.exports = function block (self) {
6972
size: block.data.length
7073
})
7174
})
72-
}
75+
})
7376
}
7477
}
7578

0 commit comments

Comments
 (0)