reader

package
v0.0.85 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2024 License: MIT Imports: 14 Imported by: 75

Documentation

Index

Constants

View Source
const (
	// although this is more than enough for most cases
	MaxReadSize = 1 << 23 // 8MB
)

Variables

View Source
var ErrTimeout = errors.New("Timeout")
View Source
var (
	ErrTooLarge = errors.New("reader: too large only 8MB allowed as per MaxReadSize")
)

Functions

func ConnReadN added in v0.0.62

func ConnReadN(ctx context.Context, reader io.Reader, N int64) ([]byte, error)

ConnReadN reads at most N bytes from reader and it optimized for connection based readers like net.Conn it should not be used for file/buffer based reading, ConnReadN should be preferred instead of 'conn.Read() without loop' . It ignores EOF, UnexpectedEOF and timeout errors Note: you are responsible for adding a timeout to context

func ConnReadNWithTimeout added in v0.0.62

func ConnReadNWithTimeout(reader io.Reader, N int64, after time.Duration) ([]byte, error)

ConnReadNWithTimeout is same as ConnReadN but it takes timeout instead of context and it returns error if read does not finish in given time

func IsAcceptedError added in v0.0.62

func IsAcceptedError(err error) bool

IsAcceptedError checks if the error is accepted error for example: connection refused, io.EOF, io.ErrUnexpectedEOF while reading from connection

Types

type FrozenReader

type FrozenReader struct{}

FrozenReader is a reader that never returns

func (FrozenReader) Read

func (reader FrozenReader) Read(p []byte) (n int, err error)

Read into the buffer

type KeyPressReader added in v0.0.17

type KeyPressReader struct {
	Timeout time.Duration

	Once       *sync.Once
	Raw        bool
	BufferSize int
	// contains filtered or unexported fields
}

func (KeyPressReader) Read added in v0.0.17

func (reader KeyPressReader) Read(p []byte) (n int, err error)

Read into the buffer

func (*KeyPressReader) Start added in v0.0.17

func (reader *KeyPressReader) Start() error

func (*KeyPressReader) Stop added in v0.0.17

func (reader *KeyPressReader) Stop() error

type ReusableReadCloser

type ReusableReadCloser struct {
	*sync.RWMutex
	io.Reader
	// contains filtered or unexported fields
}

ReusableReadCloser is a reusable reader with no-op close

func NewReusableReadCloser

func NewReusableReadCloser(raw interface{}) (*ReusableReadCloser, error)

NewReusableReadCloser is returned for any type of input

func (ReusableReadCloser) Close

func (r ReusableReadCloser) Close() error

Close is a no-op close of ReusableReadCloser

func (ReusableReadCloser) Read

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

Read []byte from Reader

type TimeoutReader

type TimeoutReader struct {
	Timeout time.Duration
	Reader  io.Reader
	// contains filtered or unexported fields
}

TimeoutReader is a reader wrapper that stops waiting after Timeout

func (TimeoutReader) Read

func (reader TimeoutReader) Read(p []byte) (n int, err error)

Read into the buffer

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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