Module: Selenium::WebDriver::Zipper Private
| Relationships & Source Files | |
| Defined in: | rb/lib/selenium/webdriver/common/zipper.rb |
Constant Summary
-
EXTENSIONS =
# File 'rb/lib/selenium/webdriver/common/zipper.rb', line 33%w[.zip .xpi].freeze
-
RUBYZIP_V3 =
# File 'rb/lib/selenium/webdriver/common/zipper.rb', line 34Zip::VERSION >= '3.0.0'
Class Method Summary
- .unzip(path) Internal use only
- .zip(path) Internal use only
-
.zip_file(path)
Alias for .zip_root.
-
.zip_root(path)
(also: .zip_file)
Internal use only
Keeps
path(a file or directory) as the archive's single top-level entry, unlike#zipwhich flattens a directory's contents; the Grid upload endpoint returns that one entry's path. - .add_zip_entry(zip, file, entry_name) private Internal use only
- .encode_zip(path, base) private Internal use only
- .with_tmp_zip(&blk) private Internal use only
Class Method Details
.add_zip_entry(zip, file, entry_name) (private)
[ GitHub ].encode_zip(path, base) (private)
[ GitHub ]# File 'rb/lib/selenium/webdriver/common/zipper.rb', line 73
def encode_zip(path, base) with_tmp_zip do |zip| ::Find.find(path) do |file| add_zip_entry zip, file, file.sub("#{base}/", '') unless File.directory?(file) end zip.commit File.open(zip.name, 'rb') { |io| Base64.strict_encode64 io.read } end end
.unzip(path)
[ GitHub ]# File 'rb/lib/selenium/webdriver/common/zipper.rb', line 37
def unzip(path) destination = Dir.mktmpdir('webdriver-unzip') FileReaper << destination Zip::File.open(path) do |zip| zip.each do |entry| to = File.join(destination, entry.name) dirname = File.dirname(to) FileUtils.mkdir_p dirname if RUBYZIP_V3 zip.extract(entry, entry.name, destination_directory: destination) else zip.extract(entry, to) end end end destination end
.with_tmp_zip(&blk) (private)
[ GitHub ]# File 'rb/lib/selenium/webdriver/common/zipper.rb', line 84
def with_tmp_zip(&blk) # Don't use Tempfile since it lacks rb_file_s_rename permission on Windows. Dir.mktmpdir do |tmp_dir| zip_path = File.join(tmp_dir, 'webdriver-zip') if RUBYZIP_V3 Zip::File.open(zip_path, create: true, &blk) else Zip::File.open(zip_path, Zip::File::CREATE, &blk) end end end
.zip(path)
[ GitHub ]# File 'rb/lib/selenium/webdriver/common/zipper.rb', line 58
def zip(path) encode_zip(path, path) end
.zip_file(path)
Alias for .zip_root.
# File 'rb/lib/selenium/webdriver/common/zipper.rb', line 69
alias zip_file zip_root
.zip_root(path) Also known as: .zip_file
Keeps path (a file or directory) as the archive's single top-level entry, unlike #zip
which flattens a directory's contents; the Grid upload endpoint returns that one entry's path.
# File 'rb/lib/selenium/webdriver/common/zipper.rb', line 64
def zip_root(path) encode_zip(path, File.dirname(path)) end