File: zip64_full_test.rb

package info (click to toggle)
ruby-zip 1.1.6-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 668 kB
  • sloc: ruby: 7,041; makefile: 11
file content (54 lines) | stat: -rw-r--r-- 1,722 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
if ENV['FULL_ZIP64_TEST']
  require 'minitest/autorun'
  require 'minitest/unit'
  require 'fileutils'
  require 'zip'

# 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! ;)

  class Zip64FullTest < MiniTest::Unit::TestCase

    def teardown
      ::Zip.reset!
    end

    def prepareTestFile(test_filename)
      ::File.delete(test_filename) if ::File.exist?(test_filename)
      return test_filename
    end

    def test_largeZipFile
      ::Zip.write_zip64_support = true
      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"
    end

  end

end