Documentation ¶
Overview ¶
Package ioutil implements some I/O utility functions.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var (
ErrEmptyReader = errors.New("reader is empty")
)
Functions ¶
func CheckClose ¶
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 ¶
NewReadCloser creates an `io.ReadCloser` with the given `io.Reader` and `io.Closer`.
func NonEmptyReader ¶
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.