spipe

package
v1.1.1-0...-81d122b Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2020 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MultiError

type MultiError interface {
	error

	// Errors returns the original errors backing this error.
	Errors() []error
}

MultiError wraps a slice of errors into a single error type.

func NewMultiError

func NewMultiError(errs []error) MultiError

NewMultiError constructs a new MultiError instance from the given slice of errors.

type MultiReadCloser

type MultiReadCloser interface {
	io.ReadCloser

	// CloseImmediately controls whether the input readers will be closed as soon
	// as they are consumed rather than waiting for a Close call.
	CloseImmediately(bool) MultiReadCloser
}

MultiReadCloser defines an io.ReadCloser implementation that can read from and close multiple input streams as if they were one long stream.

The input streams will be read to completion in the order they are given to the MultiReader instance.

If the CloseImmediately option is set to true, the given streams will be closed, in order, as soon as they hit EOF.

func NewMultiReadCloser

func NewMultiReadCloser(inputs ...io.ReadCloser) MultiReadCloser

NewMultiReadCloser returns a new MultiReadCloser instance that will read from the given inputs in the order they are passed.

type MultiReader

type MultiReader interface {
	io.Reader
}

MultiReader defines an io.Reader implementation that can read from multiple input streams as if they were one long stream.

The input streams will be read to completion in the order they are given to the MultiReader instance.

func NewMultiReader

func NewMultiReader(inputs ...io.Reader) MultiReader

NewMultiReader returns a new MultiReader instance that will read from the given inputs in the order they are passed.

This operates in a manner different to `io.MultiReader` in that this implementation will proactively start reading from a secondary stream in a single Read call. The stdlib MultiReader returns from the Read call as soon as a single, non-empty stream is exhausted.

In practice, the following code

buffer := make([]byte, 512)
spipe.NewMultiReader(reader1, reader2).Read(buffer)

is functionally closer to

buffer := bytes.NewBuffer(make([]byte, 0, 512))
io.Copy(buffer, io.MultiReader(reader1, reader2))

than it is to

buffer := make([]byte, 512)
io.MultiReader(reader1, reader2).Read(buffer)

type SplitWriteCloser

type SplitWriteCloser interface {
	io.WriteCloser

	// IgnoreErrors sets whether or not the split writer should ignore errors
	// returned from secondary writers.
	IgnoreErrors(bool) SplitWriteCloser
}

SplitWriteCloser defines an io.WriteCloser implementation that writes to and can close multiple outputs.

func NewSplitWriteCloser

func NewSplitWriteCloser(
	raw io.WriteCloser,
	addtl ...io.WriteCloser,
) SplitWriteCloser

NewSplitWriteCloser constructs a new SplitWriteCloser instance with the given primary and secondary writers.

type SplitWriter

type SplitWriter interface {
	io.Writer

	// IgnoreErrors sets whether or not the split writer should ignore errors
	// returned from secondary writers.
	IgnoreErrors(bool) SplitWriter
}

SplitWriter defines an io.Writer implementation that writes to multiple outputs.

SplitWriter's implementation differs from `io.MultiWriter` in that it provides the option to ignore errors from secondary writers which lessens the need for composed wrappers for that particular use case. If you do not wish to ignore secondary writer errors, then SplitWriter is effectively the same as `io.MultiWriter`.

func NewSplitWriter

func NewSplitWriter(raw io.Writer, addtl ...io.Writer) SplitWriter

NewSplitWriter constructs a new SplitWriter instance with the given primary and secondary writers.

Jump to

Keyboard shortcuts

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