buffr

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package buffr provides a buffered reader.

Index

Constants

This section is empty.

Variables

View Source
var ErrNegativeCount = errors.New("buffr: negative count")

ErrNegativeCount is returned when a negative number of bytes is requested.

Functions

This section is empty.

Types

type Reader

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

Reader implements buffering for an io.Reader object. Reader does not read from the underlying reader unless its buffer is empty, reducing the risk of cross-packet reading.

func NewReader

func NewReader(rd io.Reader, size int) *Reader

NewReader returns a new Reader with a buffer of the length specified by size.

func (*Reader) Buffered

func (r *Reader) Buffered() int

Buffered returns the number of bytes that can be read from the current buffer.

func (*Reader) Discard

func (r *Reader) Discard(n int) (int, error)

Discard skips the next n bytes, returning the number of bytes discarded. If Discard skips fewer than n bytes, it also returns an error.

func (*Reader) Peek

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

Peek reads data in p without advancing the reader. It returns the number of bytes read into p.

func (*Reader) Read

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

Read reads data in p. It returns the number of bytes read into p.

func (*Reader) ReadByte

func (r *Reader) ReadByte() (byte, error)

ReadByte reads the next byte.

func (*Reader) ReadSlice

func (r *Reader) ReadSlice(delim byte) ([]byte, error)

ReadSlice reads until the first occurrence of delim in the input, returning a slice pointing at the bytes in the buffer. If ReadSlice encounters the end of the buffer before finding the delimiter, it returns an io.EOF error.

func (*Reader) Reset

func (r *Reader) Reset(rd io.Reader)

Reset discards any buffered data, resets all state, and switches the buffered reader to read from rd.

Jump to

Keyboard shortcuts

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