blob: d942a8ee7ce5c8b202704b67e9dbf78c83462dfd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
package kagus
import (
"io"
)
// CountWriter wraps around an io.Writer and counts the amount of bytes written.
type CountWriter struct {
W io.Writer
N int64 // Total number of bytes written
}
func NewCountWriter(w io.Writer) *CountWriter {
return &CountWriter{W: w}
}
func (cw *CountWriter) Write(p []byte) (int, error) {
n, err := cw.W.Write(p)
cw.N += int64(n)
return n, err
}
|