filesystem

package
v0.9.7 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2026 License: EUPL-1.2 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrFileTooLarge = errors.New("file too large")
)

File system errors.

Functions

This section is empty.

Types

type FileSystem

type FileSystem interface {
	ReadFile(path string) ([]byte, error)
	WriteFile(path string, data []byte, perm os.FileMode) error
	ReadDir(path string) ([]os.DirEntry, error)
	Stat(path string) (os.FileInfo, error)
	Lstat(path string) (os.FileInfo, error)
	Open(path string) (*os.File, error)
	CreateTemp(dir, pattern string) (*os.File, error)
	Remove(path string) error
	Rename(oldPath, newPath string) error
	Chmod(path string, mode os.FileMode) error
	MkdirAll(path string, perm os.FileMode) error
	ReadFileWithLimit(path string, maxSize int64) ([]byte, error)
	WriteFileAtomic(path string, data []byte, perm os.FileMode) error
}

FileSystem defines operations for file system access. Enables dependency injection and testing.

type OSFileSystem

type OSFileSystem struct{}

OSFileSystem implements FileSystem using the standard library.

func NewOSFileSystem

func NewOSFileSystem() OSFileSystem

NewOSFileSystem creates a new OS-based file system.

func (OSFileSystem) Chmod

func (fs OSFileSystem) Chmod(path string, mode os.FileMode) error

Chmod changes the mode of the named file to mode.

func (OSFileSystem) CreateTemp

func (fs OSFileSystem) CreateTemp(dir, pattern string) (*os.File, error)

CreateTemp creates a new temporary file in the directory dir with a name beginning with pattern.

func (OSFileSystem) Lstat

func (fs OSFileSystem) Lstat(path string) (os.FileInfo, error)

Lstat returns file information for the named file, without following symbolic links.

func (OSFileSystem) MkdirAll

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

MkdirAll creates a directory named path, along with any necessary parents.

func (OSFileSystem) Open

func (fs OSFileSystem) Open(path string) (*os.File, error)

Open opens the named file for reading.

func (OSFileSystem) ReadDir

func (fs OSFileSystem) ReadDir(path string) ([]os.DirEntry, error)

ReadDir reads the named directory and returns all its entries.

func (OSFileSystem) ReadFile

func (fs OSFileSystem) ReadFile(path string) ([]byte, error)

ReadFile reads and returns the contents of the named file.

func (OSFileSystem) ReadFileWithLimit

func (fs OSFileSystem) ReadFileWithLimit(path string, maxSize int64) ([]byte, error)

ReadFileWithLimit reads a file up to maxSize bytes.

func (OSFileSystem) Remove

func (fs OSFileSystem) Remove(path string) error

Remove removes the named file or directory.

func (OSFileSystem) Rename

func (fs OSFileSystem) Rename(oldPath, newPath string) error

Rename renames (moves) oldPath to newPath.

func (OSFileSystem) Stat

func (fs OSFileSystem) Stat(path string) (os.FileInfo, error)

Stat returns file information for the named file.

func (OSFileSystem) WriteFile

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

WriteFile writes data to the named file with the specified permissions.

func (OSFileSystem) WriteFileAtomic

func (fs OSFileSystem) WriteFileAtomic(path string, data []byte, perm os.FileMode) error

WriteFileAtomic writes data atomically using temp file and rename.

Jump to

Keyboard shortcuts

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