From f6abb639e31b8f2854a750ecc28a6ce81744f0a2 Mon Sep 17 00:00:00 2001 From: Stephen Whitmore Date: Thu, 14 Apr 2016 15:41:33 -0700 Subject: [PATCH] Order matters! --- src/block-service.js | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/block-service.js b/src/block-service.js index d7bffb0..c68183a 100644 --- a/src/block-service.js +++ b/src/block-service.js @@ -26,15 +26,15 @@ function BlockService (ipfsRepo, exchange) { } this.getBlock = (multihash, extension, callback) => { - if (!multihash) { - return callback(new Error('Invalid multihash')) - } - if (typeof extension === 'function') { callback = extension extension = undefined } + if (!multihash) { + return callback(new Error('Invalid multihash')) + } + ipfsRepo.datastore.createReadStream(multihash, extension) .pipe(bl((err, data) => { if (err) { return callback(err) } @@ -43,15 +43,15 @@ function BlockService (ipfsRepo, exchange) { } this.getBlocks = (multihashes, extension, callback) => { - if (!Array.isArray(multihashes)) { - return callback(new Error('Invalid batch of multihashes')) - } - if (typeof extension === 'function') { callback = extension extension = undefined } + if (!Array.isArray(multihashes)) { + return callback(new Error('Invalid batch of multihashes')) + } + const blocks = [] async.each(multihashes, (multihash, next) => { @@ -65,28 +65,28 @@ function BlockService (ipfsRepo, exchange) { } this.deleteBlock = (multihash, extension, callback) => { - if (!multihash) { - return callback(new Error('Invalid multihash')) - } - if (typeof extension === 'function') { callback = extension extension = undefined } + if (!multihash) { + return callback(new Error('Invalid multihash')) + } + ipfsRepo.datastore.remove(multihash, extension, callback) } this.deleteBlocks = (multihashes, extension, callback) => { - if (!Array.isArray(multihashes)) { - return callback('Invalid batch of multihashes') - } - if (typeof extension === 'function') { callback = extension extension = undefined } + if (!Array.isArray(multihashes)) { + return callback('Invalid batch of multihashes') + } + async.each(multihashes, (multihash, next) => { this.deleteBlock(multihash, extension, next) }, (err) => {