New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Response.body is not a ReadableStream when constructed from a string or buffer. #1308
Comments
This have always been like this in v2 due to lack of Beside, And it's going to be a major breaking change when we do. So my advice: use v3 if you want to do any conversion hack with Response |
Thanks for the response! It's totally fair that you're not going to fix this in v2. We'll see about upgrading to v3 in the long term. I'll probably use a wrapper in my code to coerce everything into a stream when constructing a Response. Putting aside compliance with the spec, It's not clear to me how |
The fetch api is built up by so many components that implementing everything at once have been tuff, constructing Responses on your own was not the first priority to get fixed. We didn't count on many doing it. but our goal now is to make a fully spec compliant api. #924 did solve half of the issue by converting/normalizing everything into a node:stream - next switch will be to use web streams instead
For now since both whatwg & node streams are both async iterable that yields uint8arrays then the best option would be to use for..of: for await (const uint8chunk of res.body) {
// Do something with uint8array
} Alternative if you always want the res.body to always be a node stream (even when v4 comes out) is to use |
node-fetch don't give the same result if polyfilled with Node.js buffer or web stream. (See node-fetch/node-fetch#1308 for details) Vite bundling use polyfill while Webpack web stream: this lead to eosjs not being able to decode the wallet requests. With cross-node this unreliable behavior is fixed.
node-fetch don't give the same result if polyfilled with Node.js buffer or web stream. (See node-fetch/node-fetch#1308 for details) Vite bundling use polyfill while Webpack web stream: this lead to eosjs not being able to decode the wallet requests. With cross-node this unreliable behavior is fixed.
node-fetch don't give the same result if polyfilled with Node.js buffer or web stream. (See node-fetch/node-fetch#1308 for details) Vite bundling use polyfill while Webpack web stream: this lead to eosjs not being able to decode the wallet requests. With cross-node this unreliable behavior is fixed.
Response.body
should always be aReadableStream
, however, when aResponse
is constructed from something else, like a string or aBuffer
, a `Buffer is used.Reproduction
Steps to reproduce the behavior:
Using the REPL:
Expected behavior
The spec says that the body is of type
ReadableStream
: https://fetch.spec.whatwg.org/#concept-bodySo, I'd expect to receive a
ReadableStream
as the body, instead of aBuffer
.When I try this same snippet of code in a browser, I get the following:
Your Environment
Additional context
This is particularly problematic when I'm trying to test my code using fetch-mock, as the default behavior results in Buffers everywhere.
The text was updated successfully, but these errors were encountered: