fsutil

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package fsutil provides filesystem abstractions for testability.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FileSystem

type FileSystem interface {
	// Open opens the named file for reading.
	Open(name string) (fs.File, error)

	// Create creates or truncates the named file.
	Create(name string) (io.WriteCloser, error)

	// ReadFile reads the named file and returns its contents.
	ReadFile(name string) ([]byte, error)

	// WriteFile writes data to the named file, creating it if necessary.
	WriteFile(name string, data []byte, perm os.FileMode) error

	// Stat returns a FileInfo describing the named file.
	Stat(name string) (fs.FileInfo, error)

	// MkdirAll creates a directory and all necessary parents.
	MkdirAll(path string, perm os.FileMode) error

	// Remove removes the named file or empty directory.
	Remove(name string) error

	// RemoveAll removes path and any children it contains.
	RemoveAll(path string) error

	// Exists checks if a file or directory exists.
	Exists(name string) bool
}

FileSystem abstracts filesystem operations for testability. Use OSFileSystem for production; MemoryFileSystem for testing.

type MemoryFileSystem

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

MemoryFileSystem provides an in-memory filesystem for testing.

func NewMemoryFileSystem

func NewMemoryFileSystem() *MemoryFileSystem

NewMemoryFileSystem creates a new in-memory filesystem.

func (*MemoryFileSystem) Create

func (m *MemoryFileSystem) Create(name string) (io.WriteCloser, error)

Create creates or truncates a file.

func (*MemoryFileSystem) Exists

func (m *MemoryFileSystem) Exists(name string) bool

Exists checks if a file or directory exists.

func (*MemoryFileSystem) MkdirAll

func (m *MemoryFileSystem) MkdirAll(path string, perm os.FileMode) error

MkdirAll creates directories.

func (*MemoryFileSystem) Open

func (m *MemoryFileSystem) Open(name string) (fs.File, error)

Open opens a file for reading.

func (*MemoryFileSystem) ReadFile

func (m *MemoryFileSystem) ReadFile(name string) ([]byte, error)

ReadFile reads a file's contents.

func (*MemoryFileSystem) Remove

func (m *MemoryFileSystem) Remove(name string) error

Remove removes a file or empty directory.

func (*MemoryFileSystem) RemoveAll

func (m *MemoryFileSystem) RemoveAll(path string) error

RemoveAll removes a path and children.

func (*MemoryFileSystem) Stat

func (m *MemoryFileSystem) Stat(name string) (fs.FileInfo, error)

Stat returns file info.

func (*MemoryFileSystem) WriteFile

func (m *MemoryFileSystem) WriteFile(name string, data []byte, perm os.FileMode) error

WriteFile writes data to a file.

type OSFileSystem

type OSFileSystem struct{}

OSFileSystem implements FileSystem using the os package.

func (OSFileSystem) Create

func (OSFileSystem) Create(name string) (io.WriteCloser, error)

Create creates the named file.

func (OSFileSystem) Exists

func (OSFileSystem) Exists(name string) bool

Exists checks if a file exists.

func (OSFileSystem) MkdirAll

func (OSFileSystem) MkdirAll(path string, perm os.FileMode) error

MkdirAll creates a directory path.

func (OSFileSystem) Open

func (OSFileSystem) Open(name string) (fs.File, error)

Open opens the named file.

func (OSFileSystem) ReadFile

func (OSFileSystem) ReadFile(name string) ([]byte, error)

ReadFile reads the named file.

func (OSFileSystem) Remove

func (OSFileSystem) Remove(name string) error

Remove removes the named file or directory.

func (OSFileSystem) RemoveAll

func (OSFileSystem) RemoveAll(path string) error

RemoveAll removes the path and any children.

func (OSFileSystem) Stat

func (OSFileSystem) Stat(name string) (fs.FileInfo, error)

Stat returns file info for the named file.

func (OSFileSystem) WriteFile

func (OSFileSystem) WriteFile(name string, data []byte, perm os.FileMode) error

WriteFile writes data to the named file.

Jump to

Keyboard shortcuts

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