chunkedbuffer

package
v1.125.1-cluster Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2025 License: Apache-2.0 Imports: 8 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Put added in v1.102.18

func Put(cb *Buffer)

Put returns cb to the pool, so it could be reused via Get() call.

The cb cannot be used after Put() call.

Types

type Buffer

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

Buffer provides in-memory buffer optimized for storing big bytes volumes.

It stores the data in chunks of fixed size. This reduces memory fragmentation and memory waste comparing to the contiguous slices of bytes.

func Get added in v1.102.18

func Get() *Buffer

Get returns Buffer from the pool.

Return back the Buffer to the pool via Put() call when it is no longer needed.

func (*Buffer) Len

func (cb *Buffer) Len() int

Len returns the length of the data stored at cb.

func (*Buffer) MustClose

func (cb *Buffer) MustClose()

MustClose closes cb for subsequent reuse.

func (*Buffer) MustReadAt

func (cb *Buffer) MustReadAt(p []byte, off int64)

MustReadAt reads len(p) bytes from cb at the offset off.

func (*Buffer) MustWrite

func (cb *Buffer) MustWrite(p []byte)

MustWrite writes p to cb.

func (*Buffer) MustWriteTo added in v1.102.18

func (cb *Buffer) MustWriteTo(w io.Writer)

MustWriteTo writes cb contents w.

Use this function only if w cannot return errors. For example, if w is bytes.Buffer of bytesutil.ByteBuffer. If w can return errors, then use WriteTo function instead.

func (*Buffer) NewReader

func (cb *Buffer) NewReader() filestream.ReadCloser

NewReader returns a reader for reading the data stored in cb.

func (*Buffer) Path

func (cb *Buffer) Path() string

Path returns cb path.

func (*Buffer) ReadFrom added in v1.102.18

func (cb *Buffer) ReadFrom(r io.Reader) (int64, error)

ReadFrom reads all the data from r and appends it to cb.

func (*Buffer) Reset

func (cb *Buffer) Reset()

Reset resets the cb, so it can be reused for writing new data into it.

Reset frees up memory chunks allocated for cb, so they could be reused by other Buffer instances.

func (*Buffer) SizeBytes

func (cb *Buffer) SizeBytes() int

SizeBytes returns the number of bytes occupied by the cb.

func (*Buffer) Write

func (cb *Buffer) Write(p []byte) (int, error)

Write implements io.Writer interface for cb.

func (*Buffer) WriteTo

func (cb *Buffer) WriteTo(w io.Writer) (int64, error)

WriteTo writes cb data to w.

Jump to

Keyboard shortcuts

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