mem

package
v0.4.19 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrIsDir = errors.New("is a directory")
)

Functions

This section is empty.

Types

type FS

type FS struct {
	Files map[string]File
	Dirs  map[string]iofs.FileMode
	Errs  map[string]error
}

Provide the in-memory implementation of the internal FS interface.

This is a simple in-memory filesystem that can be used for testing. It is not thread-safe. There are two ways to use this:

  1. Use the New() function to create a new FS instance and then use the WithFile() and WithError() options to populate the filesystem.
  2. Create a FS instance and then populate the Files, Dirs, and Errs fields directly.

func New

func New(opts ...Option) *FS

New creates a new MemFS instance with the specified options.

func (*FS) Mkdir

func (fs *FS) Mkdir(path string, perm iofs.FileMode) error

func (*FS) MkdirAll

func (fs *FS) MkdirAll(path string, perm iofs.FileMode) error

func (*FS) Open

func (fs *FS) Open(name string) (iofs.File, error)

func (*FS) ReadFile

func (fs *FS) ReadFile(name string) ([]byte, error)

func (*FS) WriteFile

func (fs *FS) WriteFile(name string, data []byte, perm iofs.FileMode) error

type File

type File struct {
	Bytes []byte
	Perm  iofs.FileMode
	// contains filtered or unexported fields
}

File is an in-memory implementation of the iofs.File interface.

func (*File) Close

func (f *File) Close() error

func (*File) Read

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

func (*File) Stat

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

type Option

type Option func(*FS)

Option is a functional option for creating a MemFS instance.

func WithDir

func WithDir(name string, perm iofs.FileMode) Option

WithDir adds a directory to the MemFS instance.

func WithError

func WithError(name string, err error) Option

WithError adds an error to the MemFS instance. When the file is opened, the error will be returned.

func WithFile

func WithFile(name, data string, perm iofs.FileMode) Option

WithFile adds a file to the MemFS instance. Only the first permission specified is used. Errors are panic'd.

Jump to

Keyboard shortcuts

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