fs

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package memfs provides a writable in-memory filesystem implementing spidermonkey.WritableFS. It backs tests and fully isolated interpreters: giving two interpreters separate memfs instances isolates their file views completely, with no host filesystem involved.

Paths follow io/fs conventions: slash-separated, unrooted, "." is the root directory. Parent directories are not created implicitly — use Mkdir or MkdirAll first, as a Node-style guest would expect ENOENT otherwise.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MemFS

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

MemFS is a writable in-memory filesystem. The zero value is not usable; call NewMemFS. MemFS is safe for concurrent use.

func NewMemFS

func NewMemFS() *MemFS

NewMemFS returns an empty filesystem containing only the root directory.

func (*MemFS) Chmod

func (fsys *MemFS) Chmod(name string, mode iofs.FileMode) error

Chmod changes the permission bits of name, keeping the file-type bits (iofs.ModeDir, ...) intact. A guest chmod maps here, so a subsequent Stat reflects the new mode.

func (*MemFS) Chtimes

func (fsys *MemFS) Chtimes(name string, _ time.Time, mtime time.Time) error

Chtimes sets the modification time of name (the os.Chtimes shape). The access time is accepted for signature compatibility but not stored: io/iofs.FileInfo has no atime accessor, so nothing could ever observe it.

func (*MemFS) Mkdir

func (fsys *MemFS) Mkdir(name string, perm iofs.FileMode) error

Mkdir creates a directory. The parent must already exist.

func (*MemFS) MkdirAll

func (fsys *MemFS) MkdirAll(name string, perm iofs.FileMode) error

MkdirAll creates name and any missing parents.

func (*MemFS) Open

func (fsys *MemFS) Open(name string) (iofs.File, error)

Open opens the named file or directory for reading.

func (*MemFS) OpenFile

func (fsys *MemFS) OpenFile(name string, flag int, perm iofs.FileMode) (iofs.File, error)

OpenFile opens name with OS-style flags (os.O_CREATE, os.O_TRUNC, os.O_APPEND, ...). When the flags request write access the returned file also implements io.Writer. Creating a file requires its parent directory to exist.

func (*MemFS) Remove

func (fsys *MemFS) Remove(name string) error

Remove removes a file or an empty directory.

func (*MemFS) Rename

func (fsys *MemFS) Rename(oldname, newname string) error

Rename moves oldname to newname, replacing a non-directory target. Moving a directory moves its whole subtree.

func (*MemFS) WriteFile

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

WriteFile creates or truncates name with data (parent must exist).

Jump to

Keyboard shortcuts

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