vfs

package
v0.0.0-...-6cad993 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2024 License: BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReadDir

func ReadDir(ctx context.Context, fs FS, path string) (rv []fs.FileInfo, rvErr error)

ReadDir is analogous to os.ReadDir.

func ReadFile

func ReadFile(ctx context.Context, fs FS, path string) (rv []byte, rvErr error)

ReadFile is analogous to os.ReadFile.

func Stat

func Stat(ctx context.Context, fs FS, path string) (rv fs.FileInfo, rvErr error)

Stat is analogous to os.Stat.

func Walk

func Walk(ctx context.Context, fs FS, root string, walkFn filepath.WalkFunc) error

Walk is analogous to filepath.Walk.

func WriteFile

func WriteFile(ctx context.Context, fs FS, path string, data []byte) error

WriteFile is analogous to os.WriteFile.

Types

type FS

type FS interface {
	// Open the given path for reading only. If the path is a directory,
	// implementations should return a ReadDirFile.
	Open(ctx context.Context, name string) (File, error)

	// Create creates or truncates the named file. If the file already exists,
	// it is truncated. If the file does not exist, it is created with mode 0666
	// (before umask). If successful, methods on the returned File can be used
	// for I/O; the associated file descriptor has mode O_RDWR. If there is an
	// error, it will be of type *PathError.
	Create(ctx context.Context, name string) (File, error)

	// Close causes any resources associated with the FS to be cleaned up.
	Close(ctx context.Context) error
}

FS represents a virtual filesystem.

func InRepoRoot

func InRepoRoot() (FS, error)

InRepoRoot returns a FS which uses the local filesystem with the root being the root of the Git repository where the current working directory resides. Absolute paths may only be passed to Open() if they are subdirectories of the given root. Relative paths must not contain ".."

func Local

func Local(root string) FS

Local returns a FS which uses the local filesystem with the given root. Absolute paths may only be passed to Open() if they are subdirectories of the given root. Relative paths must not contain ".."

type File

type File interface {
	// Close the File.
	Close(ctx context.Context) error
	// Read behaves like io.Reader. It should return an error if this is a
	// directory.
	Read(ctx context.Context, buf []byte) (int, error)
	// Stat returns FileInfo associated with the File.
	Stat(ctx context.Context) (fs.FileInfo, error)

	// ReadDir returns the contents of the File if it is a directory, and
	// returns an error otherwise. Should behave the same as os.File.Readdir.
	ReadDir(ctx context.Context, n int) ([]fs.FileInfo, error)

	// Write is analogous to os.File.Write(). It writes the contents of b to the
	// File and returns the number of bytes written and an error, if any. Write
	// returns a non-nil error when n != len(b). Only valid if the File was
	// created using FS.Create.
	Write(ctx context.Context, b []byte) (n int, err error)
}

File represents a virtual file.

type FileInfo

type FileInfo struct {
	Name    string
	Size    int64
	Mode    os.FileMode
	ModTime time.Time
	IsDir   bool
	Sys     interface{}
}

FileInfo implements fs.FileInfo by simply filling out the return values for all of the methods.

func (FileInfo) Get

func (fi FileInfo) Get() *FileInfoImpl

Get returns an fs.FileInfo backed by this FileInfo.

type FileInfoImpl

type FileInfoImpl struct {
	FileInfo
}

FileInfoImpl implements fs.FileInfo.

func (*FileInfoImpl) IsDir

func (fi *FileInfoImpl) IsDir() bool

IsDir implements fs.FileInfo.

func (*FileInfoImpl) ModTime

func (fi *FileInfoImpl) ModTime() time.Time

ModTime implements fs.FileInfo.

func (*FileInfoImpl) Mode

func (fi *FileInfoImpl) Mode() os.FileMode

Mode implements fs.FileInfo.

func (*FileInfoImpl) Name

func (fi *FileInfoImpl) Name() string

Name implements fs.FileInfo.

func (*FileInfoImpl) Size

func (fi *FileInfoImpl) Size() int64

Size implements fs.FileInfo.

func (*FileInfoImpl) Sys

func (fi *FileInfoImpl) Sys() interface{}

Sys implements fs.FileInfo.

type ReuseContextFile

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

ReuseContextFile is a File which reuses the same Context for all calls. This is useful for passing the File into library functions which do not use Contexts.

func WithContext

func WithContext(ctx context.Context, f File) *ReuseContextFile

WithContext returns a ReuseContextFile which wraps the given File.

func (*ReuseContextFile) Close

func (f *ReuseContextFile) Close() error

Close closes the ReuseContextFile.

func (*ReuseContextFile) Read

func (f *ReuseContextFile) Read(buf []byte) (int, error)

Read reads from the ReuseContextFile.

func (*ReuseContextFile) Stat

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

Stat returns the fs.FileInfo describing the ReuseContextFile.

type TempDirFS

type TempDirFS struct {
	FS
	// contains filtered or unexported fields
}

TempDirFS is a FS implementation which is rooted in a temporary directory. Calling Close causes the directory to be deleted.

func TempDir

func TempDir(_ context.Context, dir, prefix string) (*TempDirFS, error)

TempDir returns a FS which is rooted in a temporary directory. Calling Close causes the directory to be deleted.

func (*TempDirFS) Close

func (fs *TempDirFS) Close(ctx context.Context) error

Close deletes the temporary directory.

func (*TempDirFS) Dir

func (fs *TempDirFS) Dir() string

Dir returns the temporary directory.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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