iobuf

package
v3.81.3 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2024 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BufferedReadSeeker

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

BufferedReadSeeker provides a buffered reading interface with seeking capabilities. It wraps an io.Reader and optionally an io.Seeker, allowing for efficient reading and seeking operations, even on non-seekable underlying readers.

For small amounts of data, it uses an in-memory buffer (bytes.Buffer) to store read bytes. When the amount of data exceeds a specified threshold, it switches to disk-based buffering using a temporary file. This approach balances memory usage and performance, allowing efficient handling of both small and large data streams.

The struct manages the transition between in-memory and disk-based buffering transparently, providing a seamless reading and seeking experience regardless of the underlying data size or the seekability of the original reader.

If the underlying reader is seekable, direct seeking operations are performed on it. For non-seekable readers, seeking is emulated using the buffer or temporary file.

func NewBufferedReaderSeeker

func NewBufferedReaderSeeker(r io.Reader) *BufferedReadSeeker

NewBufferedReaderSeeker creates and initializes a BufferedReadSeeker. It takes an io.Reader and checks if it supports seeking. If the reader supports seeking, it is stored in the seeker field.

func (*BufferedReadSeeker) Close added in v3.80.2

func (br *BufferedReadSeeker) Close() error

Close closes the BufferedReadSeeker and releases any resources used. It closes the temporary file if one was created and removes it from disk and returns the buffer to the pool.

func (*BufferedReadSeeker) Read

func (br *BufferedReadSeeker) Read(out []byte) (int, error)

Read reads len(out) bytes from the reader starting at the current index. It handles both seekable and non-seekable underlying readers efficiently.

func (*BufferedReadSeeker) ReadAt

func (br *BufferedReadSeeker) ReadAt(out []byte, offset int64) (int, error)

ReadAt reads len(out) bytes into out starting at offset off in the underlying input source. It uses Seek and Read to implement random access reading.

func (*BufferedReadSeeker) Seek

func (br *BufferedReadSeeker) Seek(offset int64, whence int) (int64, error)

Seek sets the offset for the next Read or Write to offset. It supports both seekable and non-seekable underlying readers.

Jump to

Keyboard shortcuts

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