marcgg
marcgg

Reputation: 66436

How to create a zip archive using Ruby on Rails?

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.

Upvotes: 13

Views: 11641

Answers (3)

leomayleomay
leomayleomay

Reputation: 561

if gzip is an option, I recommend Gzip embedded in ActiveSupport

Upvotes: -3

nas
nas

Reputation: 3696

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.

Upvotes: 5

khelll
khelll

Reputation: 23990

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.

Upvotes: 14

Related Questions