(ctx context.Context, bucketName string, objectKey string, fileName string)
| 66 | } |
| 67 | |
| 68 | func (basics *Bucket) DownloadFile(ctx context.Context, bucketName string, objectKey string, fileName string) (*int64, error) { |
| 69 | f, err := os.Create(fileName) |
| 70 | if err != nil { |
| 71 | return nil, fmt.Errorf("failed to create file %q, %v", fileName, err) |
| 72 | } |
| 73 | defer f.Close() |
| 74 | |
| 75 | downloader := manager.NewDownloader(basics.S3Client, func(u *manager.Downloader) { |
| 76 | u.PartSize = downloadPartSize |
| 77 | }) |
| 78 | |
| 79 | numBytes, err := downloader.Download(ctx, f, &s3.GetObjectInput{ |
| 80 | Bucket: aws.String(bucketName), |
| 81 | Key: aws.String(objectKey), |
| 82 | }) |
| 83 | |
| 84 | if err != nil { |
| 85 | return nil, fmt.Errorf("failed to download file, %v", err) |
| 86 | } |
| 87 | |
| 88 | return &numBytes, nil |
| 89 | } |
no test coverage detected