luci: Index | Files

package chunkstream

import ""


Package Files

buffer.go chunk.go chunkNode.go view.go

type Buffer Uses

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 Uses

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 Uses

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 Uses

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 Uses

func (b *Buffer) FirstChunk() Chunk

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

func (*Buffer) Len Uses

func (b *Buffer) Len() int64

Len returns the total amount of data in the buffer.

func (*Buffer) View Uses

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 Uses

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 Uses

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.

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 Uses

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 Uses

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 Uses

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 Uses

func (r *View) Consumed() int64

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

func (*View) Index Uses

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 Uses

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

func (*View) ReadByte Uses

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

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

func (*View) Remaining Uses

func (r *View) Remaining() int64

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

func (*View) Skip Uses

func (r *View) Skip(count int64)

Skip advances the View forwards a fixed number of bytes.

Package chunkstream imports 4 packages (graph) and is imported by 2 packages. Updated 2020-11-26. Refresh now. Tools for package owners.