Skip to content

Commit

Permalink
httputil: Avoid displaying percentage in download progress when conte…
Browse files Browse the repository at this point in the history
…nt length is not defined (#539)
  • Loading branch information
LINKIWI authored Feb 8, 2024
1 parent 0c6620a commit 006c13b
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions httputil/progress/progress.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,19 @@ func (p *progress) Write(buf []byte) (int, error) {

// Writes the current download progress to stdout.
func (p *progress) ShowProgress() {
message := fmt.Sprintf("%s: %s out of %s (%s)",
p.header,
formatMb(p.current),
formatMb(p.total),
formatPercentage(p.current, p.total))
var message string

if p.total > 0 {
message = fmt.Sprintf("%s: %s out of %s (%s)",
p.header,
formatMb(p.current),
formatMb(p.total),
formatPercentage(p.current, p.total))
} else {
message = fmt.Sprintf("%s: %s",
p.header,
formatMb(p.current))
}

if message == p.lastMessage {
return
Expand Down

0 comments on commit 006c13b

Please sign in to comment.