lib/parsers/zip_parser/file_reader.rb
# Parse an IO handle to a ZIP archive into an array of Entry objects.
#
# @param io[#tell, #seek, #read, #size] an IO-ish object
# @return [Array<ZipEntry>] an array of entries within the ZIP being parsed
Parse an IO handle to a ZIP archive into an array of Entry objects.
Parse an IO handle to a ZIP archive into an array of Entry objects .
def read_zip_structure(io:)
    zip_file_size = io.size
    eocd_offset = get_eocd_offset(io, zip_file_size)
    zip64_end_of_cdir_location = get_zip64_eocd_location(io, eocd_offset)
    num_files, cdir_location, cdir_size =
      if zip64_end_of_cdir_location
        num_files_and_central_directory_offset_zip64(io, zip64_end_of_cdir_location)
      else
        num_files_and_central_directory_offset(io, eocd_offset)
      end
    log { format('Located the central directory start at %d', cdir_location) }
    seek(io, cdir_location)
    central_directory_str = io.read(cdir_size + 1024)
    raise InvalidCentralDirectory if central_directory_str.nil?
    central_directory_io = StringIO.new(central_directory_str)
    log do
      format(
        'Read %d bytes with central directory + EOCD record and locator',
        central_directory_str.bytesize)
    end
    entries = (0...num_files).map do |entry_n|
      offset_location = cdir_location + central_directory_io.pos
      log do
        format(
          'Reading the central directory entry %d starting at offset %d',
          entry_n, offset_location)
      end
      read_cdir_entry(central_directory_io)
    end
    entries
  end
def read_zip_structure ( io : ) zip_file_size = io . size eocd_offset = get_eocd_offset ( io , zip_file_size ) zip64_end_of_cdir_location = get_zip64_eocd_location ( io , eocd_offset ) num_files , cdir_location , cdir_size = if zip64_end_of_cdir_location num_files_and_central_directory_offset_zip64 ( io , zip64_end_of_cdir_location ) else num_files_and_central_directory_offset ( io , eocd_offset ) end log { format ( 'Located the central directory start at %d' , cdir_location ) } seek ( io , cdir_location ) central_directory_str = io . read ( cdir_size + 1024 ) raise InvalidCentralDirectory if central_directory_str . nil? central_directory_io = StringIO . new ( central_directory_str ) log do format ( 'Read %d bytes with central directory + EOCD record and locator' , central_directory_str . bytesize ) end entries = ( 0 ... num_files ) . map do | entry_n | offset_location = cdir_location + central_directory_io . pos log do format ( 'Reading the central directory entry %d starting at offset %d' , entry_n , offset_location ) end read_cdir_entry ( central_directory_io ) end entries end
Parse an IO handle to a ZIP archive into an array of Entry objects.
Parse an IO handle to a ZIP archive into an array of Entry objects .
# In zip_tricks we read the entire central directory _and_ enything behind it. # Strictly speaking, we should be able to read `cdir_size` bytes and not a byte more. # BUT! in format_parser we avoid unbounded reads, as a matter of fact they are forbidden. # So we will again limit ouselves to cdir_size, and we will take cushion of 1 KB.
an array of entries within the ZIP being parsed
an array of entries within the ZIP being parsed
Array<ZipEntry>
io
an IO-ish object
an IO - ish object