byteutil

package module
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2024 License: MIT Imports: 4 Imported by: 24

README

go-byteutil

A useful package of byte utilities.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrBeyondBufferLen is returned if .WriteAt() is attempted beyond buffer length.
	ErrBeyondBufferLen = errors.New("start beyond buffer length")
)

Functions

func B2S

func B2S(b []byte) string

B2S returns a string representation of []byte without allocation. Since Go strings are immutable, the bytes passed to String must not be modified as long as the returned string value exists.

func Copy

func Copy(b []byte) []byte

Copy returns a copy of []byte.

func S2B

func S2B(s string) []byte

S2B returns a []byte representation of string without allocation.

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) Full added in v1.0.2

func (buf *Buffer) Full() []byte

Full returns the full capacity byteslice allocated for this buffer.

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) ReadFrom added in v1.2.0

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

ReadFrom will read bytes from reader into buffer, fulfilling io.ReaderFrom.

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'.

func (*Buffer) WriteTo added in v1.2.0

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

WriteTo will write bytes from buffer into writer, fulfilling io.WriterTo.

Jump to

Keyboard shortcuts

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