utils

package
v1.46.0 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2025 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Contains deprecated

func Contains(input []string, s string) bool

Deprecated: Use slices.Contains instead. Contains returns true if input contains the given string.

func SafeRead

func SafeRead(reader io.Reader, data []byte) (int, error)

SafeRead reads len(data) bytes from reader to data. It also guarantees that if not all data was not read, there is an error, but masks the io.EOF error out if all the data requested was read. In other words, it guarantees there is an error returned, if not all bytes requested were read, and only then there is an error.

func SafeReadAt

func SafeReadAt(reader *MultiReader, data []byte, offset int64) (int, error)

SafeReadAt reads len(data) bytes from reader at offset to data. It also guarantees that if not all data was not read, there is an error, but masks the io.EOF error out if all the data requested was read. In other words, it guarantees there is an error returned, if not all bytes requested were read, and only then there is an error.

Types

type BytesReader

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

func NewBytesReader

func NewBytesReader(b []byte) *BytesReader

func (*BytesReader) Append

func (r *BytesReader) Append(data []byte)

func (*BytesReader) Bytes

func (r *BytesReader) Bytes(offset int64, n int) ([]byte, error)

Bytes returns the slice of n bytes at the provided offset. It returns io.EOF if n bytes are not available.

func (*BytesReader) Len

func (r *BytesReader) Len() int

Len returns the number of bytes of the unread portion of the slice.

func (*BytesReader) ReadAt

func (r *BytesReader) ReadAt(b []byte, off int64) (n int, err error)

ReadAt implements the io.ReaderAt interface.

type MultiReader

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

MultiReader supports reading from two concatenated readers, which have to be either bytes readers or multi readers. The static typing of the readers (instead of using io.ReaderAt interface) makes this escape analysis compatible: the buffers passed for Read don't escape because of the MultiReader.

func NewMultiReaderFromBytesReader

func NewMultiReaderFromBytesReader(a *BytesReader) *MultiReader

Creates a new MultiReader from an existing BytesReader.

func NewMultiReaderFromBytesReaders

func NewMultiReaderFromBytesReaders(a, b *BytesReader) *MultiReader

Creates a new MultiReader from a pair of existing BytesReaders.

func NewMultiReaderFromMultiReader

func NewMultiReaderFromMultiReader(a *MultiReader, off int64, n int64) *MultiReader

Creates a new MultiReader from an existing MultiReader.

func NewMultiReaderFromMultiReaders

func NewMultiReaderFromMultiReaders(a *MultiReader, off int64, n int64, b *MultiReader) *MultiReader

Creates a new MultiReader from a pair of existing MultiReaders.

func (*MultiReader) Append

func (r *MultiReader) Append(data []byte)

func (*MultiReader) Bytes

func (r *MultiReader) Bytes(offset int64, n int) ([]byte, error)

Bytes returns the slice of n bytes at the provided offset. It returns io.EOF if n bytes are not available.

func (*MultiReader) HasBytesReaders

func (r *MultiReader) HasBytesReaders() bool

Is this MultiReader built from 1+ BytesReaders?

func (*MultiReader) HasMultiReaders

func (r *MultiReader) HasMultiReaders() bool

Is this MultiReader built from 1+ MultiReaders?

func (*MultiReader) Len

func (r *MultiReader) Len() int

func (*MultiReader) ReadAt

func (r *MultiReader) ReadAt(p []byte, offset int64) (n int, err error)

Implements io.ReaderAt

func (*MultiReader) UnpackBytesReaders

func (r *MultiReader) UnpackBytesReaders() (*BytesReader, *BytesReader)

UnpackBytesReaders extracts the BytesReader instance(s) in use by the MultiReader.

func (*MultiReader) UnpackMultiReaders

func (r *MultiReader) UnpackMultiReaders() (*MultiReader, *MultiReader)

UnpackMultiReaders extracts the MultiReader instance(s) in use by the MultiReader.

Jump to

Keyboard shortcuts

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