Skip to content

Instantly share code, notes, and snippets.

@IndianGuru
Created September 4, 2011 05:17
Show Gist options
  • Save IndianGuru/1192307 to your computer and use it in GitHub Desktop.
Save IndianGuru/1192307 to your computer and use it in GitHub Desktop.
File compression
require "rubygems"
require "bundler/setup"
require 'zip/zip'
# Hard-coding the file names
file = "jruby-complete.jar"
zip = "zip.zip"
if File.exists?(file)
#Create a Zip object to put compressed data in
Zip::ZipFile.open(zip, true) do |zipfile|
begin
puts "#{file} is being added to the archive."
#add a file to the zip object
zipfile.add(file,file)
rescue Exception => e
puts "Error adding to zipfile: \n #{e}."
end
end
else
puts "\nFile could not be found."
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment