bytebuf

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2021 License: MPL-2.0 Imports: 10 Imported by: 0

README

bytebuf

Go Reference CI Status

bytebuf is a library that provides an interface for a concurrency-safe read-only buffer of bytes, constructors from a variety of types, along with some optimized implementations for copying said buffers to files, network connections, etc.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReadAll

func ReadAll(b ByteBuf) ([]byte, error)

ReadAll reads an entire ByteBuf into a byte slice and returns it. This may be more efficient than calling ioutil.ReadAll(buf.AsReader()).

Types

type ByteBuf

type ByteBuf interface {
	io.ReaderAt
	io.Closer

	// The io.WriterTo implementation for all ByteBufs is guaranteed to be
	// concurrency-safe - i.e. it does not modify an internal offset and
	// can be used multiple times without changing the written data.
	io.WriterTo

	// Length returns the length of this ByteBuf.
	Length() int64

	// AsReader returns an io.Reader that reads the contents of this
	// ByteBuf. The returned Reader will only be valid so long as this
	// ByteBuf has not been closed.
	AsReader() io.Reader
}

ByteBuf is an interface for a concurrency-safe read-only buffer of bytes that can be read in a variety of ways.

func Append

func Append(one, two ByteBuf) ByteBuf

Append appends one ByteBuf to another. The original buffers are unmodified.

func Empty added in v0.0.2

func Empty() ByteBuf

Empty creates an empty ByteBuf.

func NewFromBytesReader

func NewFromBytesReader(r *bytes.Reader) ByteBuf

NewFromBytesReader creates a ByteBuf from an underlying file.

func NewFromFile

func NewFromFile(f *os.File) (ByteBuf, error)

NewFromFile creates a ByteBuf from an underlying file.

func NewFromReader

func NewFromReader(r io.Reader, dir string) (ByteBuf, error)

NewFromReader creates a ByteBuf from an io.Reader. It will buffer data to disk in the provided directory.

func NewFromSlice

func NewFromSlice(b []byte) ByteBuf

NewFromSlice creates a ByteBuf from an underlying slice. This avoids an extra allocation for the single-slice case compared to NewFromSlices.

func NewFromSlices

func NewFromSlices(bs ...[]byte) ByteBuf

NewFromSlices creates a ByteBuf from multiple slices.

func NewFromString added in v0.0.2

func NewFromString(s string) ByteBuf

NewFromString creates a ByteBuf from an underlying string. This is a convenience method around NewFromSlice.

Jump to

Keyboard shortcuts

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