From cb05374b180fed480fb302d577a47f61e6e19ee7 Mon Sep 17 00:00:00 2001 From: Xpl0itU <24777100+Xpl0itU@users.noreply.github.com> Date: Wed, 17 Jan 2024 21:02:36 +0100 Subject: [PATCH] Refactor downloadFile function to simplify progress reporting --- downloader.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/downloader.go b/downloader.go index 6120113..113ccfb 100644 --- a/downloader.go +++ b/downloader.go @@ -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 { filePath := filepath.Base(dstPath) - var speed int64 var startTime time.Time for attempt := 1; attempt <= maxRetries; attempt++ { @@ -100,9 +99,7 @@ func downloadFile(ctx context.Context, progressReporter ProgressReporter, client } downloaded += int64(n) - endTime := time.Now() - speed = calculateDownloadSpeed(downloaded, startTime, endTime) - progressReporter.UpdateDownloadProgress(downloaded, speed, filePath) + progressReporter.UpdateDownloadProgress(downloaded, calculateDownloadSpeed(downloaded, startTime, time.Now()), filePath) } break }