Documentation
¶
Overview ¶
Code generated by osa/gen. DO NOT EDIT.
Package osa provides abstractions over various OS-related operations.
Here is a simple example of how to use this package:
import (
os "github.com/echocrow/osa"
)
data, err := os.ReadFile("file.go") // Use "os" as usual.
if err != nil {
log.Fatal(err)
}
Note: This package only supports a subset of functions and variables of the actual os standard library package.
Index ¶
- Variables
- func Exit(code int)
- func Getwd() (dir string, err error)
- func IsExist(err error) bool
- func IsNotExist(err error) bool
- func IsPathSeparator(c uint8) bool
- func Mkdir(name string, perm FileMode) error
- func MkdirAll(name string, perm FileMode) error
- func MkdirTemp(dir, pattern string) (string, error)
- func Open(name string) (fs.File, error)
- func Patch(o I) func()
- func PathSeparator() uint8
- func ReadFile(name string) ([]byte, error)
- func Remove(name string) error
- func RemoveAll(path string) error
- func Rename(oldpath, newpath string) error
- func UserCacheDir() (string, error)
- func UserConfigDir() (string, error)
- func UserHomeDir() (string, error)
- func WriteFile(name string, data []byte, perm FileMode) error
- type DirEntry
- type FileInfo
- type FileMode
- type I
- type PathError
- type Stdio
- Bugs
Constants ¶
This section is empty.
Variables ¶
var ( Stdin io.Reader = stdin{} Stdout io.Writer = stdout{} Stderr io.Writer = stderr{} )
Stdin, Stdout, and Stderr are readers and writers for the standard input, standard output, and standard error streams.
Functions ¶
func IsExist ¶
IsExist returns a boolean indicating whether the error is known to report that a file or directory already exists.
func IsNotExist ¶
IsNotExist returns a boolean indicating whether the error is known to report that a file or directory does not exist.
func IsPathSeparator ¶
IsPathSeparator reports whether c is a directory separator character.
func MkdirTemp ¶
MkdirTemp creates a new temporary directory in the directory dir and returns the pathname of the new directory.
func Patch ¶
func Patch(o I) func()
Patch monkey-patches the OS abstraction and returns a restore function.
BUG(echocrow): Patch is not yet thread-safe.
BUG(echocrow): Calling Patch multiple times before resetting may result in incomplete resets when reset funcs are not invoked in reverse order.
func PathSeparator ¶
func PathSeparator() uint8
PathSeparator returns the directory separator character.
func UserCacheDir ¶
UserCacheDir returns the default directory to use for cached data.
func UserConfigDir ¶
UserConfigDir returns the default directory to use for configuration data.
func UserHomeDir ¶
UserHomeDir returns the current user's home directory.
Types ¶
type I ¶
type I interface {
// Open opens the named file.
Open(name string) (fs.File, error)
// Lstat returns a FileInfo describing the named file.
Stat(name string) (FileInfo, error)
// IsExist returns a boolean indicating whether the error is known to report
// that a file or directory already exists.
IsExist(err error) bool
// IsNotExist returns a boolean indicating whether the error is known to
// report that a file or directory does not exist.
IsNotExist(err error) bool
// PathSeparator returns the directory separator character.
PathSeparator() uint8
// IsPathSeparator reports whether c is a directory separator character.
IsPathSeparator(c uint8) bool
// Mkdir creates a new directory.
Mkdir(name string, perm FileMode) error
// MkdirAll creates a directory named path, along with any necessary parents.
MkdirAll(name string, perm FileMode) error
// MkdirTemp creates a new temporary directory in the directory dir and
// returns the pathname of the new directory.
MkdirTemp(dir, pattern string) (string, error)
// ReadDir reads the named directory and returns all its directory entries
// sorted by filename.
ReadDir(name string) ([]DirEntry, error)
// WriteFile writes data to the named file, creating it if necessary.
WriteFile(name string, data []byte, perm FileMode) error
// ReadFile reads the named file and returns the contents.
ReadFile(name string) ([]byte, error)
// Rename renames (moves) oldpath to newpath.
Rename(oldpath, newpath string) error
// Remove removes the named file or empty directory.
Remove(name string) error
// RemoveAll removes path and any children it contains
RemoveAll(path string) error
// Getwd returns a rooted path name corresponding to the current directory.
Getwd() (dir string, err error)
// UserCacheDir returns the default directory to use for cached data.
UserCacheDir() (string, error)
// UserConfigDir returns the default directory to use for configuration data.
UserConfigDir() (string, error)
// UserHomeDir returns the current user's home directory.
UserHomeDir() (string, error)
// Exit causes the current program to exit with the given status code.
Exit(code int)
// Stdio returns IO readers and writers for Stdin, Stdout, and Stderr.
Stdio
}
Interface I describes available OS methods on the OS abstraction.
type Stdio ¶
type Stdio interface {
// Stdin returns IO reader for Stdin.
Stdin() io.Reader
// Stdout returns IO writer for Stdout.
Stdout() io.Writer
// Stderr returns IO writer for Stderr.
Stderr() io.Writer
}
Stdio describes a set of functions that return IO readers or writers for Stdin, Stdout, and Stderr.
Notes ¶
Bugs ¶
Patch is not yet thread-safe.
Calling Patch multiple times before resetting may result in incomplete resets when reset funcs are not invoked in reverse order.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package main generates simple osa wrapper implementations.
|
Package main generates simple osa wrapper implementations. |
|
Code generated by osa/gen.
|
Code generated by osa/gen. |
|
Package testos provides utilities for common OS assert/require test operations.
|
Package testos provides utilities for common OS assert/require test operations. |
|
Package testosa provides tests for OSA implementations.
|
Package testosa provides tests for OSA implementations. |
|
Package vos provides a basic virtual OS abstraction implementation.
|
Package vos provides a basic virtual OS abstraction implementation. |