go4.org: go4.org/readerutil Index | Examples | Files | Directories

package readerutil

import "go4.org/readerutil"

Package readerutil provides and operates on io.Readers.

Package readerutil contains io.Reader types.

Index

Examples

Package Files

bufreaderat.go countingreader.go fakeseeker.go multireaderat.go readersize.go readerutil.go

func NewBufferingReaderAt Uses

func NewBufferingReaderAt(r io.Reader) io.ReaderAt

NewBufferingReaderAt returns an io.ReaderAt that reads from r as necessary and keeps a copy of all data read in memory.

func NewFakeSeeker Uses

func NewFakeSeeker(r io.Reader, size int64) io.ReadSeeker

NewFakeSeeker returns a ReadSeeker that can pretend to Seek (based on the provided total size of the reader's content), but any reads will fail if the fake seek position doesn't match reality.

func NewStatsReadSeeker Uses

func NewStatsReadSeeker(v *expvar.Int, rs io.ReadSeeker) io.ReadSeeker

NewReaderStats returns an io.ReadSeeker that will have the number of bytes read from rs added to v.

func NewStatsReader Uses

func NewStatsReader(v *expvar.Int, r io.Reader) io.Reader

NewReaderStats returns an io.Reader that will have the number of bytes read from r added to v.

Code:

var (
    // r is the io.Reader we'd like to count read from.
    r   = strings.NewReader("Hello world")
    v   = expvar.NewInt("read-bytes")
    sw  = NewStatsReader(v, r)
)
// Read from the wrapped io.Reader, StatReader will count the bytes.
io.Copy(ioutil.Discard, sw)
fmt.Printf("Read %s bytes\n", v.String())

Output:

Read 11 bytes

func Size Uses

func Size(r io.Reader) (size int64, ok bool)

Size tries to determine the length of r. If r is an io.Seeker, Size may seek to guess the length.

type CountingReader Uses

type CountingReader struct {
    Reader io.Reader
    N      *int64
}

CountingReader wraps a Reader, incrementing N by the number of bytes read. No locking is performed.

func (CountingReader) Read Uses

func (cr CountingReader) Read(p []byte) (n int, err error)

type ReadSeekCloser Uses

type ReadSeekCloser interface {
    io.Reader
    io.Seeker
    io.Closer
}

A ReadSeekCloser can Read, Seek, and Close.

type ReaderAtCloser Uses

type ReaderAtCloser interface {
    io.ReaderAt
    io.Closer
}

type SizeReaderAt Uses

type SizeReaderAt interface {
    Size() int64
    io.ReaderAt
}

A SizeReaderAt is a ReaderAt with a Size method.

An io.SectionReader implements SizeReaderAt.

func NewMultiReaderAt Uses

func NewMultiReaderAt(parts ...SizeReaderAt) SizeReaderAt

NewMultiReaderAt is like io.MultiReader but produces a ReaderAt (and Size), instead of just a reader.

Directories

PathSynopsis
singlereaderpackage singlereader provides Open and Close operations, reusing existing file descriptors when possible.

Package readerutil imports 8 packages (graph) and is imported by 40 packages. Updated 2018-04-13. Refresh now. Tools for package owners.