...

Package afero

import "github.com/spf13/afero"
Overview
Index
Subdirectories

Overview ▾

Index ▾

Constants
Variables
func DirExists(fs Fs, path string) (bool, error)
func Exists(fs Fs, path string) (bool, error)
func FileContainsAnyBytes(fs Fs, filename string, subslices [][]byte) (bool, error)
func FileContainsBytes(fs Fs, filename string, subslice []byte) (bool, error)
func FullBaseFsPath(basePathFs *BasePathFs, relativePath string) string
func GetTempDir(fs Fs, subPath string) string
func Glob(fs Fs, pattern string) (matches []string, err error)
func IsDir(fs Fs, path string) (bool, error)
func IsEmpty(fs Fs, path string) (bool, error)
func NeuterAccents(s string) string
func ReadAll(r io.Reader) ([]byte, error)
func ReadDir(fs Fs, dirname string) ([]os.FileInfo, error)
func ReadFile(fs Fs, filename string) ([]byte, error)
func SafeWriteReader(fs Fs, path string, r io.Reader) (err error)
func TempDir(fs Fs, dir, prefix string) (name string, err error)
func UnicodeSanitize(s string) string
func Walk(fs Fs, root string, walkFn filepath.WalkFunc) error
func WriteFile(fs Fs, filename string, data []byte, perm os.FileMode) error
func WriteReader(fs Fs, path string, r io.Reader) (err error)
type Afero
    func (a Afero) DirExists(path string) (bool, error)
    func (a Afero) Exists(path string) (bool, error)
    func (a Afero) FileContainsAnyBytes(filename string, subslices [][]byte) (bool, error)
    func (a Afero) FileContainsBytes(filename string, subslice []byte) (bool, error)
    func (a Afero) GetTempDir(subPath string) string
    func (a Afero) IsDir(path string) (bool, error)
    func (a Afero) IsEmpty(path string) (bool, error)
    func (a Afero) ReadDir(dirname string) ([]os.FileInfo, error)
    func (a Afero) ReadFile(filename string) ([]byte, error)
    func (a Afero) SafeWriteReader(path string, r io.Reader) (err error)
    func (a Afero) TempDir(dir, prefix string) (name string, err error)
    func (a Afero) TempFile(dir, pattern string) (f File, err error)
    func (a Afero) Walk(root string, walkFn filepath.WalkFunc) error
    func (a Afero) WriteFile(filename string, data []byte, perm os.FileMode) error
    func (a Afero) WriteReader(path string, r io.Reader) (err error)
type BasePathFile
    func (f *BasePathFile) Name() string
    func (f *BasePathFile) ReadDir(n int) ([]fs.DirEntry, error)
type BasePathFs
    func (b *BasePathFs) Chmod(name string, mode os.FileMode) (err error)
    func (b *BasePathFs) Chown(name string, uid, gid int) (err error)
    func (b *BasePathFs) Chtimes(name string, atime, mtime time.Time) (err error)
    func (b *BasePathFs) Create(name string) (f File, err error)
    func (b *BasePathFs) LstatIfPossible(name string) (os.FileInfo, bool, error)
    func (b *BasePathFs) Mkdir(name string, mode os.FileMode) (err error)
    func (b *BasePathFs) MkdirAll(name string, mode os.FileMode) (err error)
    func (b *BasePathFs) Name() string
    func (b *BasePathFs) Open(name string) (f File, err error)
    func (b *BasePathFs) OpenFile(name string, flag int, mode os.FileMode) (f File, err error)
    func (b *BasePathFs) ReadlinkIfPossible(name string) (string, error)
    func (b *BasePathFs) RealPath(name string) (path string, err error)
    func (b *BasePathFs) Remove(name string) (err error)
    func (b *BasePathFs) RemoveAll(name string) (err error)
    func (b *BasePathFs) Rename(oldname, newname string) (err error)
    func (b *BasePathFs) Stat(name string) (fi os.FileInfo, err error)
    func (b *BasePathFs) SymlinkIfPossible(oldname, newname string) error
type CacheOnReadFs
    func (u *CacheOnReadFs) Chmod(name string, mode os.FileMode) error
    func (u *CacheOnReadFs) Chown(name string, uid, gid int) error
    func (u *CacheOnReadFs) Chtimes(name string, atime, mtime time.Time) error
    func (u *CacheOnReadFs) Create(name string) (File, error)
    func (u *CacheOnReadFs) Mkdir(name string, perm os.FileMode) error
    func (u *CacheOnReadFs) MkdirAll(name string, perm os.FileMode) error
    func (u *CacheOnReadFs) Name() string
    func (u *CacheOnReadFs) Open(name string) (File, error)
    func (u *CacheOnReadFs) OpenFile(name string, flag int, perm os.FileMode) (File, error)
    func (u *CacheOnReadFs) Remove(name string) error
    func (u *CacheOnReadFs) RemoveAll(name string) error
    func (u *CacheOnReadFs) Rename(oldname, newname string) error
    func (u *CacheOnReadFs) Stat(name string) (os.FileInfo, error)
type CopyOnWriteFs
    func (u *CopyOnWriteFs) Chmod(name string, mode os.FileMode) error
    func (u *CopyOnWriteFs) Chown(name string, uid, gid int) error
    func (u *CopyOnWriteFs) Chtimes(name string, atime, mtime time.Time) error
    func (u *CopyOnWriteFs) Create(name string) (File, error)
    func (u *CopyOnWriteFs) LstatIfPossible(name string) (os.FileInfo, bool, error)
    func (u *CopyOnWriteFs) Mkdir(name string, perm os.FileMode) error
    func (u *CopyOnWriteFs) MkdirAll(name string, perm os.FileMode) error
    func (u *CopyOnWriteFs) Name() string
    func (u *CopyOnWriteFs) Open(name string) (File, error)
    func (u *CopyOnWriteFs) OpenFile(name string, flag int, perm os.FileMode) (File, error)
    func (u *CopyOnWriteFs) ReadlinkIfPossible(name string) (string, error)
    func (u *CopyOnWriteFs) Remove(name string) error
    func (u *CopyOnWriteFs) RemoveAll(name string) error
    func (u *CopyOnWriteFs) Rename(oldname, newname string) error
    func (u *CopyOnWriteFs) Stat(name string) (os.FileInfo, error)
    func (u *CopyOnWriteFs) SymlinkIfPossible(oldname, newname string) error
