DenoDDeno
Powered by
csjhC
Denoβ€’2y agoβ€’
8 replies
csjh

Using `Deno.FsFile.prototype.readable` with `Response`

I was trying to stream a file into a response with the snippet:
const file = await Deno.open(path);
const resp = new Response(file.readable);
file.close();
return resp;
const file = await Deno.open(path);
const resp = new Response(file.readable);
file.close();
return resp;

but it throws a
BadResource
BadResource
error. This makes sense, because closing the file would destroy the associated stream, but if I have to close the file at some point, how can I put it in a Response? afaict any way I do it will either error or leave a leak. I guess I could add a finalizer for the file but that seems silly.
Deno banner
DenoJoin
Chat about Deno, a modern runtime for JavaScript and TypeScript.
20,944Members
Resources
Recent Announcements

Similar Threads

Was this page helpful?

Similar Threads

`.read()` method in `Deno.Conn` or `Deno.FsFile` in Deno 2.0
DavidDDavid / help
3y ago
Stream a Sharp object / Node Readable with Deno.serve()
functiondjFfunctiondj / help
2y ago
Using SolidJS with Deno
MqxMMqx / help
2y ago
Using ESBuild with Deno
MqxMMqx / help
3y ago