mauritz
mauritz3w ago

Deno FileServer Tutorial Incorrect?

I had a look at the official fileserver tutorial (https://docs.deno.com/runtime/tutorials/file_server/) and saw the below
try {
const file = await Deno.open("." + filepath, { read: true });
return new Response(file.readable);
} catch {
return new Response("404 Not Found", { status: 404 });
}
try {
const file = await Deno.open("." + filepath, { read: true });
return new Response(file.readable);
} catch {
return new Response("404 Not Found", { status: 404 });
}
However, if my understanding is correct, the file resource is leaked because it's never closed but if opened with using it might be closed before the Response finished streaming. Am I missing something and the example is actually correct or is this bad code?
Deno
Write a file server
In-depth documentation, guides, and reference materials for building secure, high-performance JavaScript and TypeScript applications with Deno
0 Replies
No replies yetBe the first to reply to this messageJoin