sbuf

package
v1.7.4 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2023 License: BSD-2-Clause, ISC, ISC Imports: 1 Imported by: 0

Documentation

Overview

Package sbuf implements a byte buffer that can be wiped. The underlying byte slice is wiped on read before being declaimed, and when the buffer is closed, its storage is zeroised.

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
}

A Buffer is a variable-sized buffer of bytes with Read and Write methods. The zero value for Buffer is an empty buffer ready to use.

func NewBuffer

func NewBuffer(n int) *Buffer

NewBuffer creates a new buffer with the specified capacity.

func NewBufferFrom

func NewBufferFrom(p []byte) *Buffer

NewBufferFrom creates a new buffer from the byte slice passed in. The original data will be wiped.

func (*Buffer) Bytes

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

Bytes returns the bytes currently in the buffer, and closes itself.

func (*Buffer) Cap

func (buf *Buffer) Cap() int

Cap returns the capacity of the buffer.

func (*Buffer) Close

func (buf *Buffer) Close()

Close destroys and zeroises the buffer. The buffer will be re-opened on the next write.

func (*Buffer) Len

func (buf *Buffer) Len() int

Len returns the length of the buffer.

func (*Buffer) Read

func (buf *Buffer) Read(p []byte) (int, 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 (buf *Buffer) ReadByte() (byte, error)

ReadByte reads the next byte from the buffer. If the buffer has no data to return, err is io.EOF; otherwise it is nil.

func (*Buffer) Write

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

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

func (*Buffer) WriteByte

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

WriteByte adds the byte c to the buffer, growing the buffer as needed.

Jump to

Keyboard shortcuts

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