brokenio

package
v0.0.0-...-160f2ba Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2021 License: GPL-3.0 Imports: 3 Imported by: 0

README

This is a wrapper around an io.ReadCloser.
When asked for n bytes, it will return a faulty read with a probability of probFail and severity controlled by fracFail.

Documentation

Overview

Example (SetVerbose)
package main

import (
	"github.com/andrew-torda/goutil/brokenio"
	"io/ioutil"
	"strings"
)

var longstring = "0123456789012345678901234567890123456789"

func main() {
	rdr := brokenio.NewReader(ioutil.NopCloser(strings.NewReader(longstring)))
	rdr.SetVerbose(true)
	tmp := make([]byte, len(longstring))
	rdr.Read(tmp)
	rdr.Close()
}
Output:

Closing 1 calls and 40 bytes

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BrknRdrClsr

type BrknRdrClsr struct {
	// contains filtered or unexported fields
}

A Reader is modelled on the various Readers in the standard library, but with variables controlling the frequency of errors. These values are the fraction of time an error will take place, so a value of 0.05 means failure in 5% of the cases. If verbose is true, print out the amount of data when the file is closed.

func NewReader

func NewReader(rIn io.ReadCloser) *BrknRdrClsr

NewReader returns a new Reader - a wrapper around the old one

func (*BrknRdrClsr) Close

func (r *BrknRdrClsr) Close() error

Close wraps the original Close method.

func (*BrknRdrClsr) Read

func (r *BrknRdrClsr) Read(p []byte) (n int, err error)

Read wraps the original reader and sums up the amount of data that has gone through. It generates an error with a probability given by freqFailure. On the first call, we might return zero data to simulate a zero length file which is a rather common occurrence.

func (*BrknRdrClsr) SetFracFail

func (r *BrknRdrClsr) SetFracFail(frac float32)

SetFracFail sets the amount of the bytes which will be trashed

func (*BrknRdrClsr) SetProbFail

func (r *BrknRdrClsr) SetProbFail(prob float32)

SetProbFail set the probability of a file reading failure. It must be between zero and 1.

func (*BrknRdrClsr) SetProbZeroFile

func (r *BrknRdrClsr) SetProbZeroFile(prob float32)

SetProbZeroFile sets the rate at which we simply return 0 bytes on the first read. It must be a value from 0 to 1. We do not check if the argument is valid.

func (*BrknRdrClsr) SetVerbose

func (r *BrknRdrClsr) SetVerbose(newV bool)

SetVerbose sets the verbosity flag to true or false

Jump to

Keyboard shortcuts

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