@@ -189,9 +189,16 @@ type parallelDownloadConfig struct {
189189func parallelDownload (ctx context.Context , c * parallelDownloadConfig ) error {
190190 eg , ctx := errgroup .WithContext (ctx )
191191
192- eg .Go (func () error {
193- return progressBar (ctx , c .ContentLength , c .PartialDir )
194- })
192+ bar := pb .Start64 (c .ContentLength ).SetWriter (stdout ).Set (pb .Bytes , true )
193+ defer bar .Finish ()
194+
195+ // check file size already downloaded for resume
196+ size , err := checkProgress (c .PartialDir )
197+ if err != nil {
198+ return errors .Wrap (err , "failed to get directory size" )
199+ }
200+
201+ bar .SetCurrent (size )
195202
196203 for _ , task := range c .Tasks {
197204 task := task
@@ -200,14 +207,14 @@ func parallelDownload(ctx context.Context, c *parallelDownloadConfig) error {
200207 if err != nil {
201208 return err
202209 }
203- return task .download (req )
210+ return task .download (req , bar )
204211 })
205212 }
206213
207214 return eg .Wait ()
208215}
209216
210- func (t * task ) download (req * http.Request ) error {
217+ func (t * task ) download (req * http.Request , bar * pb. ProgressBar ) error {
211218 resp , err := t .Client .Do (req )
212219 if err != nil {
213220 return errors .Wrapf (err , "failed to get response: %q" , t .String ())
@@ -220,7 +227,9 @@ func (t *task) download(req *http.Request) error {
220227 }
221228 defer output .Close ()
222229
223- if _ , err := io .Copy (output , resp .Body ); err != nil {
230+ rd := bar .NewProxyReader (resp .Body )
231+
232+ if _ , err := io .Copy (output , rd ); err != nil {
224233 return errors .Wrapf (err , "failed to write response body: %q" , t .String ())
225234 }
226235
0 commit comments