Skip to content
This repository has been archived by the owner on Aug 11, 2021. It is now read-only.

Commit

Permalink
Returns !block + !error when block not present.
Browse files Browse the repository at this point in the history
  • Loading branch information
hackergrrl committed Apr 15, 2016
1 parent 803e4e1 commit afe3405
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/block-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,19 @@ function BlockService (ipfsRepo, exchange) {
return callback(new Error('Invalid multihash'))
}

ipfsRepo.datastore.createReadStream(multihash, extension)
.pipe(bl((err, data) => {
if (err) { return callback(err) }
callback(null, new Block(data, extension))
}))
ipfsRepo.datastore.exists(multihash, (err, exists) => {
if (err) { return callback(err) }

if (exists) {
ipfsRepo.datastore.createReadStream(multihash, extension)
.pipe(bl((err, data) => {
if (err) { return callback(err) }
callback(null, new Block(data, extension))
}))
} else {
callback(null, null)
}
})
}

this.getBlocks = (multihashes, extension, callback) => {
Expand All @@ -57,7 +65,9 @@ function BlockService (ipfsRepo, exchange) {
async.each(multihashes, (multihash, next) => {
this.getBlock(multihash, extension, (err, block) => {
if (err) { return next(err) }
blocks.push(block)
if (block) {
blocks.push(block)
}
next()
})
}, (err) => {
Expand Down

0 comments on commit afe3405

Please sign in to comment.