如何使用 Ruby on Rails 创建 zip 存档?
我的目录中有一堆文件。我想将其中一些压缩到一个 zip 存档中。
我可以看到有 各种 solutions 这样做。我可以使用诸如 rubyzip 之类的 gem 或运行 exec
并仅使用命令行工具。
这将影响我正在开发的系统的一个重要部分,因此我希望获得一些关于使用 Rails 创建 zip 文件的反馈和/或指导。
I have a bunch of files in a directory. I want to zip some of them together into a zip archive.
I can see there are various solutions for doing so. I could use a gem such as rubyzip or run exec
and just use a command line tool.
This is going to impact an important part of the system I'm working on so I'd love to have some feedback and/or directions on creating zip files with Rails.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
rubyzip 是一个不错的选择。我用它来压缩我之前开发的社交应用程序中私人消息中的附件。但是,如果您要压缩的文件很大,那么建议您使用 进行一些后台处理例如,delayed_job。
rubyzip is a good choice. I Have used it to zip attachments in private messaging in a social app that i worked on before. However, if the files you are zipping are of big sizes, then you are advised to do some background processing using delayed_job for example.
如果您只是压缩文件而不执行任何其他操作,那么我建议使用 exec 或 system 或 %x 来执行压缩,因为安装和使用 gem 来执行这样的小任务没有多大意义。
但是,如果您想要做的不仅仅是压缩某个目录并利用 gem 提供的其他功能,那么显而易见的选择是使用 rubyzip gem。
If you are only zipping the files and not doing anything else then I would suggest using exec or system or %x to do the zipping because installing and using a gem for such a minor task doesn't make much sense.
However, if you want to do more than just zipping some directory and utilize other functionality that the gem offers then the obvious choice would be to use the rubyzip gem.
如果可以选择 gzip,我建议将 Gzip 嵌入 ActiveSupport
if gzip is an option, I recommend Gzip embedded in ActiveSupport