Skip to content

Commit

Permalink
Nasty Kludge to get around ipfs/js-ipfs#1049
Browse files Browse the repository at this point in the history
  • Loading branch information
mitra42 committed Oct 27, 2017
1 parent 1abf790 commit a8ab4b2
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions js/TransportIPFS.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,15 @@ class TransportIPFS extends Transport {
//return this.promisified.ipfs.block.get(cid).then((result) => result.data) // OLD way, works below 250k bytes, where files.cat doesnt !
return this.ipfs.files.cat(cid)
.then((stream) => Dweb.utils.p_streamToBuffer(stream, verbose))
.then((data) => { // Horrible Kludge - stream returns 0 length if short file not IPLD
if (data.length) {
return data
} else {
if (verbose) console.log("Kludge alert - files.cat failed, trying block.get");
return this.promisified.ipfs.block.get(cid)
.then((blk) => blk.data);
}
})
.then((data)=> { if (verbose) console.log("fetched ",data.length); return data; })
.catch((err) => {
console.log("Caught misc error in TransportIPFS.p_rawfetch", err);
Expand Down

0 comments on commit a8ab4b2

Please sign in to comment.