Documentation
¶
Overview ¶
Package badio contains extensions to Go's testing/iotest package and implements Readers and Writers useful mainly for testing.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsBadIOError ¶
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 ¶
NewBreakReader returns a Reader that behaves like r except that it will return a BadIOError (not io.EOF) once it has read n bytes.
Example ¶
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 ¶
NewByteReader returns a Reader that implements Read by returning an infinite stream of the given byte.
func NewNullReader ¶
NewNullReader returns a Reader that implements Read by returning an infinite stream of zeros, analogous to `cat /dev/zero`.
func NewRandomReader ¶
NewRandomReader returns a Reader that implements Read by perpetually reading cryptographically secure pseudorandom numbers.
func NewSequenceReader ¶
NewSequenceReader returns a Reader that implements Read by perpetually repeating the given byte sequence.
Example ¶
r := NewSequenceReader([]byte("na")) p := make([]byte, 20) r.Read(p) fmt.Printf("ba%s\n", p)
Output: banananananananananana
func NewTruncateReader ¶
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.
Example ¶
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
Types ¶
This section is empty.