chunkstream

package
v0.0.0-...-1643519 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2024 License: Apache-2.0 Imports: 4 Imported by: 1

Documentation

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
}

Buffer is a collection of ordered Chunks that can cheaply read and shifted as if it were a continuous byte stream.

A Buffer is not goroutine-safe.

The primary means of interacting with a Buffer is to construct a View and then use it to access the Buffer's contents. Views can be used concurrently, and View operations are goroutine-safe.

func (*Buffer) Append

func (b *Buffer) Append(c ...Chunk)

Append adds additional Chunks to the buffer.

After completion, the Chunk is now owned by the Buffer and should not be used anymore externally.

func (*Buffer) Bytes

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

Bytes constructs a byte slice containing the contents of the Buffer.

This is a potentially expensive operation, and should generally be used only for debugging and tests, as it defeats most of the purpose of this package.

func (*Buffer) Consume

func (b *Buffer) Consume(c int64)

Consume removes the specified number of bytes from the beginning of the Buffer. If Consume skips past all of the data in a Chunk is no longer needed, it is Release()d.

func (*Buffer) FirstChunk

func (b *Buffer) FirstChunk() Chunk

FirstChunk returns the first Chunk in the Buffer, or nil if the Buffer has no Chunks.

func (*Buffer) Len

func (b *Buffer) Len() int64

Len returns the total amount of data in the buffer.

func (*Buffer) View

func (b *Buffer) View() *View

View returns a View instance bound to this Buffer and spanning all data currently in the Buffer.

The View is no longer valid after Consume is called on the Buffer.

func (*Buffer) ViewLimit

func (b *Buffer) ViewLimit(limit int64) *View

ViewLimit constructs a View instance, but artificially constrains it to read at most the specified number of bytes.

This is useful when reading a subset of the data into a Buffer, as ReadFrom does not allow a size to be specified.

type Chunk

type Chunk interface {
	// Bytes returns the underlying byte slice contained by this Chunk.
	Bytes() []byte

	// Release releases the Chunk. After being released, a Chunk's methods must no
	// longer be used.
	//
	// It is a good idea to set your chunk variable to nil after releasing it.
	Release()
}

Chunk wraps a fixed-size byte buffer. It is the primary interface used by the chunk library.

A Chunk reference should be released once the user is finished with it. After being released, it may no longer be accessed.

type View

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

View is static read-only snapshot of the contents of the Buffer, presented as a contiguous stream of bytes.

View implements the io.Reader and io.ByteReader interfaces. It also offers a series of utility functions optimized for the chunks.

func (*View) Clone

func (r *View) Clone() *View

Clone returns a copy of the View view.

The clone is bound to the same underlying Buffer as the source.

func (*View) CloneLimit

func (r *View) CloneLimit(limit int64) *View

CloneLimit returns a copy of the View view, optionally truncating it.

The clone is bound to the same underlying Buffer as the source.

func (*View) Consumed

func (r *View) Consumed() int64

Consumed returns the number of bytes that have been skipped via Skip or higher-level calls.

func (*View) Index

func (r *View) Index(needle []byte) int64

Index scans the View for the specified needle bytes. If they are found, their index in the View is returned. Otherwise, Index returns -1.

The View is not modified during the search.

func (*View) Read

func (r *View) Read(b []byte) (int, error)

func (*View) ReadByte

func (r *View) ReadByte() (byte, error)

ReadByte implements io.ByteReader, reading a single byte from the buffer.

func (*View) Remaining

func (r *View) Remaining() int64

Remaining returns the number of bytes remaining in the Reader view.

func (*View) Skip

func (r *View) Skip(count int64)

Skip advances the View forwards a fixed number of bytes.

Jump to

Keyboard shortcuts

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