Skip to content
This repository has been archived by the owner on Mar 8, 2024. It is now read-only.

Commit

Permalink
Merge pull request #10 from vaultec81/master
Browse files Browse the repository at this point in the history
Update for latest IPFS, bug fix.
  • Loading branch information
Henry Rodrick authored Jul 25, 2019
2 parents 81847d0 + 480d425 commit 37847f4
Showing 1 changed file with 9 additions and 18 deletions.
27 changes: 9 additions & 18 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,25 +79,16 @@ function getFile(ipfs, rootHash, filename, callback) {
}

console.log("Requesting '" + rootHash + "/" + filename + "'")

const stream = ipfs.cat(hash);
stream.then((value) => {
console.log("Received data for file '" + rootHash + "/" + fileName + "' size: " + value.length)

callback(null, value);
}).catch((err) => {
callback(err, null);
})

var resBuf = new ArrayBuffer(fileSize)
var bufView = new Uint8Array(resBuf)
var offs = 0

const stream = ipfs.catReadableStream(hash)
console.log("Received stream for file '" + rootHash + "/" + fileName + "'")
stream.on('data', function (chunk) {
console.log("Received " + chunk.length + " bytes for file '" +
rootHash + "/" + fileName + "'")
bufView.set(chunk, offs)
offs += chunk.length
});
stream.on('error', function (err) {
callback(err, null)
});
stream.on('end', function () {
callback(null, resBuf)
});
});
}

Expand Down

0 comments on commit 37847f4

Please sign in to comment.