From a0d0d8564ddba5459c171db290a7fe58a0b86e65 Mon Sep 17 00:00:00 2001 From: haad Date: Fri, 17 Nov 2017 09:57:11 +0100 Subject: [PATCH] fix: Promisify .block (get, put, rm, stat) --- src/core/components/block.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/core/components/block.js b/src/core/components/block.js index 7027d8302f..89b18db7d3 100644 --- a/src/core/components/block.js +++ b/src/core/components/block.js @@ -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 = {} @@ -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) => { @@ -69,7 +72,7 @@ module.exports = function block (self) { size: block.data.length }) }) - } + }) } }