blog.robotex.de

Ruby: Handling zip files

There is a zip gem for Ruby. You can find it here

Creating zip files

First, you have to install the zip gem:

$> gem install zip

or, when using rails, you can add it to your Rails.root/Gemfile:

gem 'zip'

Then you can do something like this:

require 'zip/zip'

Zip::ZipFile.open("output.zip", Zip::ZipFile::CREATE) do |zip_file|
  zip_file.add "filename_in_the_zipfile.txt", "some_source_file.txt"
end

Back