1
1
mirror of https://github.com/walles/moar.git synced 2024-11-22 21:50:43 +03:00
moar/m/inspection-reader.go
Johan Walles 27817741fc Fix a bytes counting race condition
Before this change, if the file grew after we read it, but before we
noted its size, then tailing could misbehave.
2024-07-15 07:03:06 +02:00

16 lines
283 B
Go

package m
import "io"
// Pass-through reader that counts the number of bytes read.
type inspectionReader struct {
base io.Reader
bytesCount int64
}
func (r *inspectionReader) Read(p []byte) (n int, err error) {
n, err = r.base.Read(p)
r.bytesCount += int64(n)
return
}