readwrite

package
v0.0.0-...-2bb2ce4 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2022 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrLimitExceeded = errors.New("Read limit exceeded")

ErrLimitExceeded signals that the underlying reader has more available bytes than the expected limit

Functions

func CopyWithLimit

func CopyWithLimit(w io.Writer, r io.Reader, props ReadLimitProps) (int64, error)

CopyWithLimit copies props.Limit bytes from an io.Reader to an io.Writer. The copy fails if the reader has more bytes than the expected limit

Types

type BiReadWriter

type BiReadWriter interface {
	UniRead
	UniWrite
}

BiReadWriter interface for wrappers that need to process bidirectional communication between two endpoints.

type LimitReader

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

LimitReader is an io.Reader wrapper that ensures that no more than limit bytes are read from the reader

func NewLimitReader

func NewLimitReader(reader io.Reader, props ReadLimitProps) LimitReader

NewLimitReader returns a new LimitReader

func (LimitReader) Read

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

Read is the implementation of Reader for LimitReader

type ReadLimitProps

type ReadLimitProps struct {
	// FailOnExceed defines whether the LimitReader should return an
	// error if the underlying reader has more bytes than the limit
	FailOnExceed bool

	// Limit is the maximum number of bytes that can be read from the
	// reader and copied to the provided buffer
	Limit int64

	// ErrOnEOF sets whether the reader should return an io.EOF error
	// after finishing reading the underlying source
	ErrOnEOF bool
}

ReadLimitProps sets up the behaviour of the limit reader

type UniRead

type UniRead interface {
	// Read processes input from the remote endpoint provided
	// in the reader and writes to the writer the generated
	// output for the remote endpoint as a response, if any
	Read(io.Writer, io.Reader) (int, error)
}

UniRead defines an interface for unidirectional communication between a remote endpoint to the local endpoint

type UniReadFunc

type UniReadFunc func(io.Writer, io.Reader) (int, error)

UniReadFunc is the implementation of UniRead for functions

func (UniReadFunc) Read

func (f UniReadFunc) Read(w io.Writer, r io.Reader) (int, error)

Read is the implementation of Read for UniRead

type UniWrite

type UniWrite interface {
	// Write processes input from the local endpoint provided
	// in the reader and writes to the writer the generated
	// output for the remote endpoint as a response, if any
	Write(io.Writer, io.Reader) (int, error)
}

UniWrite defines an interface for unidirectional communication from the local endpoint to a remote endpoint

type UniWriteFunc

type UniWriteFunc func(io.Writer, io.Reader) (int, error)

UniWriteFunc is the implementation of UniWrite for functions

func (UniWriteFunc) Write

func (f UniWriteFunc) Write(w io.Writer, r io.Reader) (int, error)

Write is the implementation of Write for UniWrite

type Writer

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

Writer is a wrapper around a []byte so that it can be used as an io.Writer

func NewWriter

func NewWriter(p []byte) *Writer

NewWriter creates a new instance of a Writer

func (*Writer) Write

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

Write implements io.Write for a Writer

Jump to

Keyboard shortcuts

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