limitedbuf

package module
v0.0.0-...-a0bca64 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2023 License: Apache-2.0 Imports: 3 Imported by: 1

README

limitedbuf-go

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrWriteExceedsBufCap = errors.New("exceeds buffer capacty")

ErrWriteExceedsBufCap is returned when write exceeds buffer capacity.

Functions

This section is empty.

Types

type Buffer

type Buffer interface {
	Write(p []byte) (int, error)
	Bytes() []byte
	Len() int
}

Buffer implements core methods to manipulate a bytes slice.

type LimitedBuf

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

LimitedBuf implements io.Writer interface.

func NewBuffer

func NewBuffer(buf []byte, max int) *LimitedBuf

NewBuffer creates a new buffer which implements io.Writer interface. The bytes slice passed should be allocated with Len: 0 Cap: default You cannot pass nil and expect the buffer to created. The max argument specifies the max number of bytes to allow in the buffer.

func (*LimitedBuf) Bytes

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

Bytes is wrapper which calls bytes.Bytes()

func (*LimitedBuf) Len

func (b *LimitedBuf) Len() int

Len is wrapper which calls bytes.Len()

func (*LimitedBuf) Write

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

Write first checks if there is enough capacity in the buffer to write p, If the validation fails, Write method returns 0 and ErrWriteExceedsBufCap.

Jump to

Keyboard shortcuts

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