reader

package
v0.0.0-...-98dad3e Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2024 License: Apache-2.0 Imports: 2 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrTooLong = fmt.Errorf("the incoming sample data is too long")

Functions

func LimitReader

func LimitReader(r io.Reader, n int64) io.Reader

LimitReader returns a Reader that reads from r but stops with ErrTooLong after n bytes. The underlying implementation is a *LimitedReader.

func NewLimitReadCloser

func NewLimitReadCloser(r io.ReadCloser, n int64) io.ReadCloser

Types

type LimitedReader

type LimitedReader struct {
	R io.Reader // underlying reader
	N int64     // max bytes remaining
}

A LimitedReader reads from R but limits the amount of data returned to just N bytes. Each call to Read updates N to reflect the new amount remaining. Read returns ErrTooLong when N <= 0 or when the underlying R returns EOF.

func (*LimitedReader) Read

func (l *LimitedReader) Read(p []byte) (n int, err error)

Jump to

Keyboard shortcuts

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