Fix IPFS cat decoding for ipfs-http-client 56 (Uint8Array) #251
No files matched your search
+7
-3
@@ -50,11 +50,15 @@ class IPFS {
|
||||
return fetch(`${this._config['gatewayUrl']}/${ipfsHash}`).then(r => r.text());
|
||||
} else {
|
||||
const res = this._ipfsAPI.cat(ipfsHash);
|
||||
// ipfs-http-client >= 56 yields Uint8Array chunks. Their toString()
|
||||
// returns comma-separated byte values instead of text, so decode the
|
||||
// bytes explicitly (TextDecoder works in both Node and browsers).
|
||||
const decoder = new TextDecoder();
|
||||
let str = '';
|
||||
for await (const buffer of res) {
|
||||
str += buffer.toString();
|
||||
for await (const chunk of res) {
|
||||
str += decoder.decode(chunk, { stream: true });
|
||||
}
|
||||
return Promise.resolve(str);
|
||||
return Promise.resolve(str + decoder.decode());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@kredits/contracts",
|
||||
"version": "7.5.0",
|
||||
"version": "7.5.1",
|
||||
"description": "Smart contracts and JavaScript API for Kredits",
|
||||
"main": "./lib/kredits.js",
|
||||
"directories": {
|
||||
|
||||
Reference in new issue
Block a user