io

package
v0.0.0-...-02bf512 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package io provides io functions

SPDX-License-Identifier: Apache-2.0

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrorReader

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

ErrorReader is an io.Reader that returns a non-eof error after some input bytes have been read. This is mostly useful for testing, where the input bytes can get the code being tested to reach a desired state first, then verify that code correctly handles non-eof errors.

When the error is returned, the number of bytes is always 0. If there is at least one byte remaining to read and a call to read asks for more bytes than remain, the result of the call is (num remaining bytes, nil), and the next call to read returns (0, error). If the input is an empty slice, the first call to read returns (0, error).

Once all input bytes have been read and the error has been returned, any further calls to read will continue to return (0, error).

func NewErrorReader

func NewErrorReader(input []byte, err error) *ErrorReader

NewErrorReader constructs an ErrorReader from a set of input bytes and an error

func (*ErrorReader) Read

func (r *ErrorReader) Read(p []byte) (int, error)

Read is the io.Reader method, that eventually returns with the provided error

type ErrorWriter

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

ErrorWriter is the Writer analog to ErrorReader, it returns a non-eof error after some output bytes have been written. A preallocated slice of bytes tracks the bytes written, so the caller can compare.

func NewErrorWriter

func NewErrorWriter(count int, err error) *ErrorWriter

NewErrorWriter constructs an ErrorWriter from a count of output bytes to allow and an error

func (*ErrorWriter) Output

func (w *ErrorWriter) Output() []byte

Output provides the output written to the write so far, for comparison

func (*ErrorWriter) Write

func (w *ErrorWriter) Write(p []byte) (int, error)

Write is the io.Writer method, that eventually returns with the provided error

Directories

Path Synopsis
Package writer provides writers
Package writer provides writers

Jump to

Keyboard shortcuts

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