Skip to content

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.MaxFileBytes

MaxFileBytes 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.

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”.

func WriteFile(name string, data []byte, perm FileMode) error

WriteFile 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 uint32

A FileMode holds permission bits; only the low nine bits are applied.

type PathError struct {
Op string
Path string
Err error
}

PathError records an error and the operation and file path that caused it.

func (e *PathError) Error() string
func (e *PathError) Unwrap() error