version: 1.10

package iotest

import "testing/iotest"

Overview

Package iotest implements Readers and Writers useful mainly for testing.

Index

Package files

logger.go reader.go writer.go

Variables

  1. var ErrTimeout = errors.New("timeout")

func DataErrReader

  1. func DataErrReader(r io.Reader) io.Reader

DataErrReader changes the way errors are handled by a Reader. Normally, a Reader
returns an error (typically EOF) from the first Read call after the last piece
of data is read. DataErrReader wraps a Reader and changes its behavior so the
final error is returned along with the final data, instead of in the first call
after the final data.

func HalfReader

  1. func HalfReader(r io.Reader) io.Reader

HalfReader returns a Reader that implements Read by reading half as many
requested bytes from r.

func NewReadLogger

  1. func NewReadLogger(prefix string, r io.Reader) io.Reader

NewReadLogger returns a reader that behaves like r except that it logs (using
log.Printf) each read to standard error, printing the prefix and the hexadecimal
data read.

func NewWriteLogger

  1. func NewWriteLogger(prefix string, w io.Writer) io.Writer

NewWriteLogger returns a writer that behaves like w except that it logs (using
log.Printf) each write to standard error, printing the prefix and the
hexadecimal data written.

func OneByteReader

  1. func OneByteReader(r io.Reader) io.Reader

OneByteReader returns a Reader that implements each non-empty Read by reading
one byte from r.

func TimeoutReader

  1. func TimeoutReader(r io.Reader) io.Reader

TimeoutReader returns ErrTimeout on the second read with no data. Subsequent
calls to read succeed.

func TruncateWriter

  1. func TruncateWriter(w io.Writer, n int64) io.Writer

TruncateWriter returns a Writer that writes to w but stops silently after n
bytes.