diff --git a/lib/zip/central_directory.rb b/lib/zip/central_directory.rb index 4ea444d..f5dd25a 100644 --- a/lib/zip/central_directory.rb +++ b/lib/zip/central_directory.rb @@ -6,15 +6,16 @@ module Zip class CentralDirectory extend Forwardable - END_OF_CDS = 0x06054b50 - ZIP64_END_OF_CDS = 0x06064b50 - ZIP64_EOCD_LOCATOR = 0x07064b50 + END_OF_CD_SIG = 0x06054b50 + ZIP64_END_OF_CD_SIG = 0x06064b50 + ZIP64_EOCD_LOCATOR_SIG = 0x07064b50 STATIC_EOCD_SIZE = 22 ZIP64_STATIC_EOCD_SIZE = 56 ZIP64_EOCD_LOC_SIZE = 20 - MAX_FILE_COMMENT_SIZE = 1 << 16 - MAX_END_OF_CDS_SIZE = MAX_FILE_COMMENT_SIZE + STATIC_EOCD_SIZE + MAX_FILE_COMMENT_SIZE = (1 << 16) - 1 + MAX_END_OF_CD_SIZE = + MAX_FILE_COMMENT_SIZE + STATIC_EOCD_SIZE + ZIP64_EOCD_LOC_SIZE attr_accessor :comment @@ -47,7 +48,7 @@ module Zip def write_e_o_c_d(io, offset, cdir_size) #:nodoc: tmp = [ - END_OF_CDS, + END_OF_CD_SIG, 0, # @numberOfThisDisk 0, # @numberOfDiskWithStartOfCDir @entry_set ? [@entry_set.size, 0xFFFF].min : 0, @@ -64,7 +65,7 @@ module Zip def write_64_e_o_c_d(io, offset, cdir_size) #:nodoc: tmp = [ - ZIP64_END_OF_CDS, + ZIP64_END_OF_CD_SIG, 44, # size of zip64 end of central directory record (excludes signature and field itself) VERSION_MADE_BY, VERSION_NEEDED_TO_EXTRACT_ZIP64, @@ -82,7 +83,7 @@ module Zip def write_64_eocd_locator(io, zip64_eocd_offset) tmp = [ - ZIP64_EOCD_LOCATOR, + ZIP64_EOCD_LOCATOR_SIG, 0, # number of disk containing the start of zip64 eocd record zip64_eocd_offset, # offset of the start of zip64 eocd record in its disk 1 # total number of disks @@ -93,15 +94,7 @@ module Zip private :write_64_eocd_locator def unpack_64_e_o_c_d(buffer) #:nodoc: - index = buffer.rindex([ZIP64_END_OF_CDS].pack('V')) - raise Error, 'Zip64 end of central directory signature not found' unless index - - l_index = buffer.rindex([ZIP64_EOCD_LOCATOR].pack('V')) - raise Error, 'Zip64 end of central directory signature locator not found' unless l_index - - buf = buffer.slice(index..l_index) - - _, # ZIP64_END_OF_CDS signature. We know we have this at this point. + _, # ZIP64_END_OF_CD_SIG. We know we have this at this point. @size_of_zip64_e_o_c_d, @version_made_by, @version_needed_for_extract, @@ -110,7 +103,7 @@ module Zip @total_number_of_entries_in_cdir_on_this_disk, @size, @size_in_bytes, - @cdir_offset = buf.unpack('VQ