GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Why Go
  • Case Studies
  • Use Cases
  • Security
  • Learn
  • Effective Go
  • Go User Manual
  • Standard library
  • Release Notes
  • API
  • Packages
  • Recorded Talks
  • Meetups
  • Conferences

This view

  • Original page
  • New address

GeezerVison is showing pkg.go.dev — badio package - github.com/cavaliercoder/badio - Go Packages

Details

  • unchecked Valid go.mod file

    The Go module system was introduced in Go 1.11 and is the official dependency management solution for Go.

  • checked Redistributable license

    Redistributable licenses place minimal restrictions on how software can be used, modified, and redistributed.

  • unchecked Tagged version

    Modules with tagged versions give importers more predictable builds.

  • unchecked Stable version

    When a project reaches major version v1 it is considered stable.

  • Learn more about best practices

Repository

github.com/cavaliercoder/badio

Links

  • Open Source Insights Logo Open Source Insights

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 ¶

  • func IsBadIOError(err error) bool
  • func NewBreakReader(r io.Reader, n int64) io.Reader
  • func NewByteReader(b byte) io.Reader
  • func NewNullReader() io.Reader
  • func NewRandomReader() io.Reader
  • func NewSequenceReader(b []byte) io.Reader
  • func NewTruncateReader(r io.Reader, n int64) io.Reader

Examples ¶

  • NewBreakReader
  • NewSequenceReader
  • NewTruncateReader

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.

Source Files ¶

View all Source files
  • break_reader.go
  • byte_reader.go
  • doc.go
  • errors.go
  • random_reader.go
  • sequence_reader.go
  • truncate_reader.go
Click to show internal directories.
Click to hide internal directories.
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.