Skip to content

Commit 89eb04e

Browse files
authored
feat(resume): add progress bar when checking existing data (#1031)
Fixes #1026 When resuming a large file transfer (>10MB), display a progress bar showing 'Checking [filename]' while scanning the existing file to determine which chunks are missing. This provides visual feedback during the check phase, preventing users from thinking the application has frozen on large files. Co-authored-by: Murat Aslan <[email protected]>
1 parent 211c65a commit 89eb04e

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/utils/utils.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,24 @@ func MissingChunks(fname string, fsize int64, chunkSize int) (chunkRanges []int6
334334
return
335335
}
336336

337+
// Show progress bar for large files (> 10MB)
338+
var bar *progressbar.ProgressBar
339+
showProgress := fsize > 10*1024*1024
340+
if showProgress {
341+
fnameShort := path.Base(fname)
342+
if len(fnameShort) > 20 {
343+
fnameShort = fnameShort[:20] + "..."
344+
}
345+
bar = progressbar.NewOptions64(fsize,
346+
progressbar.OptionSetWriter(os.Stderr),
347+
progressbar.OptionShowBytes(true),
348+
progressbar.OptionSetDescription(fmt.Sprintf("Checking %s", fnameShort)),
349+
progressbar.OptionClearOnFinish(),
350+
progressbar.OptionFullWidth(),
351+
progressbar.OptionThrottle(100*time.Millisecond),
352+
)
353+
}
354+
337355
emptyBuffer := make([]byte, chunkSize)
338356
chunkNum := 0
339357
chunks := make([]int64, int64(math.Ceil(float64(fsize)/float64(chunkSize))))
@@ -349,6 +367,12 @@ func MissingChunks(fname string, fsize int64, chunkSize int) (chunkRanges []int6
349367
chunkNum++
350368
}
351369
currentLocation += int64(bytesread)
370+
if showProgress && bar != nil {
371+
bar.Add(bytesread)
372+
}
373+
}
374+
if showProgress && bar != nil {
375+
bar.Finish()
352376
}
353377
if chunkNum == 0 {
354378
chunkRanges = []int64{}

0 commit comments

Comments
 (0)