@@ -14,14 +14,7 @@ import (
1414)
1515
1616func (s * storager ) Download (ctx context.Context , location string , options ... storage.Option ) (reader io.ReadCloser , err error ) {
17- retry := base .NewRetry ()
18- for i := 0 ; i < maxRetries ; i ++ {
19- reader , err = s .download (ctx , location , options )
20- if ! isRetryError (err ) {
21- return reader , err
22- }
23- sleepBeforeRetry (retry )
24- }
17+ reader , err = s .download (ctx , location , options )
2518 return reader , err
2619}
2720
@@ -35,12 +28,13 @@ func (s *storager) download(ctx context.Context, location string, options []stor
3528 key := & option.AES256Key {}
3629 stream := & option.Stream {}
3730 option .Assign (options , & md5 , & crc , & key , & stream )
31+
3832 if len (key .Key ) != 0 {
3933 if err := SetCustomKeyHeader (key , call .Header ()); err != nil {
4034 return nil , err
4135 }
4236 }
43- object , err := call . Do ( )
37+ object , err := s . getObject ( ctx , location , options )
4438 if err == nil {
4539 if err = md5 .Decode (object .Md5Hash ); err == nil {
4640 err = crc .Decode (object .Crc32c )
@@ -49,32 +43,23 @@ func (s *storager) download(ctx context.Context, location string, options []stor
4943 if err != nil {
5044 return nil , err
5145 }
52-
5346 if len (key .Key ) != 0 {
5447 if err := SetCustomKeyHeader (key , call .Header ()); err != nil {
5548 return nil , err
5649 }
5750 }
5851 if stream .PartSize > 0 {
5952 stream .Size = int (object .Size )
60- readSeeker := NewReadSeeker (call , int (object .Size ))
53+ readSeeker := NewReadSeeker (ctx , s , call , int (object .Size ))
6154 reader := base .NewStreamReader (stream , readSeeker )
6255 return reader , nil
6356 }
6457
6558 var response * nhttp.Response
66- retry := base .NewRetry ()
67- for i := 0 ; i < maxRetries ; i ++ {
59+ err = runWithRetries (ctx , func () error {
6860 response , err = call .Download ()
69- if err == nil {
70- break
71- }
72- if ! isRetryError (err ) {
73- return nil , errors .Wrapf (err , "failed to download gs://%v/%v " , s .bucket , location )
74- }
75- sleepBeforeRetry (retry )
76- }
77-
61+ return err
62+ }, s )
7863 if err != nil {
7964 return nil , errors .Wrapf (err , "failed to download gs://%v/%v " , s .bucket , location )
8065 }
0 commit comments