2014-01-21 05:31:06 +08:00
|
|
|
if ENV['FULL_ZIP64_TEST']
|
|
|
|
require 'minitest/autorun'
|
|
|
|
require 'minitest/unit'
|
|
|
|
require 'fileutils'
|
|
|
|
require 'zip'
|
Add read/write support for zip64 extensions
This commit adds the capability of creating archives larger than
4GB via zip64 extensions. It also fixes bugs reading archives of
this size (specifically, the 64-bit offset of the local file
header was not being read from the central directory entry).
To maximize compatibility, zip64 extensions are used only when
required. Unfortunately, at the time we write a local file header,
we don't know the size of the file and thus whether a Zip64
Extended Information Extra Field will be required. Therefore
this commit writes a 'placeholder' extra field to reserve space
for the zip64 entry, which will be written if necessary when
we update the local entry with the final sizes and CRC. I use
the signature "\x99\x99" for this field, following the example
of DotNetZip which does the same.
This commit also adds a rake task, zip64_full_test, which
fully tests zip64 by actually creating and verifying a 4GB zip
file. Please note, however, that this test requires UnZip
version 6.00 or newer, which may not be supplied by your OS.
This test doesn't run along with the main unit tests because
it takes a few minutes to complete.
2013-09-28 10:41:00 +08:00
|
|
|
|
|
|
|
# test zip64 support for real, by actually exceeding the 32-bit size/offset limits
|
|
|
|
# this test does not, of course, run with the normal unit tests! ;)
|
|
|
|
|
2014-01-21 05:31:06 +08:00
|
|
|
class Zip64FullTest < MiniTest::Unit::TestCase
|
|
|
|
def prepareTestFile(test_filename)
|
|
|
|
File.delete(test_filename) if File.exists?(test_filename)
|
|
|
|
return test_filename
|
Add read/write support for zip64 extensions
This commit adds the capability of creating archives larger than
4GB via zip64 extensions. It also fixes bugs reading archives of
this size (specifically, the 64-bit offset of the local file
header was not being read from the central directory entry).
To maximize compatibility, zip64 extensions are used only when
required. Unfortunately, at the time we write a local file header,
we don't know the size of the file and thus whether a Zip64
Extended Information Extra Field will be required. Therefore
this commit writes a 'placeholder' extra field to reserve space
for the zip64 entry, which will be written if necessary when
we update the local entry with the final sizes and CRC. I use
the signature "\x99\x99" for this field, following the example
of DotNetZip which does the same.
This commit also adds a rake task, zip64_full_test, which
fully tests zip64 by actually creating and verifying a 4GB zip
file. Please note, however, that this test requires UnZip
version 6.00 or newer, which may not be supplied by your OS.
This test doesn't run along with the main unit tests because
it takes a few minutes to complete.
2013-09-28 10:41:00 +08:00
|
|
|
end
|
|
|
|
|
2014-01-21 05:31:06 +08:00
|
|
|
def test_largeZipFile
|
|
|
|
first_text = 'starting out small'
|
|
|
|
last_text = 'this tests files starting after 4GB in the archive'
|
|
|
|
test_filename = prepareTestFile('huge.zip')
|
|
|
|
Zip::OutputStream.open(test_filename) do |io|
|
|
|
|
io.put_next_entry('first_file.txt')
|
|
|
|
io.write(first_text)
|
|
|
|
|
|
|
|
# write just over 4GB (stored, so the zip file exceeds 4GB)
|
|
|
|
buf = 'blah' * 16384
|
|
|
|
io.put_next_entry('huge_file', nil, nil, Zip::Entry::STORED)
|
|
|
|
65537.times { io.write(buf) }
|
|
|
|
|
|
|
|
io.put_next_entry('last_file.txt')
|
|
|
|
io.write(last_text)
|
|
|
|
end
|
|
|
|
|
|
|
|
Zip::File.open(test_filename) do |zf|
|
|
|
|
assert_equal %w(first_file.txt huge_file last_file.txt), zf.entries.map(&:name)
|
|
|
|
assert_equal first_text, zf.read('first_file.txt')
|
|
|
|
assert_equal last_text, zf.read('last_file.txt')
|
|
|
|
end
|
|
|
|
|
|
|
|
# note: if this fails, be sure you have UnZip version 6.0 or newer
|
|
|
|
# as this is the first version to support zip64 extensions
|
|
|
|
# but some OSes (*cough* OSX) still bundle a 5.xx release
|
|
|
|
assert system("unzip -t #{test_filename}"), "third-party zip validation failed"
|
Add read/write support for zip64 extensions
This commit adds the capability of creating archives larger than
4GB via zip64 extensions. It also fixes bugs reading archives of
this size (specifically, the 64-bit offset of the local file
header was not being read from the central directory entry).
To maximize compatibility, zip64 extensions are used only when
required. Unfortunately, at the time we write a local file header,
we don't know the size of the file and thus whether a Zip64
Extended Information Extra Field will be required. Therefore
this commit writes a 'placeholder' extra field to reserve space
for the zip64 entry, which will be written if necessary when
we update the local entry with the final sizes and CRC. I use
the signature "\x99\x99" for this field, following the example
of DotNetZip which does the same.
This commit also adds a rake task, zip64_full_test, which
fully tests zip64 by actually creating and verifying a 4GB zip
file. Please note, however, that this test requires UnZip
version 6.00 or newer, which may not be supplied by your OS.
This test doesn't run along with the main unit tests because
it takes a few minutes to complete.
2013-09-28 10:41:00 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2014-01-21 05:31:06 +08:00
|
|
|
|