sbuffer

package
v1.1.7 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2023 License: Zlib Imports: 3 Imported by: 0

Documentation

Overview

Single-Buffer backing for readers.

Use when reading from a large Reader when only small defined sequential slices are needed. Uses a single buffer for reading.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNeedCap     = errors.New("Requested more then buffer size.")
	ErrUsedTooMuch = errors.New("Used more then requested.")
)

Functions

This section is empty.

Types

type Buffer

type Buffer interface {
	// Get the next slice of data. Will return at least "needed", but may return more.
	// The returned slice should not be used after Next or Used is called.
	// The returned slice may be shorter then needed if the inner read returns a short
	// read (for example, returns an io.EOF).
	Next(needed int) ([]byte, error)

	// Called after using the slice returned from Next. This frees
	// the underlying buffer for more data.
	Used(used int)
}

func NewBuffer

func NewBuffer(read io.Reader, bufferSize int) Buffer

Read from read for more data. The bufferSize should be several times the max read size to prevent excessive copying.

Jump to

Keyboard shortcuts

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