Skip to content

Commit 25c121e

Browse files
mikealdanieldaf
authored andcommitted
fix: get block with empty data (ipfs-inactive#789)
* Fix for empty data in block. Found this very strange bug when creating DAGNode's with empty buffers for data. streamToValue returns an empty array when the data is empty, which down the line triggers an exception in ipfs-block because this sends an empty array instead of a buffer. * fix: get empty block for response without X-Stream-Output js-ipfs currently does not set the X-Stream-Output header on block.get responses so we also need a check for an empty array on our buffered res. License: MIT Signed-off-by: Alan Shaw <[email protected]> * chore: update to latest interface-ipfs-core License: MIT Signed-off-by: Alan Shaw <[email protected]>
1 parent b73c35a commit 25c121e

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
"eslint-plugin-react": "^7.9.1",
8080
"go-ipfs-dep": "~0.4.15",
8181
"gulp": "^3.9.1",
82-
"interface-ipfs-core": "~0.68.1",
82+
"interface-ipfs-core": "~0.69.0",
8383
"ipfsd-ctl": "~0.37.3",
8484
"pull-stream": "^3.6.8",
8585
"socket.io": "^2.1.1",

src/block/get.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,18 @@ module.exports = (send) => {
3434
const transform = (res, callback) => {
3535
if (Buffer.isBuffer(res)) {
3636
callback(null, new Block(res, cid))
37+
// For empty blocks, concat-stream can't infer the encoding so we are
38+
// passed back an empty array
39+
} else if (Array.isArray(res) && res.length === 0) {
40+
callback(null, new Block(Buffer.alloc(0), cid))
3741
} else {
3842
streamToValue(res, (err, data) => {
3943
if (err) {
4044
return callback(err)
4145
}
46+
// For empty blocks, concat-stream can't infer the encoding so we are
47+
// passed back an empty array
48+
if (!data.length) data = Buffer.alloc(0)
4249
callback(null, new Block(data, cid))
4350
})
4451
}

0 commit comments

Comments
 (0)