type DirsMerger
type File
    func TempFile(fs Fs, dir, pattern string) (f File, err error)
type FromIOFS
    func (f FromIOFS) Chmod(name string, mode os.FileMode) error
    func (f FromIOFS) Chown(name string, uid, gid int) error
    func (f FromIOFS) Chtimes(name string, atime time.Time, mtime time.Time) error
    func (f FromIOFS) Create(name string) (File, error)
    func (f FromIOFS) Mkdir(name string, perm os.FileMode) error
    func (f FromIOFS) MkdirAll(path string, perm os.FileMode) error
    func (f FromIOFS) Name() string
    func (f FromIOFS) Open(name string) (File, error)
    func (f FromIOFS) OpenFile(name string, flag int, perm os.FileMode) (File, error)
    func (f FromIOFS) Remove(name string) error
    func (f FromIOFS) RemoveAll(path string) error
    func (f FromIOFS) Rename(oldname, newname string) error
    func (f FromIOFS) Stat(name string) (os.FileInfo, error)
type Fs
    func NewBasePathFs(source Fs, path string) Fs
    func NewCacheOnReadFs(base Fs, layer Fs, cacheTime time.Duration) Fs
    func NewCopyOnWriteFs(base Fs, layer Fs) Fs
    func NewMemMapFs() Fs
    func NewOsFs() Fs
    func NewReadOnlyFs(source Fs) Fs
    func NewRegexpFs(source Fs, re *regexp.Regexp) Fs
type HttpFs
    func NewHttpFs(source Fs) *HttpFs
    func (h HttpFs) Chmod(name string, mode os.FileMode) error
    func (h HttpFs) Chown(name string, uid, gid int) error
    func (h HttpFs) Chtimes(name string, atime time.Time, mtime time.Time) error
    func (h HttpFs) Create(name string) (File, error)
    func (h HttpFs) Dir(s string) *httpDir
    func (h HttpFs) Mkdir(name string, perm os.FileMode) error
    func (h HttpFs) MkdirAll(path string, perm os.FileMode) error
    func (h HttpFs) Name() string
    func (h HttpFs) Open(name string) (http.File, error)
    func (h HttpFs) OpenFile(name string, flag int, perm os.FileMode) (File, error)
    func (h HttpFs) Remove(name string) error
    func (h HttpFs) RemoveAll(path string) error
    func (h HttpFs) Rename(oldname, newname string) error
    func (h HttpFs) Stat(name string) (os.FileInfo, error)
type IOFS
    func NewIOFS(fs Fs) IOFS
    func (iofs IOFS) Glob(pattern string) ([]string, error)
    func (iofs IOFS) Open(name string) (fs.File, error)
    func (iofs IOFS) ReadDir(name string) ([]fs.DirEntry, error)
    func (iofs IOFS) ReadFile(name string) ([]byte, error)
    func (iofs IOFS) Sub(dir string) (fs.FS, error)
type LinkReader
type Linker
type Lstater
type MemMapFs
    func (m *MemMapFs) Chmod(name string, mode os.FileMode) error
    func (m *MemMapFs) Chown(name string, uid, gid int) error
    func (m *MemMapFs) Chtimes(name string, atime time.Time, mtime time.Time) error
    func (m *MemMapFs) Create(name string) (File, error)
    func (m *MemMapFs) List()
    func (m *MemMapFs) LstatIfPossible(name string) (os.FileInfo, bool, error)
    func (m *MemMapFs) Mkdir(name string, perm os.FileMode) error
    func (m *MemMapFs) MkdirAll(path string, perm os.FileMode) error
    func (*MemMapFs) Name() string
    func (m *MemMapFs) Open(name string) (File, error)
    func (m *MemMapFs) OpenFile(name string, flag int, perm os.FileMode) (File, error)
    func (m *MemMapFs) Remove(name string) error
    func (m *MemMapFs) RemoveAll(path string) error
    func (m *MemMapFs) Rename(oldname, newname string) error
    func (m *MemMapFs) Stat(name string) (os.FileInfo, error)
type OsFs
    func (OsFs) Chmod(name string, mode os.FileMode) error
    func (OsFs) Chown(name string, uid, gid int) error
    func (OsFs) Chtimes(name string, atime time.Time, mtime time.Time) error
    func (OsFs) Create(name string) (File, error)
    func (OsFs) LstatIfPossible(name string) (os.FileInfo, bool, error)
    func (OsFs) Mkdir(name string, perm os.FileMode) error
    func (OsFs) MkdirAll(path string, perm os.FileMode) error
    func (OsFs) Name() string
    func (OsFs) Open(name string) (File, error)
    func (OsFs) OpenFile(name string, flag int, perm os.FileMode) (File, error)
    func (OsFs) ReadlinkIfPossible(name string) (string, error)
    func (OsFs) Remove(name string) error
    func (OsFs) RemoveAll(path string) error
    func (OsFs) Rename(oldname, newname string) error
    func (OsFs) Stat(name string) (os.FileInfo, error)
    func (OsFs) SymlinkIfPossible(oldname, newname string) error
