Comments (10)
i think this is related to go-ipfs treatement of the buffers maybe. see ipfs/kubo#1582
from js-ipfs-http-client.
That issue does affects this if there's going to be a change in the response format of ipfs cat
.. but I think there's an unrelated issue here:
Running ipfsApi.cat
, the http request for ipfs cat
responds with a buffer. The browserified version appends the buffer's string Uint8Array.prototype.toString()
to ''
which sometimes returns an incorrectly encoded string -- https://github.com/ipfs/node-ipfs-api/blob/master/src/request-api.js#L58. If buffers are the correct response type for api call to ipfs cat
, the expected result could be achieved with Buffer.concat()
or the Uint8Array can also be appened to ''
as a binary string.
Since ipfsApi.add expects a Buffer, seems reasonable for ipfsApi.cat to return Buffers? In which case maybe Buffer.concat()
is the way to go
from js-ipfs-http-client.
thoughts @diasdavid @victorbjelkholm @dignifiedquire @bcomnes ?
from js-ipfs-http-client.
@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.
from js-ipfs-http-client.
@ckeenan we just added a considerable amount of tests to node-ipfs-api (#81) and landed the field for browser tests. Could you verify that the problem remains and if so, could you add a test case demonstrating the issue, so it is easier to target the fix? Thank you :)
from js-ipfs-http-client.
@ckeenan ping
from js-ipfs-http-client.
@dignifiedquire ACK. I am trying to test with a simple html file that includes dist/ipfsapi.js
as a <script />
. ipfs.cat
returns a stream and not sure I can parse that in-browser. Is this expected?
from js-ipfs-http-client.
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)
})
})
from js-ipfs-http-client.
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
from js-ipfs-http-client.
@ckeenan great to hear :)
from js-ipfs-http-client.
Related Issues (20)
- wrap-with-directory no working for latest few versions (39.0+ for sure) HOT 5
- Need some help I try to npm install --save ipfs-http-client HOT 2
- addFromFs doesn't include headers that are injected during api initialization HOT 6
- when i excute 'npm run dev' ,then throws a error HOT 1
- Bad tag? HOT 2
- Migration of License from MIT to Dual MIT/Apache2.0 HOT 2
- SyntaxError: Unexpected reserved word HOT 2
- Does not work in Node.js 13 HOT 1
- Re-license js-ipfs-http-client to MIT + Apache 2 HOT 37
- Not working on Node.js 13 HOT 2
- There is an Alex in my Chrome browser... HOT 2
- 0.40.1 does not print anything HOT 6
- src/files/ls.js uses incorrect long listing option name HOT 1
- Problems getting root hash for static sites re-uploaded as Buffers HOT 8
- getReadableStream returns Readable with length 0 after migration to the latest version HOT 2
- Failed to construct 'URL': Invalid URL HOT 5
- Linter should enforce coding style rules that will gate merging PRs HOT 4
- Bump stream-to-it version once a PR lands there to handle response body that is undefined HOT 3
- How to find out whether an IPFS hash is a directory or file? HOT 1
- Unable to add content with the 42.0.0 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from js-ipfs-http-client.