reader

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2017 License: BSD-2-Clause Imports: 3 Imported by: 0

README

mellium.im/reader

GoDoc License

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.

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() error) io.Reader

After returns an io.Reader that proxies to another Reader and calls f after each Read that returns an io.EOF error. If io.EOF is never returned, f is never called and if io.EOF is returned multiple times, f will be called multiple times. If f is called, its return value is returned from the call to r.Read.

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 added in v0.0.2

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 added in v0.0.3

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 added in v0.0.3

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

Read calls f.

Jump to

Keyboard shortcuts

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