type ReadOnlyFs
    func (r *ReadOnlyFs) Chmod(n string, m os.FileMode) error
    func (r *ReadOnlyFs) Chown(n string, uid, gid int) error
    func (r *ReadOnlyFs) Chtimes(n string, a, m time.Time) error
    func (r *ReadOnlyFs) Create(n string) (File, error)
    func (r *ReadOnlyFs) LstatIfPossible(name string) (os.FileInfo, bool, error)
    func (r *ReadOnlyFs) Mkdir(n string, p os.FileMode) error
    func (r *ReadOnlyFs) MkdirAll(n string, p os.FileMode) error
    func (r *ReadOnlyFs) Name() string
    func (r *ReadOnlyFs) Open(n string) (File, error)
    func (r *ReadOnlyFs) OpenFile(name string, flag int, perm os.FileMode) (File, error)
    func (r *ReadOnlyFs) ReadDir(name string) ([]os.FileInfo, error)
    func (r *ReadOnlyFs) ReadlinkIfPossible(name string) (string, error)
    func (r *ReadOnlyFs) Remove(n string) error
    func (r *ReadOnlyFs) RemoveAll(p string) error
    func (r *ReadOnlyFs) Rename(o, n string) error
    func (r *ReadOnlyFs) Stat(name string) (os.FileInfo, error)
    func (r *ReadOnlyFs) SymlinkIfPossible(oldname, newname string) error
type RegexpFile
    func (f *RegexpFile) Close() error
    func (f *RegexpFile) Name() string
    func (f *RegexpFile) Read(s []byte) (int, error)
    func (f *RegexpFile) ReadAt(s []byte, o int64) (int, error)
    func (f *RegexpFile) Readdir(c int) (fi []os.FileInfo, err error)
    func (f *RegexpFile) Readdirnames(c int) (n []string, err error)
    func (f *RegexpFile) Seek(o int64, w int) (int64, error)
    func (f *RegexpFile) Stat() (os.FileInfo, error)
    func (f *RegexpFile) Sync() error
    func (f *RegexpFile) Truncate(s int64) error
    func (f *RegexpFile) Write(s []byte) (int, error)
    func (f *RegexpFile) WriteAt(s []byte, o int64) (int, error)
    func (f *RegexpFile) WriteString(s string) (int, error)
type RegexpFs
    func (r *RegexpFs) Chmod(name string, mode os.FileMode) error
    func (r *RegexpFs) Chown(name string, uid, gid int) error
    func (r *RegexpFs) Chtimes(name string, a, m time.Time) error
    func (r *RegexpFs) Create(name string) (File, error)
    func (r *RegexpFs) Mkdir(n string, p os.FileMode) error
    func (r *RegexpFs) MkdirAll(n string, p os.FileMode) error
    func (r *RegexpFs) Name() string
    func (r *RegexpFs) Open(name string) (File, error)
    func (r *RegexpFs) OpenFile(name string, flag int, perm os.FileMode) (File, error)
    func (r *RegexpFs) Remove(name string) error
    func (r *RegexpFs) RemoveAll(p string) error
    func (r *RegexpFs) Rename(oldname, newname string) error
    func (r *RegexpFs) Stat(name string) (os.FileInfo, error)
type Symlinker
type UnionFile
    func (f *UnionFile) Close() error
    func (f *UnionFile) Name() string
    func (f *UnionFile) Read(s []byte) (int, error)
    func (f *UnionFile) ReadAt(s []byte, o int64) (int, error)
    func (f *UnionFile) Readdir(c int) (ofi []os.FileInfo, err error)
    func (f *UnionFile) Readdirnames(c int) ([]string, error)
    func (f *UnionFile) Seek(o int64, w int) (pos int64, err error)
    func (f *UnionFile) Stat() (os.FileInfo, error)
    func (f *UnionFile) Sync() (err error)
    func (f *UnionFile) Truncate(s int64) (err error)
    func (f *UnionFile) Write(s []byte) (n int, err error)
    func (f *UnionFile) WriteAt(s []byte, o int64) (n int, err error)
    func (f *UnionFile) WriteString(s string) (n int, err error)

Package files

afero.go basepath.go cacheOnReadFs.go const_win_unix.go copyOnWriteFs.go httpFs.go iofs.go ioutil.go lstater.go match.go memmap.go os.go path.go readonlyfs.go regexpfs.go symlink.go unionFile.go util.go

Constants

const BADFD = syscall.EBADFD

Filepath separator defined by os.Separator.

const FilePathSeparator = string(filepath.Separator)

Variables

var (
    ErrFileClosed        = errors.New("File is closed")
    ErrOutOfRange        = errors.New("out of range")
    ErrTooLarge          = errors.New("too large")
    ErrFileNotFound      = os.ErrNotExist
    ErrFileExists        = os.ErrExist
    ErrDestinationExists = os.ErrExist
)

ErrNoReadlink is the error that will be wrapped in an os.Path if a file system does not support the readlink operation either directly or through its delegated filesystem. As expressed by support for the LinkReader interface.

var ErrNoReadlink = errors.New("readlink not supported")

ErrNoSymlink is the error that will be wrapped in an os.LinkError if a file system does not support Symlink's either directly or through its delegated filesystem. As expressed by support for the Linker interface.

var ErrNoSymlink = errors.New("symlink not supported")

func DirExists

func DirExists(fs Fs, path string) (bool, error)

DirExists checks if a path exists and is a directory.

func Exists

func Exists(fs Fs, path string) (bool, error)

Check if a file or directory exists.

func FileContainsAnyBytes

func FileContainsAnyBytes(fs Fs, filename string, subslices [][]byte) (bool, error)

Check if a file contains any of the specified byte slices.

func FileContainsBytes

func FileContainsBytes(fs Fs, filename string, subslice []byte) (bool, error)

Check if a file contains a specified byte slice.

func FullBaseFsPath

func FullBaseFsPath(basePathFs *BasePathFs, relativePath string) string

func GetTempDir

func GetTempDir(fs Fs, subPath string) string

GetTempDir returns the default temp directory with trailing slash if subPath is not empty then it will be created recursively with mode 777 rwx rwx rwx

func Glob

func Glob(fs Fs, pattern string) (matches []string, err error)

