DenoDDeno
Powered by
ZidanZ
Denoβ€’3y agoβ€’
9 replies
Zidan

Closing a file

How do I close a file after opening and streaming it?
My handler function code is as follows:
return new Promise(
  (grant) => {
    Deno.open(
      asset.path
    ).then(
      (file) => {
        grant(
          new Response(
            file.readable,
            {
              status: 200,
              headers: {
                "content-type": asset.type,
                "content-length": file.stat.size.toString()
              }
            }
          )
        )
      }
    )
  }
);
return new Promise(
  (grant) => {
    Deno.open(
      asset.path
    ).then(
      (file) => {
        grant(
          new Response(
            file.readable,
            {
              status: 200,
              headers: {
                "content-type": asset.type,
                "content-length": file.stat.size.toString()
              }
            }
          )
        )
      }
    )
  }
);

Is there a good way of closing the "file" after returning the "Response" object?
Deno banner
DenoJoin
Chat about Deno, a modern runtime for JavaScript and TypeScript.
20,934Members
Resources
Recent Announcements

Similar Threads

Was this page helpful?

Similar Threads

File Permissions on Deno.FileInfo
IndustrialIIndustrial / help
3y ago
Closing a websocket server in a unit test
v1rtlVv1rtl / help
4y ago