Documentation ¶
Overview ¶
Package vfs represents a virtual filesystem
Index ¶
- type Directory
- func (d *Directory) Close() error
- func (d *Directory) Info() (fs.FileInfo, error)
- func (d *Directory) IsDir() bool
- func (d *Directory) ModTime() time.Time
- func (d *Directory) Mode() fs.FileMode
- func (d *Directory) Name() string
- func (d *Directory) Read(_ []byte) (int, error)
- func (d *Directory) ReadDir(n int) ([]fs.DirEntry, error)
- func (d *Directory) Size() int64
- func (d *Directory) Stat() (fs.FileInfo, error)
- func (d *Directory) Sys() any
- func (d *Directory) Type() fs.FileMode
- type File
- func (f *File) Close() error
- func (f *File) Info() (fs.FileInfo, error)
- func (f *File) IsDir() bool
- func (f *File) ModTime() time.Time
- func (f *File) Mode() fs.FileMode
- func (f *File) Name() string
- func (f *File) Read(bytes []byte) (int, error)
- func (f *File) Size() int64
- func (f *File) Stat() (fs.FileInfo, error)
- func (f *File) Sys() any
- func (f *File) Type() fs.FileMode
- type VFS
- func (v *VFS) AddDir(dirPath string) *directoryContents
- func (v *VFS) AddFile(path string, bytes []byte, time time.Time) (*fileContents, error)
- func (v *VFS) Open(name string) (fs.File, error)
- func (v *VFS) ReadDir(name string) ([]fs.DirEntry, error)
- func (v *VFS) ReadFile(name string) ([]byte, error)
- func (v *VFS) Stat(name string) (fs.FileInfo, error)
- func (v *VFS) Sub(dir string) (fs.FS, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Directory ¶
type Directory struct {
// contains filtered or unexported fields
}
Directory is a wrapper around directoryContents which stores the state needed to implement ReadDirFile
func (*Directory) ReadDir ¶
ReadDir reads the contents of the directory and returns a slice of up to n DirEntry values in directory order. Subsequent calls on the same file will yield further DirEntry values.
If n > 0, ReadDir returns at most n DirEntry structures. In this case, if ReadDir returns an empty slice, it will return a non-nil error explaining why. At the end of a directory, the error is io.EOF.
If n <= 0, ReadDir returns all the DirEntry values from the directory in a single slice. In this case, if ReadDir succeeds (reads all the way to the end of the directory), it returns the slice and a nil error. If it encounters an error before the end of the directory, ReadDir returns the DirEntry list read until that point and a non-nil error.
type VFS ¶
type VFS struct {
// contains filtered or unexported fields
}
func FromDir ¶
func FromDir(workingDir string, predicate func(fileName string, info fs.DirEntry) bool) (*VFS, error)
FromDir creates a Virtual File System (VFS) from the workingDir on the local computer
Only files or folders which match the predicate will be added into the file system A nil predicate will result in all files and folders being added into the file system
func (*VFS) Open ¶
Open opens the named file.
When Open returns an error, it should be of type *PathError with the Op field set to "open", the Path field set to name, and the Err field describing the problem.
Open should reject attempts to open names that do not satisfy ValidPath(name), returning a *PathError with Err set to ErrInvalid or ErrNotExist.
func (*VFS) ReadDir ¶
ReadDir reads the named directory and returns a list of directory entries sorted by filename.
func (*VFS) ReadFile ¶
ReadFile reads the named file and returns its contents. A successful call returns a nil error, not io.EOF. (Because ReadFile reads the whole file, the expected EOF from the final Read is not treated as an error to be reported.)
The caller is permitted to modify the returned byte slice. This method should return a copy of the underlying data.