vfs

package
v0.0.67 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2024 License: Apache-2.0, NCSA Imports: 7 Imported by: 0

Documentation

Overview

Package vfs defines a generic file system interface commonly used by Kythe libraries.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotSupported = errors.New("operation not supported")

ErrNotSupported is returned for all unsupported VFS operations.

Functions

func Create

func Create(ctx context.Context, path string) (io.WriteCloser, error)

Create creates a new file for writing, using the Default VFS.

func Glob

func Glob(ctx context.Context, glob string) ([]string, error)

Glob returns all the paths matching the specified glob pattern, using the Default VFS.

func MkdirAll

func MkdirAll(ctx context.Context, path string, mode os.FileMode) error

MkdirAll recursively creates the specified directory path with the given permissions, using the Default VFS.

func ReadFile

func ReadFile(ctx context.Context, filename string) ([]byte, error)

ReadFile is the equivalent of ioutil.ReadFile using the Default VFS.

func Remove

func Remove(ctx context.Context, path string) error

Remove deletes the file specified by path, using the Default VFS.

func Rename

func Rename(ctx context.Context, oldPath, newPath string) error

Rename renames oldPath to newPath, using the Default VFS, overwriting newPath if it exists.

func Stat

func Stat(ctx context.Context, path string) (os.FileInfo, error)

Stat returns file status information for path, using the Default VFS.

func Walk added in v0.0.49

