@@ -529,7 +529,7 @@ func (o *DownloadObjectOutput) mapFromGetObjectOutput(out *s3.GetObjectOutput, c
529
529
// download. These options are copies of the original Options instance, the client of which DownloadObject is called from.
530
530
// Modifying the options will not impact the original Client and Options instance.
531
531
func (c * Client ) DownloadObject (ctx context.Context , input * DownloadObjectInput , opts ... func (* Options )) (* DownloadObjectOutput , error ) {
532
- i := downloader {in : input , options : c .options .Copy (), w : input . WriterAt }
532
+ i := downloader {in : input , options : c .options .Copy ()}
533
533
for _ , opt := range opts {
534
534
opt (& i .options )
535
535
}
@@ -541,7 +541,6 @@ type downloader struct {
541
541
options Options
542
542
in * DownloadObjectInput
543
543
out * DownloadObjectOutput
544
- w io.WriterAt
545
544
546
545
wg sync.WaitGroup
547
546
m sync.Mutex
@@ -571,7 +570,7 @@ func (d *downloader) download(ctx context.Context) (*DownloadObjectOutput, error
571
570
return d .singleDownload (ctx , clientOptions ... )
572
571
}
573
572
574
- var output * GetObjectOutput
573
+ var output * DownloadObjectOutput
575
574
if d .options .MultipartDownloadType == types .MultipartDownloadTypePart {
576
575
if d .in .Range != "" {
577
576
return d .singleDownload (ctx , clientOptions ... )
@@ -583,7 +582,7 @@ func (d *downloader) download(ctx context.Context) (*DownloadObjectOutput, error
583
582
584
583
if output .PartsCount > 1 {
585
584
partSize := output .ContentLength
586
- ch := make (chan dlchunk , d .options .Concurrency )
585
+ ch := make (chan dlChunk , d .options .Concurrency )
587
586
for i := 0 ; i < d .options .Concurrency ; i ++ {
588
587
d .wg .Add (1 )
589
588
go d .downloadPart (ctx , ch , clientOptions ... )
@@ -594,25 +593,23 @@ func (d *downloader) download(ctx context.Context) (*DownloadObjectOutput, error
594
593
break
595
594
}
596
595
597
- ch <- dlchunk {w : d .w , start : d .pos - d .offset , part : i }
596
+ ch <- dlChunk {w : d .in . WriterAt , start : d .pos - d .offset , part : i }
598
597
d .pos += partSize
599
598
}
600
599
601
600
close (ch )
602
601
d .wg .Wait ()
603
602
}
604
603
} else {
605
- var total int64
606
604
if d .in .Range == "" {
607
605
output = d .getChunk (ctx , 0 , d .byteRange (), clientOptions ... )
608
- total = d .getTotalBytes ()
609
606
} else {
610
607
d .pos , d .totalBytes = d .getDownloadRange ()
611
608
d .offset = d .pos
612
- total = d .totalBytes
613
609
}
610
+ total := d .totalBytes
614
611
615
- ch := make (chan dlchunk , d .options .Concurrency )
612
+ ch := make (chan dlChunk , d .options .Concurrency )
616
613
for i := 0 ; i < d .options .Concurrency ; i ++ {
617
614
d .wg .Add (1 )
618
615
go d .downloadPart (ctx , ch , clientOptions ... )
@@ -625,7 +622,7 @@ func (d *downloader) download(ctx context.Context) (*DownloadObjectOutput, error
625
622
}
626
623
627
624
// Queue the next range of bytes to read.
628
- ch <- dlchunk {w : d .w , start : d .pos - d .offset , withRange : d .byteRange ()}
625
+ ch <- dlChunk {w : d .in . WriterAt , start : d .pos - d .offset , withRange : d .byteRange ()}
629
626
d .pos += d .options .PartSizeBytes
630
627
}
631
628
@@ -659,17 +656,17 @@ func (d *downloader) init(ctx context.Context) error {
659
656
}
660
657
661
658
func (d * downloader ) singleDownload (ctx context.Context , clientOptions ... func (* s3.Options )) (* DownloadObjectOutput , error ) {
662
- chunk := dlchunk {w : d .w }
663
- d .in .PartNumber = 0
659
+ chunk := dlChunk {w : d .in . WriterAt }
660
+ // d.in.PartNumber = 0
664
661
output , err := d .downloadChunk (ctx , chunk , clientOptions ... )
665
662
if err != nil {
666
- return output , err
663
+ return nil , err
667
664
}
668
665
669
- return output , err
666
+ return output , nil
670
667
}
671
668
672
- func (d * downloader ) downloadPart (ctx context.Context , ch chan dlchunk , clientOptions ... func (* s3.Options )) {
669
+ func (d * downloader ) downloadPart (ctx context.Context , ch chan dlChunk , clientOptions ... func (* s3.Options )) {
673
670
defer d .wg .Done ()
674
671
for {
675
672
chunk , ok := <- ch
@@ -690,8 +687,8 @@ func (d *downloader) downloadPart(ctx context.Context, ch chan dlchunk, clientOp
690
687
691
688
// getChunk grabs a chunk of data from the body.
692
689
// Not thread safe. Should only used when grabbing data on a single thread.
693
- func (d * downloader ) getChunk (ctx context.Context , part int32 , rng string , clientOptions ... func (* s3.Options )) * GetObjectOutput {
694
- chunk := dlchunk {w : d .w , start : d .pos - d .offset , part : part , withRange : rng }
690
+ func (d * downloader ) getChunk (ctx context.Context , part int32 , rng string , clientOptions ... func (* s3.Options )) * DownloadObjectOutput {
691
+ chunk := dlChunk {w : d .in . WriterAt , start : d .pos - d .offset , part : part , withRange : rng }
695
692
696
693
output , err := d .downloadChunk (ctx , chunk , clientOptions ... )
697
694
if err != nil {
@@ -705,7 +702,7 @@ func (d *downloader) getChunk(ctx context.Context, part int32, rng string, clien
705
702
}
706
703
707
704
// downloadChunk downloads the chunk from s3
708
- func (d * downloader ) downloadChunk (ctx context.Context , chunk dlchunk , clientOptions ... func (* s3.Options )) (* DownloadObjectOutput , error ) {
705
+ func (d * downloader ) downloadChunk (ctx context.Context , chunk dlChunk , clientOptions ... func (* s3.Options )) (* DownloadObjectOutput , error ) {
709
706
params := d .in .mapGetObjectInput (! d .options .DisableChecksumValidation )
710
707
if chunk .part != 0 {
711
708
params .PartNumber = aws .Int32 (chunk .part )
@@ -750,7 +747,7 @@ func (d *downloader) downloadChunk(ctx context.Context, chunk dlchunk, clientOpt
750
747
return output , err
751
748
}
752
749
753
- func (d * downloader ) tryDownloadChunk (ctx context.Context , params * s3.GetObjectInput , chunk * dlchunk , clientOptions ... func (* s3.Options )) (* s3.GetObjectOutput , int64 , error ) {
750
+ func (d * downloader ) tryDownloadChunk (ctx context.Context , params * s3.GetObjectInput , chunk * dlChunk , clientOptions ... func (* s3.Options )) (* s3.GetObjectOutput , int64 , error ) {
754
751
out , err := d .options .S3 .GetObject (ctx , params , clientOptions ... )
755
752
if err != nil {
756
753
return nil , 0 , err
@@ -865,7 +862,7 @@ func (d *downloader) setErr(e error) {
865
862
d .err = e
866
863
}
867
864
868
- type dlchunk struct {
865
+ type dlChunk struct {
869
866
w io.WriterAt
870
867
871
868
start int64
@@ -875,7 +872,7 @@ type dlchunk struct {
875
872
withRange string
876
873
}
877
874
878
- func (c * dlchunk ) Write (p []byte ) (int , error ) {
875
+ func (c * dlChunk ) Write (p []byte ) (int , error ) {
879
876
n , err := c .w .WriteAt (p , c .start + c .cur )
880
877
c .cur += int64 (n )
881
878
0 commit comments