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.