7 func NewCountingWriter(w io.Writer, f func(uint64)) io.WriteCloser {
8 return &countingReadWriter{
14 func NewCountingReader(r io.Reader, f func(uint64)) io.ReadCloser {
15 return &countingReadWriter{
21 type countingReadWriter struct {
27 func (crw *countingReadWriter) Read(buf []byte) (int, error) {
28 n, err := crw.reader.Read(buf)
29 crw.counter(uint64(n))
33 func (crw *countingReadWriter) Write(buf []byte) (int, error) {
34 n, err := crw.writer.Write(buf)
35 crw.counter(uint64(n))
39 func (crw *countingReadWriter) Close() error {
40 if c, ok := crw.writer.(io.Closer); ok {