limitbuf

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package limitbuf provides a sticky-error string builder with a hard byte limit. It is useful in renderers whose WriteString errors are intentionally ignored at individual call sites.

Index

Constants

This section is empty.

Variables

View Source
var ErrTooLarge = errors.New("buffer exceeds size limit")

ErrTooLarge reports that a write would exceed a Buffer's byte limit.

Functions

This section is empty.

Types

type Buffer

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

Buffer accumulates text up to limit bytes. A non-positive limit is unlimited. Once a write would exceed the limit, all later writes return the same sticky error and no partial write is retained.

func New

func New(limit int) *Buffer

New returns an empty Buffer with the supplied byte limit.

func (*Buffer) Err

func (b *Buffer) Err() error

Err returns the first size error encountered by the Buffer.

func (*Buffer) Len

func (b *Buffer) Len() int

Len returns the number of retained bytes.

func (*Buffer) String

func (b *Buffer) String() string

func (*Buffer) Write

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

func (*Buffer) WriteByte

func (b *Buffer) WriteByte(c byte) error

WriteByte appends c if it fits within the byte limit.

func (*Buffer) WriteRune

func (b *Buffer) WriteRune(r rune) (int, error)

WriteRune appends r if its UTF-8 encoding fits within the byte limit.

func (*Buffer) WriteString

func (b *Buffer) WriteString(s string) (int, error)

WriteString appends s if it fits within the byte limit.

Jump to

Keyboard shortcuts

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