ioutil

package
v4.1.0+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 12, 2019 License: BSD-3-Clause, BSD-3-Clause, BSD-3-Clause Imports: 6 Imported by: 0

README

ioutil

Helper functions for I/O, similar to the "ioutil" package. The main change is to wrap I/O errors with stacks.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeserializeFromJSONFile

func DeserializeFromJSONFile(path string, objPtr interface{}) error

DeserializeFromJSONFile deserializes the given JSON file into the object pointed to by objPtr. It may return an error for which ioutil.IsNotExist() returns true.

func IsExist

func IsExist(err error) bool

IsExist wraps os.IsExist to work around https://github.com/golang/go/issues/17164 .

func IsNotExist

func IsNotExist(err error) bool

IsNotExist is like os.IsNotExist, but handles wrapped errors, too.

func Lstat

func Lstat(name string) (os.FileInfo, error)

Lstat wraps Lstat from "os".

func Mkdir

func Mkdir(path string, perm os.FileMode) error

Mkdir wraps MkdirAll from "os".

func MkdirAll

func MkdirAll(path string, perm os.FileMode) error

MkdirAll wraps MkdirAll from "os".

func OpenFile

func OpenFile(name string, flag int, perm os.FileMode) (*os.File, error)

OpenFile wraps OpenFile from "os".

func ReadAll

func ReadAll(r io.Reader) ([]byte, error)

ReadAll wraps ReadAll from "io/ioutil".

func ReadDir

func ReadDir(dirname string) ([]os.FileInfo, error)

ReadDir wraps ReadDir from "io/ioutil".

func ReadFile

func ReadFile(filename string) ([]byte, error)

ReadFile wraps ReadFile from "io/ioutil".

func Remove

func Remove(name string) error

Remove wraps Remove from "os".

func RemoveAll

func RemoveAll(name string) error

RemoveAll wraps RemoveAll from "os".

func Rename

func Rename(oldpath, newpath string) error

Rename wraps Rename from "os".

func SerializeToJSONFile

func SerializeToJSONFile(obj interface{}, path string) error

SerializeToJSONFile serializes the given object as JSON and writes it to the given file, making its parent directory first if necessary.

func Stat

func Stat(name string) (os.FileInfo, error)

Stat wraps Stat from "os".

func TempDir

func TempDir(dir, prefix string) (name string, err error)

TempDir wraps TempDir from "io/ioutil".

func WriteFile

func WriteFile(filename string, data []byte, perm os.FileMode) error

WriteFile wraps WriteFile from "io/ioutil".

func WriteSerializedFile

func WriteSerializedFile(
	filename string, data []byte, perm os.FileMode) (err error)

WriteSerializedFile writes (or overwrites) `data` into `filename`. If `filename` doesn't exist, it's created with `perm` permissions. If `filename` does exist, the data is first overwritten to the file, and then the file is truncated to the length of the data. If the data represents a serialized data structure where the length is explicitly stated in, or implicitly calculated from, the data itself on a read, then this is approximately an atomic write (without the performance overhead of writing to a temp file and renaming it). NOTE: it's technically possible a partial OS write could lead to a corrupted file, though in practice this seems much more rare than ioutil.WriteFile() leaving behind an empty file.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL