rubyzip 1.2.3 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +64 -23
- data/lib/zip.rb +5 -3
- data/lib/zip/constants.rb +52 -0
- data/lib/zip/crypto/decrypted_io.rb +39 -0
- data/lib/zip/decompressor.rb +19 -1
- data/lib/zip/dos_time.rb +5 -0
- data/lib/zip/entry.rb +34 -10
- data/lib/zip/errors.rb +2 -0
- data/lib/zip/extra_field/generic.rb +1 -1
- data/lib/zip/extra_field/universal_time.rb +39 -12
- data/lib/zip/file.rb +68 -34
- data/lib/zip/inflater.rb +22 -36
- data/lib/zip/input_stream.rb +28 -24
- data/lib/zip/ioextras/abstract_input_stream.rb +6 -0
- data/lib/zip/null_decompressor.rb +1 -9
- data/lib/zip/pass_thru_decompressor.rb +13 -22
- data/lib/zip/streamable_stream.rb +1 -6
- data/lib/zip/version.rb +1 -1
- metadata +12 -154
- data/test/basic_zip_file_test.rb +0 -60
- data/test/case_sensitivity_test.rb +0 -69
- data/test/central_directory_entry_test.rb +0 -69
- data/test/central_directory_test.rb +0 -100
- data/test/crypto/null_encryption_test.rb +0 -57
- data/test/crypto/traditional_encryption_test.rb +0 -80
- data/test/data/WarnInvalidDate.zip +0 -0
- data/test/data/file1.txt +0 -46
- data/test/data/file1.txt.deflatedData +0 -0
- data/test/data/file2.txt +0 -1504
- data/test/data/globTest.zip +0 -0
- data/test/data/globTest/foo.txt +0 -0
- data/test/data/globTest/foo/bar/baz/foo.txt +0 -0
- data/test/data/globTest/food.txt +0 -0
- data/test/data/gpbit3stored.zip +0 -0
- data/test/data/mimetype +0 -1
- data/test/data/notzippedruby.rb +0 -7
- data/test/data/ntfs.zip +0 -0
- data/test/data/oddExtraField.zip +0 -0
- data/test/data/path_traversal/Makefile +0 -10
- data/test/data/path_traversal/jwilk/README.md +0 -5
- 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 +0 -3
- 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/rubycode2.zip +0 -0
- data/test/data/test.xls +0 -0
- data/test/data/testDirectory.bin +0 -0
- data/test/data/zip64-sample.zip +0 -0
- data/test/data/zipWithDirs.zip +0 -0
- data/test/data/zipWithEncryption.zip +0 -0
- data/test/deflater_test.rb +0 -65
- data/test/encryption_test.rb +0 -42
- data/test/entry_set_test.rb +0 -163
- data/test/entry_test.rb +0 -154
- data/test/errors_test.rb +0 -35
- data/test/extra_field_test.rb +0 -76
- data/test/file_extract_directory_test.rb +0 -54
- data/test/file_extract_test.rb +0 -83
- data/test/file_permissions_test.rb +0 -65
- data/test/file_split_test.rb +0 -57
- data/test/file_test.rb +0 -601
- data/test/filesystem/dir_iterator_test.rb +0 -58
- data/test/filesystem/directory_test.rb +0 -139
- data/test/filesystem/file_mutating_test.rb +0 -87
- data/test/filesystem/file_nonmutating_test.rb +0 -508
- data/test/filesystem/file_stat_test.rb +0 -64
- data/test/gentestfiles.rb +0 -126
- data/test/inflater_test.rb +0 -14
- data/test/input_stream_test.rb +0 -182
- data/test/ioextras/abstract_input_stream_test.rb +0 -102
- data/test/ioextras/abstract_output_stream_test.rb +0 -106
- data/test/ioextras/fake_io_test.rb +0 -18
- data/test/local_entry_test.rb +0 -154
- data/test/output_stream_test.rb +0 -128
- data/test/pass_thru_compressor_test.rb +0 -30
- data/test/pass_thru_decompressor_test.rb +0 -14
- data/test/path_traversal_test.rb +0 -141
- data/test/samples/example_recursive_test.rb +0 -37
- data/test/settings_test.rb +0 -95
- data/test/test_helper.rb +0 -234
- data/test/unicode_file_names_and_comments_test.rb +0 -62
- data/test/zip64_full_test.rb +0 -51
- data/test/zip64_support_test.rb +0 -14
@@ -2,18 +2,10 @@ module Zip
|
|
2
2
|
module NullDecompressor #:nodoc:all
|
3
3
|
module_function
|
4
4
|
|
5
|
-
def
|
5
|
+
def read(_length = nil, _outbuf = nil)
|
6
6
|
nil
|
7
7
|
end
|
8
8
|
|
9
|
-
def produce_input
|
10
|
-
nil
|
11
|
-
end
|
12
|
-
|
13
|
-
def input_finished?
|
14
|
-
true
|
15
|
-
end
|
16
|
-
|
17
9
|
def eof
|
18
10
|
true
|
19
11
|
end
|
@@ -1,38 +1,29 @@
|
|
1
1
|
module Zip
|
2
2
|
class PassThruDecompressor < Decompressor #:nodoc:all
|
3
|
-
def initialize(
|
4
|
-
super
|
5
|
-
@chars_to_read = chars_to_read
|
3
|
+
def initialize(*args)
|
4
|
+
super
|
6
5
|
@read_so_far = 0
|
7
|
-
@has_returned_empty_string = false
|
8
6
|
end
|
9
7
|
|
10
|
-
def
|
11
|
-
if
|
12
|
-
has_returned_empty_string_val = @has_returned_empty_string
|
13
|
-
@has_returned_empty_string = true
|
14
|
-
return '' unless has_returned_empty_string_val
|
15
|
-
return
|
16
|
-
end
|
8
|
+
def read(length = nil, outbuf = '')
|
9
|
+
return ((length.nil? || length.zero?) ? "" : nil) if eof
|
17
10
|
|
18
|
-
if
|
19
|
-
|
11
|
+
if length.nil? || (@read_so_far + length) > decompressed_size
|
12
|
+
length = decompressed_size - @read_so_far
|
20
13
|
end
|
21
|
-
@read_so_far += number_of_bytes
|
22
|
-
@input_stream.read(number_of_bytes, buf)
|
23
|
-
end
|
24
14
|
|
25
|
-
|
26
|
-
|
15
|
+
@read_so_far += length
|
16
|
+
input_stream.read(length, outbuf)
|
27
17
|
end
|
28
18
|
|
29
|
-
def
|
30
|
-
@read_so_far >=
|
19
|
+
def eof
|
20
|
+
@read_so_far >= decompressed_size
|
31
21
|
end
|
32
22
|
|
33
|
-
|
34
|
-
alias eof? input_finished?
|
23
|
+
alias_method :eof?, :eof
|
35
24
|
end
|
25
|
+
|
26
|
+
::Zip::Decompressor.register(::Zip::COMPRESSION_METHOD_STORE, ::Zip::PassThruDecompressor)
|
36
27
|
end
|
37
28
|
|
38
29
|
# Copyright (C) 2002, 2003 Thomas Sondergaard
|
@@ -2,12 +2,7 @@ module Zip
|
|
2
2
|
class StreamableStream < DelegateClass(Entry) # nodoc:all
|
3
3
|
def initialize(entry)
|
4
4
|
super(entry)
|
5
|
-
|
6
|
-
::File.dirname(zipfile)
|
7
|
-
else
|
8
|
-
nil
|
9
|
-
end
|
10
|
-
@temp_file = Tempfile.new(::File.basename(name), dirname)
|
5
|
+
@temp_file = Tempfile.new(::File.basename(name))
|
11
6
|
@temp_file.binmode
|
12
7
|
end
|
13
8
|
|
data/lib/zip/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubyzip
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Simonov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-02-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -94,6 +94,7 @@ files:
|
|
94
94
|
- lib/zip/central_directory.rb
|
95
95
|
- lib/zip/compressor.rb
|
96
96
|
- lib/zip/constants.rb
|
97
|
+
- lib/zip/crypto/decrypted_io.rb
|
97
98
|
- lib/zip/crypto/encryption.rb
|
98
99
|
- lib/zip/crypto/null_encryption.rb
|
99
100
|
- lib/zip/crypto/traditional_encryption.rb
|
@@ -134,84 +135,15 @@ files:
|
|
134
135
|
- samples/qtzip.rb
|
135
136
|
- samples/write_simple.rb
|
136
137
|
- samples/zipfind.rb
|
137
|
-
- test/basic_zip_file_test.rb
|
138
|
-
- test/case_sensitivity_test.rb
|
139
|
-
- test/central_directory_entry_test.rb
|
140
|
-
- test/central_directory_test.rb
|
141
|
-
- test/crypto/null_encryption_test.rb
|
142
|
-
- test/crypto/traditional_encryption_test.rb
|
143
|
-
- test/data/WarnInvalidDate.zip
|
144
|
-
- test/data/file1.txt
|
145
|
-
- test/data/file1.txt.deflatedData
|
146
|
-
- test/data/file2.txt
|
147
|
-
- test/data/globTest.zip
|
148
|
-
- test/data/globTest/foo.txt
|
149
|
-
- test/data/globTest/foo/bar/baz/foo.txt
|
150
|
-
- test/data/globTest/food.txt
|
151
|
-
- test/data/gpbit3stored.zip
|
152
|
-
- test/data/mimetype
|
153
|
-
- test/data/notzippedruby.rb
|
154
|
-
- test/data/ntfs.zip
|
155
|
-
- test/data/oddExtraField.zip
|
156
|
-
- test/data/path_traversal/Makefile
|
157
|
-
- test/data/path_traversal/jwilk/README.md
|
158
|
-
- test/data/path_traversal/jwilk/absolute1.zip
|
159
|
-
- test/data/path_traversal/jwilk/absolute2.zip
|
160
|
-
- test/data/path_traversal/jwilk/dirsymlink.zip
|
161
|
-
- test/data/path_traversal/jwilk/dirsymlink2a.zip
|
162
|
-
- test/data/path_traversal/jwilk/dirsymlink2b.zip
|
163
|
-
- test/data/path_traversal/jwilk/relative0.zip
|
164
|
-
- test/data/path_traversal/jwilk/relative2.zip
|
165
|
-
- test/data/path_traversal/jwilk/symlink.zip
|
166
|
-
- test/data/path_traversal/relative1.zip
|
167
|
-
- test/data/path_traversal/tilde.zip
|
168
|
-
- test/data/path_traversal/tuzovakaoff/README.md
|
169
|
-
- test/data/path_traversal/tuzovakaoff/absolutepath.zip
|
170
|
-
- test/data/path_traversal/tuzovakaoff/symlink.zip
|
171
|
-
- test/data/rubycode.zip
|
172
|
-
- test/data/rubycode2.zip
|
173
|
-
- test/data/test.xls
|
174
|
-
- test/data/testDirectory.bin
|
175
|
-
- test/data/zip64-sample.zip
|
176
|
-
- test/data/zipWithDirs.zip
|
177
|
-
- test/data/zipWithEncryption.zip
|
178
|
-
- test/deflater_test.rb
|
179
|
-
- test/encryption_test.rb
|
180
|
-
- test/entry_set_test.rb
|
181
|
-
- test/entry_test.rb
|
182
|
-
- test/errors_test.rb
|
183
|
-
- test/extra_field_test.rb
|
184
|
-
- test/file_extract_directory_test.rb
|
185
|
-
- test/file_extract_test.rb
|
186
|
-
- test/file_permissions_test.rb
|
187
|
-
- test/file_split_test.rb
|
188
|
-
- test/file_test.rb
|
189
|
-
- test/filesystem/dir_iterator_test.rb
|
190
|
-
- test/filesystem/directory_test.rb
|
191
|
-
- test/filesystem/file_mutating_test.rb
|
192
|
-
- test/filesystem/file_nonmutating_test.rb
|
193
|
-
- test/filesystem/file_stat_test.rb
|
194
|
-
- test/gentestfiles.rb
|
195
|
-
- test/inflater_test.rb
|
196
|
-
- test/input_stream_test.rb
|
197
|
-
- test/ioextras/abstract_input_stream_test.rb
|
198
|
-
- test/ioextras/abstract_output_stream_test.rb
|
199
|
-
- test/ioextras/fake_io_test.rb
|
200
|
-
- test/local_entry_test.rb
|
201
|
-
- test/output_stream_test.rb
|
202
|
-
- test/pass_thru_compressor_test.rb
|
203
|
-
- test/pass_thru_decompressor_test.rb
|
204
|
-
- test/path_traversal_test.rb
|
205
|
-
- test/samples/example_recursive_test.rb
|
206
|
-
- test/settings_test.rb
|
207
|
-
- test/test_helper.rb
|
208
|
-
- test/unicode_file_names_and_comments_test.rb
|
209
|
-
- test/zip64_full_test.rb
|
210
|
-
- test/zip64_support_test.rb
|
211
138
|
homepage: http://github.com/rubyzip/rubyzip
|
212
139
|
licenses:
|
213
140
|
- BSD 2-Clause
|
214
|
-
metadata:
|
141
|
+
metadata:
|
142
|
+
bug_tracker_uri: https://github.com/rubyzip/rubyzip/issues
|
143
|
+
changelog_uri: https://github.com/rubyzip/rubyzip/blob/v2.2.0/Changelog.md
|
144
|
+
documentation_uri: https://www.rubydoc.info/gems/rubyzip/2.2.0
|
145
|
+
source_code_uri: https://github.com/rubyzip/rubyzip/tree/v2.2.0
|
146
|
+
wiki_uri: https://github.com/rubyzip/rubyzip/wiki
|
215
147
|
post_install_message:
|
216
148
|
rdoc_options: []
|
217
149
|
require_paths:
|
@@ -220,89 +152,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
220
152
|
requirements:
|
221
153
|
- - ">="
|
222
154
|
- !ruby/object:Gem::Version
|
223
|
-
version:
|
155
|
+
version: '2.4'
|
224
156
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
225
157
|
requirements:
|
226
158
|
- - ">="
|
227
159
|
- !ruby/object:Gem::Version
|
228
160
|
version: '0'
|
229
161
|
requirements: []
|
230
|
-
rubygems_version: 3.0.
|
162
|
+
rubygems_version: 3.0.3
|
231
163
|
signing_key:
|
232
164
|
specification_version: 4
|
233
165
|
summary: rubyzip is a ruby module for reading and writing zip files
|
234
|
-
test_files:
|
235
|
-
- test/file_permissions_test.rb
|
236
|
-
- test/path_traversal_test.rb
|
237
|
-
- test/ioextras/abstract_input_stream_test.rb
|
238
|
-
- test/ioextras/fake_io_test.rb
|
239
|
-
- test/ioextras/abstract_output_stream_test.rb
|
240
|
-
- test/central_directory_test.rb
|
241
|
-
- test/central_directory_entry_test.rb
|
242
|
-
- test/crypto/traditional_encryption_test.rb
|
243
|
-
- test/crypto/null_encryption_test.rb
|
244
|
-
- test/input_stream_test.rb
|
245
|
-
- test/file_extract_directory_test.rb
|
246
|
-
- test/basic_zip_file_test.rb
|
247
|
-
- test/inflater_test.rb
|
248
|
-
- test/file_extract_test.rb
|
249
|
-
- test/pass_thru_compressor_test.rb
|
250
|
-
- test/filesystem/file_nonmutating_test.rb
|
251
|
-
- test/filesystem/file_stat_test.rb
|
252
|
-
- test/filesystem/file_mutating_test.rb
|
253
|
-
- test/filesystem/dir_iterator_test.rb
|
254
|
-
- test/filesystem/directory_test.rb
|
255
|
-
- test/extra_field_test.rb
|
256
|
-
- test/zip64_support_test.rb
|
257
|
-
- test/local_entry_test.rb
|
258
|
-
- test/samples/example_recursive_test.rb
|
259
|
-
- test/entry_test.rb
|
260
|
-
- test/case_sensitivity_test.rb
|
261
|
-
- test/zip64_full_test.rb
|
262
|
-
- test/pass_thru_decompressor_test.rb
|
263
|
-
- test/settings_test.rb
|
264
|
-
- test/gentestfiles.rb
|
265
|
-
- test/encryption_test.rb
|
266
|
-
- test/file_test.rb
|
267
|
-
- test/deflater_test.rb
|
268
|
-
- test/test_helper.rb
|
269
|
-
- test/errors_test.rb
|
270
|
-
- test/file_split_test.rb
|
271
|
-
- test/data/file2.txt
|
272
|
-
- test/data/testDirectory.bin
|
273
|
-
- test/data/globTest/foo.txt
|
274
|
-
- test/data/globTest/foo/bar/baz/foo.txt
|
275
|
-
- test/data/globTest/food.txt
|
276
|
-
- test/data/file1.txt
|
277
|
-
- test/data/rubycode.zip
|
278
|
-
- test/data/WarnInvalidDate.zip
|
279
|
-
- test/data/zipWithDirs.zip
|
280
|
-
- test/data/rubycode2.zip
|
281
|
-
- test/data/mimetype
|
282
|
-
- test/data/zipWithEncryption.zip
|
283
|
-
- test/data/path_traversal/tilde.zip
|
284
|
-
- test/data/path_traversal/Makefile
|
285
|
-
- test/data/path_traversal/relative1.zip
|
286
|
-
- test/data/path_traversal/jwilk/dirsymlink.zip
|
287
|
-
- test/data/path_traversal/jwilk/symlink.zip
|
288
|
-
- test/data/path_traversal/jwilk/README.md
|
289
|
-
- test/data/path_traversal/jwilk/relative2.zip
|
290
|
-
- test/data/path_traversal/jwilk/relative0.zip
|
291
|
-
- test/data/path_traversal/jwilk/absolute2.zip
|
292
|
-
- test/data/path_traversal/jwilk/dirsymlink2b.zip
|
293
|
-
- test/data/path_traversal/jwilk/absolute1.zip
|
294
|
-
- test/data/path_traversal/jwilk/dirsymlink2a.zip
|
295
|
-
- test/data/path_traversal/tuzovakaoff/symlink.zip
|
296
|
-
- test/data/path_traversal/tuzovakaoff/README.md
|
297
|
-
- test/data/path_traversal/tuzovakaoff/absolutepath.zip
|
298
|
-
- test/data/oddExtraField.zip
|
299
|
-
- test/data/gpbit3stored.zip
|
300
|
-
- test/data/ntfs.zip
|
301
|
-
- test/data/notzippedruby.rb
|
302
|
-
- test/data/globTest.zip
|
303
|
-
- test/data/file1.txt.deflatedData
|
304
|
-
- test/data/test.xls
|
305
|
-
- test/data/zip64-sample.zip
|
306
|
-
- test/unicode_file_names_and_comments_test.rb
|
307
|
-
- test/entry_set_test.rb
|
308
|
-
- test/output_stream_test.rb
|
166
|
+
test_files: []
|
data/test/basic_zip_file_test.rb
DELETED
@@ -1,60 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class BasicZipFileTest < MiniTest::Test
|
4
|
-
include AssertEntry
|
5
|
-
|
6
|
-
def setup
|
7
|
-
@zip_file = ::Zip::File.new(TestZipFile::TEST_ZIP2.zip_name)
|
8
|
-
@testEntryNameIndex = 0
|
9
|
-
end
|
10
|
-
|
11
|
-
def test_entries
|
12
|
-
assert_equal(TestZipFile::TEST_ZIP2.entry_names.sort,
|
13
|
-
@zip_file.entries.entries.sort.map { |e| e.name })
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_each
|
17
|
-
count = 0
|
18
|
-
visited = {}
|
19
|
-
@zip_file.each do |entry|
|
20
|
-
assert(TestZipFile::TEST_ZIP2.entry_names.include?(entry.name))
|
21
|
-
assert(!visited.include?(entry.name))
|
22
|
-
visited[entry.name] = nil
|
23
|
-
count = count.succ
|
24
|
-
end
|
25
|
-
assert_equal(TestZipFile::TEST_ZIP2.entry_names.length, count)
|
26
|
-
end
|
27
|
-
|
28
|
-
def test_foreach
|
29
|
-
count = 0
|
30
|
-
visited = {}
|
31
|
-
::Zip::File.foreach(TestZipFile::TEST_ZIP2.zip_name) do |entry|
|
32
|
-
assert(TestZipFile::TEST_ZIP2.entry_names.include?(entry.name))
|
33
|
-
assert(!visited.include?(entry.name))
|
34
|
-
visited[entry.name] = nil
|
35
|
-
count = count.succ
|
36
|
-
end
|
37
|
-
assert_equal(TestZipFile::TEST_ZIP2.entry_names.length, count)
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_get_input_stream
|
41
|
-
count = 0
|
42
|
-
visited = {}
|
43
|
-
@zip_file.each do |entry|
|
44
|
-
assert_entry(entry.name, @zip_file.get_input_stream(entry), entry.name)
|
45
|
-
assert(!visited.include?(entry.name))
|
46
|
-
visited[entry.name] = nil
|
47
|
-
count = count.succ
|
48
|
-
end
|
49
|
-
assert_equal(TestZipFile::TEST_ZIP2.entry_names.length, count)
|
50
|
-
end
|
51
|
-
|
52
|
-
def test_get_input_stream_block
|
53
|
-
fileAndEntryName = @zip_file.entries.first.name
|
54
|
-
@zip_file.get_input_stream(fileAndEntryName) do |zis|
|
55
|
-
assert_entry_contents_for_stream(fileAndEntryName,
|
56
|
-
zis,
|
57
|
-
fileAndEntryName)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
@@ -1,69 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class ZipCaseSensitivityTest < MiniTest::Test
|
4
|
-
include CommonZipFileFixture
|
5
|
-
|
6
|
-
SRC_FILES = [['test/data/file1.txt', 'testfile.rb'],
|
7
|
-
['test/data/file2.txt', 'testFILE.rb']]
|
8
|
-
|
9
|
-
def teardown
|
10
|
-
::Zip.case_insensitive_match = false
|
11
|
-
end
|
12
|
-
|
13
|
-
# Ensure that everything functions normally when +case_insensitive_match = false+
|
14
|
-
def test_add_case_sensitive
|
15
|
-
::Zip.case_insensitive_match = false
|
16
|
-
|
17
|
-
SRC_FILES.each { |fn, _en| assert(::File.exist?(fn)) }
|
18
|
-
zf = ::Zip::File.new(EMPTY_FILENAME, ::Zip::File::CREATE)
|
19
|
-
|
20
|
-
SRC_FILES.each { |fn, en| zf.add(en, fn) }
|
21
|
-
zf.close
|
22
|
-
|
23
|
-
zfRead = ::Zip::File.new(EMPTY_FILENAME)
|
24
|
-
assert_equal(SRC_FILES.size, zfRead.entries.length)
|
25
|
-
SRC_FILES.each_with_index { |a, i|
|
26
|
-
assert_equal(a.last, zfRead.entries[i].name)
|
27
|
-
AssertEntry.assert_contents(a.first,
|
28
|
-
zfRead.get_input_stream(a.last) { |zis| zis.read })
|
29
|
-
}
|
30
|
-
end
|
31
|
-
|
32
|
-
# Ensure that names are treated case insensitively when adding files and +case_insensitive_match = false+
|
33
|
-
def test_add_case_insensitive
|
34
|
-
::Zip.case_insensitive_match = true
|
35
|
-
|
36
|
-
SRC_FILES.each { |fn, _en| assert(::File.exist?(fn)) }
|
37
|
-
zf = ::Zip::File.new(EMPTY_FILENAME, ::Zip::File::CREATE)
|
38
|
-
|
39
|
-
assert_raises Zip::EntryExistsError do
|
40
|
-
SRC_FILES.each { |fn, en| zf.add(en, fn) }
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
# Ensure that names are treated case insensitively when reading files and +case_insensitive_match = true+
|
45
|
-
def test_add_case_sensitive_read_case_insensitive
|
46
|
-
::Zip.case_insensitive_match = false
|
47
|
-
|
48
|
-
SRC_FILES.each { |fn, _en| assert(::File.exist?(fn)) }
|
49
|
-
zf = ::Zip::File.new(EMPTY_FILENAME, ::Zip::File::CREATE)
|
50
|
-
|
51
|
-
SRC_FILES.each { |fn, en| zf.add(en, fn) }
|
52
|
-
zf.close
|
53
|
-
|
54
|
-
::Zip.case_insensitive_match = true
|
55
|
-
|
56
|
-
zfRead = ::Zip::File.new(EMPTY_FILENAME)
|
57
|
-
assert_equal(SRC_FILES.collect { |_fn, en| en.downcase }.uniq.size, zfRead.entries.length)
|
58
|
-
assert_equal(SRC_FILES.last.last.downcase, zfRead.entries.first.name.downcase)
|
59
|
-
AssertEntry.assert_contents(SRC_FILES.last.first,
|
60
|
-
zfRead.get_input_stream(SRC_FILES.last.last) { |zis| zis.read })
|
61
|
-
end
|
62
|
-
|
63
|
-
private
|
64
|
-
|
65
|
-
def assert_contains(zf, entryName, filename = entryName)
|
66
|
-
assert(zf.entries.detect { |e| e.name == entryName } != nil, "entry #{entryName} not in #{zf.entries.join(', ')} in zip file #{zf}")
|
67
|
-
assert_entry_contents(zf, entryName, filename) if File.exist?(filename)
|
68
|
-
end
|
69
|
-
end
|
@@ -1,69 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class ZipCentralDirectoryEntryTest < MiniTest::Test
|
4
|
-
def test_read_from_stream
|
5
|
-
File.open('test/data/testDirectory.bin', 'rb') do |file|
|
6
|
-
entry = ::Zip::Entry.read_c_dir_entry(file)
|
7
|
-
|
8
|
-
assert_equal('longAscii.txt', entry.name)
|
9
|
-
assert_equal(::Zip::Entry::DEFLATED, entry.compression_method)
|
10
|
-
assert_equal(106_490, entry.size)
|
11
|
-
assert_equal(3784, entry.compressed_size)
|
12
|
-
assert_equal(0xfcd1799c, entry.crc)
|
13
|
-
assert_equal('', entry.comment)
|
14
|
-
|
15
|
-
entry = ::Zip::Entry.read_c_dir_entry(file)
|
16
|
-
assert_equal('empty.txt', entry.name)
|
17
|
-
assert_equal(::Zip::Entry::STORED, entry.compression_method)
|
18
|
-
assert_equal(0, entry.size)
|
19
|
-
assert_equal(0, entry.compressed_size)
|
20
|
-
assert_equal(0x0, entry.crc)
|
21
|
-
assert_equal('', entry.comment)
|
22
|
-
|
23
|
-
entry = ::Zip::Entry.read_c_dir_entry(file)
|
24
|
-
assert_equal('short.txt', entry.name)
|
25
|
-
assert_equal(::Zip::Entry::STORED, entry.compression_method)
|
26
|
-
assert_equal(6, entry.size)
|
27
|
-
assert_equal(6, entry.compressed_size)
|
28
|
-
assert_equal(0xbb76fe69, entry.crc)
|
29
|
-
assert_equal('', entry.comment)
|
30
|
-
|
31
|
-
entry = ::Zip::Entry.read_c_dir_entry(file)
|
32
|
-
assert_equal('longBinary.bin', entry.name)
|
33
|
-
assert_equal(::Zip::Entry::DEFLATED, entry.compression_method)
|
34
|
-
assert_equal(1_000_024, entry.size)
|
35
|
-
assert_equal(70_847, entry.compressed_size)
|
36
|
-
assert_equal(0x10da7d59, entry.crc)
|
37
|
-
assert_equal('', entry.comment)
|
38
|
-
|
39
|
-
entry = ::Zip::Entry.read_c_dir_entry(file)
|
40
|
-
assert_nil(entry)
|
41
|
-
# Fields that are not check by this test:
|
42
|
-
# version made by 2 bytes
|
43
|
-
# version needed to extract 2 bytes
|
44
|
-
# general purpose bit flag 2 bytes
|
45
|
-
# last mod file time 2 bytes
|
46
|
-
# last mod file date 2 bytes
|
47
|
-
# compressed size 4 bytes
|
48
|
-
# uncompressed size 4 bytes
|
49
|
-
# disk number start 2 bytes
|
50
|
-
# internal file attributes 2 bytes
|
51
|
-
# external file attributes 4 bytes
|
52
|
-
# relative offset of local header 4 bytes
|
53
|
-
|
54
|
-
# file name (variable size)
|
55
|
-
# extra field (variable size)
|
56
|
-
# file comment (variable size)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
def test_read_entry_from_truncated_zip_file
|
61
|
-
fragment = ''
|
62
|
-
File.open('test/data/testDirectory.bin') { |f| fragment = f.read(12) } # cdir entry header is at least 46 bytes
|
63
|
-
fragment.extend(IOizeString)
|
64
|
-
entry = ::Zip::Entry.new
|
65
|
-
entry.read_c_dir_entry(fragment)
|
66
|
-
fail 'ZipError expected'
|
67
|
-
rescue ::Zip::Error
|
68
|
-
end
|
69
|
-
end
|