oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
74.21k stars 2.77k forks source link

TypeError: ReadableStreamBYOBReader needs a ReadableByteStreamController #12908

Open brettwillis opened 3 months ago

brettwillis commented 3 months ago

What version of Bun is running?

1.1.21+70ca2b76c

What platform is your computer?

Darwin 23.5.0 arm64 arm

What steps can reproduce the bug?

Send request with body to the Bun server, request.body.getReader() throws when trying to obtain a ReadableStreamBYOBReader.

// (simplified)
Bun.serve({
  async fetch(req) {
    const reader = await req.body.getReader({ mode: 'byob' }); // <-- TypeError: ReadableStreamBYOBReader needs a ReadableByteStreamController
    // ...
  }
})

What is the expected behavior?

ReadableStream should support byob mode.

What do you see instead?

TypeError: ReadableStreamBYOBReader needs a ReadableByteStreamController

Additional information

No response

brettwillis commented 1 month ago

Hey guys it's been a while and no triage. Are "byob" streams intentionally not implemented?

// test.js
Bun.serve({
  host: 'localhost',
  port: '8080',
  async fetch(req) {
    const reader = await req.body?.getReader({ mode: 'byob' });
    return new Response('done');
  }
});

Then curl http://localhost:8080 -d 'Hello'.

1 | Bun.serve({
2 |   host: 'localhost',
3 |   port: '8080',
4 |   async fetch(req) {
5 |     const reader = await req.body?.getReader({ mode: 'byob' });
              ^
TypeError: ReadableStreamBYOBReader needs a ReadableByteStreamController
      at /Users/..../test.js:5:36
      at fetch (/Users/..../test.js:4:15)
POST - / failed
brettwillis commented 1 month ago

Docs claim that ReadableStream is fully implemented https://bun.sh/docs/runtime/nodejs-apis#readablestream. Am I the only one encountering this?