Documentation
¶
Overview ¶
Package virtfs provides a virtual file tree. It is intended to be used to build a tree that can be written to a new file system or archive that takes an io/fs.FS. It supports symbolic links and implements io/fs.ReadLinkFS.
For memory efficiency regular files are not copied into the virtual fs itself. Instead, their original source path is just mapped to the virtual fs path. Opening the virtual file opens the original file underneath.
Index ¶
- Variables
- type FS
- func (fsys *FS) Add(name string, openFn FileOpenFunc) error
- func (fsys *FS) Lstat(name string) (fs.FileInfo, error)
- func (fsys *FS) Mkdir(name string) error
- func (fsys *FS) MkdirAll(name string) error
- func (fsys *FS) Open(name string) (fs.File, error)
- func (fsys *FS) ReadLink(name string) (string, error)
- func (fsys *FS) Symlink(oldname, newname string) error
- type FileOpenFunc
- type PathError
Constants ¶
This section is empty.
Variables ¶
var ( // ErrFileNotExist is returned if a tree node that is looked up does not // exist. ErrFileNotExist = fs.ErrNotExist // ErrFileExist is returned if a tree node exists that was not expected. ErrFileExist = fs.ErrExist // ErrFileInvalid is returned if a file is invalid for the requested // operation. ErrFileInvalid = fs.ErrInvalid // ErrFileNotDir is returned if a file exists but is not a directory. ErrFileNotDir = errors.New("not a directory") // ErrFileNotRegular is returned if the source is not a regular file. ErrFileNotRegular = errors.New("source is not a regular file") // ErrInvalidArgument is returned if an invalid argument is given. ErrInvalidArgument = errors.New("invalid argument") // ErrSymlinkTooDeep is returned if there are too many symbolic links to // follow. ErrSymlinkTooDeep = errors.New("nested links too deep") )
Functions ¶
This section is empty.
Types ¶
type FS ¶
type FS struct {
// contains filtered or unexported fields
}
FS represents a simple fs.FS that supports directories, regular files and symbolic links
Regular files that should be copied from another source can be added with FS.Add.It supports adding symbolic links with FS.Symlink. Use FS.Mkdir or FS.MkdirAll to create any required directories beforehand.
func (*FS) Add ¶
func (fsys *FS) Add(name string, openFn FileOpenFunc) error
Add creates a new regular file with the given name.
File content is read from the file returned by the given FileOpenFunc. It returns a PathError in case of errors.
func (*FS) Lstat ¶
Lstat returns information about the file with the given name.
It returns a PathError in case of errors. It does not follow symbolic links and returns symbolic links directly.
func (*FS) Mkdir ¶
Mkdir creates a new directory with the given name.
It returns PathError in case of errors.
func (*FS) MkdirAll ¶
MkdirAll creates a directory with the given name along with all necessary parents.
It returns a PathError in case of errors. If the directory exists already, it does nothing and returns nil.
func (*FS) Open ¶
Open opens the named file.
It returns a PathError in case of errors. It does not follow symbolic links and returns symbolic links directly.
type FileOpenFunc ¶
FileOpenFunc returns an open fs.File or an error if opening fails.