zipruby 还是 rubyzip?
我这里有一个 ruby on Rails 站点(rails 2.0.2,ruby 1.8.6),安装了 rubyzip 和 zipruby,但它们在 File.exists 上有冲突?方法,所以我想删除一个。关于未来最好的 zipping api 的普遍共识是什么?
两者相比是否有显着优势?
I've got a ruby on rails site here (rails 2.0.2, ruby 1.8.6) with both rubyzip and zipruby installed, but they conflict on the File.exists? method so I want to remove one. What's the general consensus out there on the best zipping api going forward?
Are there significant advantages of one over another?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
据我所知,rubyzip 有时会奇怪地处理 zip 文件,因为它自己处理 zip 文件索引和记录。例如,如果您使用 rubyzip 解压 docx 文件并重新打包,Microsoft Word 将无法打开它。但 zipruby 使用非常标准的 libzip C 库(有轻微的定制)并且不会破坏 docx。因此,如果您的目标是格式兼容性,我建议使用 zipruby。也许自从我尝试后 rubyzip 已经有所改进 - 但你应该自己尝试一下。
From what I've seen, rubyzip sometimes handles zip files strangely because it does its own handling of the zip file index and records. For example, if you use rubyzip to unpack a docx file and repack it, Microsoft Word won't open it. But zipruby uses the very standard libzip C library (with slight customizations) and won't mangle a docx. So if you're aiming for format compatibility, I'd suggest using zipruby. Maybe rubyzip has improved since I tried it - but you should try it yourself.
完全随机的答案,因为我也从未尝试过:从当前状态来看,RubyZip 可能更有希望。从以下(少量)数据来看,RubyZip 更受欢迎,并且似乎与新版本的 Ruby 配合得更好:
RubyZip with 1.9: http://isitruby19.com/rubyzip
ZipRuby 1.9:http://isitruby19.com/zipruby
除非你得到更好的证据,否则我会选择 rubyZip。另请参阅 哪些 zip 库适用于 Ruby 1.9.2 ?。然而,还有一个 RubyZip 的分支 (https://github.com/postmodern/rubyzip2)表明它的受欢迎程度。而且文档看起来更有趣。
Totally random answer, as I've never tried either: moving forward from your current state, RubyZip might be more promising. Judging from the following (scant) data, RubyZip is both more popular and seems to work better with new versions of Ruby:
RubyZip with 1.9: http://isitruby19.com/rubyzip
ZipRuby with 1.9: http://isitruby19.com/zipruby
Unless you get some better evidence, I'd go with rubyZip. Also see What zip library works well with Ruby 1.9.2?. However, there's also a fork of RubyZip (https://github.com/postmodern/rubyzip2) again pointing to its popularity. And the docs looks more interesting.
我经常使用 https://github.com/toretore/zippy gem,我认为它相当好的。它是 rubyzip 的包装器,极大地简化了 zip 文件的操作。
I have used https://github.com/toretore/zippy gem a lot and I think it is quite good. It is wrapper for rubyzip and it dramatically simplifies operations with zip files.
如果您只需要从 zip 文件中获取单个文件或几个文件,您可以尝试使用
Pinch
,它可以让您通过 ruby 中的 http 提取文件捏:通过网络从 zip 文件内检索文件!
If you only need to get a single file or a few files from a zipfile you can try to use
Pinch
which will let you extract a file over http in rubyPinch: Retrieve a file from inside a zip file, over the network!
rubyzip 似乎不提供密码保护,而 zipruby 则提供: 链接
rubyzip does not appear to do password protection, while zipruby does: link
看来 rubyzip 可以为文件存储不正确的未压缩值,这会导致某些解压缩库(如 miniz)在解压缩时失败。 zipruby 看起来存储了正确的未压缩大小。我会选择 zipruby。
It appears that rubyzip can store the incorrect uncompressed value for a file, which causes some uncompression libraries (like miniz) to fail when uncompressing. zipruby looks like it stores the correct uncompressed size. I'm going to go with zipruby.