Skip to content

Commit 9386054

Browse files
Write directly to file (#171)
1 parent f144d21 commit 9386054

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

pkg/leeway/cache.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -494,19 +494,20 @@ func (rs *S3RemoteCache) getObject(ctx context.Context, key string, path string)
494494
downloader := manager.NewDownloader(rs.s3Client, func(d *manager.Downloader) {
495495
d.PartSize = S3_PART_SIZE
496496
})
497-
buffer := manager.NewWriteAtBuffer([]byte{})
498-
res, err := downloader.Download(context.TODO(), buffer, &s3.GetObjectInput{
497+
498+
file, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY, 0644)
499+
if err != nil {
500+
return 0, xerrors.Errorf("failed to write s3 download to %s: %s", path, err)
501+
}
502+
defer file.Close()
503+
res, err := downloader.Download(context.TODO(), file, &s3.GetObjectInput{
499504
Bucket: aws.String(rs.BucketName),
500505
Key: aws.String(key),
501506
})
502507
if err != nil {
503508
return res, err
504509
}
505510

506-
err = os.WriteFile(path, buffer.Bytes(), 0644)
507-
if err != nil {
508-
return 0, xerrors.Errorf("failed to write s3 download to %s: %s", path, err)
509-
}
510511
return res, nil
511512
}
512513

0 commit comments

Comments
 (0)