cmorten / opine

Minimalist web framework for Deno ported from ExpressJS.
https://github.com/cmorten/opine/blob/main/.github/API/api.md
MIT License
854 stars 43 forks source link

[QUESTION] how to send ReadableStream<Uint8Array>? #169

Closed mattn closed 2 years ago

mattn commented 2 years ago

I'm trying to send image data which is given from S3 using deno_s3 like below.

    const obj = await bucket.getObject("xxx.png");
    //const b = await new Response(obj?.body).text();
    // how to send obj without read whole data on memory.
    res.type("image/png").send(b);

Can I get this?

cmorten commented 2 years ago

Opine is using the Deno std library for responding to requests, which in turn makes use of the Response Web API which supports ReadableStream<Uint8Array> for it's ResponseInit https://github.com/cmorten/opine/blob/main/src/request.ts#L88

Is res.send() not working for you? If you can share an error etc. this would be useful.

cmorten commented 2 years ago

I think I've pushed a fix so you can pass ReadableStream to res.send() please could you test it out and confirm?

Failing that it might be worth trying to pass to res.end() directly.

Please reopen if the issue isn't resolved in https://github.com/cmorten/opine/releases/tag/2.3.3.