Skip to content

Commit dcf65a2

Browse files
committed
download from s3 to pipewriter
1 parent e091926 commit dcf65a2

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

pkg/skbn/s3.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,10 @@ func DownloadFromS3(iClient interface{}, path string, pw *nio.PipeWriter) error
103103
for attempt < attempts {
104104
attempt++
105105

106-
buffer := &aws.WriteAtBuffer{}
107106
downloader := s3manager.NewDownloader(s)
107+
downloader.Concurrency = 1 // support PipeWriterWrapper
108108

109-
_, err := downloader.Download(buffer,
109+
_, err := downloader.Download(pipeWriterWrapper{pw},
110110
&s3.GetObjectInput{
111111
Bucket: aws.String(bucket),
112112
Key: aws.String(s3Path),
@@ -118,16 +118,20 @@ func DownloadFromS3(iClient interface{}, path string, pw *nio.PipeWriter) error
118118
utils.Sleep(attempt)
119119
continue
120120
}
121-
122-
// this is a workaround
123-
// we do not want to save the entire file to memory
124-
pw.Write(buffer.Bytes())
125121
return nil
126122
}
127123

128124
return nil
129125
}
130126

127+
type pipeWriterWrapper struct {
128+
pw *nio.PipeWriter
129+
}
130+
131+
func (pww pipeWriterWrapper) WriteAt(p []byte, off int64) (n int, err error) {
132+
return pww.pw.Write(p)
133+
}
134+
131135
// UploadToS3 uploads a single file to S3
132136
func UploadToS3(iClient interface{}, toPath, fromPath string, pr *nio.PipeReader) error {
133137
s := iClient.(*session.Session)

0 commit comments

Comments
 (0)