问题描述
我正在努力让 rubyzip 将目录附加到 zipoutputstream.(我想要输出流,所以我可以从 rails 控制器发送它).我的代码遵循这个例子:
I'm struggling with getting rubyzip to append directories to a zipoutputstream. (I want the output stream so I can send it from a rails controller). My code follows this example:
http://info.michael-simons.eu/2008/01/21/using-rubyzip-to-create-zip-files-on-the-fly/
当修改为在要添加的文件列表中包含目录时,出现以下错误:
When modified to include directories in the list of files to add I get the following error:
任何帮助将不胜感激.
更新
在尝试了许多解决方案后,我在 zipruby 上取得了最大的成功,它有一个干净的 api 和很好的例子:http://zipruby.rubyforge.org/.
After trying a number of solutions I had best success with zipruby which has a clean api and good examples: http://zipruby.rubyforge.org/.
推荐答案
Zip::ZipFile.open(path, Zip::ZipFile::CREATE) do |zip|
songs.each do |song|
zip.add "record/#{song.title.parameterize}.mp3", song.file.to_file.path
end
end
这篇关于使用 rubyzip 将文件和嵌套目录添加到 zipoutputstream的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!