Sha256: 8a0ffc38396948a855d5104d7ba4240710b2cf02673657ec37e025a0a4b82e91

Contents?: true

Size: 641 Bytes

Versions: 2

Compression:

Stored size: 641 Bytes

Contents

module ZipDir
  class Unzipper
    attr_reader :zip_path
    def initialize(zip_path)
      @zip_path, @unzip_path = zip_path, Dir.mktmpdir
    end

    def cleanup
      @unzipped = false
      FileUtils.remove_entry_secure @unzip_path
    end

    def unzip_path
      unzip unless unzipped?
      @unzip_path
    end

    def unzipped?
      !!@unzipped
    end

    def unzip
      ::Zip::File.open(zip_path) do |zip_file|
        zip_file.each do |entry|
          file_path = "#{@unzip_path}/#{entry.name}"
          entry.extract(file_path) unless File.exists?(file_path)
        end
      end
      @unzipped = true
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
zip_dir-0.1.2 lib/zip_dir/unzipper.rb
zip_dir-0.1.1 lib/zip_dir/unzipper.rb