func Walk(ctx context.Context, 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. See filepath.Walk for more details.

Types

type FileReader added in v0.0.31

type FileReader interface {
	io.ReadCloser
	io.ReaderAt
	io.Seeker
}

FileReader composes interfaces from io that readable files from the vfs must implement.

func Open

func Open(ctx context.Context, path string) (FileReader, error)

Open opens an existing file for reading, using the Default VFS.

type Interface

type Interface interface {
	Reader
	Writer
}

Interface is a virtual file system interface for reading and writing files. It is used to wrap the normal os package functions so that other file storage implementations be used in lieu. For instance, there could be implementations for cloud storage back-ends or databases. Depending on the implementation, the Writer methods can be unsupported and always return ErrNotSupported.

var Default Interface = LocalFS{}

Default is the global default VFS used by Kythe libraries that wish to access the file system. This is usually the LocalFS and should only be changed in very specialized cases (i.e. don't change it).

type LocalFS

type LocalFS struct{}

LocalFS implements the VFS interface using the standard Go library.

func (LocalFS) Create

func (LocalFS) Create(_ context.Context, path string) (io.WriteCloser, error)

Create implements part of the VFS interface.

func (LocalFS) CreateTempFile added in v0.0.31

func (LocalFS) CreateTempFile(_ context.Context, dir, pattern string) (TempFile, error)

CreateTempFile implements part of the VFS interface.

func (LocalFS) Glob

func (LocalFS) Glob(_ context.Context, glob string) ([]string, error)

Glob implements part of the VFS interface.

func (LocalFS) MkdirAll

func (LocalFS) MkdirAll(_ context.Context, path string, mode os.FileMode) error

MkdirAll implements part of the VFS interface.

func (LocalFS) Open

func (LocalFS) Open(_ context.Context, path string) (FileReader, error)

Open implements part of the VFS interface.

func (LocalFS) Remove

func (LocalFS) Remove(_ context.Context, path string) error

Remove implements part of the VFS interface.

func (LocalFS) Rename

func (LocalFS) Rename(_ context.Context, oldPath, newPath string) error

Rename implements part of the VFS interface.

func (LocalFS) Stat

func (LocalFS) Stat(_ context.Context, path string) (os.FileInfo, error)

Stat implements part of the VFS interface.

func (LocalFS) Walk added in v0.0.49

func (LocalFS) Walk(_ context.Context, root string, walkFn filepath.WalkFunc) error

Walk implements part of the VFS interface.

type Reader

type Reader interface {
	// Stat returns file status information for path, as os.Stat.
	Stat(ctx context.Context, path string) (os.FileInfo, error)

	// Open opens an existing file for reading, as os.Open.
	Open(ctx context.Context, path string) (FileReader, error)

	// Glob returns all the paths matching the specified glob pattern, as
	// filepath.Glob.
	Glob(ctx context.Context, glob string) ([]string, error)
}

Reader is a virtual file system interface for reading files.

type TempFile added in v0.0.31

type TempFile interface {
	io.WriteCloser
	Name() string
}

TempFile composes io.WriteCloser and access to its "name". For file-based implementations, this should be the full path to the full.

func CreateTempFile added in v0.0.31

func CreateTempFile(ctx context.Context, dir, pattern string) (TempFile, error)

CreateTempFile creates a new TempFile, using the Default VFS.

type UnseekableFileReader added in v0.0.31

type UnseekableFileReader struct {
	io.ReadCloser
}

UnseekableFileReader implements the io.Seeker and io.ReaderAt at portion of FileReader with stubs that always return ErrNotSupported.

func (UnseekableFileReader) ReadAt added in v0.0.31

func (UnseekableFileReader) ReadAt([]byte, int64) (int, error)

ReadAt implements io.ReaderAt interface. It is not supported.

func (UnseekableFileReader) Seek added in v0.0.31

Seek implements io.Seeker interface. It is not supported.

type UnsupportedWriter

type UnsupportedWriter struct{ Reader }

UnsupportedWriter implements the Writer interface methods with stubs that always return ErrNotSupported.

func (UnsupportedWriter) Create

Create implements part of Writer interface. It is not supported.

func (UnsupportedWriter) CreateTempFile added in v0.0.31

func (UnsupportedWriter) CreateTempFile(_ context.Context, dir, pattern string) (TempFile, error)

CreateTempFile implements part of the VFS interface. It is not supported.

func (UnsupportedWriter) MkdirAll

MkdirAll implements part of Writer interface. It is not supported.

func (UnsupportedWriter) Remove

Remove implements part of Writer interface. It is not supported.

func (UnsupportedWriter) Rename

func (UnsupportedWriter) Rename(_ context.Context, _, _ string) error

Rename implements part of Writer interface. It is not supported.

type Walker added in v0.0.49

type Walker interface {
	// Walk walks the file tree rooted at root, calling walkFn for each file or directory in the tree, including root.
	// See filepath.Walk for more details.
	Walk(ctx context.Context, root string, walkFn filepath.WalkFunc) error
}

Walker is a virtual file system interface for traversing directories.

func NewWalker added in v0.0.49

func NewWalker(r Reader) Walker

NewWalker returns a Walker instance over the provided reader.

type Writer

type Writer interface {
	// MkdirAll recursively creates the specified directory path with the given
	// permissions, as os.MkdirAll.
	MkdirAll(ctx context.Context, path string, mode os.FileMode) error

	// Create creates a new file for writing, as os.Create.
	Create(ctx context.Context, path string) (io.WriteCloser, error)

	// CreateTempFile creates a new temp file returning a TempFile. The
	// name of the file is constructed from dir pattern and per
	// ioutil.TempFile:
	// 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, CreateTempFile
	// uses an unspecified default directory.
	CreateTempFile(ctx context.Context, dir, pattern string) (TempFile, error)

	// Rename renames oldPath to newPath, as os.Rename, overwriting newPath if
	// it exists.
	Rename(ctx context.Context, oldPath, newPath string) error

	// Remove deletes the file specified by path, as os.Remove.
	Remove(ctx context.Context, path string) error
}

Writer is a virtual file system interface for writing files.

Directories

Path Synopsis
Package zip defines a VFS implementation that understands a zip archive as an isolated, read-only file system.
Package zip defines a VFS implementation that understands a zip archive as an isolated, read-only file system.

Jump to

Keyboard shortcuts

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