std/os
import "github.com/eugenioenko/goalchemy/std/os"Package os reads and writes whole files on the host file system. Errors are *PathError values whose Err matches ErrNotExist, ErrExist, ErrPermission or errors.ErrUnsupported through errors.Is, as in Go. Hosts without a file system, such as browsers, fail every call with an error matching errors.ErrUnsupported.
const MaxFileBytes = os.MaxFileBytesMaxFileBytes is the largest file ReadFile returns and WriteFile accepts.
var ( ErrInvalid = errors.New("invalid argument") ErrPermission = errors.New("permission denied") ErrExist = errors.New("file already exists") ErrNotExist = errors.New("file does not exist"))Portable analogs of the io/fs errors.
ReadFile
Section titled “ReadFile”func ReadFile(name string) ([]byte, error)ReadFile reads the named file and returns its contents. A directory fails with op “read”, as on Linux; other failures use op “open”.
WriteFile
Section titled “WriteFile”func WriteFile(name string, data []byte, perm FileMode) errorWriteFile writes data to the named file, creating it if necessary. If the file does not exist, WriteFile creates it with permissions perm (before the umask); otherwise WriteFile truncates it before writing, without changing permissions.
type FileMode
Section titled “type FileMode”type FileMode uint32A FileMode holds permission bits; only the low nine bits are applied.
type PathError
Section titled “type PathError”type PathError struct { Op string Path string Err error}PathError records an error and the operation and file path that caused it.
PathError.Error
Section titled “PathError.Error”func (e *PathError) Error() stringPathError.Unwrap
Section titled “PathError.Unwrap”func (e *PathError) Unwrap() error