buffbits

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2021 License: MIT Imports: 3 Imported by: 0

README

buffbits

License Go Reference Lint/Test

buffbits provides a buffered reader/writer that exposes bit level io access.

Install

go get github.com/larzconwell/buffbits

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidCount = errors.New("buffbits: read/write with invalid bit count")

ErrInvalidCount is the error used when a read/write occurs with a bit count that is too large or too small.

Functions

This section is empty.

Types

type Reader added in v0.2.0

type Reader struct {
	// contains filtered or unexported fields
}

Reader implements buffered bit level read access from an underlying io.Reader. Buffered reading is powered by the bufio package. If an error occurs while reading from a Reader, no more data will be read and all subsequent calls will return an error.

func NewReader added in v0.2.0

func NewReader(r io.Reader) *Reader

NewReader creates a buffered bit reader reading from r.

func NewReaderSize added in v0.2.0

func NewReaderSize(r io.Reader, size int) *Reader

NewReaderSize creates a buffered bit reader reading from r using a buffer of size bytes.

func (*Reader) Err added in v0.2.0

func (r *Reader) Err() error

Err returns the first error that was encountered by the Reader.

func (*Reader) Read added in v0.2.0

func (r *Reader) Read(count int) (uint64, error)

Read reads count bits from the Reader and returns them in the lower positions of the returned 64bit integer. If count bits cannot be read then io.ErrUnexpectedEOF is returned. count must not exceed 64 and must be at least 0.

func (*Reader) Reset added in v0.2.0

func (r *Reader) Reset(reader io.Reader)

Reset discards any state and switches reading from the provided reader.

type Writer

type Writer struct {
	// contains filtered or unexported fields
}

Writer implements buffered bit level write access to an underlying io.Writer. Buffered writing is powered by the bufio package. If an error occurs while writing to a Writer, no more data will be written and all subsequent calls will return an error. After all data has been written, the client should call Flush to guarantee all the data has been written to the underlying io.Writer.

func NewWriter

func NewWriter(w io.Writer) *Writer

NewWriter creates a buffered bit writer writing to w.

func NewWriterSize

func NewWriterSize(w io.Writer, size int) *Writer

NewWriterSize creates a buffered bit writer writing to w using a buffer of size bytes.

func (*Writer) Err

func (w *Writer) Err() error

Err returns the first error that was encountered by the Writer.

func (*Writer) Flush

func (w *Writer) Flush() error

Flush writes all the buffered data and pads to the last byte with 0s.

func (*Writer) Reset added in v0.2.0

func (w *Writer) Reset(writer io.Writer)

Reset discards any state and switches writing to the provided writer.

func (*Writer) Write

func (w *Writer) Write(value uint64, count int) error

Write writes the lowest count bits of value to the Writer. count must not exceed 64 and must be at least 0.

Jump to

Keyboard shortcuts

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