mirror of
https://github.com/kopia/kopia.git
synced 2026-05-18 19:54:37 -04:00
27 lines
472 B
Go
27 lines
472 B
Go
package cas
|
|
|
|
import (
|
|
"io"
|
|
"sync/atomic"
|
|
)
|
|
|
|
// countingReader wraps an io.ReadCloser and counts bytes read.
|
|
type countingReader struct {
|
|
io.ReadCloser
|
|
|
|
counter *int64
|
|
}
|
|
|
|
func (cr *countingReader) Read(b []byte) (int, error) {
|
|
n, err := cr.ReadCloser.Read(b)
|
|
atomic.AddInt64(cr.counter, int64(n))
|
|
return n, err
|
|
}
|
|
|
|
func newCountingReader(source io.ReadCloser, counter *int64) io.ReadCloser {
|
|
return &countingReader{
|
|
ReadCloser: source,
|
|
counter: counter,
|
|
}
|
|
}
|