fs

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package fs provides filesystem abstractions and implementations.

Index

Constants

This section is empty.

Variables

This section is empty.

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
	WriteFileAtomic(path string, data []byte, perm os.FileMode) error
	MkdirAll(path string, perm os.FileMode) error
	EnsureDirs(path string) error
	UserHomeDir() (string, error)
	ListDir(path string) ([]os.DirEntry, error)
	Remove(path string) error
	RemoveAll(path string) error
	Stat(path string) (os.FileInfo, error)
	CreateAtomic(path string) (io.WriteCloser, error)
	Open(path string) (domain.File, error)
}

FileSystem defines the interface for local filesystem operations.

type OSFileSystem

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

OSFileSystem implements filesystem operations using the local OS filesystem primitives.

func NewOSFileSystem

func NewOSFileSystem(maxFileSize int64) *OSFileSystem

NewOSFileSystem creates a new OSFileSystem.

func (*OSFileSystem) CreateAtomic

func (fs *OSFileSystem) CreateAtomic(name string) (io.WriteCloser, error)

CreateAtomic creates a new file, failing if it already exists (O_EXCL).

func (*OSFileSystem) EnsureDirs

func (fs *OSFileSystem) EnsureDirs(path string) error

EnsureDirs creates the given directory path if it does not exist.

func (*OSFileSystem) ListDir

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

ListDir lists the contents of a directory. Returns a slice of DirEntry for each entry in the directory.

func (*OSFileSystem) MkdirAll

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

MkdirAll creates a directory and all necessary parents.

func (*OSFileSystem) Open

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

Open opens a file for reading.

func (*OSFileSystem) ReadFile

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

ReadFile reads the entire content of a file with safety limits. It checks for MaxFileSize and binary content.

func (*OSFileSystem) Remove

func (fs *OSFileSystem) Remove(path string) error

Remove deletes a file or empty directory.

func (*OSFileSystem) RemoveAll

func (fs *OSFileSystem) RemoveAll(path string) error

RemoveAll deletes a path and any children it contains.

func (*OSFileSystem) Stat

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

Stat returns the FileInfo for a file.

func (*OSFileSystem) UserHomeDir

func (fs *OSFileSystem) UserHomeDir() (string, error)

UserHomeDir returns the current user's home directory.

func (*OSFileSystem) WriteFile

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

WriteFile writes the entire content to a file.

func (*OSFileSystem) WriteFileAtomic

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

WriteFileAtomic writes content to a file atomically using temp file + rename pattern. This ensures that if the process crashes mid-write, the original file remains intact. The temp file is created in the same directory as the target to ensure atomic rename.

Jump to

Keyboard shortcuts

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