3

Amazon S3 API for Ruby 仅在将块传递给 read 方法时流式传输对象。我正在为 em-ftpd 开发一个驱动程序,它需要一个 IOish 对象来将 S3 数据流式传输到客户端。如果简单地通过 myS3Object.read,整个文件被加载到内存中,如 S3 API 所述。有什么方法可以将其封装成自定义 IO 类之类的东西,这样我就可以将流传递给 em-ftpd?

这是我的代码:

def get_file(path)
  #loading whole file into memory - not efficient
  yield bucket.objects[path].read
end

这是 em-ftpd 中的代码,它获取我的代码的结果,最好是作为 IOish 对象,使用块来获取其数据块:

# send a file to the client
def cmd_retr(param)
  send_unauthorised and return unless logged_in?
  send_param_required and return if param.nil?

  path = build_path(param)

  @driver.get_file(path) do |data|
    if data
      send_response "150 Data transfer starting #{data.size} bytes"
      send_outofband_data(data)
    else
      send_response "551 file not available"
    end
  end
end

谢谢你。

4

1 回答 1

1

原来我需要创建一个带有 S3 数据缓冲区的类以及 read 和 eof 方法?

于 2012-10-25T04:42:50.543 回答