Buffer implementing io.WriterAt in go


I’m using the aws-sdk to download a file from an s3 bucket. The S3 download function want’s something that implements io.WriterAt however bytes.Buffer doesn’t implement that. Right now I’m creating a file which implements io.WriterAt but I’d like something in memory.


For cases involving the AWS SDK, use aws.WriteAtBuffer to download S3 objects into memory.

requestInput := s3.GetObjectInput{
    Bucket: aws.String(bucket),
    Key:    aws.String(key),

buf := aws.NewWriteAtBuffer([]byte{})
downloader.Download(buf, &requestInput)

fmt.Printf("Downloaded %v bytes", len(buf.Bytes()))

Answered By – Sam

Answer Checked By – Candace Johnson (GoLangFix Volunteer)

Leave a Reply

Your email address will not be published.