README
¶
BadIO
Package badio contains extensions to Go's testing/iotest package and implements Readers and Writers useful mainly for testing.
Installation
$ go get github.com/cavaliercoder/badio
Example
r := badio.NewSequenceReader([]byte("na"))
p := make([]byte, 20)
r.Read(p)
fmt.Printf("ba%s\n", p)
// Prints: banananananananananana
License
Copyright (c) 2015 Ryan Armstrong
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
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.