Documentation
¶
Overview ¶
Package fs provides filesystem abstractions and implementations.
Index ¶
- type FileSystem
- type OSFileSystem
- func (fs *OSFileSystem) CreateAtomic(name string) (io.WriteCloser, error)
- func (fs *OSFileSystem) EnsureDirs(path string) error
- func (fs *OSFileSystem) ListDir(path string) ([]os.DirEntry, error)
- func (fs *OSFileSystem) MkdirAll(path string, perm os.FileMode) error
- func (fs *OSFileSystem) Open(path string) (domain.File, error)
- func (fs *OSFileSystem) ReadFile(path string) ([]byte, error)
- func (fs *OSFileSystem) Remove(path string) error
- func (fs *OSFileSystem) RemoveAll(path string) error
- func (fs *OSFileSystem) Stat(path string) (os.FileInfo, error)
- func (fs *OSFileSystem) UserHomeDir() (string, error)
- func (fs *OSFileSystem) WriteFile(name string, data []byte, perm os.FileMode) error
- func (fs *OSFileSystem) WriteFileAtomic(path string, content []byte, perm os.FileMode) error
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) WriteFileAtomic ¶
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.