rr

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2022 License: MIT Imports: 2 Imported by: 3

README

rr, aka RestartReader

RestartReader allows you to read bytes from an io.Reader without removing them.

RestartReader wraps io.ReadCloser or io.Reader and implements it. It holds the data from every Read in a buffer, and allows you to call .Restart(), causing subsequent Read calls to start from the beginning again. This is useful when you need to read the first few bytes of a stream or file, before passing off the full data to another function.

Import it with:

go get github.com/makeworld-the-better-one/rr

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrClosed = errors.New("RestartReader: closed")

Functions

This section is empty.

Types

type RestartReader

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

func NewRestartReader

func NewRestartReader(r io.Reader) *RestartReader

NewRestartReader creates and initializes a new RestartReader that reads from the provided io.Reader.

func (*RestartReader) Close

func (rr *RestartReader) Close() error

Close clears the buffer and closes the underlying io.Reader if possible, returning its error.

func (*RestartReader) Read

func (rr *RestartReader) Read(p []byte) (n int, err error)

func (*RestartReader) Restart

func (rr *RestartReader) Restart()

Restart causes subsequent Read calls to read from the beginning, instead of where they left off.

Jump to

Keyboard shortcuts

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