readers

package
v1.52.3-0...-16af9ab Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2020 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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.Reader

NewPatternReader creates a reader, that returns a deterministic byte pattern. After length bytes are read

func NoCloser

func NoCloser(in io.Reader) io.Reader

NoCloser makes sure that the io.Reader passed in can't upgraded to an io.Closer.

This is for use with http.NewRequest to make sure the body doesn't get upgraded to an io.Closer and the body closed unexpectedly.

func ReadFill

func ReadFill(r io.Reader, buf []byte) (n int, err error)

ReadFill reads as much data from r into buf as it can

It reads until the buffer is full or r.Read returned an error.

This is io.ReadFull but when you just want as much data as possible, not an exact size of block.

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.

func (*CountingReader) Read

func (cr *CountingReader) Read(b []byte) (int, error)

Read reads from the underlying reader.

type ErrorReader

type ErrorReader struct {
	Err error
}

ErrorReader wraps an error to return on Read

func (ErrorReader) Read

func (er ErrorReader) Read(p []byte) (n int, err error)

Read always returns the error

type LimitedReadCloser

type LimitedReadCloser struct {
	*io.LimitedReader
	io.Closer
}

LimitedReadCloser adds io.Closer to io.LimitedReader. Create one with NewLimitedReadCloser

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

Jump to

Keyboard shortcuts

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