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?

vaughanos
  • 521
  • 5
  • 10

6 Answers6

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.

Kelvin
  • 20,119
  • 3
  • 60
  • 68
  • 1
    @vaughanos 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 :) – Kelvin Aug 05 '11 at 15:54
  • Thanks @kelvin, I'm new so don't have the appropriate 'reputation', but do appreciate your answer. – vaughanos Aug 07 '11 at 22:13
  • @vaughanos sorry about that - I forgot that 15 points are required to upvote. – Kelvin Aug 08 '11 at 14:51
  • Thanks, @Kevin. I agree, in my environment, zipruby produces working .docx files, rubyzip doesn't. Very helpful – Ray Baxter Oct 18 '12 at 06:58
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.

Community
  • 1
  • 1
Dan Rosenstark
  • 68,471
  • 58
  • 283
  • 421
  • 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. – vaughanos Aug 04 '11 at 22:52
  • @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. – Dan Rosenstark Aug 05 '11 at 12:12
  • 1
    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. – Zach Dennis Sep 15 '11 at 02:43
  • take a look at http://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). – Morozov Oct 19 '15 at 07:50
  • This wasn't a problem with ZipRuby :). – Morozov Oct 19 '15 at 08:02
0

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

muirbot
  • 2,061
  • 1
  • 20
  • 29
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.

Keith Johnston
  • 2,151
  • 1
  • 13
  • 14
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.

iafonov
  • 5,152
  • 1
  • 25
  • 21
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!

epatel
  • 45,805
  • 17
  • 110
  • 144