Documentation ¶
Overview ¶
Package vfs provides an abstraction of the os and io packages that is easy to test.
Index ¶
- Variables
- func Contains(fileSystem Stater, p, prefix string) (bool, error)
- func MkdirAll(fileSystem MkdirStater, path string, perm fs.FileMode) error
- func Walk(fileSystem LstatReadDirer, path string, walkFn filepath.WalkFunc) error
- func WalkSlash(fileSystem LstatReadDirer, path string, walkFn filepath.WalkFunc) error
- type EmptyFS
- func (EmptyFS) Chmod(name string, mode fs.FileMode) error
- func (EmptyFS) Chown(name string, uid, git int) error
- func (EmptyFS) Chtimes(name string, atime, mtime time.Time) error
- func (EmptyFS) Create(name string) (*os.File, error)
- func (EmptyFS) Glob(pattern string) ([]string, error)
- func (EmptyFS) Lchown(name string, uid, git int) error
- func (EmptyFS) Link(oldname, newname string) error
- func (EmptyFS) Lstat(name string) (fs.FileInfo, error)
- func (EmptyFS) Mkdir(name string, perm fs.FileMode) error
- func (EmptyFS) Open(name string) (fs.File, error)
- func (EmptyFS) OpenFile(name string, flag int, perm fs.FileMode) (*os.File, error)
- func (EmptyFS) PathSeparator() rune
- func (EmptyFS) RawPath(name string) (string, error)
- func (EmptyFS) ReadDir(dirname string) ([]fs.DirEntry, error)
- func (EmptyFS) ReadFile(filename string) ([]byte, error)
- func (EmptyFS) Readlink(name string) (string, error)
- func (EmptyFS) Remove(name string) error
- func (EmptyFS) RemoveAll(name string) error
- func (EmptyFS) Rename(oldpath, newpath string) error
- func (EmptyFS) Stat(name string) (fs.FileInfo, error)
- func (EmptyFS) Symlink(oldname, newname string) error
- func (EmptyFS) Truncate(name string, size int64) error
- func (EmptyFS) WriteFile(filename string, data []byte, perm fs.FileMode) error
- type FS
- type LstatReadDirer
- type MkdirStater
- type PathFS
- func (p *PathFS) Chmod(name string, mode fs.FileMode) error
- func (p *PathFS) Chown(name string, uid, gid int) error
- func (p *PathFS) Chtimes(name string, atime, mtime time.Time) error
- func (p *PathFS) Create(name string) (*os.File, error)
- func (p *PathFS) Glob(pattern string) ([]string, error)
- func (p *PathFS) Join(op, name string) (string, error)
- func (p *PathFS) Lchown(name string, uid, gid int) error
- func (p *PathFS) Link(oldname, newname string) error
- func (p *PathFS) Lstat(name string) (fs.FileInfo, error)
- func (p *PathFS) Mkdir(name string, perm fs.FileMode) error
- func (p *PathFS) Open(name string) (fs.File, error)
- func (p *PathFS) OpenFile(name string, flag int, perm fs.FileMode) (*os.File, error)
- func (p *PathFS) PathSeparator() rune
- func (p *PathFS) RawPath(path string) (string, error)
- func (p *PathFS) ReadDir(dirname string) ([]fs.DirEntry, error)
- func (p *PathFS) ReadFile(name string) ([]byte, error)
- func (p *PathFS) Readlink(name string) (string, error)
- func (p *PathFS) Remove(name string) error
- func (p *PathFS) RemoveAll(name string) error
- func (p *PathFS) Rename(oldpath, newpath string) error
- func (p *PathFS) Stat(name string) (fs.FileInfo, error)
- func (p *PathFS) Symlink(oldname, newname string) error
- func (p *PathFS) Truncate(name string, size int64) error
- func (p *PathFS) WriteFile(filename string, data []byte, perm fs.FileMode) error
- type ReadOnlyFS
- func (r *ReadOnlyFS) Chmod(name string, mode fs.FileMode) error
- func (r *ReadOnlyFS) Chown(name string, uid, gid int) error
- func (r *ReadOnlyFS) Chtimes(name string, atime, mtime time.Time) error
- func (r *ReadOnlyFS) Create(name string) (*os.File, error)
- func (r *ReadOnlyFS) Glob(pattern string) ([]string, error)
- func (r *ReadOnlyFS) Lchown(name string, uid, gid int) error
- func (r *ReadOnlyFS) Link(oldname, newname string) error
- func (r *ReadOnlyFS) Lstat(name string) (fs.FileInfo, error)
- func (r *ReadOnlyFS) Mkdir(name string, perm fs.FileMode) error
- func (r *ReadOnlyFS) Open(name string) (fs.File, error)
- func (r *ReadOnlyFS) OpenFile(name string, flag int, perm fs.FileMode) (*os.File, error)
- func (r *ReadOnlyFS) PathSeparator() rune
- func (r *ReadOnlyFS) RawPath(path string) (string, error)
- func (r *ReadOnlyFS) ReadDir(name string) ([]fs.DirEntry, error)
- func (r *ReadOnlyFS) ReadFile(name string) ([]byte, error)
- func (r *ReadOnlyFS) Readlink(name string) (string, error)
- func (r *ReadOnlyFS) Remove(name string) error
- func (r *ReadOnlyFS) RemoveAll(name string) error
- func (r *ReadOnlyFS) Rename(oldpath, newpath string) error
- func (r *ReadOnlyFS) Stat(name string) (fs.FileInfo, error)
- func (r *ReadOnlyFS) Symlink(oldname, newname string) error
- func (r *ReadOnlyFS) Truncate(name string, size int64) error
- func (r *ReadOnlyFS) WriteFile(filename string, data []byte, perm fs.FileMode) error
- type Stater
Constants ¶
This section is empty.
Variables ¶
var OSFS = &osfs{}
OSFS is the FS that calls os and io functions directly.
var SkipDir = fs.SkipDir
SkipDir is fs.SkipDir.
Functions ¶
func Contains ¶
Contains returns true if p is reachable by traversing through prefix. prefix must exist, but p may not. It is an expensive but accurate alternative to the deprecated filepath.HasPrefix.
func MkdirAll ¶
func MkdirAll(fileSystem MkdirStater, path string, perm fs.FileMode) error
MkdirAll is equivalent to os.MkdirAll but operates on fileSystem.
Types ¶
type EmptyFS ¶
type EmptyFS struct{}
An EmptyFS is a VFS that does not contain any files.
func (EmptyFS) PathSeparator ¶
type FS ¶
type FS interface { Chmod(name string, mode fs.FileMode) error Chown(name string, uid, git int) error Chtimes(name string, atime, mtime time.Time) error Create(name string) (*os.File, error) Glob(pattern string) ([]string, error) Lchown(name string, uid, git int) error Link(oldname, newname string) error Lstat(name string) (fs.FileInfo, error) Mkdir(name string, perm fs.FileMode) error Open(name string) (fs.File, error) OpenFile(name string, flag int, perm fs.FileMode) (*os.File, error) PathSeparator() rune RawPath(name string) (string, error) ReadDir(dirname string) ([]fs.DirEntry, error) ReadFile(filename string) ([]byte, error) Readlink(name string) (string, error) Remove(name string) error RemoveAll(name string) error Rename(oldpath, newpath string) error Stat(name string) (fs.FileInfo, error) Symlink(oldname, newname string) error Truncate(name string, size int64) error WriteFile(filename string, data []byte, perm fs.FileMode) error }
An FS is an abstraction over commonly-used functions in the os and io packages.
type LstatReadDirer ¶
type LstatReadDirer interface { Lstat(name string) (fs.FileInfo, error) ReadDir(name string) ([]fs.DirEntry, error) }
A LstatReadDirer implements all the functionality needed by Walk.
type MkdirStater ¶
type MkdirStater interface { Mkdir(name string, perm fs.FileMode) error Stat(name string) (fs.FileInfo, error) }
A MkdirStater implements all the functionality needed by MkdirAll.
type PathFS ¶
type PathFS struct {
// contains filtered or unexported fields
}
A PathFS operates on an existing FS, but prefixes all names with a path. All names must be absolute paths, with the exception of symlinks, which may be relative.
func NewPathFS ¶
NewPathFS returns a new *PathFS operating on fileSystem and prefixing all names with path.
func (*PathFS) PathSeparator ¶
PathSeparator implements PathSeparator.
type ReadOnlyFS ¶
type ReadOnlyFS struct {
// contains filtered or unexported fields
}
A ReadOnlyFS operates on an existing FS, but any methods that modify the FS return an error.
func NewReadOnlyFS ¶
func NewReadOnlyFS(fileSystem FS) *ReadOnlyFS
NewReadOnlyFS returns a new *ReadOnlyFS operating on fileSystem.
func (*ReadOnlyFS) Chmod ¶
func (r *ReadOnlyFS) Chmod(name string, mode fs.FileMode) error
Chmod implements os.Chmod.
func (*ReadOnlyFS) Chown ¶
func (r *ReadOnlyFS) Chown(name string, uid, gid int) error
Chown implements os.Chown.
func (*ReadOnlyFS) Chtimes ¶
func (r *ReadOnlyFS) Chtimes(name string, atime, mtime time.Time) error
Chtimes implements os.Chtimes.
func (*ReadOnlyFS) Create ¶
func (r *ReadOnlyFS) Create(name string) (*os.File, error)
Create implements os.Create.
func (*ReadOnlyFS) Glob ¶
func (r *ReadOnlyFS) Glob(pattern string) ([]string, error)
Glob implements filepath.Glob.
func (*ReadOnlyFS) Lchown ¶
func (r *ReadOnlyFS) Lchown(name string, uid, gid int) error
Lchown implements os.Lchown.
func (*ReadOnlyFS) Link ¶
func (r *ReadOnlyFS) Link(oldname, newname string) error
Link implements os.Link.
func (*ReadOnlyFS) Lstat ¶
func (r *ReadOnlyFS) Lstat(name string) (fs.FileInfo, error)
Lstat implements os.Lstat.
func (*ReadOnlyFS) Mkdir ¶
func (r *ReadOnlyFS) Mkdir(name string, perm fs.FileMode) error
Mkdir implements os.Mkdir.
func (*ReadOnlyFS) Open ¶
func (r *ReadOnlyFS) Open(name string) (fs.File, error)
Open implements os.Open.
func (*ReadOnlyFS) PathSeparator ¶
func (r *ReadOnlyFS) PathSeparator() rune
PathSeparator implements PathSeparator.
func (*ReadOnlyFS) RawPath ¶
func (r *ReadOnlyFS) RawPath(path string) (string, error)
RawPath implements RawPath.
func (*ReadOnlyFS) ReadDir ¶
func (r *ReadOnlyFS) ReadDir(name string) ([]fs.DirEntry, error)
ReadDir implements os.ReadDir.
func (*ReadOnlyFS) ReadFile ¶
func (r *ReadOnlyFS) ReadFile(name string) ([]byte, error)
ReadFile implements os.ReadFile.
func (*ReadOnlyFS) Readlink ¶
func (r *ReadOnlyFS) Readlink(name string) (string, error)
Readlink implements os.Readlink.
func (*ReadOnlyFS) Remove ¶
func (r *ReadOnlyFS) Remove(name string) error
Remove implements os.Remove.
func (*ReadOnlyFS) RemoveAll ¶
func (r *ReadOnlyFS) RemoveAll(name string) error
RemoveAll implements os.RemoveAll.
func (*ReadOnlyFS) Rename ¶
func (r *ReadOnlyFS) Rename(oldpath, newpath string) error
Rename implements os.Rename.
func (*ReadOnlyFS) Stat ¶
func (r *ReadOnlyFS) Stat(name string) (fs.FileInfo, error)
Stat implements os.Stat.
func (*ReadOnlyFS) Symlink ¶
func (r *ReadOnlyFS) Symlink(oldname, newname string) error
Symlink implements os.Symlink.