Closed Naatan closed 6 years ago
I can't see anything wrong here. It is expected behaviour. I suppose, you'd like to achieve smooth bar replacement effect, if so see complex example.
In the code you provided, you can avoid Atoi
:
size := resp.ContentLength
Also size
could be unknown, i.e. less than zero, so you'd better add following after io.Copy
line:
n, err := io.Copy(dest, reader)
if size <= 0 {
bar.SetTotal(n, err == nil)
}
Strange, this is what I am seeing:
https://asciinema.org/a/7t8pAwshsi5oyQWxyMX1hide2
I can repro it in few different terminals.
Smooth bar replacement looks interesting, I'll see if that helps. Still seems like there's something weird going on here though.
resp.ContentLength
didn't work for me, it was coming up empty.
Make sure, you're on latest commit. Tiny URL in your example returns no content length, so I had to set total at the end to reproduce.
Take the following sample code:
Note that this is using 3 channel workers, so only 3 downloads occur at a time. A new worker (and thus progressbar) isnt created until an old one has completed.
When you run the code you briefly see all progressbars spawned and then see the expired ones disappear soon after. It seems it is prioritising creating new progressbars over destroying old ones, making it so your screen gets filled with stale progressbars and creating a glitchy user experience.