Class: EPUB::OCF::PhysicalContainer::Rubyzip

Inherits:
EPUB::OCF::PhysicalContainer show all
Defined in:
lib/epub/ocf/physical_container/rubyzip.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
21
22
23
24
# File 'lib/epub/ocf/physical_container/rubyzip.rb', line 7

def open
  orig_encoding = Zip.force_entry_names_encoding
  begin
    Zip.force_entry_names_encoding = "UTF-8"
    Zip::File.open @container_path do |archive|
      @monitor.synchronize do
        @archive = archive
        begin
          yield self
        ensure
          @archive = nil
        end
      end
    end
  ensure
    Zip.force_entry_names_encoding = orig_encoding
  end
end

#read(path_name) ⇒ Object



26
27
28
29
30
31
32
33
34
# File 'lib/epub/ocf/physical_container/rubyzip.rb', line 26

def read(path_name)
  if @archive
    @archive.read(path_name)
  else
    open {|container| container.read(path_name)}
  end
rescue Errno::ENOENT => error
  raise NoEntry.from_error(error)
end