rubyzip 1.1.7 → 1.2.4
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of rubyzip might be problematic. Click here for more details.
- checksums.yaml +5 -5
- data/README.md +87 -45
- data/Rakefile +3 -4
- data/lib/zip.rb +11 -5
- data/lib/zip/central_directory.rb +8 -8
- data/lib/zip/compressor.rb +1 -2
- data/lib/zip/constants.rb +5 -5
- data/lib/zip/crypto/null_encryption.rb +4 -6
- data/lib/zip/crypto/traditional_encryption.rb +5 -5
- data/lib/zip/decompressor.rb +3 -3
- data/lib/zip/deflater.rb +8 -6
- data/lib/zip/dos_time.rb +5 -6
- data/lib/zip/entry.rb +120 -128
- data/lib/zip/entry_set.rb +14 -14
- data/lib/zip/errors.rb +1 -0
- data/lib/zip/extra_field.rb +8 -8
- data/lib/zip/extra_field/generic.rb +8 -8
- data/lib/zip/extra_field/ntfs.rb +14 -16
- data/lib/zip/extra_field/old_unix.rb +9 -10
- data/lib/zip/extra_field/universal_time.rb +14 -14
- data/lib/zip/extra_field/unix.rb +8 -9
- data/lib/zip/extra_field/zip64.rb +12 -11
- data/lib/zip/extra_field/zip64_placeholder.rb +1 -2
- data/lib/zip/file.rb +81 -81
- data/lib/zip/filesystem.rb +144 -143
- data/lib/zip/inflater.rb +5 -5
- data/lib/zip/input_stream.rb +22 -13
- data/lib/zip/ioextras.rb +1 -3
- data/lib/zip/ioextras/abstract_input_stream.rb +6 -10
- data/lib/zip/ioextras/abstract_output_stream.rb +3 -5
- data/lib/zip/null_compressor.rb +2 -2
- data/lib/zip/null_decompressor.rb +3 -3
- data/lib/zip/null_input_stream.rb +0 -0
- data/lib/zip/output_stream.rb +13 -14
- data/lib/zip/pass_thru_compressor.rb +4 -4
- data/lib/zip/pass_thru_decompressor.rb +3 -4
- data/lib/zip/streamable_directory.rb +2 -2
- data/lib/zip/streamable_stream.rb +3 -3
- data/lib/zip/version.rb +1 -1
- data/samples/example.rb +29 -39
- data/samples/example_filesystem.rb +16 -18
- data/samples/example_recursive.rb +31 -25
- data/samples/{gtkRubyzip.rb → gtk_ruby_zip.rb} +23 -25
- data/samples/qtzip.rb +18 -27
- data/samples/write_simple.rb +12 -13
- data/samples/zipfind.rb +26 -34
- data/test/basic_zip_file_test.rb +11 -15
- data/test/case_sensitivity_test.rb +69 -0
- data/test/central_directory_entry_test.rb +32 -36
- data/test/central_directory_test.rb +46 -50
- data/test/crypto/null_encryption_test.rb +8 -4
- data/test/crypto/traditional_encryption_test.rb +5 -5
- data/test/data/gpbit3stored.zip +0 -0
- data/test/data/notzippedruby.rb +1 -1
- data/test/data/oddExtraField.zip +0 -0
- data/test/data/path_traversal/Makefile +10 -0
- data/test/data/path_traversal/jwilk/README.md +5 -0
- data/test/data/path_traversal/jwilk/absolute1.zip +0 -0
- data/test/data/path_traversal/jwilk/absolute2.zip +0 -0
- data/test/data/path_traversal/jwilk/dirsymlink.zip +0 -0
- data/test/data/path_traversal/jwilk/dirsymlink2a.zip +0 -0
- data/test/data/path_traversal/jwilk/dirsymlink2b.zip +0 -0
- data/test/data/path_traversal/jwilk/relative0.zip +0 -0
- data/test/data/path_traversal/jwilk/relative2.zip +0 -0
- data/test/data/path_traversal/jwilk/symlink.zip +0 -0
- data/test/data/path_traversal/relative1.zip +0 -0
- data/test/data/path_traversal/tilde.zip +0 -0
- data/test/data/path_traversal/tuzovakaoff/README.md +3 -0
- data/test/data/path_traversal/tuzovakaoff/absolutepath.zip +0 -0
- data/test/data/path_traversal/tuzovakaoff/symlink.zip +0 -0
- data/test/data/rubycode.zip +0 -0
- data/test/data/test.xls +0 -0
- data/test/deflater_test.rb +10 -12
- data/test/encryption_test.rb +2 -2
- data/test/entry_set_test.rb +50 -25
- data/test/entry_test.rb +76 -87
- data/test/errors_test.rb +1 -2
- data/test/extra_field_test.rb +19 -21
- data/test/file_extract_directory_test.rb +12 -14
- data/test/file_extract_test.rb +33 -40
- data/test/file_permissions_test.rb +65 -0
- data/test/file_split_test.rb +24 -27
- data/test/file_test.rb +266 -179
- data/test/filesystem/dir_iterator_test.rb +13 -17
- data/test/filesystem/directory_test.rb +101 -93
- data/test/filesystem/file_mutating_test.rb +52 -65
- data/test/filesystem/file_nonmutating_test.rb +223 -229
- data/test/filesystem/file_stat_test.rb +17 -19
- data/test/gentestfiles.rb +54 -62
- data/test/inflater_test.rb +1 -1
- data/test/input_stream_test.rb +52 -40
- data/test/ioextras/abstract_input_stream_test.rb +22 -23
- data/test/ioextras/abstract_output_stream_test.rb +33 -33
- data/test/ioextras/fake_io_test.rb +1 -1
- data/test/local_entry_test.rb +36 -38
- data/test/output_stream_test.rb +20 -21
- data/test/pass_thru_compressor_test.rb +5 -6
- data/test/pass_thru_decompressor_test.rb +0 -1
- data/test/path_traversal_test.rb +141 -0
- data/test/samples/example_recursive_test.rb +37 -0
- data/test/settings_test.rb +18 -15
- data/test/test_helper.rb +52 -46
- data/test/unicode_file_names_and_comments_test.rb +17 -7
- data/test/zip64_full_test.rb +10 -12
- data/test/zip64_support_test.rb +0 -1
- metadata +94 -65
@@ -2,9 +2,8 @@ require 'test_helper'
|
|
2
2
|
require 'zip/filesystem'
|
3
3
|
|
4
4
|
class ZipFsFileStatTest < MiniTest::Test
|
5
|
-
|
6
5
|
def setup
|
7
|
-
@zip_file = ::Zip::File.new(
|
6
|
+
@zip_file = ::Zip::File.new('test/data/zipWithDirs.zip')
|
8
7
|
end
|
9
8
|
|
10
9
|
def teardown
|
@@ -12,55 +11,54 @@ class ZipFsFileStatTest < MiniTest::Test
|
|
12
11
|
end
|
13
12
|
|
14
13
|
def test_blocks
|
15
|
-
|
14
|
+
assert_nil(@zip_file.file.stat('file1').blocks)
|
16
15
|
end
|
17
16
|
|
18
17
|
def test_ino
|
19
|
-
assert_equal(0, @zip_file.file.stat(
|
18
|
+
assert_equal(0, @zip_file.file.stat('file1').ino)
|
20
19
|
end
|
21
20
|
|
22
21
|
def test_uid
|
23
|
-
assert_equal(0, @zip_file.file.stat(
|
22
|
+
assert_equal(0, @zip_file.file.stat('file1').uid)
|
24
23
|
end
|
25
24
|
|
26
25
|
def test_gid
|
27
|
-
assert_equal(0, @zip_file.file.stat(
|
26
|
+
assert_equal(0, @zip_file.file.stat('file1').gid)
|
28
27
|
end
|
29
28
|
|
30
29
|
def test_ftype
|
31
|
-
assert_equal(
|
32
|
-
assert_equal(
|
30
|
+
assert_equal('file', @zip_file.file.stat('file1').ftype)
|
31
|
+
assert_equal('directory', @zip_file.file.stat('dir1').ftype)
|
33
32
|
end
|
34
33
|
|
35
34
|
def test_mode
|
36
|
-
assert_equal(
|
37
|
-
assert_equal(
|
38
|
-
assert_equal(
|
39
|
-
assert_equal(
|
35
|
+
assert_equal(0o600, @zip_file.file.stat('file1').mode & 0o777)
|
36
|
+
assert_equal(0o600, @zip_file.file.stat('file1').mode & 0o777)
|
37
|
+
assert_equal(0o755, @zip_file.file.stat('dir1').mode & 0o777)
|
38
|
+
assert_equal(0o755, @zip_file.file.stat('dir1').mode & 0o777)
|
40
39
|
end
|
41
40
|
|
42
41
|
def test_dev
|
43
|
-
assert_equal(0, @zip_file.file.stat(
|
42
|
+
assert_equal(0, @zip_file.file.stat('file1').dev)
|
44
43
|
end
|
45
44
|
|
46
45
|
def test_rdev
|
47
|
-
assert_equal(0, @zip_file.file.stat(
|
46
|
+
assert_equal(0, @zip_file.file.stat('file1').rdev)
|
48
47
|
end
|
49
48
|
|
50
49
|
def test_rdev_major
|
51
|
-
assert_equal(0, @zip_file.file.stat(
|
50
|
+
assert_equal(0, @zip_file.file.stat('file1').rdev_major)
|
52
51
|
end
|
53
52
|
|
54
53
|
def test_rdev_minor
|
55
|
-
assert_equal(0, @zip_file.file.stat(
|
54
|
+
assert_equal(0, @zip_file.file.stat('file1').rdev_minor)
|
56
55
|
end
|
57
56
|
|
58
57
|
def test_nlink
|
59
|
-
assert_equal(1, @zip_file.file.stat(
|
58
|
+
assert_equal(1, @zip_file.file.stat('file1').nlink)
|
60
59
|
end
|
61
60
|
|
62
61
|
def test_blksize
|
63
|
-
assert_nil(@zip_file.file.stat(
|
62
|
+
assert_nil(@zip_file.file.stat('file1').blksize)
|
64
63
|
end
|
65
|
-
|
66
64
|
end
|
data/test/gentestfiles.rb
CHANGED
@@ -3,13 +3,15 @@
|
|
3
3
|
$VERBOSE = true
|
4
4
|
|
5
5
|
class TestFiles
|
6
|
-
RANDOM_ASCII_FILE1 =
|
7
|
-
RANDOM_ASCII_FILE2 =
|
8
|
-
RANDOM_ASCII_FILE3 =
|
9
|
-
RANDOM_BINARY_FILE1 =
|
10
|
-
RANDOM_BINARY_FILE2 =
|
6
|
+
RANDOM_ASCII_FILE1 = 'test/data/generated/randomAscii1.txt'
|
7
|
+
RANDOM_ASCII_FILE2 = 'test/data/generated/randomAscii2.txt'
|
8
|
+
RANDOM_ASCII_FILE3 = 'test/data/generated/randomAscii3.txt'
|
9
|
+
RANDOM_BINARY_FILE1 = 'test/data/generated/randomBinary1.bin'
|
10
|
+
RANDOM_BINARY_FILE2 = 'test/data/generated/randomBinary2.bin'
|
11
11
|
|
12
|
-
|
12
|
+
NULL_FILE = 'test/data/generated/null.zip' # Zero length, so not a zip file.
|
13
|
+
|
14
|
+
EMPTY_TEST_DIR = 'test/data/generated/emptytestdir'
|
13
15
|
|
14
16
|
ASCII_TEST_FILES = [RANDOM_ASCII_FILE1, RANDOM_ASCII_FILE2, RANDOM_ASCII_FILE3]
|
15
17
|
BINARY_TEST_FILES = [RANDOM_BINARY_FILE1, RANDOM_BINARY_FILE2]
|
@@ -18,34 +20,32 @@ class TestFiles
|
|
18
20
|
|
19
21
|
class << self
|
20
22
|
def create_test_files
|
21
|
-
|
23
|
+
Dir.mkdir 'test/data/generated' unless Dir.exist?('test/data/generated')
|
22
24
|
|
23
|
-
|
24
|
-
|
25
|
-
|
25
|
+
ASCII_TEST_FILES.each_with_index do |filename, index|
|
26
|
+
create_random_ascii(filename, 1E4 * (index + 1))
|
27
|
+
end
|
26
28
|
|
27
|
-
|
28
|
-
|
29
|
-
|
29
|
+
BINARY_TEST_FILES.each_with_index do |filename, index|
|
30
|
+
create_random_binary(filename, 1E4 * (index + 1))
|
31
|
+
end
|
30
32
|
|
31
|
-
|
33
|
+
system("touch #{NULL_FILE}")
|
34
|
+
|
35
|
+
ensure_dir(EMPTY_TEST_DIR)
|
32
36
|
end
|
33
37
|
|
34
38
|
private
|
35
39
|
|
36
40
|
def create_random_ascii(filename, size)
|
37
|
-
File.open(filename,
|
38
|
-
while
|
39
|
-
file << rand
|
40
|
-
end
|
41
|
+
File.open(filename, 'wb') do |file|
|
42
|
+
file << rand while file.tell < size
|
41
43
|
end
|
42
44
|
end
|
43
45
|
|
44
46
|
def create_random_binary(filename, size)
|
45
|
-
File.open(filename,
|
46
|
-
while
|
47
|
-
file << [rand].pack("V")
|
48
|
-
end
|
47
|
+
File.open(filename, 'wb') do |file|
|
48
|
+
file << [rand].pack('V') while file.tell < size
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
@@ -56,79 +56,71 @@ class TestFiles
|
|
56
56
|
end
|
57
57
|
Dir.mkdir(name)
|
58
58
|
end
|
59
|
-
|
60
59
|
end
|
61
60
|
end
|
62
61
|
|
63
|
-
|
64
62
|
# For representation and creation of
|
65
63
|
# test data
|
66
64
|
class TestZipFile
|
67
65
|
attr_accessor :zip_name, :entry_names, :comment
|
68
66
|
|
69
|
-
def initialize(zip_name, entry_names, comment =
|
70
|
-
@zip_name=zip_name
|
71
|
-
@entry_names=entry_names
|
67
|
+
def initialize(zip_name, entry_names, comment = '')
|
68
|
+
@zip_name = zip_name
|
69
|
+
@entry_names = entry_names
|
72
70
|
@comment = comment
|
73
71
|
end
|
74
72
|
|
75
|
-
def
|
76
|
-
raise "failed to create test zip '#{TEST_ZIP1.zip_name}'" unless system("/usr/bin/zip #{TEST_ZIP1.zip_name} test/data/file2.txt")
|
77
|
-
raise "failed to remove entry from '#{TEST_ZIP1.zip_name}'" unless system("/usr/bin/zip #{TEST_ZIP1.zip_name} -d test/data/file2.txt")
|
73
|
+
def self.create_test_zips
|
74
|
+
raise "failed to create test zip '#{TEST_ZIP1.zip_name}'" unless system("/usr/bin/zip -q #{TEST_ZIP1.zip_name} test/data/file2.txt")
|
75
|
+
raise "failed to remove entry from '#{TEST_ZIP1.zip_name}'" unless system("/usr/bin/zip -q #{TEST_ZIP1.zip_name} -d test/data/file2.txt")
|
78
76
|
|
79
|
-
File.open(
|
80
|
-
File.open(
|
81
|
-
::File.chmod(
|
77
|
+
File.open('test/data/generated/empty.txt', 'w') {}
|
78
|
+
File.open('test/data/generated/empty_chmod640.txt', 'w') {}
|
79
|
+
::File.chmod(0o640, 'test/data/generated/empty_chmod640.txt')
|
82
80
|
|
83
|
-
File.open(
|
84
|
-
ziptestTxt=
|
85
|
-
File.open(
|
86
|
-
File.open(
|
87
|
-
while
|
88
|
-
file << ziptestTxt
|
89
|
-
end
|
81
|
+
File.open('test/data/generated/short.txt', 'w') { |file| file << 'ABCDEF' }
|
82
|
+
ziptestTxt = ''
|
83
|
+
File.open('test/data/file2.txt') { |file| ziptestTxt = file.read }
|
84
|
+
File.open('test/data/generated/longAscii.txt', 'w') do |file|
|
85
|
+
file << ziptestTxt while file.tell < 1E5
|
90
86
|
end
|
91
87
|
|
92
|
-
testBinaryPattern=
|
93
|
-
File.open(
|
88
|
+
testBinaryPattern = ''
|
89
|
+
File.open('test/data/generated/empty.zip') { |file| testBinaryPattern = file.read }
|
94
90
|
testBinaryPattern *= 4
|
95
91
|
|
96
|
-
File.open(
|
97
|
-
while
|
98
|
-
file << testBinaryPattern << rand << "\0"
|
99
|
-
end
|
92
|
+
File.open('test/data/generated/longBinary.bin', 'wb') do |file|
|
93
|
+
file << testBinaryPattern << rand << "\0" while file.tell < 6E5
|
100
94
|
end
|
101
95
|
|
102
|
-
raise "failed to create test zip '#{TEST_ZIP2.zip_name}'" unless system("/usr/bin/zip #{TEST_ZIP2.zip_name} #{TEST_ZIP2.entry_names.join(' ')}")
|
96
|
+
raise "failed to create test zip '#{TEST_ZIP2.zip_name}'" unless system("/usr/bin/zip -q #{TEST_ZIP2.zip_name} #{TEST_ZIP2.entry_names.join(' ')}")
|
103
97
|
|
104
98
|
if RUBY_PLATFORM =~ /mswin|mingw|cygwin/
|
105
|
-
raise "failed to add comment to test zip '#{TEST_ZIP2.zip_name}'" unless system("echo #{TEST_ZIP2.comment}| /usr/bin/zip -
|
99
|
+
raise "failed to add comment to test zip '#{TEST_ZIP2.zip_name}'" unless system("echo #{TEST_ZIP2.comment}| /usr/bin/zip -zq #{TEST_ZIP2.zip_name}\"")
|
106
100
|
else
|
107
101
|
# without bash system interprets everything after echo as parameters to
|
108
102
|
# echo including | zip -z ...
|
109
|
-
raise "failed to add comment to test zip '#{TEST_ZIP2.zip_name}'" unless system("bash -c \"echo #{TEST_ZIP2.comment} | /usr/bin/zip -
|
103
|
+
raise "failed to add comment to test zip '#{TEST_ZIP2.zip_name}'" unless system("bash -c \"echo #{TEST_ZIP2.comment} | /usr/bin/zip -zq #{TEST_ZIP2.zip_name}\"")
|
110
104
|
end
|
111
105
|
|
112
|
-
raise "failed to create test zip '#{TEST_ZIP3.zip_name}'" unless system("/usr/bin/zip #{TEST_ZIP3.zip_name} #{TEST_ZIP3.entry_names.join(' ')}")
|
106
|
+
raise "failed to create test zip '#{TEST_ZIP3.zip_name}'" unless system("/usr/bin/zip -q #{TEST_ZIP3.zip_name} #{TEST_ZIP3.entry_names.join(' ')}")
|
113
107
|
|
114
|
-
raise "failed to create test zip '#{TEST_ZIP4.zip_name}'" unless system("/usr/bin/zip #{TEST_ZIP4.zip_name} #{TEST_ZIP4.entry_names.join(' ')}")
|
108
|
+
raise "failed to create test zip '#{TEST_ZIP4.zip_name}'" unless system("/usr/bin/zip -q #{TEST_ZIP4.zip_name} #{TEST_ZIP4.entry_names.join(' ')}")
|
115
109
|
rescue
|
116
110
|
# If there are any Windows developers wanting to use a command line zip.exe
|
117
111
|
# to help create the following files, there's a free one available from
|
118
112
|
# http://stahlworks.com/dev/index.php?tool=zipunzip
|
119
113
|
# that works with the above code
|
120
114
|
raise $!.to_s +
|
121
|
-
|
122
|
-
|
123
|
-
|
115
|
+
"\n\nziptest.rb requires the Info-ZIP program 'zip' in the path\n" \
|
116
|
+
"to create test data. If you don't have it you can download\n" \
|
117
|
+
'the necessary test files at http://sf.net/projects/rubyzip.'
|
124
118
|
end
|
125
119
|
|
126
|
-
TEST_ZIP1 = TestZipFile.new(
|
127
|
-
TEST_ZIP2 = TestZipFile.new(
|
128
|
-
|
129
|
-
TEST_ZIP3 = TestZipFile.new(
|
130
|
-
TEST_ZIP4 = TestZipFile.new(
|
131
|
-
|
120
|
+
TEST_ZIP1 = TestZipFile.new('test/data/generated/empty.zip', [])
|
121
|
+
TEST_ZIP2 = TestZipFile.new('test/data/generated/5entry.zip', %w[test/data/generated/longAscii.txt test/data/generated/empty.txt test/data/generated/empty_chmod640.txt test/data/generated/short.txt test/data/generated/longBinary.bin],
|
122
|
+
'my zip comment')
|
123
|
+
TEST_ZIP3 = TestZipFile.new('test/data/generated/test1.zip', %w[test/data/file1.txt])
|
124
|
+
TEST_ZIP4 = TestZipFile.new('test/data/generated/zipWithDir.zip', ['test/data/file1.txt',
|
125
|
+
TestFiles::EMPTY_TEST_DIR])
|
132
126
|
end
|
133
|
-
|
134
|
-
|
data/test/inflater_test.rb
CHANGED
data/test/input_stream_test.rb
CHANGED
@@ -3,6 +3,16 @@ require 'test_helper'
|
|
3
3
|
class ZipInputStreamTest < MiniTest::Test
|
4
4
|
include AssertEntry
|
5
5
|
|
6
|
+
class IOLike
|
7
|
+
extend Forwardable
|
8
|
+
|
9
|
+
def initialize(path, mode)
|
10
|
+
@file = File.new(path, mode)
|
11
|
+
end
|
12
|
+
|
13
|
+
delegate ::Zip::File::IO_METHODS => :@file
|
14
|
+
end
|
15
|
+
|
6
16
|
def test_new
|
7
17
|
zis = ::Zip::InputStream.new(TestZipFile::TEST_ZIP2.zip_name)
|
8
18
|
assert_stream_contents(zis, TestZipFile::TEST_ZIP2)
|
@@ -10,21 +20,20 @@ class ZipInputStreamTest < MiniTest::Test
|
|
10
20
|
zis.close
|
11
21
|
end
|
12
22
|
|
13
|
-
def
|
14
|
-
::Zip::InputStream.open(TestZipFile::TEST_ZIP2.zip_name)
|
15
|
-
|zis|
|
23
|
+
def test_open_with_block
|
24
|
+
::Zip::InputStream.open(TestZipFile::TEST_ZIP2.zip_name) do |zis|
|
16
25
|
assert_stream_contents(zis, TestZipFile::TEST_ZIP2)
|
17
26
|
assert_equal(true, zis.eof?)
|
18
|
-
|
27
|
+
end
|
19
28
|
end
|
20
29
|
|
21
|
-
def
|
22
|
-
zis = ::Zip::InputStream.open(File.new(TestZipFile::TEST_ZIP2.zip_name,
|
30
|
+
def test_open_without_block
|
31
|
+
zis = ::Zip::InputStream.open(File.new(TestZipFile::TEST_ZIP2.zip_name, 'rb'))
|
23
32
|
assert_stream_contents(zis, TestZipFile::TEST_ZIP2)
|
24
33
|
end
|
25
34
|
|
26
|
-
def
|
27
|
-
::Zip::InputStream.open(File.new(TestZipFile::TEST_ZIP2.zip_name,
|
35
|
+
def test_open_buffer_with_block
|
36
|
+
::Zip::InputStream.open(File.new(TestZipFile::TEST_ZIP2.zip_name, 'rb')) do |zis|
|
28
37
|
assert_stream_contents(zis, TestZipFile::TEST_ZIP2)
|
29
38
|
assert_equal(true, zis.eof?)
|
30
39
|
end
|
@@ -44,36 +53,42 @@ class ZipInputStreamTest < MiniTest::Test
|
|
44
53
|
end
|
45
54
|
end
|
46
55
|
|
47
|
-
def
|
56
|
+
def test_open_buffer_without_block
|
48
57
|
zis = ::Zip::InputStream.open(TestZipFile::TEST_ZIP2.zip_name)
|
49
58
|
assert_stream_contents(zis, TestZipFile::TEST_ZIP2)
|
50
59
|
end
|
51
60
|
|
52
|
-
def
|
53
|
-
::Zip::InputStream.open(TestZipFile::TEST_ZIP2.zip_name)
|
54
|
-
|
61
|
+
def test_open_io_like_with_block
|
62
|
+
::Zip::InputStream.open(IOLike.new(TestZipFile::TEST_ZIP2.zip_name, 'rb')) do |zis|
|
63
|
+
assert_stream_contents(zis, TestZipFile::TEST_ZIP2)
|
64
|
+
assert_equal(true, zis.eof?)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_incomplete_reads
|
69
|
+
::Zip::InputStream.open(TestZipFile::TEST_ZIP2.zip_name) do |zis|
|
55
70
|
entry = zis.get_next_entry # longAscii.txt
|
56
71
|
assert_equal(false, zis.eof?)
|
57
72
|
assert_equal(TestZipFile::TEST_ZIP2.entry_names[0], entry.name)
|
58
|
-
assert zis.gets.
|
73
|
+
assert !zis.gets.empty?
|
59
74
|
assert_equal(false, zis.eof?)
|
60
75
|
entry = zis.get_next_entry # empty.txt
|
61
76
|
assert_equal(TestZipFile::TEST_ZIP2.entry_names[1], entry.name)
|
62
77
|
assert_equal(0, entry.size)
|
63
|
-
|
78
|
+
assert_nil(zis.gets)
|
64
79
|
assert_equal(true, zis.eof?)
|
65
80
|
entry = zis.get_next_entry # empty_chmod640.txt
|
66
81
|
assert_equal(TestZipFile::TEST_ZIP2.entry_names[2], entry.name)
|
67
82
|
assert_equal(0, entry.size)
|
68
|
-
|
83
|
+
assert_nil(zis.gets)
|
69
84
|
assert_equal(true, zis.eof?)
|
70
85
|
entry = zis.get_next_entry # short.txt
|
71
86
|
assert_equal(TestZipFile::TEST_ZIP2.entry_names[3], entry.name)
|
72
|
-
assert zis.gets.
|
87
|
+
assert !zis.gets.empty?
|
73
88
|
entry = zis.get_next_entry # longBinary.bin
|
74
89
|
assert_equal(TestZipFile::TEST_ZIP2.entry_names[4], entry.name)
|
75
|
-
assert zis.gets.
|
76
|
-
|
90
|
+
assert !zis.gets.empty?
|
91
|
+
end
|
77
92
|
end
|
78
93
|
|
79
94
|
def test_incomplete_reads_from_string_io
|
@@ -82,24 +97,24 @@ class ZipInputStreamTest < MiniTest::Test
|
|
82
97
|
entry = zis.get_next_entry # longAscii.txt
|
83
98
|
assert_equal(false, zis.eof?)
|
84
99
|
assert_equal(TestZipFile::TEST_ZIP2.entry_names[0], entry.name)
|
85
|
-
assert zis.gets.
|
100
|
+
assert !zis.gets.empty?
|
86
101
|
assert_equal(false, zis.eof?)
|
87
102
|
entry = zis.get_next_entry # empty.txt
|
88
103
|
assert_equal(TestZipFile::TEST_ZIP2.entry_names[1], entry.name)
|
89
104
|
assert_equal(0, entry.size)
|
90
|
-
|
105
|
+
assert_nil(zis.gets)
|
91
106
|
assert_equal(true, zis.eof?)
|
92
107
|
entry = zis.get_next_entry # empty_chmod640.txt
|
93
108
|
assert_equal(TestZipFile::TEST_ZIP2.entry_names[2], entry.name)
|
94
109
|
assert_equal(0, entry.size)
|
95
|
-
|
110
|
+
assert_nil(zis.gets)
|
96
111
|
assert_equal(true, zis.eof?)
|
97
112
|
entry = zis.get_next_entry # short.txt
|
98
113
|
assert_equal(TestZipFile::TEST_ZIP2.entry_names[3], entry.name)
|
99
|
-
assert zis.gets.
|
114
|
+
assert !zis.gets.empty?
|
100
115
|
entry = zis.get_next_entry # longBinary.bin
|
101
116
|
assert_equal(TestZipFile::TEST_ZIP2.entry_names[4], entry.name)
|
102
|
-
assert zis.gets.
|
117
|
+
assert !zis.gets.empty?
|
103
118
|
end
|
104
119
|
end
|
105
120
|
|
@@ -114,25 +129,24 @@ class ZipInputStreamTest < MiniTest::Test
|
|
114
129
|
end
|
115
130
|
|
116
131
|
def test_rewind
|
117
|
-
::Zip::InputStream.open(TestZipFile::TEST_ZIP2.zip_name)
|
118
|
-
|zis|
|
132
|
+
::Zip::InputStream.open(TestZipFile::TEST_ZIP2.zip_name) do |zis|
|
119
133
|
e = zis.get_next_entry
|
120
134
|
assert_equal(TestZipFile::TEST_ZIP2.entry_names[0], e.name)
|
121
135
|
|
122
136
|
# Do a little reading
|
123
|
-
buf =
|
137
|
+
buf = ''
|
124
138
|
buf << zis.read(100)
|
125
139
|
assert_equal(100, zis.pos)
|
126
|
-
buf << (zis.gets ||
|
127
|
-
buf << (zis.gets ||
|
140
|
+
buf << (zis.gets || '')
|
141
|
+
buf << (zis.gets || '')
|
128
142
|
assert_equal(false, zis.eof?)
|
129
143
|
|
130
144
|
zis.rewind
|
131
145
|
|
132
|
-
buf2 =
|
146
|
+
buf2 = ''
|
133
147
|
buf2 << zis.read(100)
|
134
|
-
buf2 << (zis.gets ||
|
135
|
-
buf2 << (zis.gets ||
|
148
|
+
buf2 << (zis.gets || '')
|
149
|
+
buf2 << (zis.gets || '')
|
136
150
|
|
137
151
|
assert_equal(buf, buf2)
|
138
152
|
|
@@ -141,20 +155,19 @@ class ZipInputStreamTest < MiniTest::Test
|
|
141
155
|
assert_equal(0, zis.pos)
|
142
156
|
|
143
157
|
assert_entry(e.name, zis, e.name)
|
144
|
-
|
158
|
+
end
|
145
159
|
end
|
146
160
|
|
147
161
|
def test_mix_read_and_gets
|
148
|
-
::Zip::InputStream.open(TestZipFile::TEST_ZIP2.zip_name)
|
149
|
-
|zis|
|
162
|
+
::Zip::InputStream.open(TestZipFile::TEST_ZIP2.zip_name) do |zis|
|
150
163
|
zis.get_next_entry
|
151
|
-
assert_equal(
|
164
|
+
assert_equal('#!/usr/bin/env ruby', zis.gets.chomp)
|
152
165
|
assert_equal(false, zis.eof?)
|
153
|
-
assert_equal(
|
166
|
+
assert_equal('', zis.gets.chomp)
|
154
167
|
assert_equal(false, zis.eof?)
|
155
|
-
assert_equal(
|
168
|
+
assert_equal('$VERBOSE =', zis.read(10))
|
156
169
|
assert_equal(false, zis.eof?)
|
157
|
-
|
170
|
+
end
|
158
171
|
end
|
159
172
|
|
160
173
|
def test_ungetc
|
@@ -163,8 +176,7 @@ class ZipInputStreamTest < MiniTest::Test
|
|
163
176
|
first_line = zis.gets.chomp
|
164
177
|
first_line.reverse.bytes.each { |b| zis.ungetc(b) }
|
165
178
|
assert_equal('#!/usr/bin/env ruby', zis.gets.chomp)
|
166
|
-
assert_equal(
|
179
|
+
assert_equal('$VERBOSE =', zis.read(10))
|
167
180
|
end
|
168
181
|
end
|
169
|
-
|
170
182
|
end
|