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;

but it throws a 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.
Was this page helpful?