Minor formatting changes to ProgressReader. Newlines when complete

This commit is contained in:
Charles Hooper 2013-03-14 01:37:47 +00:00
parent e614690f07
commit 3686feaccc
1 changed files with 5 additions and 1 deletions

View File

@ -113,13 +113,17 @@ func (r *progressReader) Read(p []byte) (n int, err error) {
// Only update progress for every 1% read
update_every := int(0.01 * float64(r.read_total))
if r.read_progress - r.last_update > update_every {
if r.read_progress - r.last_update > update_every || r.read_progress == r.read_total {
fmt.Fprintf(r.output, "%d/%d (%.0f%%)\r",
r.read_progress,
r.read_total,
float64(r.read_progress) / float64(r.read_total) * 100)
r.last_update = r.read_progress
}
// Send newline when complete
if err == io.EOF {
fmt.Fprintf(r.output, "\n")
}
return read, err
}