zio

package
v0.0.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: May 18, 2025 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrReadLimit is the error that indicates read limit is reached.
	// This error is returns from [LimitReader].
	ErrReadLimit = errors.New("zio: read limit reached")
	// ErrWriteLimit is the error that indicates write limit is reached.
	// This error is returns from [LimitWriter].
	ErrWriteLimit = errors.New("zio: write limit reached")
)

Functions

func Copy

func Copy(dst io.Writer, src io.Reader) (written int64, err error)

Copy copies from src to dst until either EOF is reached on src or an error occurs. It returns the number of bytes copied and the first error encountered while copying, if any.

A successful Copy returns err == nil, not err == EOF. Because Copy is defined to read from src until EOF, it does not treat an EOF from Read as an error to be reported.

It panics if nil writer or nil reader is given.

See also io.Copy and io.CopyBuffer. Copy uses buffer pool internally for performance improvement.

func LimitReader

func LimitReader(r io.Reader, limit int64) io.Reader

LimitReader returns a io.Reader that reads from r but stops when the limit is reached. Unlike io.LimitedReader, the returned reader returns ErrReadLimit when the limit is reached. It returns nil of given r is nil.

func LimitWriter

func LimitWriter(w io.Writer, limit int64) io.Writer

LimitWriter returns a io.Writer that writes to w but stops when the limit is reached. Returned writer returns ErrWriteLimit when the limit is reached. It returns nil of given w is nil.

func NopReadCloser

func NopReadCloser(r io.Reader) io.ReadCloser

NopReadCloser wraps given Reader and returns ReadCloser that do nothing when io.ReadCloser.Close is called.

func NopWriteCloser

func NopWriteCloser(w io.Writer) io.WriteCloser

NopWriteCloser wraps given Writer and returns WriteCloser that do nothing when io.WriteCloser.Close is called.

func TeeReadCloser

func TeeReadCloser(rc io.ReadCloser, wc io.WriteCloser) io.ReadCloser

TeeReadCloser returns a io.ReadCloser that writes to wc what it reads from rc. All reads from rc are written to wc. There is no internal buffering. Therefor, the write must complete before the read completes. If given ReadCloser rc is nil, it returns nil. If given WriteCloser wc is nil, it returns rc itself. The returned reader works like below.

  • 1. Read from the rc.
  • 2. Write into the writer wc. Write is performed even read operation returned an error.
  • 3. Return written bytes and write error if any. (Write error is prior to the read error.)
  • 4. Return read bytes and read error.

func TeeReader

func TeeReader(r io.Reader, w io.Writer) io.Reader

TeeReader returns a io.Reader that writes to w what it reads from r. All reads from r are written to w. There is no internal buffering. Therefor, the write must complete before the read completes. If given reader r is nil, it returns nil. If given writer w is nil, it returns r itself. See also io.TeeReader. The reader works like below.

  • 1. Read from the reader r.
  • 2. Write into the writer w. Write is performed even read operation returned an error.
  • 3. Return written bytes and write error if any. (Write error is prior to the read error.)
  • 4. Return read bytes and read error.

Types

This section is empty.

Jump to

Keyboard shortcuts

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