stream

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2024 License: Apache-2.0 Imports: 10 Imported by: 1

README

stream

stream helpers

Package stream provides helpers for reading from and writing to stream.

Dependencies

Nothing other than std.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrWhence = errors.New("unknown whence")
	ErrOffset = errors.New("invalid offset")
)
View Source
var (
	ErrInvalidSize = errors.New("invalid size")
)

Functions

func NewCancellable

func NewCancellable(ctx context.Context, r io.Reader) io.Reader

NewCancellable combines ctx and r so that a returned Reader reads from r and also respects context cancellation.

The returned Reader stores a first error encountered, including EOF and context cancellation. If any error has occurred, any subsequent Read calls always return same error.

The context cancellation prevents afterwards Read calls from actually reading the underlying r. However that does not mean that it would unblock already blocking Read calls (e.g. reading sockets, terminals, etc.) If r is possible to block long and you wish to unblock it in that case, r itself must be cancellable by its own mean. For files, you can combine os.Pipe and platform specific poll functions, for example, epoll for Linux, kqueue for Mac OS.

The returned Reader is not goroutine safe. Calling Read multiple times simultaneously may cause undefined behaviors.

func NewMultiError

func NewMultiError(errs []error) error

NewMultiError wraps errors into single error ignoring nil error in errs. If all errors are nil or len(errs) == 0, NewMultiError returns nil.

func NewMultiErrorUnchecked

func NewMultiErrorUnchecked(errs []error) error

NewMultiErrorUnchecked wraps errors into single error. As suffix "unchecked" implies it does not do any filtering for errs. The returned error is always non nil even if all errors are nil or len(errs) == 0.

func NewMultiReadCloser

func NewMultiReadCloser[T io.ReadCloser](r ...T) io.ReadCloser

Types

type FileLike

type FileLike interface {
	Stat() (fs.FileInfo, error)
	io.ReaderAt
}

type ReadAtReadSeekCloser

type ReadAtReadSeekCloser interface {
	io.ReaderAt
	io.ReadSeekCloser
}

func NewMultiReadAtSeekCloser

func NewMultiReadAtSeekCloser(readers []SizedReaderAt) ReadAtReadSeekCloser

type ReadAtSizer

type ReadAtSizer interface {
	io.ReaderAt
	Size() int64
}

type SizedReaderAt

type SizedReaderAt struct {
	R    io.ReaderAt
	Size int64
}

func SizedReadersFromFileLike

func SizedReadersFromFileLike[T FileLike](files []T) ([]SizedReaderAt, error)

SizedReadersFromFileLike constructs []SizedReaderAt from file like objects. For example, *os.File and afero.File implement FileLike.

func SizedReadersFromReadAtSizer

func SizedReadersFromReadAtSizer[T ReadAtSizer](readers []T) []SizedReaderAt

SizedReadersFromReadAtSizer constructs []SizedReaderAt from ReaderAt with Size method. For example, *io.SectionReader implements ReadAtSizer.

Jump to

Keyboard shortcuts

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