mirror of
https://github.com/Xpl0itU/WiiUDownloader.git
synced 2025-05-27 13:34:36 -04:00
Use ctxio package for context aware downloads
This commit is contained in:
parent
770d8e45f9
commit
a30fb575b2
3 changed files with 13 additions and 1 deletions
|
@ -12,6 +12,7 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
ctxio "github.com/jbenet/go-context/io"
|
||||
"golang.org/x/sync/errgroup"
|
||||
"golang.org/x/sync/semaphore"
|
||||
)
|
||||
|
@ -82,7 +83,9 @@ func downloadFileWithSemaphore(ctx context.Context, progressReporter ProgressRep
|
|||
|
||||
progressReporter.SetTotalDownloadedForFile(basePath, 0)
|
||||
writerProgress := newWriterProgress(file, progressReporter, basePath)
|
||||
_, err = io.Copy(writerProgress, resp.Body)
|
||||
writerProgressWithContext := ctxio.NewWriter(ctx, writerProgress)
|
||||
bodyReaderWithContext := ctxio.NewReader(ctx, resp.Body)
|
||||
_, err = io.Copy(writerProgressWithContext, bodyReaderWithContext)
|
||||
if err != nil {
|
||||
file.Close()
|
||||
resp.Body.Close()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue