import "go.chromium.org/luci/common/data/chunkstream"
buffer.go chunk.go chunkNode.go view.go
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.
Append adds additional Chunks to the buffer.
After completion, the Chunk is now owned by the Buffer and should not be used anymore externally.
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.
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.
FirstChunk returns the first Chunk in the Buffer, or nil if the Buffer has no Chunks.
Len returns the total amount of data in the buffer.
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.
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 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 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.
Clone returns a copy of the View view.
The clone is bound to the same underlying Buffer as the source.
CloneLimit returns a copy of the View view, optionally truncating it.
The clone is bound to the same underlying Buffer as the source.
Consumed returns the number of bytes that have been skipped via Skip or higher-level calls.
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.
ReadByte implements io.ByteReader, reading a single byte from the buffer.
Remaining returns the number of bytes remaining in the Reader view.
Skip advances the View forwards a fixed number of bytes.
Package chunkstream imports 4 packages (graph) and is imported by 2 packages. Updated 2019-12-09. Refresh now. Tools for package owners.