kisom / sbuf

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

sbuf

import "github.com/kisom/sbuf"

NB: the canonical version of this is contained in the goutils repository.

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. It is meant to be a drop-in replacement for bytes.Buffer.

sbuf.go

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(n int) *Buffer

NewBuffer creates a new buffer with the specified capacity.

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.


Generated by godoc2md

About

License:ISC License


Languages

Language:Go 100.0%