views:

756

answers:

3

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.

+3  A: 

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.

khelll
Thanks for the answer. Regarding rubyzip, is it maintained or at least fully working? And thanks for the delayed_job, it sounds like a nice next step for what I'm trying to do
marcgg
I'm not working on that project anymore but I believe it's working. Anyway you still can use the exec and send the command to linux to execute it.
khelll
Rubyzip is a good choice; if then you would need to extend the code to also unzip the content of an archive, you could easily add that, and you would not depend from any external program. Generally speaking (even it could be not your case), using a gem is the better solution, IMO.
kiamlaluno
Ok I'll go for rubyzip, it looks good. thanks
marcgg
+1  A: 

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.

nas
Why would it be bad to use a gem for just zipping? Could you elaborate?
marcgg
You would just be adding a layer of abstraction that's unnecessary. Exec calls the system command directly, loading a gem would have memory overhead without good reason. If you are going to use the other features of the gem though, by all means use it.
bensie
exactly what bensie has said
nas
A: 

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

leomayleomay