summaryrefslogtreecommitdiff
path: root/vendor/github.com/vbauerster/mpb/proxyreader.go
blob: d2692ccf4a70de45e27e9802614ada411d711c4a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
package mpb

import (
	"io"
	"time"
)

// proxyReader is io.Reader wrapper, for proxy read bytes
type proxyReader struct {
	io.ReadCloser
	bar *Bar
	iT  time.Time
}

func (pr *proxyReader) Read(p []byte) (n int, err error) {
	n, err = pr.ReadCloser.Read(p)
	if n > 0 {
		pr.bar.IncrBy(n, time.Since(pr.iT))
		pr.iT = time.Now()
	}
	return
}