Documentation ¶
Overview ¶
Package readers provides io.Reader related utilities.
Index ¶
- func NewContextReader(ctx context.Context, r io.Reader) io.Reader
- func NewFakeSeeker(in io.Reader, length int64) io.ReadSeeker
- func NewGzipReader(in io.ReadCloser) (io.ReadCloser, error)
- func NewLimitedReadCloser(rc io.ReadCloser, limit int64) (lrc io.ReadCloser)
- func NewPatternReader(length int64) io.ReadSeeker
- func NoCloser(in io.Reader) io.Reader
- func ReadFill(r io.Reader, buf []byte) (n int, err error)
- type CountingReader
- type ErrorReader
- type FakeSeeker
- type LimitedReadCloser
- type NoSeeker
- type RepeatableReader
- func NewRepeatableLimitReader(r io.Reader, size int) *RepeatableReader
- func NewRepeatableLimitReaderBuffer(r io.Reader, buf []byte, size int64) *RepeatableReader
- func NewRepeatableReader(r io.Reader) *RepeatableReader
- func NewRepeatableReaderBuffer(r io.Reader, buf []byte) *RepeatableReader
- func NewRepeatableReaderSized(r io.Reader, size int) *RepeatableReader
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewContextReader ¶ added in v1.55.0
NewContextReader creates a reader, that returns any errors that ctx gives
func NewFakeSeeker ¶ added in v1.59.1
func NewFakeSeeker(in io.Reader, length int64) io.ReadSeeker
NewFakeSeeker creates a fake io.ReadSeeker from an io.Reader
This can be seeked before reading to discover the length passed in.
func NewGzipReader ¶ added in v1.61.1
func NewGzipReader(in io.ReadCloser) (io.ReadCloser, error)
NewGzipReader returns an io.ReadCloser which will read the stream and close it when Close is called.
Unfortunately gz.Reader does not close the underlying stream so we can't use that directly.
func NewLimitedReadCloser ¶
func NewLimitedReadCloser(rc io.ReadCloser, limit int64) (lrc io.ReadCloser)
NewLimitedReadCloser returns a LimitedReadCloser wrapping rc to limit it to reading limit bytes. If limit < 0 then it does not wrap rc, it just returns it.
func NewPatternReader ¶
func NewPatternReader(length int64) io.ReadSeeker
NewPatternReader creates a reader, that returns a deterministic byte pattern. After length bytes are read
Types ¶
type CountingReader ¶
type CountingReader struct {
// contains filtered or unexported fields
}
CountingReader holds a reader and a read count of how many bytes were read so far.
func NewCountingReader ¶
func NewCountingReader(in io.Reader) *CountingReader
NewCountingReader returns a CountingReader, which will read from the given reader while keeping track of how many bytes were read.
func (*CountingReader) BytesRead ¶
func (cr *CountingReader) BytesRead() uint64
BytesRead returns how many bytes were read from the underlying reader so far.
type ErrorReader ¶ added in v1.50.20
type ErrorReader struct {
Err error
}
ErrorReader wraps an error to return on Read
type FakeSeeker ¶ added in v1.59.1
type FakeSeeker struct {
// contains filtered or unexported fields
}
FakeSeeker adapts an io.Seeker into an io.ReadSeeker
type LimitedReadCloser ¶
type LimitedReadCloser struct { *io.LimitedReader io.Closer }
LimitedReadCloser adds io.Closer to io.LimitedReader. Create one with NewLimitedReadCloser
func (*LimitedReadCloser) Close ¶ added in v1.62.1
func (lrc *LimitedReadCloser) Close() error
Close closes the underlying io.Closer. The error, if any, will be ignored if data is read completely
type NoSeeker ¶ added in v1.62.1
NoSeeker adapts an io.Reader into an io.ReadSeeker.
However if Seek() is called it will return an error.
type RepeatableReader ¶
type RepeatableReader struct {
// contains filtered or unexported fields
}
A RepeatableReader implements the io.ReadSeeker it allow to seek cached data back and forth within the reader but will only read data from the internal Reader as necessary and will play nicely with the Account and io.LimitedReader to reflect current speed
func NewRepeatableLimitReader ¶
func NewRepeatableLimitReader(r io.Reader, size int) *RepeatableReader
NewRepeatableLimitReader create new repeatable reader from Reader r with an initial buffer of size wrapped in an io.LimitReader to read only size.
func NewRepeatableLimitReaderBuffer ¶
func NewRepeatableLimitReaderBuffer(r io.Reader, buf []byte, size int64) *RepeatableReader
NewRepeatableLimitReaderBuffer create new repeatable reader from Reader r and buf wrapped in an io.LimitReader to read only size.
func NewRepeatableReader ¶
func NewRepeatableReader(r io.Reader) *RepeatableReader
NewRepeatableReader create new repeatable reader from Reader r
func NewRepeatableReaderBuffer ¶
func NewRepeatableReaderBuffer(r io.Reader, buf []byte) *RepeatableReader
NewRepeatableReaderBuffer create new repeatable reader from Reader r using the buffer passed in.
func NewRepeatableReaderSized ¶
func NewRepeatableReaderSized(r io.Reader, size int) *RepeatableReader
NewRepeatableReaderSized create new repeatable reader from Reader r with an initial buffer of size.
func (*RepeatableReader) Read ¶
func (r *RepeatableReader) Read(b []byte) (n int, err error)
Read data from original Reader into bytes Data is either served from the underlying Reader or from cache if was already read
func (*RepeatableReader) Seek ¶
func (r *RepeatableReader) Seek(offset int64, whence int) (int64, error)
Seek implements the io.Seeker interface. If seek position is passed the cache buffer length the function will return the maximum offset that can be used and "fs.RepeatableReader.Seek: offset is unavailable" Error