Class: EPUB::OCF::PhysicalContainer::Zipruby

Inherits:
EPUB::OCF::PhysicalContainer show all
Defined in:
lib/epub/ocf/physical_container/zipruby.rb

Instance Method Summary collapse

Methods inherited from EPUB::OCF::PhysicalContainer

adapter, adapter=, find_adapter, #initialize, open, read

Constructor Details

This class inherits a constructor from EPUB::OCF::PhysicalContainer

Instance Method Details

#openObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/epub/ocf/physical_container/zipruby.rb', line 7

def open
  Zip::Archive.open @container_path do |archive|
    @monitor.synchronize do
      begin
        @archive = archive
        yield self
      rescue ::Zip::Error => error
        raise NoEntry.from_error(error)
      ensure
        @archive = nil
      end
    end
  end
end

#read(path_name) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/epub/ocf/physical_container/zipruby.rb', line 22

def read(path_name)
  if @archive
    @archive.fopen(path_name) {|entry| entry.read}
  else
    open {|container| container.read(path_name)}
  end
rescue ::Zip::Error => error
  raise NoEntry.from_error(error)
ensure
  @archive = nil
end