lifobuffer

package
v0.0.0-...-b988991 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package lifobuffer implements bytes buffer with LIFO order (last-in-first-out)

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidWriteCount = errors.New("lifo.Buffer.WriteTo:" +
	" invalid Write count")

ErrInvalidWriteCount is returned when WriteTo's writer returns wrong count

Functions

This section is empty.

Types

type Buffer

type Buffer []byte

Buffer is LIFO bytes buffer type

func NewBuffer

func NewBuffer(p []byte) *Buffer

NewBuffer returns new buffer with pre-defined buffer or nil

func (*Buffer) Len

func (b *Buffer) Len() int

Len returns the length of the buffer

func (*Buffer) Next

func (b *Buffer) Next(n int) (p []byte)

Next returns a slice containing the next n bytes from the buffer, advancing the buffer as if the bytes had been returned by Read. If there are fewer than n bytes in the buffer, Next returns the entire buffer.

func (*Buffer) Read

func (b *Buffer) Read(p []byte) (n int, err error)

Read reads the next len(p) bytes from the buffer or until the buffer is drained. The return value n is the number of bytes read. If the buffer has no data to return, err is io.EOF (unless len(p) is zero); otherwise it is nil.

func (*Buffer) ReadByte

func (b *Buffer) ReadByte() (c byte, err error)

ReadByte reads and returns the next byte from the buffer. If no byte is available, it returns error io.EOF.

func (*Buffer) Write

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

Write appends the contents of p to the buffer, growing the buffer as needed. The return value n is the length of p. The err will be always nil

func (*Buffer) WriteByte

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

WriteByte appends the byte c to the buffer, growing the buffer as needed. It always returns nil

func (*Buffer) WriteTo

func (b *Buffer) WriteTo(w io.Writer) (n int64, err error)

WriteTo writes data to w until the buffer is drained or an error occurs. The return value n is the number of bytes written; it always fits into an int, but it is int64 to match the io.WriterTo interface. Any error encountered during the write is also returned. If w returns invalid count err will be ErrInvalidWriteCount

Jump to

Keyboard shortcuts

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