fs

package
v0.0.0-...-c9cfaf6 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2020 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Overview

Package fs provides a filesystem abstraction.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotExist = errors.New("file does not exist")

ErrNotExist is returned when a file does not exist.

Functions

func ReadFile

func ReadFile(ctx context.Context, fs Readable, name string) ([]byte, error)

ReadFile reads the named file from the given filesystem and returns the contents.

func WriteFile

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

WriteFile writes data to the named file in the supplied filesystem.

Types

type FileInfo

type FileInfo struct {
	Path    string    // path to the file relative to the filesystem
	Size    int64     // size in bytes
	ModTime time.Time // modification time
}

FileInfo describes a file.

type Interface

type Interface interface {
	Writable
	Readable
}

Interface is a filesystem abstraction.

var Null Interface = null{}

Null contains no files and discards writes.

func NewLocal

func NewLocal(root string) Interface

NewLocal returns a filesystem rooted at the provided path on the local system.

func NewMem

func NewMem() Interface

NewMem builds an in-memory filesystem.

func NewMemWithFiles

func NewMemWithFiles(files map[string][]byte) Interface

NewMemWithFiles creates an in-memory filesystem initialized with the given files.

func NewSub

func NewSub(fs Interface, prefix string) Interface

NewSub returns the sub-filesystem of fs rooted at prefix.

type Readable

type Readable interface {
	Open(ctx context.Context, name string) (io.ReadCloser, error)
	Stat(ctx context.Context, name string) (*FileInfo, error)
	List(ctx context.Context, prefix string) ([]*FileInfo, error)
}

Readable can read from named files.

type Writable

type Writable interface {
	Create(ctx context.Context, name string) (io.WriteCloser, error)
	Remove(ctx context.Context, name string) error
}

Writable can create named files.

Jump to

Keyboard shortcuts

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