README

mellium.im/reader

GoDoc License

Buy Me A Coffee

A collection of io.Reader's that perform various useful functions.

import "mellium.im/reader"

License

The package may be used under the terms of the BSD 2-Clause License a copy of which may be found in the LICENSE file.

Expand ▾ Collapse ▴

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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.

Types

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.

Source Files