Skip to content
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

Use readable byte stream for Blob.stream() and Response.body #17386

Open
saschanaz opened this issue Jan 13, 2023 · 8 comments
Open

Use readable byte stream for Blob.stream() and Response.body #17386

saschanaz opened this issue Jan 13, 2023 · 8 comments

Comments

@saschanaz
Copy link

saschanaz commented Jan 13, 2023

Corresponds to whatwg/fetch#1593 and w3c/FileAPI#188.

@crowlKats
Copy link
Member

crowlKats commented Jan 13, 2023

We actually already use readable byte streams for both of these APIs which seem to align with behaviour in the spec PRs, so will close this

@saschanaz
Copy link
Author

Oh, interesting! In that case are you interested to how to spec the behavior? whatwg/fetch#1593 (comment)

@saschanaz
Copy link
Author

BTW, new Blob([]).stream().getReader({ mode: 'byob' }) succeeds but new Response(new Uint8Array([1,2])).body.getReader({mode: 'byob'}) still fails on Deno 1.29.2. I guess the Fetch change didn't land to the stable version yet?

@crowlKats crowlKats reopened this Jan 13, 2023
@saschanaz
Copy link
Author

saschanaz commented Jan 13, 2023

(await fetch('https://example.com')).body.getReader({mode: 'byob'}) does succeed, so I guess the only remaining item is to extract byte stream from BodyInit.

@crowlKats
Copy link
Member

actually, apparently i missed the fact that there was a recent-ish change #16038 that might have changed our behaviour.

@crowlKats
Copy link
Member

BTW, new Blob([]).stream().getReader({ mode: 'byob' }) succeeds but new Response(new Uint8Array([1,2])).body.getReader({mode: 'byob'}) still fails on Deno 1.29.2. I guess the Fetch change didn't land to the stable version yet?

seems like Response constructor with either string or typedarray has a different path, and is creating the stream differently:

deno/ext/fetch/22_body.js

Lines 95 to 100 in 10e4b2e

this.streamOrStatic = new ReadableStream({
start(controller) {
controller.enqueue(chunkToU8(body));
controller.close();
},
});

looks like a trivial change

@crowlKats
Copy link
Member

Oh, interesting! In that case are you interested to how to spec the behavior? whatwg/fetch#1593 (comment)

cc @lucacasonato

@jimmywarting
Copy link
Contributor

  • (await fetch('https://example.com')).body.getReader({mode: 'byob'}) works
  • new Response('foo').body.getReader({mode: 'byob'}) dose not...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants