Skip to content

Commit

Permalink
Include rate and progress in part completion output.
Browse files Browse the repository at this point in the history
  • Loading branch information
stefansundin committed Nov 14, 2021
1 parent a73bc70 commit f44602c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
12 changes: 4 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ func run() (int, error) {
}
}

var s flowrate.Status
partStartTime := time.Now()
partData := make([]byte, min(partSize, fileSize-offset))
n, err := f.ReadAt(partData, offset)
Expand Down Expand Up @@ -548,13 +549,8 @@ func run() (int, error) {
}
}

var targetRate string
if rate != 0 {
targetRate = fmt.Sprintf(" (limit: %s/s)", formatSize(rate))
}

s := reader.Status()
fmt.Printf("\033[2K\rUploading part %d: %s, %s/s%s, %s remaining. (total: %s, %s remaining)", partNumber, s.Progress, formatSize(s.CurRate), targetRate, s.TimeRem.Round(time.Second), s.TotalProgress, s.TotalTimeRem.Round(time.Second))
s = reader.Status()
fmt.Printf("\033[2K\rUploading part %d: %s, %s/s%s, %s remaining. (total: %s, %s remaining)", partNumber, s.Progress, formatSize(s.CurRate), formatLimit(rate), s.TimeRem.Round(time.Second), s.TotalProgress, s.TotalTimeRem.Round(time.Second))
}

// Part upload has completed or failed
Expand All @@ -565,7 +561,7 @@ func run() (int, error) {
} else {
timeElapsed = timeElapsed.Round(time.Second)
}
fmt.Printf("\033[2K\rUploaded part %d in %s.\n", partNumber, timeElapsed)
fmt.Printf("\033[2K\rUploaded part %d in %s (%s/s%s). (total: %s, %s remaining)\n", partNumber, timeElapsed, formatSize(s.CurRate), formatLimit(rate), s.TotalProgress, s.TotalTimeRem.Round(time.Second))

// Check if the user wants to stop
if interrupted {
Expand Down
7 changes: 7 additions & 0 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,13 @@ func formatFilesize(size int64) string {
}
}

func formatLimit(rate int64) string {
if rate == 0 {
return ""
}
return fmt.Sprintf(" (limit: %s/s)", formatSize(rate))
}

func getSha256Sum(sumsFn string, entryPath string) (string, error) {
entryPath, err := filepath.Abs(entryPath)

Expand Down

0 comments on commit f44602c

Please sign in to comment.