Skip to content

Commit d9d52f3

Browse files
committed
revise godocs of ProxyReader and ProxyWriter
1 parent 9050bce commit d9d52f3

1 file changed

Lines changed: 17 additions & 9 deletions

File tree

bar.go

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,15 @@ type renderFrame struct {
6161
err error
6262
}
6363

64-
// ProxyReader wraps io.Reader with metrics required for progress
65-
// tracking. If `r` is 'unknown total/size' reader it's mandatory
66-
// to call `(*Bar).SetTotal(-1, true)` after the wrapper returns
67-
// `io.EOF`. If bar is already completed or aborted, returns nil.
68-
// Panics if `r` is nil.
69-
func (b *Bar) ProxyReader(r io.Reader) io.ReadCloser {
64+
// ProxyReader wraps io.Reader with metrics required for progress tracking.
65+
// Panics if `r` is nil. If `r` is io.ReadCloser then calling Close on `pr`
66+
// will close underlying `r`s io.ReadCloser. If underlying *Bar instance is
67+
// already completed or aborted then value of `pr` is nil. If underlying
68+
// *Bar instance was initialized with total <= 0 then it's necessary to call
69+
// `(*Bar).SetTotal(-1, true)` after copy operation completes. Most of the
70+
// time it means that there is need to call `(*Bar).SetTotal(-1, true)` after
71+
// io.Copy(dst, pr) returns.
72+
func (b *Bar) ProxyReader(r io.Reader) (pr io.ReadCloser) {
7073
if r == nil {
7174
panic("expected non nil io.Reader")
7275
}
@@ -82,9 +85,14 @@ func (b *Bar) ProxyReader(r io.Reader) io.ReadCloser {
8285
}
8386

8487
// ProxyWriter wraps io.Writer with metrics required for progress tracking.
85-
// If bar is already completed or aborted, returns nil.
86-
// Panics if `w` is nil.
87-
func (b *Bar) ProxyWriter(w io.Writer) io.WriteCloser {
88+
// Panics if `w` is nil. If `w` is io.WriteCloser then calling Close on `pw`
89+
// will close underlying `w`s io.WriteCloser. If underlying *Bar instance is
90+
// already completed or aborted then value of `pw` is nil. If underlying
91+
// *Bar instance was initialized with total <= 0 then it's necessary to call
92+
// `(*Bar).SetTotal(-1, true)` after copy operation completes. Most of the
93+
// time it means that there is need to call `(*Bar).SetTotal(-1, true)` after
94+
// io.Copy(pw, src) returns.
95+
func (b *Bar) ProxyWriter(w io.Writer) (pw io.WriteCloser) {
8896
if w == nil {
8997
panic("expected non nil io.Writer")
9098
}

0 commit comments

Comments
 (0)