Sha256: 6a757155b3c976659084d0c6b831f2cffb5f3ee9ea7b0c8231e2e705edf87eb1

Contents?: true

Size: 1.14 KB

Versions: 4

Compression:

Stored size: 1.14 KB

Contents

require 'zip/zip'
require 'tempfile'
require 'find'

module Selenium
  module WebDriver
    module Zipper

      EXTENSIONS = %w[.zip .xpi]

      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

      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

    end # Zipper
  end # WebDriver
end # Selenium

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
selenium-webdriver-0.1.2 lib/selenium/webdriver/common/zipper.rb
selenium-webdriver-0.1.1 lib/selenium/webdriver/common/zipper.rb
selenium-webdriver-0.1.0 lib/selenium/webdriver/common/zipper.rb
selenium-webdriver-0.0.29 lib/selenium/webdriver/common/zipper.rb