iomisc

package
v0.0.0-...-bbc9ce3 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 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, reader io.Reader, toMatch ...[]byte) ([]byte, error)

ReadUntilMatch reads from a Reader until it encounters an occurrence of one of the byte slices specified in toMatch. 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 ReadUntilMatchString

func ReadUntilMatchString(ctx context.Context, reader io.Reader, strings ...string) (string, error)

ReadUntilMatchString has identical behavior to ReadUntilMatch, but accepts and returns strings instead of byte slices.

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