Module: Selenium::WebDriver::Zipper
- Defined in:
- lib/selenium/webdriver/common/zipper.rb
Constant Summary collapse
- EXTENSIONS =
%w[.zip .xpi]
Class Method Summary collapse
Class Method Details
.unzip(path) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/selenium/webdriver/common/zipper.rb', line 11 def self.unzip(path) destination = Dir.mktmpdir("unzip") FileReaper << destination Zip::ZipFile.open(path) do |zip| zip.each do |entry| to = File.join(destination, entry.name) dirname = File.dirname(to) FileUtils.mkdir_p dirname unless File.exist? dirname zip.extract(entry, to) end end destination end |
.zip(path) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/selenium/webdriver/common/zipper.rb', line 28 def self.zip(path) tmp_zip = Tempfile.new("webdriver-zip") begin zos = Zip::ZipOutputStream.new(tmp_zip.path) ::Find.find(path) do |file| next if File.directory?(file) entry = file.sub("#{path}/", '') zos.put_next_entry(entry) zos << File.read(file) p :added => file, :as => entry end zos.close tmp_zip.rewind [tmp_zip.read].pack("m") ensure tmp_zip.close end end |