lib/selenium/webdriver/common/zipper.rb in selenium-webdriver-0.1.3.dev vs lib/selenium/webdriver/common/zipper.rb in selenium-webdriver-0.1.3
- old
+ new
@@ -24,29 +24,24 @@
destination
end
def self.zip(path)
- tmp_zip = Tempfile.new("webdriver-zip")
+ # can't use Tempfile here since it doesn't support File::BINARY mode on 1.8
+ Dir.mktmpdir { |tmp_dir|
+ zip_path = File.join(tmp_dir, "webdriver-zip")
- begin
- zos = Zip::ZipOutputStream.new(tmp_zip.path)
+ Zip::ZipFile.open(zip_path, Zip::ZipFile::CREATE) { |zip|
+ ::Find.find(path) do |file|
+ next if File.directory?(file)
+ entry = file.sub("#{path}/", '')
- ::Find.find(path) do |file|
- next if File.directory?(file)
- entry = file.sub("#{path}/", '')
+ zip.add entry, file
+ end
+ }
- zos.put_next_entry(entry)
- zos << File.read(file)
- end
-
- zos.close
- tmp_zip.rewind
-
- [tmp_zip.read].pack("m")
- ensure
- tmp_zip.close
- end
+ File.open(zip_path, "rb") { |io| Base64.encode64 io.read }
+ }
end
end # Zipper
end # WebDriver
end # Selenium