Glob returns the names of all files matching pattern or nil if there is no matching file. The syntax of patterns is the same as in Match. The pattern may describe hierarchical names such as /usr/*/bin/ed (assuming the Separator is '/').

Glob ignores file system errors such as I/O errors reading directories. The only possible returned error is ErrBadPattern, when pattern is malformed.

This was adapted from (http://golang.org/pkg/path/filepath) and uses several built-ins from that package.

func IsDir

func IsDir(fs Fs, path string) (bool, error)

IsDir checks if a given path is a directory.

func IsEmpty

func IsEmpty(fs Fs, path string) (bool, error)

IsEmpty checks if a given file or directory is empty.

func NeuterAccents

func NeuterAccents(s string) string

Transform characters with accents into plain forms.

func ReadAll

func ReadAll(r io.Reader) ([]byte, error)

ReadAll reads from r until an error or EOF and returns the data it read. A successful call returns err == nil, not err == EOF. Because ReadAll is defined to read from src until EOF, it does not treat an EOF from Read as an error to be reported.

func ReadDir

func ReadDir(fs Fs, dirname string) ([]os.FileInfo, error)

func ReadFile

func ReadFile(fs Fs, filename string) ([]byte, error)

func SafeWriteReader

func SafeWriteReader(fs Fs, path string, r io.Reader) (err error)

func TempDir

func TempDir(fs Fs, dir, prefix string) (name string, err error)

func UnicodeSanitize

func UnicodeSanitize(s string) string

Rewrite string to remove non-standard path characters

func Walk

func Walk(fs Fs, root string, walkFn filepath.WalkFunc) error

func WriteFile

func WriteFile(fs Fs, filename string, data []byte, perm os.FileMode) error

func WriteReader

func WriteReader(fs Fs, path string, r io.Reader) (err error)

type Afero

type Afero struct {
    Fs
}

func (Afero) DirExists

func (a Afero) DirExists(path string) (bool, error)

func (Afero) Exists

func (a Afero) Exists(path string) (bool, error)

func (Afero) FileContainsAnyBytes

func (a Afero) FileContainsAnyBytes(filename string, subslices [][]byte) (bool, error)

func (Afero) FileContainsBytes

func (a Afero) FileContainsBytes(filename string, subslice []byte) (bool, error)

func (Afero) GetTempDir

func (a Afero) GetTempDir(subPath string) string

func (Afero) IsDir

func (a Afero) IsDir(path string) (bool, error)

func (Afero) IsEmpty

func (a Afero) IsEmpty(path string) (bool, error)

func (Afero) ReadDir

func (a Afero) ReadDir(dirname string) ([]os.FileInfo, error)

ReadDir reads the directory named by dirname and returns a list of sorted directory entries.

func (Afero) ReadFile

func (a Afero) ReadFile(filename string) ([]byte, error)

ReadFile reads the file named by filename and returns the contents. A successful call returns err == nil, not err == EOF. Because ReadFile reads the whole file, it does not treat an EOF from Read as an error to be reported.

func (Afero) SafeWriteReader

func (a Afero) SafeWriteReader(path string, r io.Reader) (err error)

Same as WriteReader but checks to see if file/directory already exists.

func (Afero) TempDir

func (a Afero) TempDir(dir, prefix string) (name string, err error)

TempDir creates a new temporary directory in the directory dir with a name beginning with prefix and returns the path of the new directory. If dir is the empty string, TempDir uses the default directory for temporary files (see os.TempDir). Multiple programs calling TempDir simultaneously will not choose the same directory. It is the caller's responsibility to remove the directory when no longer needed.

func (Afero) TempFile

func (a Afero) TempFile(dir, pattern string) (f File, err error)

TempFile creates a new temporary file in the directory dir, opens the file for reading and writing, and returns the resulting *os.File. The filename is generated by taking pattern and adding a random string to the end. If pattern includes a "*", the random string replaces the last "*". If dir is the empty string, TempFile uses the default directory for temporary files (see os.TempDir). Multiple programs calling TempFile simultaneously will not choose the same file. The caller can use f.Name() to find the pathname of the file. It is the caller's responsibility to remove the file when no longer needed.

func (Afero) Walk

func (a Afero) Walk(root string, walkFn filepath.WalkFunc) error

func (Afero) WriteFile

func (a Afero) WriteFile(filename string, data []byte, perm os.FileMode) error

WriteFile writes data to a file named by filename. If the file does not exist, WriteFile creates it with permissions perm; otherwise WriteFile truncates it before writing.

func (Afero) WriteReader

func (a Afero) WriteReader(path string, r io.Reader) (err error)

Takes a reader and a path and writes the content

type BasePathFile

type BasePathFile struct {
    File
    // contains filtered or unexported fields
}

func (*BasePathFile) Name

func (f *BasePathFile) Name() string

func (*BasePathFile) ReadDir

func (f *BasePathFile) ReadDir(n int) ([]fs.DirEntry, error)

type BasePathFs

The BasePathFs restricts all operations to a given path within an Fs. The given file name to the operations on this Fs will be prepended with the base path before calling the base Fs. Any file name (after filepath.Clean()) outside this base path will be treated as non existing file.

Note that it does not clean the error messages on return, so you may reveal the real path on errors.

type BasePathFs struct {
    // contains filtered or unexported fields
}

func (*BasePathFs) Chmod

func (b *BasePathFs) Chmod(name string, mode os.FileMode) (err error)

func (*BasePathFs) Chown

func (b *BasePathFs) Chown(name string, uid, gid int) (err error)

func (*BasePathFs) Chtimes

func (b *BasePathFs) Chtimes(name string, atime, mtime time.Time) (err error)

func (*BasePathFs) Create

func (b *BasePathFs) Create(name string) (f File, err error)

func (*BasePathFs) LstatIfPossible

func (b *BasePathFs) LstatIfPossible(name string) (os.FileInfo, bool, error)

func (*BasePathFs) Mkdir

func (b *BasePathFs) Mkdir(name string, mode os.FileMode) (err error)

func (*BasePathFs) MkdirAll

func (b *BasePathFs) MkdirAll(name string, mode os.FileMode) (err error)

func (*BasePathFs) Name

func (b *BasePathFs) Name() string

func (*BasePathFs) Open

func (b *BasePathFs) Open(name string) (f File, err error)

func (*BasePathFs) OpenFile

func (b *BasePathFs) OpenFile(name string, flag int, mode os.FileMode) (f File, err error)

func (*BasePathFs) ReadlinkIfPossible

func (b *BasePathFs) ReadlinkIfPossible(name string) (string, error)

func (*BasePathFs) RealPath

func (b *BasePathFs) RealPath(name string) (path string, err error)

on a file outside the base path it returns the given file name and an error, else the given file with the base path prepended

func (*BasePathFs) Remove

func (b *BasePathFs) Remove(name string) (err error)

func (*BasePathFs) RemoveAll

func (b *BasePathFs) RemoveAll(name string) (err error)

func (*BasePathFs) Rename

func (b *BasePathFs) Rename(oldname, newname string) (err error)

func (*BasePathFs) Stat

func (b *BasePathFs) Stat(name string) (fi os.FileInfo, err error)

func (*BasePathFs) SymlinkIfPossible

func (b *BasePathFs) SymlinkIfPossible(oldname, newname string) error

type CacheOnReadFs

If the cache duration is 0, cache time will be unlimited, i.e. once a file is in the layer, the base will never be read again for this file.

For cache times greater than 0, the modification time of a file is checked. Note that a lot of file system implementations only allow a resolution of a second for timestamps... or as the godoc for os.Chtimes() states: "The underlying filesystem may truncate or round the values to a less precise time unit."

This caching union will forward all write calls also to the base file system first. To prevent writing to the base Fs, wrap it in a read-only filter - Note: this will also make the overlay read-only, for writing files in the overlay, use the overlay Fs directly, not via the union Fs.

type CacheOnReadFs struct {
    // contains filtered or unexported fields
}

func (*CacheOnReadFs) Chmod

func (u *CacheOnReadFs) Chmod(name string, mode os.FileMode) error

func (*CacheOnReadFs) Chown

func (u *CacheOnReadFs) Chown(name string, uid, gid int) error

func (*CacheOnReadFs) Chtimes

func (u *CacheOnReadFs) Chtimes(name string, atime, mtime time.Time) error

func (*CacheOnReadFs) Create

func (u *CacheOnReadFs) Create(name string) (File, error)

func (*CacheOnReadFs) Mkdir

func (u *CacheOnReadFs) Mkdir(name string, perm os.FileMode) error

func (*CacheOnReadFs) MkdirAll

func (u *CacheOnReadFs) MkdirAll(name string, perm os.FileMode) error

func (*CacheOnReadFs) Name

func (u *CacheOnReadFs) Name() string

func (*CacheOnReadFs) Open

func (u *CacheOnReadFs) Open(name string) (File, error)

func (*CacheOnReadFs) OpenFile

func (u *CacheOnReadFs) OpenFile(name string, flag int, perm os.FileMode) (File, error)

func (*CacheOnReadFs) Remove

func (u *CacheOnReadFs) Remove(name string) error

func (*CacheOnReadFs) RemoveAll

func (u *CacheOnReadFs) RemoveAll(name string) error

func (*CacheOnReadFs) Rename

func (u *CacheOnReadFs) Rename(oldname, newname string) error

func (*CacheOnReadFs) Stat

func (u *CacheOnReadFs) Stat(name string) (os.FileInfo, error)

type CopyOnWriteFs

The CopyOnWriteFs is a union filesystem: a read only base file system with a possibly writeable layer on top. Changes to the file system will only be made in the overlay: Changing an existing file in the base layer which is not present in the overlay will copy the file to the overlay ("changing" includes also calls to e.g. Chtimes(), Chmod() and Chown()).

Reading directories is currently only supported via Open(), not OpenFile().

type CopyOnWriteFs struct {
    // contains filtered or unexported fields
}

func (*CopyOnWriteFs) Chmod

func (u *CopyOnWriteFs) Chmod(name string, mode os.FileMode) error

func (*CopyOnWriteFs) Chown

func (u *CopyOnWriteFs) Chown(name string, uid, gid int) error

func (*CopyOnWriteFs) Chtimes

func (u *CopyOnWriteFs) Chtimes(name string, atime, mtime time.Time) error

func (*CopyOnWriteFs) Create

func (u *CopyOnWriteFs) Create(name string) (File, error)

func (*CopyOnWriteFs) LstatIfPossible

func (u *CopyOnWriteFs) LstatIfPossible(name string) (os.FileInfo, bool, error)

func (*CopyOnWriteFs) Mkdir

func (u *CopyOnWriteFs) Mkdir(name string, perm os.FileMode) error

func (*CopyOnWriteFs) MkdirAll

func (u *CopyOnWriteFs) MkdirAll(name string, perm os.FileMode) error

func (*CopyOnWriteFs) Name

func (u *CopyOnWriteFs) Name() string

func (*CopyOnWriteFs) Open

func (u *CopyOnWriteFs) Open(name string) (File, error)

This function handles the 9 different possibilities caused by the union which are the intersection of the following...

layer: doesn't exist, exists as a file, and exists as a directory
base:  doesn't exist, exists as a file, and exists as a directory

func (*CopyOnWriteFs) OpenFile

func (u *CopyOnWriteFs) OpenFile(name string, flag int, perm os.FileMode) (File, error)

func (*CopyOnWriteFs) ReadlinkIfPossible

func (u *CopyOnWriteFs) ReadlinkIfPossible(name string) (string, error)

func (*CopyOnWriteFs) Remove

func (u *CopyOnWriteFs) Remove(name string) error

Removing files present only in the base layer is not permitted. If a file is present in the base layer and the overlay, only the overlay will be removed.

func (*CopyOnWriteFs) RemoveAll

func (u *CopyOnWriteFs) RemoveAll(name string) error

func (*CopyOnWriteFs) Rename

func (u *CopyOnWriteFs) Rename(oldname, newname string) error

Renaming files present only in the base layer is not permitted

func (*CopyOnWriteFs) Stat

func (u *CopyOnWriteFs) Stat(name string) (os.FileInfo, error)

func (*CopyOnWriteFs) SymlinkIfPossible

func (u *CopyOnWriteFs) SymlinkIfPossible(oldname, newname string) error

type DirsMerger

DirsMerger is how UnionFile weaves two directories together. It takes the FileInfo slices from the layer and the base and returns a single view.

type DirsMerger func(lofi, bofi []os.FileInfo) ([]os.FileInfo, error)

type File

File represents a file in the filesystem.

type File interface {
    io.Closer
    io.Reader
    io.ReaderAt
    io.Seeker
    io.Writer
    io.WriterAt

    Name() string
    Readdir(count int) ([]os.FileInfo, error)
    Readdirnames(n int) ([]string, error)
    Stat() (os.FileInfo, error)
    Sync() error
    Truncate(size int64) error
    WriteString(s string) (ret int, err error)
}

func TempFile

func TempFile(fs Fs, dir, pattern string) (f File, err error)

type FromIOFS

FromIOFS adopts io/fs.FS to use it as afero.Fs Note that io/fs.FS is read-only so all mutating methods will return fs.PathError with fs.ErrPermission To store modifications you may use afero.CopyOnWriteFs

type FromIOFS struct {
    fs.FS
}

func (FromIOFS) Chmod

func (f FromIOFS) Chmod(name string, mode os.FileMode) error

func (FromIOFS) Chown

func (f FromIOFS) Chown(name string, uid, gid int) error

func (FromIOFS) Chtimes

func (f FromIOFS) Chtimes(name string, atime time.Time, mtime time.Time) error

func (FromIOFS) Create

func (f FromIOFS) Create(name string) (File, error)

func (FromIOFS) Mkdir

func (f FromIOFS) Mkdir(name string, perm os.FileMode) error

func (FromIOFS) MkdirAll

func (f FromIOFS) MkdirAll(path string, perm os.FileMode) error

func (FromIOFS) Name

func (f FromIOFS) Name() string

func (FromIOFS) Open

func (f FromIOFS) Open(name string) (File, error)

func (FromIOFS) OpenFile

func (f FromIOFS) OpenFile(name string, flag int, perm os.FileMode) (File, error)

func (FromIOFS) Remove

func (f FromIOFS) Remove(name string) error

func (FromIOFS) RemoveAll

func (f FromIOFS) RemoveAll(path string) error

func (FromIOFS) Rename

func (f FromIOFS) Rename(oldname, newname string) error

func (FromIOFS) Stat

func (f FromIOFS) Stat(name string) (os.FileInfo, error)

type Fs

Fs is the filesystem interface.

Any simulated or real filesystem should implement this interface.

type Fs interface {
    // Create creates a file in the filesystem, returning the file and an
    // error, if any happens.
    Create(name string) (File, error)

    // Mkdir creates a directory in the filesystem, return an error if any
    // happens.
    Mkdir(name string, perm os.FileMode) error

    // MkdirAll creates a directory path and all parents that does not exist
    // yet.
    MkdirAll(path string, perm os.FileMode) error

    // Open opens a file, returning it or an error, if any happens.
    Open(name string) (File, error)

    // OpenFile opens a file using the given flags and the given mode.
    OpenFile(name string, flag int, perm os.FileMode) (File, error)

    // Remove removes a file identified by name, returning an error, if any
    // happens.
    Remove(name string) error

    // RemoveAll removes a directory path and any children it contains. It
    // does not fail if the path does not exist (return nil).
    RemoveAll(path string) error

    // Rename renames a file.
    Rename(oldname, newname string) error

    // Stat returns a FileInfo describing the named file, or an error, if any
    // happens.
    Stat(name string) (os.FileInfo, error)

    // The name of this FileSystem
    Name() string

    // Chmod changes the mode of the named file to mode.
    Chmod(name string, mode os.FileMode) error

    // Chown changes the uid and gid of the named file.
    Chown(name string, uid, gid int) error

    // Chtimes changes the access and modification times of the named file
    Chtimes(name string, atime time.Time, mtime time.Time) error
}

func NewBasePathFs

func NewBasePathFs(source Fs, path string) Fs

func NewCacheOnReadFs

func NewCacheOnReadFs(base Fs, layer Fs, cacheTime time.Duration) Fs

func NewCopyOnWriteFs

func NewCopyOnWriteFs(base Fs, layer Fs) Fs

func NewMemMapFs

func NewMemMapFs() Fs

func NewOsFs

func NewOsFs() Fs

func NewReadOnlyFs

func NewReadOnlyFs(source Fs) Fs

func NewRegexpFs

func NewRegexpFs(source Fs, re *regexp.Regexp) Fs

type HttpFs

type HttpFs struct {
    // contains filtered or unexported fields
}

func NewHttpFs

func NewHttpFs(source Fs) *HttpFs

func (HttpFs) Chmod

func (h HttpFs) Chmod(name string, mode os.FileMode) error

func (HttpFs) Chown

func (h HttpFs) Chown(name string, uid, gid int) error

func (HttpFs) Chtimes

func (h HttpFs) Chtimes(name string, atime time.Time, mtime time.Time) error

func (HttpFs) Create

func (h HttpFs) Create(name string) (File, error)

func (HttpFs) Dir

func (h HttpFs) Dir(s string) *httpDir

func (HttpFs) Mkdir

func (h HttpFs) Mkdir(name string, perm os.FileMode) error

func (HttpFs) MkdirAll

func (h HttpFs) MkdirAll(path string, perm os.FileMode) error

func (HttpFs) Name

func (h HttpFs) Name() string

func (HttpFs) Open

func (h HttpFs) Open(name string) (http.File, error)

func (HttpFs) OpenFile

func (h HttpFs) OpenFile(name string, flag int, perm os.FileMode) (File, error)

func (HttpFs) Remove

func (h HttpFs) Remove(name string) error

func (HttpFs) RemoveAll

func (h HttpFs) RemoveAll(path string) error

func (HttpFs) Rename

func (h HttpFs) Rename(oldname, newname string) error

func (HttpFs) Stat

func (h HttpFs) Stat(name string) (os.FileInfo, error)

type IOFS

IOFS adopts afero.Fs to stdlib io/fs.FS

type IOFS struct {
    Fs
}

func NewIOFS

func NewIOFS(fs Fs) IOFS

func (IOFS) Glob

func (iofs IOFS) Glob(pattern string) ([]string, error)

func (IOFS) Open

func (iofs IOFS) Open(name string) (fs.File, error)

func (IOFS) ReadDir

func (iofs IOFS) ReadDir(name string) ([]fs.DirEntry, error)

func (IOFS) ReadFile

func (iofs IOFS) ReadFile(name string) ([]byte, error)

func (IOFS) Sub

func (iofs IOFS) Sub(dir string) (fs.FS, error)

type LinkReader

LinkReader is an optional interface in Afero. It is only implemented by the filesystems saying so.

type LinkReader interface {
    ReadlinkIfPossible(name string) (string, error)
}

type Linker

Linker is an optional interface in Afero. It is only implemented by the filesystems saying so. It will call Symlink if the filesystem itself is, or it delegates to, the os filesystem, or the filesystem otherwise supports Symlink's.

type Linker interface {
    SymlinkIfPossible(oldname, newname string) error
}

type Lstater

Lstater is an optional interface in Afero. It is only implemented by the filesystems saying so. It will call Lstat if the filesystem iself is, or it delegates to, the os filesystem. Else it will call Stat. In addtion to the FileInfo, it will return a boolean telling whether Lstat was called or not.

type Lstater interface {
    LstatIfPossible(name string) (os.FileInfo, bool, error)
}

type MemMapFs

type MemMapFs struct {
    // contains filtered or unexported fields
}

func (*MemMapFs) Chmod

func (m *MemMapFs) Chmod(name string, mode os.FileMode) error

func (*MemMapFs) Chown

func (m *MemMapFs) Chown(name string, uid, gid int) error

func (*MemMapFs) Chtimes

func (m *MemMapFs) Chtimes(name string, atime time.Time, mtime time.Time) error

func (*MemMapFs) Create

func (m *MemMapFs) Create(name string) (File, error)

func (*MemMapFs) List

func (m *MemMapFs) List()

func (*MemMapFs) LstatIfPossible

func (m *MemMapFs) LstatIfPossible(name string) (os.FileInfo, bool, error)

func (*MemMapFs) Mkdir

func (m *MemMapFs) Mkdir(name string, perm os.FileMode) error

func (*MemMapFs) MkdirAll

func (m *MemMapFs) MkdirAll(path string, perm os.FileMode) error

func (*MemMapFs) Name

func (*MemMapFs) Name() string

func (*MemMapFs) Open

func (m *MemMapFs) Open(name string) (File, error)

func (*MemMapFs) OpenFile

func (m *MemMapFs) OpenFile(name string, flag int, perm os.FileMode) (File, error)

func (*MemMapFs) Remove

func (m *MemMapFs) Remove(name string) error

func (*MemMapFs) RemoveAll

func (m *MemMapFs) RemoveAll(path string) error

func (*MemMapFs) Rename

func (m *MemMapFs) Rename(oldname, newname string) error

func (*MemMapFs) Stat

func (m *MemMapFs) Stat(name string) (os.FileInfo, error)

type OsFs

OsFs is a Fs implementation that uses functions provided by the os package.

For details in any method, check the documentation of the os package (http://golang.org/pkg/os/).

type OsFs struct{}

func (OsFs) Chmod

func (OsFs) Chmod(name string, mode os.FileMode) error

func (OsFs) Chown

func (OsFs) Chown(name string, uid, gid int) error

func (OsFs) Chtimes

func (OsFs) Chtimes(name string, atime time.Time, mtime time.Time) error

func (OsFs) Create

func (OsFs) Create(name string) (File, error)

func (OsFs) LstatIfPossible

func (OsFs) LstatIfPossible(name string) (os.FileInfo, bool, error)

func (OsFs) Mkdir

func (OsFs) Mkdir(name string, perm os.FileMode) error

func (OsFs) MkdirAll

func (OsFs) MkdirAll(path string, perm os.FileMode) error

func (OsFs) Name

func (OsFs) Name() string

func (OsFs) Open

func (OsFs) Open(name string) (File, error)

func (OsFs) OpenFile

func (OsFs) OpenFile(name string, flag int, perm os.FileMode) (File, error)

func (OsFs) ReadlinkIfPossible

func (OsFs) ReadlinkIfPossible(name string) (string, error)

func (OsFs) Remove

func (OsFs) Remove(name string) error

func (OsFs) RemoveAll

func (OsFs) RemoveAll(path string) error

func (OsFs) Rename

func (OsFs) Rename(oldname, newname string) error

func (OsFs) Stat

func (OsFs) Stat(name string) (os.FileInfo, error)

func (OsFs) SymlinkIfPossible

func (OsFs) SymlinkIfPossible(oldname, newname string) error

type ReadOnlyFs

type ReadOnlyFs struct {
    // contains filtered or unexported fields
}

func (*ReadOnlyFs) Chmod

func (r *ReadOnlyFs) Chmod(n string, m os.FileMode) error

func (*ReadOnlyFs) Chown

func (r *ReadOnlyFs) Chown(n string, uid, gid int) error

func (*ReadOnlyFs) Chtimes

func (r *ReadOnlyFs) Chtimes(n string, a, m time.Time) error

func (*ReadOnlyFs) Create

func (r *ReadOnlyFs) Create(n string) (File, error)

func (*ReadOnlyFs) LstatIfPossible

func (r *ReadOnlyFs) LstatIfPossible(name string) (os.FileInfo, bool, error)

func (*ReadOnlyFs) Mkdir

func (r *ReadOnlyFs) Mkdir(n string, p os.FileMode) error

func (*ReadOnlyFs) MkdirAll

func (r *ReadOnlyFs) MkdirAll(n string, p os.FileMode) error

func (*ReadOnlyFs) Name

func (r *ReadOnlyFs) Name() string

func (*ReadOnlyFs) Open

func (r *ReadOnlyFs) Open(n string) (File, error)

func (*ReadOnlyFs) OpenFile

func (r *ReadOnlyFs) OpenFile(name string, flag int, perm os.FileMode) (File, error)

func (*ReadOnlyFs) ReadDir

func (r *ReadOnlyFs) ReadDir(name string) ([]os.FileInfo, error)

func (*ReadOnlyFs) ReadlinkIfPossible

func (r *ReadOnlyFs) ReadlinkIfPossible(name string) (string, error)

func (*ReadOnlyFs) Remove

func (r *ReadOnlyFs) Remove(n string) error

func (*ReadOnlyFs) RemoveAll

func (r *ReadOnlyFs) RemoveAll(p string) error

func (*ReadOnlyFs) Rename

func (r *ReadOnlyFs) Rename(o, n string) error

func (*ReadOnlyFs) Stat

func (r *ReadOnlyFs) Stat(name string) (os.FileInfo, error)

func (*ReadOnlyFs) SymlinkIfPossible

func (r *ReadOnlyFs) SymlinkIfPossible(oldname, newname string) error

type RegexpFile

type RegexpFile struct {
    // contains filtered or unexported fields
}

func (*RegexpFile) Close

func (f *RegexpFile) Close() error

func (*RegexpFile) Name

func (f *RegexpFile) Name() string

func (*RegexpFile) Read

func (f *RegexpFile) Read(s []byte) (int, error)

func (*RegexpFile) ReadAt

func (f *RegexpFile) ReadAt(s []byte, o int64) (int, error)

func (*RegexpFile) Readdir

func (f *RegexpFile) Readdir(c int) (fi []os.FileInfo, err error)

func (*RegexpFile) Readdirnames

func (f *RegexpFile) Readdirnames(c int) (n []string, err error)

func (*RegexpFile) Seek

func (f *RegexpFile) Seek(o int64, w int) (int64, error)

func (*RegexpFile) Stat

func (f *RegexpFile) Stat() (os.FileInfo, error)

func (*RegexpFile) Sync

func (f *RegexpFile) Sync() error

func (*RegexpFile) Truncate

func (f *RegexpFile) Truncate(s int64) error

func (*RegexpFile) Write

func (f *RegexpFile) Write(s []byte) (int, error)

func (*RegexpFile) WriteAt

func (f *RegexpFile) WriteAt(s []byte, o int64) (int, error)

func (*RegexpFile) WriteString

func (f *RegexpFile) WriteString(s string) (int, error)

type RegexpFs

The RegexpFs filters files (not directories) by regular expression. Only files matching the given regexp will be allowed, all others get a ENOENT error ( "No such file or directory").

type RegexpFs struct {
    // contains filtered or unexported fields
}

func (*RegexpFs) Chmod

func (r *RegexpFs) Chmod(name string, mode os.FileMode) error

func (*RegexpFs) Chown

func (r *RegexpFs) Chown(name string, uid, gid int) error

func (*RegexpFs) Chtimes

func (r *RegexpFs) Chtimes(name string, a, m time.Time) error

func (*RegexpFs) Create

func (r *RegexpFs) Create(name string) (File, error)

func (*RegexpFs) Mkdir

func (r *RegexpFs) Mkdir(n string, p os.FileMode) error

func (*RegexpFs) MkdirAll

func (r *RegexpFs) MkdirAll(n string, p os.FileMode) error

func (*RegexpFs) Name

func (r *RegexpFs) Name() string

func (*RegexpFs) Open

func (r *RegexpFs) Open(name string) (File, error)

func (*RegexpFs) OpenFile

func (r *RegexpFs) OpenFile(name string, flag int, perm os.FileMode) (File, error)

func (*RegexpFs) Remove

func (r *RegexpFs) Remove(name string) error

func (*RegexpFs) RemoveAll

func (r *RegexpFs) RemoveAll(p string) error

func (*RegexpFs) Rename

func (r *RegexpFs) Rename(oldname, newname string) error

func (*RegexpFs) Stat

func (r *RegexpFs) Stat(name string) (os.FileInfo, error)

type Symlinker

Symlinker is an optional interface in Afero. It is only implemented by the filesystems saying so. It indicates support for 3 symlink related interfaces that implement the behaviors of the os methods:

type Symlinker interface {
    Lstater
    Linker
    LinkReader
}

type UnionFile

The UnionFile implements the afero.File interface and will be returned when reading a directory present at least in the overlay or opening a file for writing.

The calls to Readdir() and Readdirnames() merge the file os.FileInfo / names from the base and the overlay - for files present in both layers, only those from the overlay will be used.

When opening files for writing (Create() / OpenFile() with the right flags) the operations will be done in both layers, starting with the overlay. A successful read in the overlay will move the cursor position in the base layer by the number of bytes read.

type UnionFile struct {
    Base   File
    Layer  File
    Merger DirsMerger
    // contains filtered or unexported fields
}

func (*UnionFile) Close

func (f *UnionFile) Close() error

func (*UnionFile) Name

func (f *UnionFile) Name() string

func (*UnionFile) Read

func (f *UnionFile) Read(s []byte) (int, error)

func (*UnionFile) ReadAt

func (f *UnionFile) ReadAt(s []byte, o int64) (int, error)

func (*UnionFile) Readdir

func (f *UnionFile) Readdir(c int) (ofi []os.FileInfo, err error)

Readdir will weave the two directories together and return a single view of the overlayed directories. At the end of the directory view, the error is io.EOF if c > 0.

func (*UnionFile) Readdirnames

func (f *UnionFile) Readdirnames(c int) ([]string, error)

func (*UnionFile) Seek

func (f *UnionFile) Seek(o int64, w int) (pos int64, err error)

func (*UnionFile) Stat

func (f *UnionFile) Stat() (os.FileInfo, error)

func (*UnionFile) Sync

func (f *UnionFile) Sync() (err error)

func (*UnionFile) Truncate

func (f *UnionFile) Truncate(s int64) (err error)

func (*UnionFile) Write

func (f *UnionFile) Write(s []byte) (n int, err error)

func (*UnionFile) WriteAt

func (f *UnionFile) WriteAt(s []byte, o int64) (n int, err error)

func (*UnionFile) WriteString

func (f *UnionFile) WriteString(s string) (n int, err error)

Subdirectories

Name Synopsis
..
gcsfs
mem
sftpfs
tarfs package tarfs implements a read-only in-memory representation of a tar archive
zipfs