有没有一种简单的方法来缓冲 io.ReaderAt 和 io.WriterAt?

huangapple go评论74阅读模式
英文:

Is there an easy way to buffer io.ReaderAt and io.WriterAt?

问题

我正在为工作中的一个项目实现一个自定义的SFTP服务器,它将使用与AWS兼容的系统作为后端。根据我所看到的,我认为我应该使用sftp.Handlers接口来实现s3.Uploader和s3.Downloaders3.PutObject和s3.GetObject

我以前使用过io.PipeReaderio.PipeWriter将io.Writer连接到io.Reader,但在这种情况下,我需要做类似以下的操作:

  • Get: io.ReaderAt <- ??? <- io.Reader
  • Put: io.WriterAt -> ??? -> io.Reader

我猜想在这两种情况下,"???"将是不同的,但它们似乎都是一种类型的管道,我们将数据保留直到另一端可用。是否存在这样的机制,还是我需要自己实现它?对于实现它,有什么建议吗?

英文:

I'm implementing a custom sftp server for a project at work that will use an AWS compatible system as the backend. Based on what I am seeing, I'm thinking I should implement the sftp.Handlers interface using the s3.Uploader and s3.Downloader or s3.PutObject and s3.GetObject.

I've used io.PipeReader and io.PipeWriter before to pipe an io.Writer to an io.Reader but in this case, I need to do something like:

  • Get: io.ReaderAt <- ??? <- io.Reader
  • Put: io.WriterAt -> ??? -> io.Reader

I'm guessing ??? will be different in both cases but they both seem like they'd be a type of pipe where we hold data until it's available for the other end. Does something like this exist or do I need to implement it myself? Any suggestions on implementing it?

答案1

得分: 2

我个人正在使用https://github.com/avvmoto/buf-readerat,它专门用于缓冲ReadAt。为我节省了很多麻烦。

英文:

I'm personally making use of https://github.com/avvmoto/buf-readerat which specifically buffers ReadAt. Saved me a lot of pain.

huangapple
  • 本文由 发表于 2017年6月14日 02:33:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/44529031.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定