diff --git a/bar.go b/bar.go index 35644a4..dfdd18e 100644 --- a/bar.go +++ b/bar.go @@ -106,7 +106,7 @@ if r == nil { panic("expected non nil io.Reader") } - return newProxyReader(r, b) + return b.newProxyReader(r) } // ID returs id of the bar. diff --git a/proxyreader.go b/proxyreader.go index a16f5ec..88ab9a3 100644 --- a/proxyreader.go +++ b/proxyreader.go @@ -64,17 +64,19 @@ return n, err } -func newProxyReader(r io.Reader, bar *Bar) io.ReadCloser { +func (bar *Bar) newProxyReader(r io.Reader) io.ReadCloser { rc := toReadCloser(r) - rc = &proxyReader{rc, bar} - - if wt, isWriterTo := r.(io.WriterTo); bar.hasEwmaDecorators { - rc = &ewmaProxyReader{rc, bar} + wt, isWriterTo := r.(io.WriterTo) + if bar.hasEwmaDecorators { if isWriterTo { rc = &ewmaProxyWriterTo{rc, wt, bar} + } else { + rc = &ewmaProxyReader{rc, bar} } } else if isWriterTo { rc = &proxyWriterTo{rc, wt, bar} + } else { + rc = &proxyReader{rc, bar} } return rc }