...
1 package rifs
2
3 import (
4 "io"
5 )
6
7
8 type ReadCounter struct {
9 r io.Reader
10 counter int
11 }
12
13
14 func NewReadCounter(r io.Reader) *ReadCounter {
15 return &ReadCounter{
16 r: r,
17 }
18 }
19
20
21 func (rc *ReadCounter) Count() int {
22 return rc.counter
23 }
24
25
26 func (rc *ReadCounter) Reset() {
27 rc.counter = 0
28 }
29
30
31 func (rc *ReadCounter) Read(b []byte) (n int, err error) {
32 n, err = rc.r.Read(b)
33 rc.counter += n
34
35 return n, err
36 }
37
View as plain text