zipfs

package
v0.27.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 16, 2024 License: Apache-2.0, BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Overview

Package zipfs implements an io/fs.FS serving a read-only zip file.

Index

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

type SectionReader interface {
	io.ReaderAt
	Size() int64
}

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.

func (ZipFS) Glob

func (fsys ZipFS) Glob(pattern string) ([]string, error)

func (ZipFS) Open

func (fsys ZipFS) Open(name string) (fs.File, error)

Open opens the named file.

func (ZipFS) ReadDir

func (fsys ZipFS) ReadDir(name string) ([]fs.DirEntry, error)

func (ZipFS) ReadFile added in v0.19.7

func (fsys ZipFS) ReadFile(name string) ([]byte, error)

func (ZipFS) Stat

func (fsys ZipFS) Stat(name string) (fs.FileInfo, error)

func (ZipFS) Sub added in v0.19.7

func (fsys ZipFS) Sub(dir string) (fs.FS, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL