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

Commit

Permalink
Errors getBlock(s) on non-existence.
Browse files Browse the repository at this point in the history
  • Loading branch information
hackergrrl committed Apr 15, 2016
1 parent 560497f commit 27e4b2e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 21 deletions.
18 changes: 5 additions & 13 deletions src/block-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,11 @@ function BlockService (ipfsRepo, exchange) {
return callback(new Error('Invalid multihash'))
}

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)
}
})
ipfsRepo.datastore.createReadStream(multihash, extension)
.pipe(bl((err, data) => {
if (err) { return callback(err) }
callback(null, new Block(data, extension))
}))
}

this.getBlocks = (multihashes, extension, callback) => {
Expand Down
13 changes: 5 additions & 8 deletions test/block-service-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ module.exports = (repo) => {
it('get a non existent block', (done) => {
const b = new Block('Not stored')
bs.getBlock(b.key, (err, block) => {
expect(err).to.not.exist
expect(block).to.not.exist
expect(err).to.exist
done()
})
})
Expand Down Expand Up @@ -109,8 +108,8 @@ module.exports = (repo) => {
expect(err).to.not.exist

bs.getBlocks([b1.key, b2.key, b3.key], (err, blocks) => {
expect(err).to.not.exist
expect(blocks).to.have.lengthOf(2)
expect(err).to.exist
expect(blocks).to.have.lengthOf(0)
done()
})
})
Expand All @@ -123,8 +122,7 @@ module.exports = (repo) => {
bs.deleteBlock(b.key, (err) => {
expect(err).to.not.exist
bs.getBlock(b.key, (err, block) => {
expect(err).to.not.exist
expect(block).to.not.exist
expect(err).to.exist
done()
})
})
Expand All @@ -145,8 +143,7 @@ module.exports = (repo) => {
bs.deleteBlock(b.key, 'ext', (err) => {
expect(err).to.not.exist
bs.getBlock(b.key, 'ext', (err, block) => {
expect(err).to.not.exist
expect(block).to.not.exist
expect(err).to.exist
done()
})
})
Expand Down

0 comments on commit 27e4b2e

Please sign in to comment.