vfs

package
v1.29.6 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2023 License: MPL-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package vfs represents a virtual filesystem

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Directory

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

Directory is a wrapper around directoryContents which stores the state needed to implement ReadDirFile

func (*Directory) Close

func (d *Directory) Close() error

func (*Directory) Info

func (d *Directory) Info() (fs.FileInfo, error)

func (*Directory) IsDir

func (d *Directory) IsDir() bool

func (*Directory) ModTime

func (d *Directory) ModTime() time.Time

func (*Directory) Mode

func (d *Directory) Mode() fs.FileMode

func (*Directory) Name

func (d *Directory) Name() string

func (*Directory) Read

func (d *Directory) Read(_ []byte) (int, error)

func (*Directory) ReadDir

func (d *Directory) ReadDir(n int) ([]fs.DirEntry, error)

ReadDir reads the contents of the directory and returns a slice of up to n DirEntry values in directory order. Subsequent calls on the same file will yield further DirEntry values.

If n > 0, ReadDir returns at most n DirEntry structures. In this case, if ReadDir returns an empty slice, it will return a non-nil error explaining why. At the end of a directory, the error is io.EOF.

If n <= 0, ReadDir returns all the DirEntry values from the directory in a single slice. In this case, if ReadDir succeeds (reads all the way to the end of the directory), it returns the slice and a nil error. If it encounters an error before the end of the directory, ReadDir returns the DirEntry list read until that point and a non-nil error.

func (*Directory) Size

func (d *Directory) Size() int64

func (*Directory) Stat

func (d *Directory) Stat() (fs.FileInfo, error)

func (*Directory) Sys

func (d *Directory) Sys() any

func (*Directory) Type

func (d *Directory) Type() fs.FileMode

type File

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

func (*File) Close

func (f *File) Close() error

func (*File) Info

func (f *File) Info() (fs.FileInfo, error)

func (*File) IsDir

func (f *File) IsDir() bool

func (*File) ModTime

func (f *File) ModTime() time.Time

func (*File) Mode

func (f *File) Mode() fs.FileMode

func (*File) Name

func (f *File) Name() string

func (*File) Read

func (f *File) Read(bytes []byte) (int, error)

Read implements io.Reader

func (*File) Size

func (f *File) Size() int64

func (*File) Stat

func (f *File) Stat() (fs.FileInfo, error)

func (*File) Sys

func (f *File) Sys() any

func (*File) Type

func (f *File) Type() fs.FileMode

type VFS

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

func FromDir

func FromDir(workingDir string, predicate func(fileName string, info fs.DirEntry) bool) (*VFS, error)

FromDir creates a Virtual File System (VFS) from the workingDir on the local computer

Only files or folders which match the predicate will be added into the file system A nil predicate will result in all files and folders being added into the file system

func New

func New() *VFS

func (*VFS) AddDir

func (v *VFS) AddDir(dirPath string) *directoryContents

AddDir records a directory into the VFS.

func (*VFS) AddFile

func (v *VFS) AddFile(path string, bytes []byte, time time.Time) (*fileContents, error)

AddFile records a file into the VFS

func (*VFS) Open

func (v *VFS) Open(name string) (fs.File, error)

Open opens the named file.

When Open returns an error, it should be of type *PathError with the Op field set to "open", the Path field set to name, and the Err field describing the problem.

Open should reject attempts to open names that do not satisfy ValidPath(name), returning a *PathError with Err set to ErrInvalid or ErrNotExist.

func (*VFS) ReadDir

func (v *VFS) ReadDir(name string) ([]fs.DirEntry, error)

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

func (*VFS) ReadFile

func (v *VFS) ReadFile(name string) ([]byte, error)

ReadFile reads the named file and returns its contents. A successful call returns a nil error, not io.EOF. (Because ReadFile reads the whole file, the expected EOF from the final Read is not treated as an error to be reported.)

The caller is permitted to modify the returned byte slice. This method should return a copy of the underlying data.

func (*VFS) Stat

func (v *VFS) Stat(name string) (fs.FileInfo, error)

Stat returns a FileInfo describing the file. If there is an error, it should be of type *PathError.

func (*VFS) Sub

func (v *VFS) Sub(dir string) (fs.FS, error)

Sub returns an FS corresponding to the subtree rooted at dir.

Jump to

Keyboard shortcuts

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