大佬教程收集整理的这篇文章主要介绍了即时发送/流式传输动态 tarball 更新 1更新 2,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个列表,可以说是 3 个文件(/tmp/a.gz
、/tmp/b.gz
、/tmp/c.gz
)。我想将这些文件压缩成 tarball 并将其发送给用户。
问题是那些文件很大,我不想先创建一个tar文件,然后发送它,然后再删除它。
如何在不将其保存在 HDD 或 RAM 上的情况下动态创建和发送 tar 文件?
在控制器中,send_data
应该是正确的方法,但我目前不知道如何创建这样的 tarball 流对象。
我试过这样的事情
# in my controller
command = "tar -C /tmp -cf - a.gz b.gz c.gz | cat"
send_data `#{Command }`,type: 'application/x-tar',disposition: 'attachment',filename: 'file_name.tar'
我添加了 | cat
以消除 tar 错误消息
tar: Refusing to write archive contents to terminal (missing -f option?)
tar: Error is not recoverable: exiTing Now
它可以工作,但问题是 tar 首先加载到 RAM 中。
我将 include ActionController::live
添加到我的控制器并尝试流式传输数据,但结果仍然首先加载到 RAM
def download
filename = "some.tar"
disposition = Actiondispatch::http::Contentdisposition.format(disposition: "attachment",filename: fileName)
response.headers["Content-disposition"] = disposition
response.headers["Content-Type"] = "application/x-tar"
response.headers.delete("Content-Length")
response.headers["Cache-Control"] = "no-cache"
response.headers["Last-ModifIEd"] = Time.Now.httpdate.to_s
response.headers["X-Accel-Buffering"] = "no"
command = "tar -C /tmp -cf - a.gz b.gz c.gz | cat"
response.stream.write open("|#{CommanD}").read
ensure
response.stream.close
end
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
以上是大佬教程为你收集整理的即时发送/流式传输动态 tarball 更新 1更新 2全部内容,希望文章能够帮你解决即时发送/流式传输动态 tarball 更新 1更新 2所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。