badio

package module
v0.0.0-...-ce52801 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2016 License: MIT Imports: 3 Imported by: 0

README

BadIO

GoDoc Build Status Go Report Card

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

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

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.

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

func NewByteReader(b byte) io.Reader

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

func NewNullReader

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

func NewRandomReader() io.Reader

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

func NewSequenceReader

func NewSequenceReader(b []byte) io.Reader

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

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.

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.

Jump to

Keyboard shortcuts

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