使用 ruby​​zip 将文件和嵌套目录添加到 zipoutputstream [英] Using rubyzip to add files and nested directories to a zipoutputstream

查看:48
本文介绍了使用 ruby​​zip 将文件和嵌套目录添加到 zipoutputstream的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力让 ruby​​zip 将目录附加到 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

这篇关于使用 ruby​​zip 将文件和嵌套目录添加到 zipoutputstream的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