Help us shape the future of Go! Take the 2026 Go Developer Survey

memory

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package memory is an in-memory harness.FileSystem port: POSIX virtual paths, files and directories, no symlinks. It never touches a host filesystem and holds no package-level state.

Index

Constants

This section is empty.

Variables

View Source
var ErrLimitExceeded = errors.New("memory file system limit exceeded")

ErrLimitExceeded is wrapped by the FileError returned when a write would exceed Options.MaxBytes or Options.MaxFiles.

Functions

This section is empty.

Types

type FileSystem

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

FileSystem is safe for concurrent use.

func New

func New(options Options) *FileSystem

func (*FileSystem) AbsolutePath

func (fsys *FileSystem) AbsolutePath(_ context.Context, name string) (string, error)

func (*FileSystem) AppendFile

func (fsys *FileSystem) AppendFile(ctx context.Context, name string, content []byte) error

func (*FileSystem) CanonicalPath

func (fsys *FileSystem) CanonicalPath(ctx context.Context, name string) (string, error)

func (*FileSystem) Cleanup

func (fsys *FileSystem) Cleanup() error

func (*FileSystem) CreateDir

func (fsys *FileSystem) CreateDir(ctx context.Context, name string, recursive bool) error

CreateDir matches NodeExecutionEnv (Go's MkdirAll): a recursive create over an existing file reports not_directory; a non-recursive create over any existing entry reports unknown (EEXIST).

func (*FileSystem) CreateTempDir

func (fsys *FileSystem) CreateTempDir(ctx context.Context, prefix string) (string, error)

CreateTempDir creates directories under <Root>/tmp.

func (*FileSystem) CreateTempFile

func (fsys *FileSystem) CreateTempFile(ctx context.Context, prefix, suffix string) (string, error)

func (*FileSystem) Exists

func (fsys *FileSystem) Exists(ctx context.Context, name string) (bool, error)

func (*FileSystem) FileInfo

func (fsys *FileSystem) FileInfo(ctx context.Context, name string) (harness.FileInfo, error)

func (*FileSystem) JoinPath

func (fsys *FileSystem) JoinPath(_ context.Context, parts ...string) (string, error)

func (*FileSystem) ListDir

func (fsys *FileSystem) ListDir(ctx context.Context, name string) ([]harness.FileInfo, error)

ListDir returns entries sorted by name.

func (*FileSystem) ReadBinaryFile

func (fsys *FileSystem) ReadBinaryFile(ctx context.Context, name string) ([]byte, error)

func (*FileSystem) ReadTextFile

func (fsys *FileSystem) ReadTextFile(ctx context.Context, name string) (string, error)

func (*FileSystem) ReadTextLines

func (fsys *FileSystem) ReadTextLines(ctx context.Context, name string, maxLines int) ([]string, error)

ReadTextLines matches NodeExecutionEnv: maxLines <= 0 reads nothing and does not open the file.

func (*FileSystem) Remove

func (fsys *FileSystem) Remove(ctx context.Context, name string, recursive, force bool) error

Remove matches NodeExecutionEnv: a non-recursive remove of any directory fails with unknown (Node's ERR_FS_EISDIR) and force ignores only missing paths. The root cannot be removed.

func (*FileSystem) RenameFile

func (fsys *FileSystem) RenameFile(ctx context.Context, from, to string) error

RenameFile follows rename(2): a file replaces a file, a directory replaces a missing or empty directory. Errors carry the source path like Node's.

func (*FileSystem) Snapshot

func (fsys *FileSystem) Snapshot() map[string]string

Snapshot returns a copy of every regular file's content keyed by path.

func (*FileSystem) WorkingDirectory

func (fsys *FileSystem) WorkingDirectory() string

func (*FileSystem) WriteFile

func (fsys *FileSystem) WriteFile(ctx context.Context, name string, content []byte) error

type Options

type Options struct {
	// Root is the working directory and the confinement boundary: paths
	// resolving outside it fail with permission_denied. Defaults to "/".
	Root string
	// MaxBytes bounds the total size of file contents; zero is unbounded.
	MaxBytes int64
	// MaxFiles bounds the number of regular files; zero is unbounded.
	MaxFiles int
	// Now stamps modification times; defaults to time.Now.
	Now func() time.Time
}

Jump to

Keyboard shortcuts

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