repeat

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2023 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package repeat implements the repeat-reader. A repeat-reader outputs a given constant byte sequence repeatedly.

This package was originally written for testing and profiling parsers. A typical use may look something like this:

input := "some line to be parsed\n"
r := NewReader([]byte(input), 1000)
parser := myparse.NewParser(r)

(start profiling)
// Parse 1000 lines until non-nil error.
for parser.ParseNext() == nil {}
(stop profiling)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Reader

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

Reader outputs a given constant byte sequence repeatedly.

func NewReader

func NewReader(data []byte, n int) *Reader

NewReader returns a reader that outputs data n times. If n is negative, repeats infinitely. Copies the contents of data.

func (*Reader) Close

func (r *Reader) Close() error

Close is a no-op. Implements io.ReadCloser.

func (*Reader) Read

func (r *Reader) Read(p []byte) (int, error)

Read fills p with repetitions of the reader's data. Writes until p is full or until the last repetition was written. Subsequent calls to Read resume from where the last repetition stopped. When no more bytes are available, returns 0, EOF. Otherwise the error is nil.

Jump to

Keyboard shortcuts

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