ioutil

package
v4.0.0-rc10+incompatible Latest Latest
Warning

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

Go to latest
Published: May 24, 2017 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package ioutil implements some I/O utility functions.

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	ErrEmptyReader = errors.New("reader is empty")
)

Functions

func CheckClose

func CheckClose(c io.Closer, err *error)

CheckClose calls Close on the given io.Closer. If the given *error points to nil, it will be assigned the error returned by Close. Otherwise, any error returned by Close will be ignored. CheckClose is usually called with defer.

Example
// CheckClose is commonly used with named return values
f := func() (err error) {
	// Get a io.ReadCloser
	r := ioutil.NopCloser(strings.NewReader("foo"))

	// defer CheckClose call with an io.Closer and pointer to error
	defer CheckClose(r, &err)

	// ... work with r ...

	// if err is not nil, CheckClose will assign any close errors to it
	return err

}

err := f()
if err != nil {
	panic(err)
}
Output:

func NewReadCloser

func NewReadCloser(r io.Reader, c io.Closer) io.ReadCloser

NewReadCloser creates an `io.ReadCloser` with the given `io.Reader` and `io.Closer`.

func NonEmptyReader

func NonEmptyReader(r io.Reader) (io.Reader, error)

NonEmptyReader takes a reader and returns it if it is not empty, or `ErrEmptyReader` if it is empty. If there is an error when reading the first byte of the given reader, it will be propagated.

func WriteNopCloser

func WriteNopCloser(w io.Writer) io.WriteCloser

WriteNopCloser returns a WriteCloser with a no-op Close method wrapping the provided Writer w.

Types

This section is empty.

Jump to

Keyboard shortcuts

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