Documentation
¶
Index ¶
- Variables
- type FileSystem
- type OSFileSystem
- func (fs OSFileSystem) Chmod(path string, mode os.FileMode) error
- func (fs OSFileSystem) CreateTemp(dir, pattern string) (*os.File, error)
- func (fs OSFileSystem) Lstat(path string) (os.FileInfo, error)
- func (fs OSFileSystem) MkdirAll(path string, perm os.FileMode) error
- func (fs OSFileSystem) Open(path string) (*os.File, error)
- func (fs OSFileSystem) ReadDir(path string) ([]os.DirEntry, error)
- func (fs OSFileSystem) ReadFile(path string) ([]byte, error)
- func (fs OSFileSystem) ReadFileWithLimit(path string, maxSize int64) ([]byte, error)
- func (fs OSFileSystem) Remove(path string) error
- func (fs OSFileSystem) Rename(oldPath, newPath string) error
- func (fs OSFileSystem) Stat(path string) (os.FileInfo, error)
- func (fs OSFileSystem) WriteFile(path string, data []byte, perm os.FileMode) error
- func (fs OSFileSystem) WriteFileAtomic(path string, data []byte, perm os.FileMode) error
Constants ¶
This section is empty.
Variables ¶
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 ¶
WriteFile writes data to the named file with the specified permissions.
func (OSFileSystem) WriteFileAtomic ¶
WriteFileAtomic writes data atomically using temp file and rename.