1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
11 func NewCountingWriter(w io.Writer, f func(uint64)) io.WriteCloser {
12 return &countingReadWriter{
18 func NewCountingReader(r io.Reader, f func(uint64)) io.ReadCloser {
19 return &countingReadWriter{
25 type countingReadWriter struct {
31 func (crw *countingReadWriter) Read(buf []byte) (int, error) {
32 n, err := crw.reader.Read(buf)
33 crw.counter(uint64(n))
37 func (crw *countingReadWriter) Write(buf []byte) (int, error) {
38 n, err := crw.writer.Write(buf)
39 crw.counter(uint64(n))
43 func (crw *countingReadWriter) Close() error {
44 if c, ok := crw.writer.(io.Closer); ok {