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 EntryFunc
- type FS
- func (fsys *FS) Copy(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
- func (fsys *FS) Write(name string, data []byte) 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 EntryFunc ¶ added in v0.15.6
EntryFunc is a function that creates an entry to the given FS. It can be used to define a full fs without the need to handle the errors immediately.
func Copy ¶ added in v0.15.6
func Copy(name string, openFn FileOpenFunc) EntryFunc
func MayExist ¶ added in v0.15.6
MayExist creates an EntryFunc that wraps any other EntryFunc and allows that the file creation fails with ErrFileExist.
func MkdirAll ¶ added in v0.15.6
MkdirAll creates an EntryFunc for FS.MkdirAll.
func Symlink ¶ added in v0.15.6
Symlink creates an EntryFunc for FS.Symlink.
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) Copy ¶ added in v0.15.6
func (fsys *FS) Copy(name string, openFn FileOpenFunc) error
Copy 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.
func (*FS) ReadLink ¶
ReadLink returns the target of the symbolic link with the given name.
It returns a PathError in case of errors. It returns ErrFileInvalid in case the file is not a symbolic link.
type FileOpenFunc ¶
FileOpenFunc returns an open fs.File or an error if opening fails.