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

Commit afe3405

Browse files
committed
Returns !block + !error when block not present.
1 parent 803e4e1 commit afe3405

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

src/block-service.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,19 @@ function BlockService (ipfsRepo, exchange) {
3535
return callback(new Error('Invalid multihash'))
3636
}
3737

38-
ipfsRepo.datastore.createReadStream(multihash, extension)
39-
.pipe(bl((err, data) => {
40-
if (err) { return callback(err) }
41-
callback(null, new Block(data, extension))
42-
}))
38+
ipfsRepo.datastore.exists(multihash, (err, exists) => {
39+
if (err) { return callback(err) }
40+
41+
if (exists) {
42+
ipfsRepo.datastore.createReadStream(multihash, extension)
43+
.pipe(bl((err, data) => {
44+
if (err) { return callback(err) }
45+
callback(null, new Block(data, extension))
46+
}))
47+
} else {
48+
callback(null, null)
49+
}
50+
})
4351
}
4452

4553
this.getBlocks = (multihashes, extension, callback) => {
@@ -57,7 +65,9 @@ function BlockService (ipfsRepo, exchange) {
5765
async.each(multihashes, (multihash, next) => {
5866
this.getBlock(multihash, extension, (err, block) => {
5967
if (err) { return next(err) }
60-
blocks.push(block)
68+
if (block) {
69+
blocks.push(block)
70+
}
6171
next()
6272
})
6373
}, (err) => {

0 commit comments

Comments
 (0)