在go中实现io.WriterAt的缓冲区 [英] Buffer implementing io.WriterAt in go
本文介绍了在go中实现io.WriterAt的缓冲区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用aws-sdk从s3存储桶下载文件. S3下载功能想要实现io.WriterAt的东西,但是bytes.Buffer不能实现.现在,我正在创建一个实现io.WriterAt的文件,但是我想在内存中添加一些东西.
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()))
这篇关于在go中实现io.WriterAt的缓冲区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文