Revert "proxyReader: manual trigger complete only if total is unknown"
This reverts commit a09474634f09b0b5af55d98570abc99d0407bdc8.
Vladimir Bauer
4 years ago
| 89 | 89 |
if r == nil {
|
| 90 | 90 |
panic("expected non nil io.Reader")
|
| 91 | 91 |
}
|
| 92 | |
result := make(chan bool)
|
| 93 | |
select {
|
| 94 | |
case b.operateState <- func(s *bState) { result <- s.triggerComplete }:
|
| 95 | |
triggerComplete := <-result
|
| 96 | |
return b.newProxyReader(r, !triggerComplete)
|
| 97 | |
case <-b.done:
|
| 98 | |
return nil
|
| 99 | |
}
|
|
92 |
return b.newProxyReader(r)
|
| 100 | 93 |
}
|
| 101 | 94 |
|
| 102 | 95 |
// ID returs id of the bar.
|
| 7 | 7 |
|
| 8 | 8 |
type proxyReader struct {
|
| 9 | 9 |
io.ReadCloser
|
| 10 | |
bar *Bar
|
| 11 | |
totalUnknown bool
|
|
10 |
bar *Bar
|
| 12 | 11 |
}
|
| 13 | 12 |
|
| 14 | 13 |
func (x proxyReader) Read(p []byte) (int, error) {
|
| 15 | 14 |
n, err := x.ReadCloser.Read(p)
|
| 16 | 15 |
x.bar.IncrBy(n)
|
| 17 | |
if x.totalUnknown && err == io.EOF {
|
|
16 |
if err == io.EOF {
|
| 18 | 17 |
go x.bar.SetTotal(-1, true)
|
| 19 | 18 |
}
|
| 20 | 19 |
return n, err
|
|
| 28 | 27 |
func (x proxyWriterTo) WriteTo(w io.Writer) (int64, error) {
|
| 29 | 28 |
n, err := x.wt.WriteTo(w)
|
| 30 | 29 |
x.bar.IncrInt64(n)
|
| 31 | |
if x.totalUnknown && err == io.EOF {
|
|
30 |
if err == io.EOF {
|
| 32 | 31 |
go x.bar.SetTotal(-1, true)
|
| 33 | 32 |
}
|
| 34 | 33 |
return n, err
|
|
| 61 | 60 |
return n, err
|
| 62 | 61 |
}
|
| 63 | 62 |
|
| 64 | |
func (b *Bar) newProxyReader(r io.Reader, totalUnknown bool) (rc io.ReadCloser) {
|
| 65 | |
pr := proxyReader{toReadCloser(r), b, totalUnknown}
|
|
63 |
func (b *Bar) newProxyReader(r io.Reader) (rc io.ReadCloser) {
|
|
64 |
pr := proxyReader{toReadCloser(r), b}
|
| 66 | 65 |
if wt, ok := r.(io.WriterTo); ok {
|
| 67 | 66 |
pw := proxyWriterTo{pr, wt}
|
| 68 | 67 |
if b.hasEwma {
|