iomisc

package
v0.0.0-...-8023e94 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2021 License: BSD-2-Clause Imports: 5 Imported by: 0

Documentation

Overview

Package iomisc provides miscellaneous I/O functions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MultiCloser

func MultiCloser(closers ...io.Closer) io.Closer

MultiCloser returns an io.Closer that is the logical concatenation of the provided input closers. They are closed sequentially in the provided order. It is guaranteed that all underlying closers will be closed.

func ReadUntilMatch

func ReadUntilMatch(ctx context.Context, m *MatchingReader) ([]byte, error)

ReadUntilMatch reads from a MatchingReader until a match has been read and returns the match. Checks ctx for cancellation only between calls to m.Read(), so cancellation will not be noticed if m.Read() blocks. See https://github.com/golang/go/issues/20280 for discussion of similar issues.

func ReaderAtToReader

func ReaderAtToReader(r io.ReaderAt) io.Reader

ReaderAtToReader creates a new Reader from a ReaderAt.

Types

type MatchingReader

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

MatchingReader is an io.Reader implementation that wraps another such implementation. It reads only up until one of the sequences has been read consecutively.

func NewMatchingReader

func NewMatchingReader(reader io.Reader, toMatch [][]byte) *MatchingReader

NewMatchingReader returns a MatchingReader that matches any of toMatch.

func (*MatchingReader) Match

func (m *MatchingReader) Match() []byte

Match returns the first match among the bytes read, or nil if there has yet to be a match.

func (*MatchingReader) Read

func (m *MatchingReader) Read(p []byte) (int, error)

Read reads from the underlying reader and checks whether the pattern has been matched among the bytes read. Once a match has been found, subsequent reads will return an io.EOF.

Jump to

Keyboard shortcuts

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