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