Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

On Deploy use Deno.readFile for static files #374

Open
ry opened this issue Jul 28, 2021 · 1 comment
Open

On Deploy use Deno.readFile for static files #374

ry opened this issue Jul 28, 2021 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@ry
Copy link

ry commented Jul 28, 2021

No description provided.

@kitsonk kitsonk added the enhancement New feature or request label Aug 6, 2021
@kitsonk kitsonk self-assigned this Aug 6, 2021
@kitsonk
Copy link
Collaborator

kitsonk commented Aug 11, 2021

I've looked into this and I don't think Deno.readFile() is sufficient to serve static resources. I also don't think it is sufficient to even be able to efficiently "proxy" content as well.

For serving static files, the current Deno APIs/logic that are needed:

  • An efficient way to determine if the file exists or not. Currently using (await Deno.stat(path)).isFile)
  • An efficient way to support Last-Modified headers. Currently using (await Deno.stat(path)).mtime)
  • An efficient way to calculate and compare ETags, both weak and strong. Currently using the Deno.FileInfo returned from Deno.stat to determine if the file is larger than what I want to read into memory to be able to calculate the strong tag or reverting to mtime and size to calculate a weak one.
  • A way to send a range. While some files are read into memory if they are "small" enough, there is logic to handle large files which requires a Deno.File and the ability to "seek" in the file, where I use a limited reader to read out the amount of bytes required.
  • I also currently "stream" large bodies using the LimitedReader which implements the Deno.Reader and reads out of the Deno.File reader.
  • This hints at the fact that I need to try to calculate headers before starting to read large files and I need to know if it is a large file before I open it.

With proxying of files, it is much better and easier to just stream the fetch() body in the response. Using Deno.readFile() would just be problematic for many reasons.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants