Class: RemoteZip::Reader

Inherits:
Object
  • Object
show all
Defined in:
lib/remote_zip/reader.rb

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ Reader

Returns a new instance of Reader.



11
12
13
# File 'lib/remote_zip/reader.rb', line 11

def initialize(url)
  self.url = URI(url)
end

Instance Method Details

#each_file_with_path(&block) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/remote_zip/reader.rb', line 15

def each_file_with_path(&block)
  with_tempfile do |temp|
    temp.write(open(url).read)
    temp.flush

    extract(temp.path) do |absolute_path, zip_path|
      File.open(absolute_path) do |file|
        block.call(file, zip_path)
      end
    end
  end
rescue OpenURI::HTTPError => e
  raise DownloadError, e
end