Search code examples
javascripttypescriptdeno

Does Deno's FsFile.readable automatically close the file when the stream is exhausted?


Given the following code:

const file = await Deno.open(fsPathname, { read: true })
return new Response(file.readable, { status: 200 })

Will FsFile.readable automatically close the file once the stream has been exhausted? The documentation doesn't mention this. If the answer is 'no' then I don't see how you close the file without seriously unneeded complexity.


Solution

  • Yes, the file resource associated to its readable stream will be closed when the stream encounters EOF.

    The documentation is currently lacking, but a PR has been created to improve this and also to add an option to prevent closure of the file resource if desired.