diff --git a/lib/utils/ipfs.js b/lib/utils/ipfs.js index 7382bda..a2440a8 100644 --- a/lib/utils/ipfs.js +++ b/lib/utils/ipfs.js @@ -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()); } } diff --git a/package.json b/package.json index 65ecb90..0678443 100644 --- a/package.json +++ b/package.json @@ -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": {