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

Commit 37847f4

Browse files
author
Henry Rodrick
authored
Merge pull request #10 from vaultec81/master
Update for latest IPFS, bug fix.
2 parents 81847d0 + 480d425 commit 37847f4

File tree

1 file changed

+9
-18
lines changed

1 file changed

+9
-18
lines changed

src/index.js

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -79,25 +79,16 @@ function getFile(ipfs, rootHash, filename, callback) {
7979
}
8080

8181
console.log("Requesting '" + rootHash + "/" + filename + "'")
82+
83+
const stream = ipfs.cat(hash);
84+
stream.then((value) => {
85+
console.log("Received data for file '" + rootHash + "/" + fileName + "' size: " + value.length)
86+
87+
callback(null, value);
88+
}).catch((err) => {
89+
callback(err, null);
90+
})
8291

83-
var resBuf = new ArrayBuffer(fileSize)
84-
var bufView = new Uint8Array(resBuf)
85-
var offs = 0
86-
87-
const stream = ipfs.catReadableStream(hash)
88-
console.log("Received stream for file '" + rootHash + "/" + fileName + "'")
89-
stream.on('data', function (chunk) {
90-
console.log("Received " + chunk.length + " bytes for file '" +
91-
rootHash + "/" + fileName + "'")
92-
bufView.set(chunk, offs)
93-
offs += chunk.length
94-
});
95-
stream.on('error', function (err) {
96-
callback(err, null)
97-
});
98-
stream.on('end', function () {
99-
callback(null, resBuf)
100-
});
10192
});
10293
}
10394

0 commit comments

Comments
 (0)