buffer

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package buffer provides a concurrency-safe, byte-bounded circular buffer.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Buffer

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

Buffer retains only the newest bytes written to it. It implements io.Writer and is safe for concurrent readers and writers.

func New

func New(capacity int) *Buffer

New creates a Buffer with the requested byte capacity. Non-positive capacities are clamped to one byte.

func (*Buffer) Bytes

func (b *Buffer) Bytes() []byte

Bytes returns the retained bytes in write order as an independent copy.

func (*Buffer) Capacity

func (b *Buffer) Capacity() int

Capacity returns the maximum number of bytes retained by the buffer.

func (*Buffer) Len

func (b *Buffer) Len() int

Len returns the number of bytes currently retained by the buffer.

func (*Buffer) String

func (b *Buffer) String() string

String returns the retained bytes in write order as a string.

func (*Buffer) Write

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

Write implements io.Writer. It reports the full input length even when old or leading bytes are discarded to respect the fixed capacity.

Jump to

Keyboard shortcuts

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