Open muety opened 2 years ago
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.
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.
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
.
Awesome project, exactly what I was looking for! Would be cool, though, if you could pass an
embed.FS
(or even better, just anyfs.FS
) instead of a directory name to serve files from. What do you think?