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

Use with embed.FS #19

Open
muety opened this issue Dec 20, 2021 · 3 comments
Open

Use with embed.FS #19

muety opened this issue Dec 20, 2021 · 3 comments

Comments

@muety
Copy link

muety commented Dec 20, 2021

Awesome project, exactly what I was looking for! Would be cool, though, if you could pass an embed.FS (or even better, just any fs.FS) instead of a directory name to serve files from. What do you think?

@muety muety changed the title Use with embed.FS Use with embed.FS Dec 20, 2021
@lpar
Copy link
Owner

lpar commented Dec 20, 2021

Stdlib now has an http.FS adaptor to convert an fs.FS into an http.FileSystem, but unfortunately fs.FS doesn't support the file existence check gzipped.Dir does. There's fs.StatFS which adds Stat to the FS interface, but unfortunately embed.FS doesn't support that.

For embed.FS it should be pretty easy to write an adaptor which implements Exists(filename). For fs.FS in general, it's trickier, because the interface only has Open. Supporting fs.StatFS probably makes sense though.

@muety
Copy link
Author

muety commented Dec 20, 2021

I think it should be quite easy to come up with a wrapper around any fs.FS that uses fs.Stat() for the existence check. From my understanding, that static function takes any fs.FS as an input, calls Stat() on it if it actually implements fs.StatFS and otherwise falls back to the (slower) way of Open()ing the file to get stat. But I might have gotten something wrong.

@lpar
Copy link
Owner

lpar commented Dec 20, 2021

Aha, I didn't know about fs.Stat(). That makes things much easier. Yes, in that case a general purpose wrapper should be fairly easy.

I'm thinking that rather than change the API again, it might be better to add an alternative to gzipped.FileServer that takes any fs.FS and uses fs.Stat() internally. Subtree selection would still be possible using fs.Sub.

Adphi added a commit to linka-cloud/gzipped that referenced this issue Jun 29, 2022
lpar added a commit that referenced this issue Aug 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants