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.
To zip (compress) a file or folder Locate the file or folder that you want to zip. Press and hold (or right-click) the file or folder, select (or point to) Send to, and then select Compressed (zipped) folder. A new zipped folder with the same name is created in the same location.
rubyzip is a ruby module for reading and writing zip files.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With