zipruby or rubyzip?
Asked Answered
A

6

6

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?

Astrogation answered 2/8, 2011 at 3:25 Comment(3)
Can't you just use Ruby's zlib library that comes with Ruby itself?Carsick
Possible, but I like the convenience of the gems and am not looking to re-implement.Astrogation
@mauricio-linhares I don't think the zlib interface lets you manipulate zip files.Appolonia
C
2

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.

Closegrained answered 2/8, 2011 at 3:31 Comment(5)
thanks, good thoughts looking forward. I'm still trying to establish whether one is 'better' than the other - though general popularity may be a good enough indicator.Astrogation
@vaughanos, my general hypothesis is that popularity -> more attention and development --> you don't end up holding the bag on a gem that doesn't work because Rails or Ruby have changed.Closegrained
rubyzip doesn't always produce Windows compatible zip files. zipruby doesn't appear to have this problem. We recently hit issues with rubyzip (and rubyzip2 and the zip gem) which all failed to extract zip files on windows 7 that worked fine everywhere else.Rosenblum
take a look at blog.huangzhimin.com/2012/10/02/avoid-using-rubyzip . In my case using ZipRuby to replace files in existing archive (docx) was much easier. On the other hand Known issues in RubyZip repository advises me to rezip the whole docx to replace one file. This obviously produces a new zip without docx headers (it's still readable by word, but I need the file command to detect my file as docx).Diver
This wasn't a problem with ZipRuby :).Diver
A
17

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.

Appolonia answered 2/8, 2011 at 22:33 Comment(4)
@Astrogation If you any of the answers useful, please upvote. It encourages people to contribute better answers. Your question itself doesn't lend itself to a single definite answer, so I won't ask you to accept :)Appolonia
Thanks @kelvin, I'm new so don't have the appropriate 'reputation', but do appreciate your answer.Astrogation
@Astrogation sorry about that - I forgot that 15 points are required to upvote.Appolonia
Thanks, @Kevin. I agree, in my environment, zipruby produces working .docx files, rubyzip doesn't. Very helpfulSommers
C
2

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.

Closegrained answered 2/8, 2011 at 3:31 Comment(5)
thanks, good thoughts looking forward. I'm still trying to establish whether one is 'better' than the other - though general popularity may be a good enough indicator.Astrogation
@vaughanos, my general hypothesis is that popularity -> more attention and development --> you don't end up holding the bag on a gem that doesn't work because Rails or Ruby have changed.Closegrained
rubyzip doesn't always produce Windows compatible zip files. zipruby doesn't appear to have this problem. We recently hit issues with rubyzip (and rubyzip2 and the zip gem) which all failed to extract zip files on windows 7 that worked fine everywhere else.Rosenblum
take a look at blog.huangzhimin.com/2012/10/02/avoid-using-rubyzip . In my case using ZipRuby to replace files in existing archive (docx) was much easier. On the other hand Known issues in RubyZip repository advises me to rezip the whole docx to replace one file. This obviously produces a new zip without docx headers (it's still readable by word, but I need the file command to detect my file as docx).Diver
This wasn't a problem with ZipRuby :).Diver
K
0

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.

Kaisership answered 2/8, 2011 at 10:32 Comment(0)
L
0

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 ruby

Pinch: Retrieve a file from inside a zip file, over the network!

Litterbug answered 2/8, 2011 at 21:20 Comment(0)
L
0

rubyzip does not appear to do password protection, while zipruby does: link

Lavernlaverna answered 23/10, 2012 at 22:21 Comment(0)
R
0

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.

Revkah answered 18/8, 2014 at 3:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.