-
Notifications
You must be signed in to change notification settings - Fork 161
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
Proposal: ReadableStreamBodyReader #1238
Comments
@jasnell How would |
Couple of options there:
|
Sorry, I wasn't clear. |
ah right, forgot about that |
You mean as an engine, or as a user? Because I think the crux of this proposal is if it makes sense to add another stream reader type, considering one can already do the proposed behaviour with Succinctness alone is not a compelling argument in my opinion, because the new reader mode is more verbose than using
|
Making this a proper reader can also have weird consequences. What should happen if you call const stream = new ReadableStream({ type: "bytes" });
const reader1 = stream.getReader({ mode: "body" });
reader1.arrayBuffer().catch(() => {});
// ...some time passes
reader1.releaseLock();
const reader2 = stream.getReader();
await reader2.read(); // what does this return? Will It's also a bit weird conceptually: the We already proposed the idea of adding something like |
I think in that case we'd have no choice but to error the stream if |
No, definitely not the only argument. The goal is to standardize the pattern even in cases where |
the stream could also just read the first line and acquire the boundary from reading just some initial bytes... |
What are folks' thoughts about advancing this proposal forward? I think for the |
My preference is for #1019. |
Let's close this in favor of the other proposal |
Consuming a
ReadableStream
as either anArrayBuffer
,Blob
,FormData
, JSON, or text is a common use case. We can see this inBody
mixin from fetch and the methods implemented byRequest
andResponse
, as well as in utilities such as Node.js' custom "stream consumers" documented here: https://nodejs.org/dist/latest-v18.x/docs/api/webstreams.html#utility-consumersThe pattern is so common, it would be helpful to be able to standardize the pattern with a new type of standard reader type... Specifically something like:
Use example:
Note that the
ReadableStreamGenericReader
could but does not just include theBody
mixin. This is because theBody
mixin includes thebody
getter that really wouldn't make sense in this case. We could use it, however, if that is the preference.The key benefit of adding this is that it would standardize what is becoming a common pattern.
The text was updated successfully, but these errors were encountered: