Documentation ¶
Overview ¶
Package zipfs implements an io/fs.FS serving a read-only zip file.
Index ¶
- func BytesSectionReader(p []byte) *io.SectionReader
- type SectionReader
- type ZipFS
- func (fsys ZipFS) Glob(pattern string) ([]string, error)
- func (fsys ZipFS) Open(name string) (fs.File, error)
- func (fsys ZipFS) ReadDir(name string) ([]fs.DirEntry, error)
- func (fsys ZipFS) ReadFile(name string) ([]byte, error)
- func (fsys ZipFS) Stat(name string) (fs.FileInfo, error)
- func (fsys ZipFS) Sub(dir string) (fs.FS, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BytesSectionReader ¶ added in v0.19.6
func BytesSectionReader(p []byte) *io.SectionReader
BytesSectionReader wraps the []byte slice as a SectionReader.
Types ¶
type SectionReader ¶
SectionReader is the interface returned by io.NewSectionReader.
type ZipFS ¶
type ZipFS map[string]*zipFile
A ZipFS is a simple in-memory file system for use in tests, represented as a map from path names (arguments to Open) to information about the files or directories they represent.
The map need not include parent directories for files contained in the map; those will be synthesized if needed. But a directory can still be included by setting the zipFile.Mode's ModeDir bit; this may be necessary for detailed control over the directory's FileInfo or to create an empty directory.
File system operations read directly from the map, so that the file system can be changed by editing the map as needed. An implication is that file system operations must not run concurrently with changes to the map, which would be a race. Another implication is that opening or reading a directory requires iterating over the entire map, so a ZipFS should typically be used with not more than a few hundred entries or directory reads.
func MustNewZipFS ¶ added in v0.19.6
func MustNewZipFS(sr SectionReader) ZipFS
MustNewZipFS calls ZipFS and panics on error.
Example usage: //go:generate zip -9r assets.zip assets/ //go:embed assets.zip var assetsZIP []byte var assetsFS = zipfs.MustNewZipFS(BytesSectionReader(assetsZIP))
func NewZipFS ¶
func NewZipFS(sr SectionReader) (ZipFS, error)
NewZipFS provides the given zip file as an fs.FS.