Source File
count.go
Belonging Package
go.pact.im/x/extraio
package extraioimport ()// ErrCounterOverflow is an error that CountReader returns when the counter// overflows 64-bit unsigned integer.var ErrCounterOverflow = errors.New("extraio: counter overflow")// CountReader counts bytes read from the underlying io.Reader. It is implicitly// limited to at most math.MaxUint64 bytes and returns ErrCounterOverflow error// if the limit is exceeded. In practice, that would require counting thousands// of petabytes to reach this limitation.type CountReader struct {reader io.Readercount uint64 // mutable}// NewCountReader returns a new reader that counts bytes read from r.func ( io.Reader) *CountReader {return &CountReader{reader: }}// Count returns the count of bytes read.func ( *CountReader) () uint64 {return .count}// Read implements the io.Reader interface. It reads from the underlying// io.Reader and increments read bytes counter.func ( *CountReader) ( []byte) (int, error) {switch := math.MaxUint64 - .count; {case == 0:return 0, ErrCounterOverflowcase < uint64(len()):= [:]}, := .reader.Read()if > 0 {.count += uint64()}return ,}
The pages are generated with Golds v0.7.6. (GOOS=linux GOARCH=amd64)