bytesutil

package
v1.0.8 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2025 License: MIT Imports: 1 Imported by: 0

Documentation

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 is a simple buffer for bytes. Only one of Read or Write methods should be used for the same buffer.

func NewBuffer

func NewBuffer(buf []byte, autoResize bool) *Buffer

NewBuffer creates a new buffer with the given byte slice.

func (*Buffer) Buf

func (self *Buffer) Buf() []byte

Buf returns the byte slice of buffer.

func (*Buffer) Pos

func (self *Buffer) Pos() int

Pos returns the current position of buffer (i.e. total bytes read or written).

func (*Buffer) Read

func (self *Buffer) Read(p []byte) (int, error)

Read reads up to len(p) bytes from buffer into p. If auto is true and the buffer does not have enough bytes to read, it will read available bytes and return the number of bytes read. If auto is false and the buffer does not have enough bytes to read, it will read available bytes and return the number of bytes read and error. If there is enough bytes to read, it will read len(p) bytes and return the number of bytes read.

func (*Buffer) Write

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

Write writes up to len(p) bytes from p to buffer. If auto is true and the buffer does not have enough space to write, it will resize the buffer and write p to buffer. If auto is false and the buffer does not have enough space to write, it will write available space and return the number of bytes written and error. If there is enough space to write, it will write len(p) bytes and return the number of bytes written.

Jump to

Keyboard shortcuts

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