mirror of
https://github.com/Xpl0itU/WiiUDownloader.git
synced 2025-05-19 17:55:22 -04:00
Refactor downloadFile function to simplify progress reporting
This commit is contained in:
parent
34bdbbd8ce
commit
cb05374b18
1 changed files with 1 additions and 4 deletions
|
@ -44,7 +44,6 @@ func calculateDownloadSpeed(downloaded int64, startTime, endTime time.Time) int6
|
||||||
func downloadFile(ctx context.Context, progressReporter ProgressReporter, client *http.Client, downloadURL, dstPath string, doRetries bool, buffer []byte) error {
|
func downloadFile(ctx context.Context, progressReporter ProgressReporter, client *http.Client, downloadURL, dstPath string, doRetries bool, buffer []byte) error {
|
||||||
filePath := filepath.Base(dstPath)
|
filePath := filepath.Base(dstPath)
|
||||||
|
|
||||||
var speed int64
|
|
||||||
var startTime time.Time
|
var startTime time.Time
|
||||||
|
|
||||||
for attempt := 1; attempt <= maxRetries; attempt++ {
|
for attempt := 1; attempt <= maxRetries; attempt++ {
|
||||||
|
@ -100,9 +99,7 @@ func downloadFile(ctx context.Context, progressReporter ProgressReporter, client
|
||||||
}
|
}
|
||||||
|
|
||||||
downloaded += int64(n)
|
downloaded += int64(n)
|
||||||
endTime := time.Now()
|
progressReporter.UpdateDownloadProgress(downloaded, calculateDownloadSpeed(downloaded, startTime, time.Now()), filePath)
|
||||||
speed = calculateDownloadSpeed(downloaded, startTime, endTime)
|
|
||||||
progressReporter.UpdateDownloadProgress(downloaded, speed, filePath)
|
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue