buf

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2022 License: MIT Imports: 4 Imported by: 1

README

go-buf

This library provides a simple, fast, byte buffer with access to the underlying byte slice.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrBeyondBufferLen = errors.New("start beyond buffer length")

ErrBeyondBufferLen is returned if .WriteAt() is attempted beyond buffer length.

Functions

This section is empty.

Types

type Buffer

type Buffer struct{ B []byte }

Buffer is a simple wrapper around a byte slice.

func (*Buffer) Cap

func (buf *Buffer) Cap() int

Cap returns the capacity of the buffer's underlying byte slice.

func (*Buffer) Grow

func (buf *Buffer) Grow(sz int)

Grow will increase the buffers length by 'sz', and the capacity by at least this.

func (*Buffer) Guarantee

func (buf *Buffer) Guarantee(sz int)

Guarantee will guarantee buffer containers at least 'sz' remaining capacity.

func (*Buffer) Len

func (buf *Buffer) Len() int

Len returns the length of the buffer's underlying byte slice.

func (*Buffer) Reset

func (buf *Buffer) Reset()

Reset will reset the buffer length to 0 (retains capacity).

func (*Buffer) String

func (buf *Buffer) String() string

String returns the underlying byte slice as a string. Please note this value is tied directly to the underlying byte slice, if you write to the buffer then returned string values will also change.

To get an immutable string from buffered data, use string(buf.B).

func (*Buffer) Truncate

func (buf *Buffer) Truncate(n int)

Truncate will reduce the length of the buffer by 'n'.

func (*Buffer) Write

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

Write will append given byte slice to buffer, fulfilling io.Writer.

func (*Buffer) WriteAt

func (buf *Buffer) WriteAt(b []byte, start int64) (int, error)

WriteAt will append given byte slice to buffer at index 'start', fulfilling io.WriterAt.

func (*Buffer) WriteByte

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

WriteByte will append given byte to buffer, fulfilling io.ByteWriter.

func (*Buffer) WriteRune

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

WriteRune will append given rune to buffer.

func (*Buffer) WriteString

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

WriteString will append given string to buffer, fulfilling io.StringWriter.

func (*Buffer) WriteStringAt

func (buf *Buffer) WriteStringAt(s string, start int64) (int, error)

WriteStringAt will append given string to buffer at index 'start'.

Jump to

Keyboard shortcuts

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