memfs

package
v6.0.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: May 11, 2026 License: Apache-2.0 Imports: 16 Imported by: 12

Documentation

Overview

Package memfs provides a billy filesystem backed by memory.

Filesystems created by this package are ephemeral and process-local: data is not persisted and disappears when the filesystem is discarded or the process exits. memfs is useful for tests and temporary data, but is not a persistence layer.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(opts ...Option) billy.Filesystem

New returns a new Memory filesystem.

The returned value is a billy.Filesystem wrapped with the chroot helper, not the raw *Memory implementation.

Types

type ByName

type ByName []gofs.DirEntry

func (ByName) Len

func (a ByName) Len() int

func (ByName) Less

func (a ByName) Less(i, j int) bool

func (ByName) Swap

func (a ByName) Swap(i, j int)

type Memory

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

Memory is a convenient filesystem based on memory files.

All filesystem data is loaded into memory. Users should ensure enough memory is available for the data they intend to store.

func (*Memory) Capabilities

func (fs *Memory) Capabilities() billy.Capability

Capabilities implements the Capable interface.

func (*Memory) Chmod

func (fs *Memory) Chmod(path string, mode gofs.FileMode) error

func (*Memory) Create

func (fs *Memory) Create(filename string) (billy.File, error)

func (*Memory) Join

func (fs *Memory) Join(elem ...string) string

Falls back to Go's filepath.Join, which works differently depending on the OS where the code is being executed.

func (*Memory) Lstat

func (fs *Memory) Lstat(filename string) (os.FileInfo, error)

func (*Memory) MkdirAll

func (fs *Memory) MkdirAll(path string, perm gofs.FileMode) error

func (*Memory) Open

func (fs *Memory) Open(filename string) (billy.File, error)

func (*Memory) OpenFile

func (fs *Memory) OpenFile(filename string, flag int, perm gofs.FileMode) (billy.File, error)

func (*Memory) ReadDir

func (fs *Memory) ReadDir(path string) ([]gofs.DirEntry, error)
func (fs *Memory) Readlink(link string) (string, error)

Readlink returns the target stored for link without resolving it.

func (*Memory) Remove

func (fs *Memory) Remove(filename string) error

func (*Memory) Rename

func (fs *Memory) Rename(from, to string) error

func (*Memory) Stat

func (fs *Memory) Stat(filename string) (os.FileInfo, error)
func (fs *Memory) Symlink(target, link string) error

Symlink creates link with target stored as provided. The target may point to a missing path.

func (*Memory) TempFile

func (fs *Memory) TempFile(dir, prefix string) (billy.File, error)

type Option

type Option func(*options)

func WithUmask

func WithUmask(mask uint32) Option

WithUmask sets the umask for the memfs filesystem. The umask controls the default permissions for newly created files and directories by clearing specified permission bits. If not set, defaults to 0o022.

Jump to

Keyboard shortcuts

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