Add `Entry#zip64?` as a better way detect Zip64 entries.
This commit is contained in:
parent
307fc6c6e9
commit
ae0262df2e
|
@ -47,7 +47,7 @@ module Zip
|
||||||
if ::Zip.write_zip64_support
|
if ::Zip.write_zip64_support
|
||||||
need_zip64_eocd = cdir_offset > 0xFFFFFFFF || cdir_size > 0xFFFFFFFF \
|
need_zip64_eocd = cdir_offset > 0xFFFFFFFF || cdir_size > 0xFFFFFFFF \
|
||||||
|| @entry_set.size > 0xFFFF
|
|| @entry_set.size > 0xFFFF
|
||||||
need_zip64_eocd ||= @entry_set.any? { |entry| entry.extra['Zip64'] }
|
need_zip64_eocd ||= @entry_set.any?(&:zip64?)
|
||||||
if need_zip64_eocd
|
if need_zip64_eocd
|
||||||
write_64_e_o_c_d(io, cdir_offset, cdir_size)
|
write_64_e_o_c_d(io, cdir_offset, cdir_size)
|
||||||
write_64_eocd_locator(io, eocd_offset)
|
write_64_eocd_locator(io, eocd_offset)
|
||||||
|
@ -185,7 +185,7 @@ module Zip
|
||||||
entry = Entry.read_c_dir_entry(io)
|
entry = Entry.read_c_dir_entry(io)
|
||||||
next unless entry
|
next unless entry
|
||||||
|
|
||||||
offset = if entry.extra['Zip64']
|
offset = if entry.zip64?
|
||||||
entry.extra['Zip64'].relative_header_offset
|
entry.extra['Zip64'].relative_header_offset
|
||||||
else
|
else
|
||||||
entry.local_header_offset
|
entry.local_header_offset
|
||||||
|
|
|
@ -154,6 +154,10 @@ module Zip
|
||||||
@compression_method = (@ftype == :directory ? STORED : method)
|
@compression_method = (@ftype == :directory ? STORED : method)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def zip64?
|
||||||
|
!@extra['Zip64'].nil?
|
||||||
|
end
|
||||||
|
|
||||||
def file_type_is?(type)
|
def file_type_is?(type)
|
||||||
raise InternalError, "current filetype is unknown: #{inspect}" unless @ftype
|
raise InternalError, "current filetype is unknown: #{inspect}" unless @ftype
|
||||||
|
|
||||||
|
@ -721,7 +725,7 @@ module Zip
|
||||||
# apply missing data from the zip64 extra information field, if present
|
# apply missing data from the zip64 extra information field, if present
|
||||||
# (required when file sizes exceed 2**32, but can be used for all files)
|
# (required when file sizes exceed 2**32, but can be used for all files)
|
||||||
def parse_zip64_extra(for_local_header) #:nodoc:all
|
def parse_zip64_extra(for_local_header) #:nodoc:all
|
||||||
return if @extra['Zip64'].nil?
|
return unless zip64?
|
||||||
|
|
||||||
if for_local_header
|
if for_local_header
|
||||||
@size, @compressed_size = @extra['Zip64'].parse(@size, @compressed_size)
|
@size, @compressed_size = @extra['Zip64'].parse(@size, @compressed_size)
|
||||||
|
|
|
@ -122,13 +122,13 @@ class ZipLocalEntryTest < MiniTest::Test
|
||||||
buf1 = StringIO.new
|
buf1 = StringIO.new
|
||||||
entry = ::Zip::Entry.new('file.zip', 'entry_name')
|
entry = ::Zip::Entry.new('file.zip', 'entry_name')
|
||||||
entry.write_local_entry(buf1)
|
entry.write_local_entry(buf1)
|
||||||
assert(entry.extra['Zip64'].nil?, 'zip64 extra is unnecessarily present')
|
refute(entry.zip64?, 'zip64 extra is unnecessarily present')
|
||||||
|
|
||||||
buf2 = StringIO.new
|
buf2 = StringIO.new
|
||||||
entry.size = 0x123456789ABCDEF0
|
entry.size = 0x123456789ABCDEF0
|
||||||
entry.compressed_size = 0x0123456789ABCDEF
|
entry.compressed_size = 0x0123456789ABCDEF
|
||||||
entry.write_local_entry(buf2, rewrite: true)
|
entry.write_local_entry(buf2, rewrite: true)
|
||||||
refute_nil(entry.extra['Zip64'])
|
assert(entry.zip64?)
|
||||||
refute_equal(buf1.size, 0)
|
refute_equal(buf1.size, 0)
|
||||||
assert_equal(buf1.size, buf2.size) # it can't grow, or we'd clobber file data
|
assert_equal(buf1.size, buf2.size) # it can't grow, or we'd clobber file data
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue