badio: github.com/cavaliercoder/badio Index | Examples | Files

package badio

import "github.com/cavaliercoder/badio"

Package badio contains extensions to Go's testing/iotest package and implements Readers and Writers useful mainly for testing.

Index

Examples

Package Files

break_reader.go byte_reader.go doc.go errors.go random_reader.go sequence_reader.go truncate_reader.go

func IsBadIOError Uses

func IsBadIOError(err error) bool

IsBadIOError returns a boolean indicating whether the error is known to be an error generated by the badio package itself rather than an underlying Reader or Writer implementation or the Go standard library.

func NewBreakReader Uses

func NewBreakReader(r io.Reader, n int64) io.Reader

NewBreakReader returns a Reader that behaves like r except that it will return a BadIOError (not io.EOF) once it has read n bytes.

Code:

s := strings.NewReader("banananananananananana")
r := NewBreakReader(s, 6)

p := make([]byte, 20)
_, err := r.Read(p)

fmt.Printf("Error: %v\n", err)

Output:

Error: Reader break point at offset 6 (0x6)

func NewByteReader Uses

func NewByteReader(b byte) io.Reader

NewByteReader returns a Reader that implements Read by returning an infinite stream of the given byte.

func NewNullReader Uses

func NewNullReader() io.Reader

NewNullReader returns a Reader that implements Read by returning an infinite stream of zeros, analogous to `cat /dev/zero`.

func NewRandomReader Uses

func NewRandomReader() io.Reader

NewRandomReader returns a Reader that implements Read by perpetually reading cryptographically secure pseudorandom numbers.

func NewSequenceReader Uses

func NewSequenceReader(b []byte) io.Reader

NewSequenceReader returns a Reader that implements Read by perpetually repeating the given byte sequence.

Code:

r := NewSequenceReader([]byte("na"))

p := make([]byte, 20)
r.Read(p)

fmt.Printf("ba%s\n", p)

Output:

banananananananananana

func NewTruncateReader Uses

func NewTruncateReader(r io.Reader, n int64) io.Reader

NewTruncateReader returns a Reader that behaves like r except that it will return zero count and an io.EOF error once it has read n bytes.

Code:

s := strings.NewReader("banananananananananana")
r := NewTruncateReader(s, 6)

p := make([]byte, 20)
r.Read(p)

fmt.Printf("%s\n", bytes.Trim(p, "\x00"))

Output:

banana

Package badio imports 3 packages (graph). Updated 2016-07-21. Refresh now. Tools for package owners. This is an inactive package (no imports and no commits in at least two years).