Class: JavaClass::Gems::ZipFile

Inherits:
Object
  • Object
show all
Defined in:
lib/javaclass/gems/zip_file.rb

Overview

Abstraction of a Zip archive. Wraps around Zip::ZipFile of rubyzip

Author

Peter Kofler

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ ZipFile

Returns a new instance of ZipFile.



112
113
114
# File 'lib/javaclass/gems/zip_file.rb', line 112

def initialize(file)
  @archive = file
end

Instance Method Details

#entries(&block) ⇒ Object

List the entries of this zip for the block given.



126
127
128
129
130
# File 'lib/javaclass/gems/zip_file.rb', line 126

def entries(&block)
  Zip::ZipFile.foreach(@archive) do |entry|
    block.call(ZipEntry.new(entry))
  end
end

#read(file) ⇒ Object

Read the file from archive.



117
118
119
120
121
122
123
# File 'lib/javaclass/gems/zip_file.rb', line 117

def read(file)
  begin
    Zip::ZipFile.open(@archive) { |zipfile| zipfile.file.read(file) }
  rescue
    nil
  end
end