Class: Zippo::CentralDirectoryReader

Inherits:
Object
  • Object
show all
Defined in:
lib/zippo/central_directory_reader.rb

Overview

Reads the zip central directory from an IO stream.

Instance Method Summary collapse

Constructor Details

#initialize(io) ⇒ CentralDirectoryReader

Returns a new instance of CentralDirectoryReader.



7
8
9
# File 'lib/zippo/central_directory_reader.rb', line 7

def initialize(io)
  @io = io
end

Instance Method Details

#cd_file_headersObject



15
16
17
# File 'lib/zippo/central_directory_reader.rb', line 15

def cd_file_headers
  @cd_file_headers ||= CentralDirectoryEntriesUnpacker.new(@io, end_of_cd_record.cd_size, end_of_cd_record.cd_offset).unpack
end

#end_of_cd_recordObject



11
12
13
# File 'lib/zippo/central_directory_reader.rb', line 11

def end_of_cd_record
  @end_of_cd_record ||= EndCdRecord::Unpacker.new(read_from end_of_cd_record_position).unpack
end

#end_of_cd_record_positionObject



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/zippo/central_directory_reader.rb', line 19

def end_of_cd_record_position
  # XXX implement optimised scanning at -22 position
  [44, 22].each do |pos|
    next if pos > @io.size
    return @io.size - pos if (read 4, -pos) == EndCdRecord::PACKED_SIGNATURE
  end

  scan_from = @io.size - EndCdRecord::MAX_COMMENT_LENGTH
  scan_from = 0 if scan_from < 0
  scan_from + (read_from(scan_from).rindex(EndCdRecord::PACKED_SIGNATURE) or fail "End of Central Directory Record not found")
end