Back to

package reader

Latest Go to latest
Published: Dec 19, 2018 | License: BSD-2-Clause | Module:


Package reader contains small, reusable APIs that build on the io.Reader interface.


func After

func After(r io.Reader, f func(n int, err error) (int, error)) io.Reader

After returns an io.Reader that proxies to another Reader and calls f after each Read. The return value of f is returned from the call to r.Read instead of the original return value.

func Before

func Before(r io.Reader, f func() error) io.Reader

Before returns an io.Reader that proxies calls to Read and executes the given function exactly once before the first call. If the function errors, the error is returned and the call to Read is never proxied to the inner io.Reader (subsequent calls to Read will still be proxied). Because no call to Read returns until the one call to f returns, if f causes Read to be called, it will deadlock. If f panics, future calls of Read return without calling f. For more information see the documentation for sync.Once.

func Conn

func Conn(c net.Conn, r io.Reader) net.Conn

Conn replaces the Read method of c with r.Read. Generally, r wraps the Read method of c.

func Error

func Error(err error) io.Reader

Error returns a reader that always returns the given error for all calls to Read.

type Func

type Func func(p []byte) (n int, err error)

Func is an adapter to allow the use of ordinary functions as io.Readers. If f is a function with the appropriate signature, Func(f) is an io.Reader that calls f.

func (Func) Read

func (f Func) Read(p []byte) (n int, err error)

Read calls f.

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
f or F : Jump to identifier