-
Notifications
You must be signed in to change notification settings - Fork 300
Trouble with base64 encoded buffers via browserified ipfsApi #55
Comments
i think this is related to go-ipfs treatement of the buffers maybe. see ipfs/kubo#1582 |
That issue does affects this if there's going to be a change in the response format of Running Since ipfsApi.add expects a Buffer, seems reasonable for ipfsApi.cat to return Buffers? In which case maybe |
thoughts @diasdavid @victorbjelkholm @dignifiedquire @bcomnes ? |
@ckeenan you definitely have a point, looking at that func it is hard to understand the reason on why that call. (+ things like https://github.com/ipfs/node-ipfs-api/blob/master/src/request-api.js#L77 and https://github.com/ipfs/node-ipfs-api/blob/master/src/request-api.js#L83-L84 suggest that we need to revisit it) Now with the new documentation that @victorbjelkholm is writing (#58), we should (or even must :)) write tests accordingly with the expectations of function calls to catch this cases. |
@ckeenan ping |
@dignifiedquire ACK. I am trying to test with a simple html file that includes |
Yes this is expected, you can easily parse it like this: ipfs.cat('some hash', function (err, stream) {
var res = ''
stream.on('data', function (chunk) {
res += chunk.toString()
})
stream.on('error', function (err) {
console.error('Oh nooo', err)
})
stream.on('end', function () {
console.log('Got:', res)
})
}) |
Oh excellent. So this lets the application concatenate the data any way it likes. That indeed fixes this issue where appending the stream's data arrays to an empty string can result in incorrect encodings for some types of buffers. Looks like this is ready to close @dignifiedquire |
@ckeenan great to hear :) |
Looking up a base64 encoded buffer works fine with the node ipfs-api module. In the browser, it appears there's a problem converting it to a string from Uint8Array. Here is some code that encounters this
This change -- [https://github.com/ckeenan/node-ipfs-api/commit/0a9290a17e970b8a447cd0ba4b3a202693a1dcb5] -- resolves it, but unsure if best solution
The text was updated successfully, but these errors were encountered: