2016-06-13 04:35:28 +02:00
|
|
|
package pb
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
)
|
|
|
|
|
|
|
|
// It's proxy reader, implement io.Reader
|
|
|
|
type Reader struct {
|
|
|
|
io.Reader
|
|
|
|
bar *ProgressBar
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *Reader) Read(p []byte) (n int, err error) {
|
|
|
|
n, err = r.Reader.Read(p)
|
|
|
|
r.bar.Add(n)
|
|
|
|
return
|
|
|
|
}
|
2016-07-14 23:59:20 +02:00
|
|
|
|
|
|
|
// Close the reader when it implements io.Closer
|
|
|
|
func (r *Reader) Close() (err error) {
|
|
|
|
if closer, ok := r.Reader.(io.Closer); ok {
|
|
|
|
return closer.Close()
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|