Documentation ¶
Overview ¶
Package vfs implements a virtual file system.
Index ¶
- Variables
- type FS
- type File
- type FileInfo
- type MemFS
- func (x *MemFS) AddFile(parent *MemFile, name string, size int64, modTime time.Time, content string) (m *MemFile)
- func (x *MemFS) Close() error
- func (x *MemFS) GetFile(name string) *MemFile
- func (x *MemFS) Matches(matchRe, notMatchRe *regexp.Regexp, includeDirs bool) (names []string, err error)
- func (x *MemFS) Open(name string) (f File, err error)
- func (x *MemFS) RootFiles() (infos []FileInfo, err error)
- func (x *MemFS) Seal()
- type MemFile
- type OsFS
- type Vfs
- func (vfs *Vfs) Add(failOnMissingFile bool, path string) (err error)
- func (vfs *Vfs) Adds(failOnMissingFile bool, paths ...string) (err error)
- func (vfs *Vfs) Close() (err error)
- func (vfs *Vfs) Find(path string) (f File, err error)
- func (vfs *Vfs) Matches(matchRe, notMatchRe *regexp.Regexp, includeDirs bool) []string
- type WithReadDir
- type WithReadImmutable
- type ZipFS
Constants ¶
This section is empty.
Variables ¶
var ErrInvalid = os.ErrInvalid
var ErrReadNotImmutable = errors.New("vfs: cannot read immutable contents")
Functions ¶
This section is empty.
Types ¶
type FS ¶
type FS interface { // Open will open a file given its path. Open(name string) (File, error) // Close will discard resources in use. Close() error // Matches returns a list of paths within the FS that match a regexp (if defined), and // do not match a second regexp (if defined), with an option to include or ignore directories. Matches(match, notMatch *regexp.Regexp, includeDirs bool) (names []string, err error) // RootFiles defines all the top level files. // // For example, if there is a filesystem with just 2 files, there's no single root directory // but those 2 files are the root files. RootFiles() (infos []FileInfo, err error) }
FS defines the interface for a filesystem (e.g. directory, zip-based, in-memory).
type File ¶
type File interface { io.ReadCloser Stat() (FileInfo, error) }
File is an open'ed entry in a file system
type FileInfo ¶
type FileInfo interface { Name() string // base name of the file Size() int64 // length in bytes for regular files; system-dependent for others ModTime() time.Time // modification time IsDir() bool // abbreviation for Mode().IsDir() }
FileInfo holds file metadata.
It is intentionally a subset of os.FileInfo, so that it can interop well with the standard lib.
type MemFS ¶
type MemFS struct {
// contains filtered or unexported fields
}
type MemFile ¶
type MemFile struct {
// contains filtered or unexported fields
}
func (*MemFile) ReadImmutable ¶
type OsFS ¶
type OsFS struct {
// contains filtered or unexported fields
}
OsFS is a FileSystem that serves files out of a os file
type Vfs ¶
type Vfs struct {
// contains filtered or unexported fields
}
Vfs provides a simple virtual file system.
User can request a file from a sequence of directories or zip files, and once it is located, it is returned as a ReadCloser, along with some metadata (like lasModTime, etc).
func (*Vfs) Add ¶
Add a FS to the Vfs based off the path, which is either a directory, a zip file or other file.
Any zip file added is immediately opened for reading right away, and keept it open until Close is explicitly called.
type WithReadDir ¶
WithReadDir is implemented by Directories to get a listing of the files in them.
type WithReadImmutable ¶
WithReadImmutable is implemented by Files that store their content as an uncompressed immutable string, can provide the ReadImmutable method for efficient use.