Skip to content

Instantly share code, notes, and snippets.

@gregoriokusowski
Created March 9, 2011 11:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gregoriokusowski/862057 to your computer and use it in GitHub Desktop.
Save gregoriokusowski/862057 to your computer and use it in GitHub Desktop.
A simple unzipper :)
#rubygem: rubyzip
require 'zip/zip'
#Ex.: Unzip.from("my_file.zip").to("my_folder")
class Unzip
def initialize(source)
@source = source
end
def self.from(source)
self.new(source)
end
def to(dest)
Zip::ZipFile.open(@source) do |zip_file|
zip_file.each do |f|
f_path=File.join(dest, f.name)
FileUtils.mkdir_p(File.dirname(f_path))
zip_file.extract(f, f_path) unless File.exist?(f_path)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment