vfs

package
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 24, 2020 License: BSD-2-Clause Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type File

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

	// Readdir reads the contents of the directory associated with file and
	// returns a slice of up to n FileInfo values, as would be returned by
	// os.File.Readdir
	Readdir(count int) ([]os.FileInfo, error)
}

File represents a file

File provides a stripped down interface not as complete as os.File but are enough for my use cases. For that reason, some vfs provided in this package are not supercharged to provide correct feedback for os.File func that are not in File (for example Readdirnames is not adapted for filterfs or jailfs)

type VFS

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

VFS encapsulates operations provided to interact with the file-system

VFS functions are to be found in filepath.go and fsutil.go when they are "ported" from the standard library (path/filepath and os respectively).

func NewFilterfs

func NewFilterfs(validfn func(string) bool, wrappedfs *VFS) *VFS

NewFilterfs creates a new filterfs that relies on a validating function to allow or not access to file-system files depending on their name.

The validating function should, if appropriate, make sure that the forbidden name can be embedded in a full path name (filterfs does not take care of that). For example, disallowing access to hidden files should consider ".name", "folder/.name" and "folder/.name/file"

func NewJailfs

func NewJailfs(root string, wrappedfs *VFS) *VFS

NewJailfs creates a new composite Fs It does not check that root exists nor create it if it doesn't

func NewOsfs

func NewOsfs() *VFS

NewOsfs creates a vfs for the underlying os file-system

func NewReadonlyfs added in v0.3.0

func NewReadonlyfs(wrappedfs *VFS) *VFS

NewReadonlyfs creates a new composite read-only Fs.

func (*VFS) Copy added in v0.6.0

func (vfs *VFS) Copy(src io.Reader, dst string) (err error)

Copy copies a Reader content to a file within the vfs. dst file and its parent folders are create if they don't exist yet Copy does not prevent nor warn if dst is already existing

func (*VFS) Create

func (vfs *VFS) Create(name string) (File, error)

Create creates the named file mode 0666 (before umask) on the given filesystem, truncating it if it already exists. The associated file descriptor has mode os.O_RDWR. If there is an error, it will be of type *os.PathError.

"ported" from standard lib os.Create

func (*VFS) Exists

func (vfs *VFS) Exists(path string) (bool, error)

Exists checks if a file or directory exists

func (*VFS) MkdirAll

func (vfs *VFS) MkdirAll(path string, perm os.FileMode) error

MkdirAll creates a directory named path on the given filesystem, along with any necessary parents, and returns nil, or else returns an error. The permission bits perm are used for all directories that MkdirAll creates. If path is already a directory, MkdirAll does nothing and returns nil.

"ported" from standard lib os.MkdirAll

func (*VFS) Move

func (vfs *VFS) Move(src, dst string) error

Move moves a file or folder to a new location. If destination is in a non existing path, Move creates it first.

func (*VFS) Open

func (vfs *VFS) Open(name string) (File, error)

Open opens the named file on the given filesystem for reading. If successful, methods on the returned file can be used for reading. The associated file descriptor has mode os.O_RDONLY. If there is an error, it will be of type *PathError.

"ported" from standard lib os.Open

func (*VFS) RemoveAll

func (vfs *VFS) RemoveAll(path string) error

RemoveAll removes path and any children it contains. It removes everything it can but returns the first error it encounters. If the path does not exist, RemoveAll returns nil.

"ported" from standard lib os.RemoveAll

func (*VFS) Walk

func (vfs *VFS) Walk(root string, walkFn filepath.WalkFunc) error

Walk walks the file tree rooted at root, calling walkFn for each file or directory in the tree, including root. All errors that arise visiting files and directories are filtered by walkFn. The files are walked in lexical order, which makes the output deterministic but means that for very large directories Walk can be inefficient. Walk does not follow symbolic links.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL