readers

package
v1.67.3 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package readers provides io.Reader related utilities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewContextReader added in v1.55.0

func NewContextReader(ctx context.Context, r io.Reader) io.Reader

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

func NoCloser added in v1.6.1

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 added in v1.50.20

type ErrorReader struct {
	Err error
}

ErrorReader wraps an error to return on Read

func (ErrorReader) Read added in v1.50.20

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

Read always returns the error

type FakeSeeker added in v1.59.1

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

FakeSeeker adapts an io.Seeker into an io.ReadSeeker

func (*FakeSeeker) Read added in v1.59.1

func (r *FakeSeeker) Read(p []byte) (n int, err error)

Read data from the stream. Will give an error if seeked.

func (*FakeSeeker) Seek added in v1.59.1

func (r *FakeSeeker) Seek(offset int64, whence int) (abs int64, err error)

Seek the stream - possible only before reading

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

type NoSeeker struct {
	io.Reader
}

NoSeeker adapts an io.Reader into an io.ReadSeeker.

However if Seek() is called it will return an error.

func (NoSeeker) Seek added in v1.62.1

func (r NoSeeker) Seek(offset int64, whence int) (abs int64, err error)

Seek the stream - returns 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

Jump to

Keyboard shortcuts

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