in s3plugin/restore.go [222:252]
func downloadFile(sess *session.Session, config *PluginConfig, bucket string, fileKey string,
file *os.File) (int64, time.Duration, error) {
start := time.Now()
downloader := s3manager.NewDownloader(sess, func(u *s3manager.Downloader) {
u.PartSize = config.Options.DownloadChunkSize
})
totalBytes, err := getFileSize(downloader.S3, bucket, fileKey)
if err != nil {
return 0, -1, errors.Wrap(err, fmt.Sprintf("Error getting file size for %s in bucket %s", fileKey, bucket))
}
gplog.Verbose("File %s size = %d bytes", filepath.Base(fileKey), totalBytes)
if totalBytes <= config.Options.DownloadChunkSize {
buffer := &aws.WriteAtBuffer{}
if _, err = downloader.Download(
buffer,
&s3.GetObjectInput{
Bucket: aws.String(bucket),
Key: aws.String(fileKey),
}); err != nil {
return 0, -1, errors.Wrap(err, fmt.Sprintf("Error while downloading %s", fileKey))
}
if _, err = file.Write(buffer.Bytes()); err != nil {
return 0, -1, err
}
} else {
return downloadFileInParallel(sess, config.Options.DownloadConcurrency, config.Options.DownloadChunkSize, totalBytes, bucket, fileKey, file)
}
return totalBytes, time.Since(start), err
}