rubyzip 1.1.7 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +143 -54
- data/Rakefile +3 -4
- 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 +132 -128
- data/lib/zip/entry_set.rb +14 -14
- data/lib/zip/errors.rb +2 -0
- 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/extra_field.rb +8 -8
- data/lib/zip/file.rb +88 -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/abstract_input_stream.rb +6 -10
- data/lib/zip/ioextras/abstract_output_stream.rb +3 -5
- data/lib/zip/ioextras.rb +1 -3
- 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/lib/zip.rb +13 -5
- 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 +94 -39
- data/test/file_permissions_test.rb +65 -0
- data/test/file_split_test.rb +24 -27
- data/test/file_test.rb +286 -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 +100 -66
Binary file
|
data/test/data/notzippedruby.rb
CHANGED
Binary file
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# Based on 'relative2' in https://github.com/jwilk/path-traversal-samples,
|
2
|
+
# but create the local `tmp` folder before adding the symlink. Otherwise
|
3
|
+
# we may bail out before we get to trying to create the file.
|
4
|
+
all: relative1.zip
|
5
|
+
relative1.zip:
|
6
|
+
rm -f $(@)
|
7
|
+
mkdir -p -m 755 tmp/tmp
|
8
|
+
umask 022 && echo moo > moo
|
9
|
+
cd tmp && zip -X ../$(@) tmp tmp/../../moo
|
10
|
+
rm -rf tmp moo
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
data/test/data/rubycode.zip
CHANGED
Binary file
|
data/test/data/test.xls
ADDED
Binary file
|
data/test/deflater_test.rb
CHANGED
@@ -8,15 +8,15 @@ class DeflaterTest < MiniTest::Test
|
|
8
8
|
DEFAULT_COMP_FILE = 'test/data/generated/compressiontest_default_compression.bin'
|
9
9
|
NO_COMP_FILE = 'test/data/generated/compressiontest_no_compression.bin'
|
10
10
|
|
11
|
-
def
|
12
|
-
txt = load_file(
|
11
|
+
def test_output_operator
|
12
|
+
txt = load_file('test/data/file2.txt')
|
13
13
|
deflate(txt, DEFLATER_TEST_FILE)
|
14
14
|
inflatedTxt = inflate(DEFLATER_TEST_FILE)
|
15
15
|
assert_equal(txt, inflatedTxt)
|
16
16
|
end
|
17
17
|
|
18
18
|
def test_default_compression
|
19
|
-
txt = load_file(
|
19
|
+
txt = load_file('test/data/file2.txt')
|
20
20
|
|
21
21
|
Zip.default_compression = ::Zlib::BEST_COMPRESSION
|
22
22
|
deflate(txt, BEST_COMP_FILE)
|
@@ -34,31 +34,29 @@ class DeflaterTest < MiniTest::Test
|
|
34
34
|
assert(default < no)
|
35
35
|
end
|
36
36
|
|
37
|
-
|
38
37
|
private
|
38
|
+
|
39
39
|
def load_file(fileName)
|
40
40
|
txt = nil
|
41
|
-
File.open(fileName,
|
41
|
+
File.open(fileName, 'rb') { |f| txt = f.read }
|
42
42
|
end
|
43
43
|
|
44
44
|
def deflate(data, fileName)
|
45
|
-
File.open(fileName,
|
46
|
-
|file|
|
45
|
+
File.open(fileName, 'wb') do |file|
|
47
46
|
deflater = ::Zip::Deflater.new(file)
|
48
47
|
deflater << data
|
49
48
|
deflater.finish
|
50
49
|
assert_equal(deflater.size, data.size)
|
51
|
-
file <<
|
52
|
-
|
50
|
+
file << 'trailing data for zlib with -MAX_WBITS'
|
51
|
+
end
|
53
52
|
end
|
54
53
|
|
55
54
|
def inflate(fileName)
|
56
55
|
txt = nil
|
57
|
-
File.open(fileName,
|
58
|
-
|file|
|
56
|
+
File.open(fileName, 'rb') do |file|
|
59
57
|
inflater = ::Zip::Inflater.new(file)
|
60
58
|
txt = inflater.sysread
|
61
|
-
|
59
|
+
end
|
62
60
|
end
|
63
61
|
|
64
62
|
def test_crc
|
data/test/encryption_test.rb
CHANGED
@@ -18,7 +18,7 @@ class EncryptionTest < MiniTest::Test
|
|
18
18
|
|
19
19
|
@rand = [250, 143, 107, 13, 143, 22, 155, 75, 228, 150, 12]
|
20
20
|
@output = ::Zip::DOSTime.stub(:now, ::Zip::DOSTime.new(2014, 12, 17, 15, 56, 24)) do
|
21
|
-
Random.stub(:rand,
|
21
|
+
Random.stub(:rand, ->(_range) { @rand.shift }) do
|
22
22
|
Zip::OutputStream.write_buffer(::StringIO.new(''), Zip::TraditionalEncrypter.new('password')) do |zos|
|
23
23
|
zos.put_next_entry('file1.txt')
|
24
24
|
zos.write open(INPUT_FILE1).read
|
@@ -26,7 +26,7 @@ class EncryptionTest < MiniTest::Test
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
-
@output.unpack(
|
29
|
+
@output.unpack('C*').each_with_index do |c, i|
|
30
30
|
assert_equal test_file[i].ord, c
|
31
31
|
end
|
32
32
|
end
|
data/test/entry_set_test.rb
CHANGED
@@ -2,12 +2,12 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
class ZipEntrySetTest < MiniTest::Test
|
4
4
|
ZIP_ENTRIES = [
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
5
|
+
::Zip::Entry.new('zipfile.zip', 'name1', 'comment1'),
|
6
|
+
::Zip::Entry.new('zipfile.zip', 'name3', 'comment1'),
|
7
|
+
::Zip::Entry.new('zipfile.zip', 'name2', 'comment1'),
|
8
|
+
::Zip::Entry.new('zipfile.zip', 'name4', 'comment1'),
|
9
|
+
::Zip::Entry.new('zipfile.zip', 'name5', 'comment1'),
|
10
|
+
::Zip::Entry.new('zipfile.zip', 'name6', 'comment1')
|
11
11
|
]
|
12
12
|
|
13
13
|
def setup
|
@@ -20,20 +20,20 @@ class ZipEntrySetTest < MiniTest::Test
|
|
20
20
|
|
21
21
|
def test_include
|
22
22
|
assert(@zipEntrySet.include?(ZIP_ENTRIES.first))
|
23
|
-
assert(!@zipEntrySet.include?(::Zip::Entry.new(
|
23
|
+
assert(!@zipEntrySet.include?(::Zip::Entry.new('different.zip', 'different', 'aComment')))
|
24
24
|
end
|
25
25
|
|
26
26
|
def test_size
|
27
27
|
assert_equal(ZIP_ENTRIES.size, @zipEntrySet.size)
|
28
28
|
assert_equal(ZIP_ENTRIES.size, @zipEntrySet.length)
|
29
|
-
@zipEntrySet << ::Zip::Entry.new(
|
29
|
+
@zipEntrySet << ::Zip::Entry.new('a', 'b', 'c')
|
30
30
|
assert_equal(ZIP_ENTRIES.size + 1, @zipEntrySet.length)
|
31
31
|
end
|
32
32
|
|
33
33
|
def test_add
|
34
34
|
zes = ::Zip::EntrySet.new
|
35
|
-
entry1 = ::Zip::Entry.new(
|
36
|
-
entry2 = ::Zip::Entry.new(
|
35
|
+
entry1 = ::Zip::Entry.new('zf.zip', 'name1')
|
36
|
+
entry2 = ::Zip::Entry.new('zf.zip', 'name2')
|
37
37
|
zes << entry1
|
38
38
|
assert(zes.include?(entry1))
|
39
39
|
zes.push(entry2)
|
@@ -65,6 +65,20 @@ class ZipEntrySetTest < MiniTest::Test
|
|
65
65
|
assert_equal(ZIP_ENTRIES, @zipEntrySet.entries)
|
66
66
|
end
|
67
67
|
|
68
|
+
def test_find_entry
|
69
|
+
entries = [::Zip::Entry.new('zipfile.zip', 'MiXeDcAsEnAmE', 'comment1')]
|
70
|
+
|
71
|
+
::Zip.case_insensitive_match = true
|
72
|
+
zipEntrySet = ::Zip::EntrySet.new(entries)
|
73
|
+
assert_equal(entries[0], zipEntrySet.find_entry('MiXeDcAsEnAmE'))
|
74
|
+
assert_equal(entries[0], zipEntrySet.find_entry('mixedcasename'))
|
75
|
+
|
76
|
+
::Zip.case_insensitive_match = false
|
77
|
+
zipEntrySet = ::Zip::EntrySet.new(entries)
|
78
|
+
assert_equal(entries[0], zipEntrySet.find_entry('MiXeDcAsEnAmE'))
|
79
|
+
assert_nil(zipEntrySet.find_entry('mixedcasename'))
|
80
|
+
end
|
81
|
+
|
68
82
|
def test_entries_with_sort
|
69
83
|
::Zip.sort_entries = true
|
70
84
|
assert_equal(ZIP_ENTRIES.sort, @zipEntrySet.entries)
|
@@ -82,7 +96,7 @@ class ZipEntrySetTest < MiniTest::Test
|
|
82
96
|
end
|
83
97
|
|
84
98
|
def test_compound
|
85
|
-
newEntry = ::Zip::Entry.new(
|
99
|
+
newEntry = ::Zip::Entry.new('zf.zip', 'new entry', "new entry's comment")
|
86
100
|
assert_equal(ZIP_ENTRIES.size, @zipEntrySet.size)
|
87
101
|
@zipEntrySet << newEntry
|
88
102
|
assert_equal(ZIP_ENTRIES.size + 1, @zipEntrySet.size)
|
@@ -97,19 +111,19 @@ class ZipEntrySetTest < MiniTest::Test
|
|
97
111
|
assert_equal(@zipEntrySet, copy)
|
98
112
|
|
99
113
|
# demonstrate that this is a deep copy
|
100
|
-
copy.entries[0].name =
|
114
|
+
copy.entries[0].name = 'a totally different name'
|
101
115
|
assert(@zipEntrySet != copy)
|
102
116
|
end
|
103
117
|
|
104
118
|
def test_parent
|
105
119
|
entries = [
|
106
|
-
|
107
|
-
|
108
|
-
|
120
|
+
::Zip::Entry.new('zf.zip', 'a/'),
|
121
|
+
::Zip::Entry.new('zf.zip', 'a/b/'),
|
122
|
+
::Zip::Entry.new('zf.zip', 'a/b/c/')
|
109
123
|
]
|
110
124
|
entrySet = ::Zip::EntrySet.new(entries)
|
111
125
|
|
112
|
-
|
126
|
+
assert_nil(entrySet.parent(entries[0]))
|
113
127
|
assert_equal(entries[0], entrySet.parent(entries[1]))
|
114
128
|
assert_equal(entries[1], entrySet.parent(entries[2]))
|
115
129
|
end
|
@@ -122,17 +136,28 @@ class ZipEntrySetTest < MiniTest::Test
|
|
122
136
|
|
123
137
|
def test_glob2
|
124
138
|
entries = [
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
139
|
+
::Zip::Entry.new('zf.zip', 'a/'),
|
140
|
+
::Zip::Entry.new('zf.zip', 'a/b/b1'),
|
141
|
+
::Zip::Entry.new('zf.zip', 'a/b/c/'),
|
142
|
+
::Zip::Entry.new('zf.zip', 'a/b/c/c1')
|
143
|
+
]
|
144
|
+
entrySet = ::Zip::EntrySet.new(entries)
|
145
|
+
|
146
|
+
assert_equal(entries[0, 1], entrySet.glob('*'))
|
147
|
+
# assert_equal(entries[FIXME], entrySet.glob("**"))
|
148
|
+
# res = entrySet.glob('a*')
|
149
|
+
# assert_equal(entries.size, res.size)
|
150
|
+
# assert_equal(entrySet.map { |e| e.name }, res.map { |e| e.name })
|
151
|
+
end
|
152
|
+
|
153
|
+
def test_glob3
|
154
|
+
entries = [
|
155
|
+
::Zip::Entry.new('zf.zip', 'a/a'),
|
156
|
+
::Zip::Entry.new('zf.zip', 'a/b'),
|
157
|
+
::Zip::Entry.new('zf.zip', 'a/c')
|
129
158
|
]
|
130
159
|
entrySet = ::Zip::EntrySet.new(entries)
|
131
160
|
|
132
|
-
assert_equal(entries[0,
|
133
|
-
# assert_equal(entries[FIXME], entrySet.glob("**"))
|
134
|
-
# res = entrySet.glob('a*')
|
135
|
-
# assert_equal(entries.size, res.size)
|
136
|
-
# assert_equal(entrySet.map { |e| e.name }, res.map { |e| e.name })
|
161
|
+
assert_equal(entries[0, 2].sort, entrySet.glob('a/{a,b}').sort)
|
137
162
|
end
|
138
163
|
end
|
data/test/entry_test.rb
CHANGED
@@ -1,18 +1,9 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
3
|
class ZipEntryTest < MiniTest::Test
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
TEST_CRC = 325324
|
8
|
-
TEST_EXTRA = "Some data here"
|
9
|
-
TEST_COMPRESSIONMETHOD = ::Zip::Entry::DEFLATED
|
10
|
-
TEST_NAME = "entry name"
|
11
|
-
TEST_SIZE = 8432
|
12
|
-
TEST_ISDIRECTORY = false
|
13
|
-
TEST_TIME = Time.now
|
14
|
-
|
15
|
-
def test_constructorAndGetters
|
4
|
+
include ZipEntryData
|
5
|
+
|
6
|
+
def test_constructor_and_getters
|
16
7
|
entry = ::Zip::Entry.new(TEST_ZIPFILE,
|
17
8
|
TEST_NAME,
|
18
9
|
TEST_COMMENT,
|
@@ -33,45 +24,45 @@ class ZipEntryTest < MiniTest::Test
|
|
33
24
|
assert_equal(TEST_TIME, entry.time)
|
34
25
|
end
|
35
26
|
|
36
|
-
def
|
37
|
-
assert(::Zip::Entry.new(TEST_ZIPFILE,
|
38
|
-
assert(!::Zip::Entry.new(TEST_ZIPFILE,
|
27
|
+
def test_is_directory_and_is_file
|
28
|
+
assert(::Zip::Entry.new(TEST_ZIPFILE, 'hello').file?)
|
29
|
+
assert(!::Zip::Entry.new(TEST_ZIPFILE, 'hello').directory?)
|
39
30
|
|
40
|
-
assert(::Zip::Entry.new(TEST_ZIPFILE,
|
41
|
-
assert(!::Zip::Entry.new(TEST_ZIPFILE,
|
31
|
+
assert(::Zip::Entry.new(TEST_ZIPFILE, 'dir/hello').file?)
|
32
|
+
assert(!::Zip::Entry.new(TEST_ZIPFILE, 'dir/hello').directory?)
|
42
33
|
|
43
|
-
assert(::Zip::Entry.new(TEST_ZIPFILE,
|
44
|
-
assert(!::Zip::Entry.new(TEST_ZIPFILE,
|
34
|
+
assert(::Zip::Entry.new(TEST_ZIPFILE, 'hello/').directory?)
|
35
|
+
assert(!::Zip::Entry.new(TEST_ZIPFILE, 'hello/').file?)
|
45
36
|
|
46
|
-
assert(::Zip::Entry.new(TEST_ZIPFILE,
|
47
|
-
assert(!::Zip::Entry.new(TEST_ZIPFILE,
|
37
|
+
assert(::Zip::Entry.new(TEST_ZIPFILE, 'dir/hello/').directory?)
|
38
|
+
assert(!::Zip::Entry.new(TEST_ZIPFILE, 'dir/hello/').file?)
|
48
39
|
end
|
49
40
|
|
50
41
|
def test_equality
|
51
|
-
entry1 = ::Zip::Entry.new(
|
52
|
-
|
53
|
-
::Zip::Entry::DEFLATED,
|
54
|
-
entry2 = ::Zip::Entry.new(
|
55
|
-
|
56
|
-
::Zip::Entry::DEFLATED,
|
57
|
-
entry3 = ::Zip::Entry.new(
|
58
|
-
|
59
|
-
::Zip::Entry::DEFLATED,
|
60
|
-
entry4 = ::Zip::Entry.new(
|
61
|
-
|
62
|
-
::Zip::Entry::DEFLATED,
|
63
|
-
entry5 = ::Zip::Entry.new(
|
64
|
-
|
65
|
-
::Zip::Entry::DEFLATED,
|
66
|
-
entry6 = ::Zip::Entry.new(
|
67
|
-
|
68
|
-
::Zip::Entry::DEFLATED,
|
69
|
-
entry7 = ::Zip::Entry.new(
|
70
|
-
|
71
|
-
::Zip::Entry::STORED,
|
72
|
-
entry8 = ::Zip::Entry.new(
|
73
|
-
|
74
|
-
::Zip::Entry::STORED,
|
42
|
+
entry1 = ::Zip::Entry.new('file.zip', 'name', 'isNotCompared',
|
43
|
+
'something extra', 123, 1234,
|
44
|
+
::Zip::Entry::DEFLATED, 10_000)
|
45
|
+
entry2 = ::Zip::Entry.new('file.zip', 'name', 'isNotComparedXXX',
|
46
|
+
'something extra', 123, 1234,
|
47
|
+
::Zip::Entry::DEFLATED, 10_000)
|
48
|
+
entry3 = ::Zip::Entry.new('file.zip', 'name2', 'isNotComparedXXX',
|
49
|
+
'something extra', 123, 1234,
|
50
|
+
::Zip::Entry::DEFLATED, 10_000)
|
51
|
+
entry4 = ::Zip::Entry.new('file.zip', 'name2', 'isNotComparedXXX',
|
52
|
+
'something extraXX', 123, 1234,
|
53
|
+
::Zip::Entry::DEFLATED, 10_000)
|
54
|
+
entry5 = ::Zip::Entry.new('file.zip', 'name2', 'isNotComparedXXX',
|
55
|
+
'something extraXX', 12, 1234,
|
56
|
+
::Zip::Entry::DEFLATED, 10_000)
|
57
|
+
entry6 = ::Zip::Entry.new('file.zip', 'name2', 'isNotComparedXXX',
|
58
|
+
'something extraXX', 12, 123,
|
59
|
+
::Zip::Entry::DEFLATED, 10_000)
|
60
|
+
entry7 = ::Zip::Entry.new('file.zip', 'name2', 'isNotComparedXXX',
|
61
|
+
'something extraXX', 12, 123,
|
62
|
+
::Zip::Entry::STORED, 10_000)
|
63
|
+
entry8 = ::Zip::Entry.new('file.zip', 'name2', 'isNotComparedXXX',
|
64
|
+
'something extraXX', 12, 123,
|
65
|
+
::Zip::Entry::STORED, 100_000)
|
75
66
|
|
76
67
|
assert_equal(entry1, entry1)
|
77
68
|
assert_equal(entry1, entry2)
|
@@ -83,51 +74,51 @@ class ZipEntryTest < MiniTest::Test
|
|
83
74
|
assert(entry6 != entry7)
|
84
75
|
assert(entry7 != entry8)
|
85
76
|
|
86
|
-
assert(entry7 !=
|
77
|
+
assert(entry7 != 'hello')
|
87
78
|
assert(entry7 != 12)
|
88
79
|
end
|
89
80
|
|
90
81
|
def test_compare
|
91
|
-
assert_equal(0, (::Zip::Entry.new(
|
92
|
-
assert_equal(1, (::Zip::Entry.new(
|
93
|
-
assert_equal(-1, (::Zip::Entry.new(
|
82
|
+
assert_equal(0, (::Zip::Entry.new('zf.zip', 'a') <=> ::Zip::Entry.new('zf.zip', 'a')))
|
83
|
+
assert_equal(1, (::Zip::Entry.new('zf.zip', 'b') <=> ::Zip::Entry.new('zf.zip', 'a')))
|
84
|
+
assert_equal(-1, (::Zip::Entry.new('zf.zip', 'a') <=> ::Zip::Entry.new('zf.zip', 'b')))
|
94
85
|
|
95
86
|
entries = [
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
87
|
+
::Zip::Entry.new('zf.zip', '5'),
|
88
|
+
::Zip::Entry.new('zf.zip', '1'),
|
89
|
+
::Zip::Entry.new('zf.zip', '3'),
|
90
|
+
::Zip::Entry.new('zf.zip', '4'),
|
91
|
+
::Zip::Entry.new('zf.zip', '0'),
|
92
|
+
::Zip::Entry.new('zf.zip', '2')
|
102
93
|
]
|
103
94
|
|
104
95
|
entries.sort!
|
105
|
-
assert_equal(
|
106
|
-
assert_equal(
|
107
|
-
assert_equal(
|
108
|
-
assert_equal(
|
109
|
-
assert_equal(
|
110
|
-
assert_equal(
|
96
|
+
assert_equal('0', entries[0].to_s)
|
97
|
+
assert_equal('1', entries[1].to_s)
|
98
|
+
assert_equal('2', entries[2].to_s)
|
99
|
+
assert_equal('3', entries[3].to_s)
|
100
|
+
assert_equal('4', entries[4].to_s)
|
101
|
+
assert_equal('5', entries[5].to_s)
|
111
102
|
end
|
112
103
|
|
113
|
-
def
|
114
|
-
entry1 = ::Zip::Entry.new(
|
115
|
-
entry2 = ::Zip::Entry.new(
|
116
|
-
entry3 = ::Zip::Entry.new(
|
117
|
-
entry4 = ::Zip::Entry.new(
|
118
|
-
entry5 = ::Zip::Entry.new(
|
119
|
-
entry6 = ::Zip::Entry.new(
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
assert_equal(
|
124
|
-
assert_equal(
|
125
|
-
assert_equal(
|
126
|
-
assert_equal(
|
104
|
+
def test_parent_as_string
|
105
|
+
entry1 = ::Zip::Entry.new('zf.zip', 'aa')
|
106
|
+
entry2 = ::Zip::Entry.new('zf.zip', 'aa/')
|
107
|
+
entry3 = ::Zip::Entry.new('zf.zip', 'aa/bb')
|
108
|
+
entry4 = ::Zip::Entry.new('zf.zip', 'aa/bb/')
|
109
|
+
entry5 = ::Zip::Entry.new('zf.zip', 'aa/bb/cc')
|
110
|
+
entry6 = ::Zip::Entry.new('zf.zip', 'aa/bb/cc/')
|
111
|
+
|
112
|
+
assert_nil(entry1.parent_as_string)
|
113
|
+
assert_nil(entry2.parent_as_string)
|
114
|
+
assert_equal('aa/', entry3.parent_as_string)
|
115
|
+
assert_equal('aa/', entry4.parent_as_string)
|
116
|
+
assert_equal('aa/bb/', entry5.parent_as_string)
|
117
|
+
assert_equal('aa/bb/', entry6.parent_as_string)
|
127
118
|
end
|
128
119
|
|
129
120
|
def test_entry_name_cannot_start_with_slash
|
130
|
-
assert_raises(::Zip::EntryNameError) { ::Zip::Entry.new(
|
121
|
+
assert_raises(::Zip::EntryNameError) { ::Zip::Entry.new('zf.zip', '/hej/der') }
|
131
122
|
end
|
132
123
|
|
133
124
|
def test_store_file_without_compression
|
@@ -139,27 +130,25 @@ class ZipEntryTest < MiniTest::Test
|
|
139
130
|
end
|
140
131
|
|
141
132
|
zipfile = Zip::File.open('/tmp/no_compress.zip', Zip::File::CREATE)
|
142
|
-
mimetype_entry = Zip::Entry.new(zipfile,
|
143
|
-
'mimetype',
|
144
|
-
'',
|
145
|
-
'',
|
146
|
-
0,
|
147
|
-
0,
|
148
|
-
Zip::Entry::STORED)
|
133
|
+
mimetype_entry = Zip::Entry.new(zipfile, # @zipfile
|
134
|
+
'mimetype', # @name
|
135
|
+
'', # @comment
|
136
|
+
'', # @extra
|
137
|
+
0, # @compressed_size
|
138
|
+
0, # @crc
|
139
|
+
Zip::Entry::STORED) # @comppressed_method
|
149
140
|
|
150
141
|
zipfile.add(mimetype_entry, 'test/data/mimetype')
|
151
142
|
|
152
143
|
files.each do |file|
|
153
|
-
zipfile.add(file.sub(
|
144
|
+
zipfile.add(file.sub('test/data/globTest/', ''), file)
|
154
145
|
end
|
155
146
|
zipfile.close
|
156
147
|
|
157
|
-
f= File.open('/tmp/no_compress.zip', 'rb')
|
148
|
+
f = File.open('/tmp/no_compress.zip', 'rb')
|
158
149
|
first_100_bytes = f.read(100)
|
159
150
|
f.close
|
160
151
|
|
161
152
|
assert_match(/mimetypeapplication\/epub\+zip/, first_100_bytes)
|
162
153
|
end
|
163
|
-
|
164
|
-
|
165
154
|
end
|