rubyzip 1.2.2 → 2.1.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 +64 -23
- data/lib/zip.rb +3 -2
- data/lib/zip/dos_time.rb +5 -0
- data/lib/zip/entry.rb +36 -19
- data/lib/zip/errors.rb +1 -0
- data/lib/zip/extra_field.rb +1 -1
- data/lib/zip/extra_field/generic.rb +1 -1
- data/lib/zip/extra_field/universal_time.rb +39 -12
- data/lib/zip/file.rb +67 -33
- data/lib/zip/inflater.rb +1 -1
- data/lib/zip/input_stream.rb +1 -1
- data/lib/zip/streamable_stream.rb +1 -6
- data/lib/zip/version.rb +1 -1
- metadata +11 -153
- 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/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 -134
- 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
data/lib/zip/file.rb
CHANGED
@@ -51,50 +51,74 @@ module Zip
|
|
51
51
|
DATA_BUFFER_SIZE = 8192
|
52
52
|
IO_METHODS = [:tell, :seek, :read, :close]
|
53
53
|
|
54
|
+
DEFAULT_OPTIONS = {
|
55
|
+
restore_ownership: false,
|
56
|
+
restore_permissions: false,
|
57
|
+
restore_times: false
|
58
|
+
}.freeze
|
59
|
+
|
54
60
|
attr_reader :name
|
55
61
|
|
56
|
-
# default -> false
|
62
|
+
# default -> false.
|
57
63
|
attr_accessor :restore_ownership
|
58
|
-
|
64
|
+
|
65
|
+
# default -> false, but will be set to true in a future version.
|
59
66
|
attr_accessor :restore_permissions
|
60
|
-
|
67
|
+
|
68
|
+
# default -> false, but will be set to true in a future version.
|
61
69
|
attr_accessor :restore_times
|
70
|
+
|
62
71
|
# Returns the zip files comment, if it has one
|
63
72
|
attr_accessor :comment
|
64
73
|
|
65
74
|
# Opens a zip archive. Pass true as the second parameter to create
|
66
75
|
# a new archive if it doesn't exist already.
|
67
|
-
def initialize(
|
76
|
+
def initialize(path_or_io, create = false, buffer = false, options = {})
|
68
77
|
super()
|
69
|
-
|
78
|
+
options = DEFAULT_OPTIONS.merge(options)
|
79
|
+
@name = path_or_io.respond_to?(:path) ? path_or_io.path : path_or_io
|
70
80
|
@comment = ''
|
71
81
|
@create = create ? true : false # allow any truthy value to mean true
|
72
|
-
|
82
|
+
|
83
|
+
if ::File.size?(@name.to_s)
|
84
|
+
# There is a file, which exists, that is associated with this zip.
|
73
85
|
@create = false
|
74
|
-
@file_permissions = ::File.stat(
|
75
|
-
|
76
|
-
|
86
|
+
@file_permissions = ::File.stat(@name).mode
|
87
|
+
|
88
|
+
if buffer
|
89
|
+
read_from_stream(path_or_io)
|
90
|
+
else
|
91
|
+
::File.open(@name, 'rb') do |f|
|
92
|
+
read_from_stream(f)
|
93
|
+
end
|
77
94
|
end
|
95
|
+
elsif buffer && path_or_io.size > 0
|
96
|
+
# This zip is probably a non-empty StringIO.
|
97
|
+
read_from_stream(path_or_io)
|
78
98
|
elsif @create
|
99
|
+
# This zip is completely new/empty and is to be created.
|
79
100
|
@entry_set = EntrySet.new
|
80
|
-
elsif ::File.zero?(
|
81
|
-
|
101
|
+
elsif ::File.zero?(@name)
|
102
|
+
# A file exists, but it is empty.
|
103
|
+
raise Error, "File #{@name} has zero size. Did you mean to pass the create flag?"
|
82
104
|
else
|
83
|
-
|
105
|
+
# Everything is wrong.
|
106
|
+
raise Error, "File #{@name} not found"
|
84
107
|
end
|
108
|
+
|
85
109
|
@stored_entries = @entry_set.dup
|
86
110
|
@stored_comment = @comment
|
87
|
-
@restore_ownership = options[:restore_ownership]
|
88
|
-
@restore_permissions = options[:restore_permissions]
|
89
|
-
@restore_times = options[:restore_times]
|
111
|
+
@restore_ownership = options[:restore_ownership]
|
112
|
+
@restore_permissions = options[:restore_permissions]
|
113
|
+
@restore_times = options[:restore_times]
|
90
114
|
end
|
91
115
|
|
92
116
|
class << self
|
93
|
-
#
|
94
|
-
# to the block and is automatically closed afterwards just as with
|
95
|
-
# ruby's builtin File
|
96
|
-
def open(file_name, create = false)
|
97
|
-
zf = ::Zip::File.new(file_name, create)
|
117
|
+
# Similar to ::new. If a block is passed the Zip::File object is passed
|
118
|
+
# to the block and is automatically closed afterwards, just as with
|
119
|
+
# ruby's builtin File::open method.
|
120
|
+
def open(file_name, create = false, options = {})
|
121
|
+
zf = ::Zip::File.new(file_name, create, false, options)
|
98
122
|
return zf unless block_given?
|
99
123
|
begin
|
100
124
|
yield zf
|
@@ -119,17 +143,16 @@ module Zip
|
|
119
143
|
unless IO_METHODS.map { |method| io.respond_to?(method) }.all? || io.is_a?(String)
|
120
144
|
raise "Zip::File.open_buffer expects a String or IO-like argument (responds to #{IO_METHODS.join(', ')}). Found: #{io.class}"
|
121
145
|
end
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
end
|
146
|
+
|
147
|
+
io = ::StringIO.new(io) if io.is_a?(::String)
|
148
|
+
|
149
|
+
# https://github.com/rubyzip/rubyzip/issues/119
|
150
|
+
io.binmode if io.respond_to?(:binmode)
|
151
|
+
|
129
152
|
zf = ::Zip::File.new(io, true, true, options)
|
130
|
-
zf.read_from_stream(io)
|
131
153
|
return zf unless block_given?
|
132
154
|
yield zf
|
155
|
+
|
133
156
|
begin
|
134
157
|
zf.write_buffer(io)
|
135
158
|
rescue IOError => e
|
@@ -274,6 +297,13 @@ module Zip
|
|
274
297
|
@entry_set << new_entry
|
275
298
|
end
|
276
299
|
|
300
|
+
# Convenience method for adding the contents of a file to the archive
|
301
|
+
# in Stored format (uncompressed)
|
302
|
+
def add_stored(entry, src_path, &continue_on_exists_proc)
|
303
|
+
entry = ::Zip::Entry.new(@name, entry.to_s, nil, nil, nil, nil, ::Zip::Entry::STORED)
|
304
|
+
add(entry, src_path, &continue_on_exists_proc)
|
305
|
+
end
|
306
|
+
|
277
307
|
# Removes the specified entry.
|
278
308
|
def remove(entry)
|
279
309
|
@entry_set.delete(get_entry(entry))
|
@@ -346,7 +376,13 @@ module Zip
|
|
346
376
|
# Searches for entry with the specified name. Returns nil if
|
347
377
|
# no entry is found. See also get_entry
|
348
378
|
def find_entry(entry_name)
|
349
|
-
@entry_set.find_entry(entry_name)
|
379
|
+
selected_entry = @entry_set.find_entry(entry_name)
|
380
|
+
return if selected_entry.nil?
|
381
|
+
|
382
|
+
selected_entry.restore_ownership = @restore_ownership
|
383
|
+
selected_entry.restore_permissions = @restore_permissions
|
384
|
+
selected_entry.restore_times = @restore_times
|
385
|
+
selected_entry
|
350
386
|
end
|
351
387
|
|
352
388
|
# Searches for entries given a glob
|
@@ -358,10 +394,8 @@ module Zip
|
|
358
394
|
# if no entry is found.
|
359
395
|
def get_entry(entry)
|
360
396
|
selected_entry = find_entry(entry)
|
361
|
-
raise Errno::ENOENT, entry
|
362
|
-
|
363
|
-
selected_entry.restore_permissions = @restore_permissions
|
364
|
-
selected_entry.restore_times = @restore_times
|
397
|
+
raise Errno::ENOENT, entry if selected_entry.nil?
|
398
|
+
|
365
399
|
selected_entry
|
366
400
|
end
|
367
401
|
|
data/lib/zip/inflater.rb
CHANGED
data/lib/zip/input_stream.rb
CHANGED
@@ -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: 1.
|
4
|
+
version: 2.1.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-01-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -134,83 +134,15 @@ files:
|
|
134
134
|
- samples/qtzip.rb
|
135
135
|
- samples/write_simple.rb
|
136
136
|
- 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/tuzovakaoff/README.md
|
168
|
-
- test/data/path_traversal/tuzovakaoff/absolutepath.zip
|
169
|
-
- test/data/path_traversal/tuzovakaoff/symlink.zip
|
170
|
-
- test/data/rubycode.zip
|
171
|
-
- test/data/rubycode2.zip
|
172
|
-
- test/data/test.xls
|
173
|
-
- test/data/testDirectory.bin
|
174
|
-
- test/data/zip64-sample.zip
|
175
|
-
- test/data/zipWithDirs.zip
|
176
|
-
- test/data/zipWithEncryption.zip
|
177
|
-
- test/deflater_test.rb
|
178
|
-
- test/encryption_test.rb
|
179
|
-
- test/entry_set_test.rb
|
180
|
-
- test/entry_test.rb
|
181
|
-
- test/errors_test.rb
|
182
|
-
- test/extra_field_test.rb
|
183
|
-
- test/file_extract_directory_test.rb
|
184
|
-
- test/file_extract_test.rb
|
185
|
-
- test/file_permissions_test.rb
|
186
|
-
- test/file_split_test.rb
|
187
|
-
- test/file_test.rb
|
188
|
-
- test/filesystem/dir_iterator_test.rb
|
189
|
-
- test/filesystem/directory_test.rb
|
190
|
-
- test/filesystem/file_mutating_test.rb
|
191
|
-
- test/filesystem/file_nonmutating_test.rb
|
192
|
-
- test/filesystem/file_stat_test.rb
|
193
|
-
- test/gentestfiles.rb
|
194
|
-
- test/inflater_test.rb
|
195
|
-
- test/input_stream_test.rb
|
196
|
-
- test/ioextras/abstract_input_stream_test.rb
|
197
|
-
- test/ioextras/abstract_output_stream_test.rb
|
198
|
-
- test/ioextras/fake_io_test.rb
|
199
|
-
- test/local_entry_test.rb
|
200
|
-
- test/output_stream_test.rb
|
201
|
-
- test/pass_thru_compressor_test.rb
|
202
|
-
- test/pass_thru_decompressor_test.rb
|
203
|
-
- test/path_traversal_test.rb
|
204
|
-
- test/samples/example_recursive_test.rb
|
205
|
-
- test/settings_test.rb
|
206
|
-
- test/test_helper.rb
|
207
|
-
- test/unicode_file_names_and_comments_test.rb
|
208
|
-
- test/zip64_full_test.rb
|
209
|
-
- test/zip64_support_test.rb
|
210
137
|
homepage: http://github.com/rubyzip/rubyzip
|
211
138
|
licenses:
|
212
139
|
- BSD 2-Clause
|
213
|
-
metadata:
|
140
|
+
metadata:
|
141
|
+
bug_tracker_uri: https://github.com/rubyzip/rubyzip/issues
|
142
|
+
changelog_uri: https://github.com/rubyzip/rubyzip/blob/v2.1.0/Changelog.md
|
143
|
+
documentation_uri: https://www.rubydoc.info/gems/rubyzip/2.1.0
|
144
|
+
source_code_uri: https://github.com/rubyzip/rubyzip/tree/v2.1.0
|
145
|
+
wiki_uri: https://github.com/rubyzip/rubyzip/wiki
|
214
146
|
post_install_message:
|
215
147
|
rdoc_options: []
|
216
148
|
require_paths:
|
@@ -219,89 +151,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
219
151
|
requirements:
|
220
152
|
- - ">="
|
221
153
|
- !ruby/object:Gem::Version
|
222
|
-
version:
|
154
|
+
version: '2.4'
|
223
155
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
224
156
|
requirements:
|
225
157
|
- - ">="
|
226
158
|
- !ruby/object:Gem::Version
|
227
159
|
version: '0'
|
228
160
|
requirements: []
|
229
|
-
|
230
|
-
rubygems_version: 2.6.13
|
161
|
+
rubygems_version: 3.0.3
|
231
162
|
signing_key:
|
232
163
|
specification_version: 4
|
233
164
|
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/Makefile
|
284
|
-
- test/data/path_traversal/relative1.zip
|
285
|
-
- test/data/path_traversal/jwilk/dirsymlink.zip
|
286
|
-
- test/data/path_traversal/jwilk/symlink.zip
|
287
|
-
- test/data/path_traversal/jwilk/README.md
|
288
|
-
- test/data/path_traversal/jwilk/relative2.zip
|
289
|
-
- test/data/path_traversal/jwilk/relative0.zip
|
290
|
-
- test/data/path_traversal/jwilk/absolute2.zip
|
291
|
-
- test/data/path_traversal/jwilk/dirsymlink2b.zip
|
292
|
-
- test/data/path_traversal/jwilk/absolute1.zip
|
293
|
-
- test/data/path_traversal/jwilk/dirsymlink2a.zip
|
294
|
-
- test/data/path_traversal/tuzovakaoff/symlink.zip
|
295
|
-
- test/data/path_traversal/tuzovakaoff/README.md
|
296
|
-
- test/data/path_traversal/tuzovakaoff/absolutepath.zip
|
297
|
-
- test/data/oddExtraField.zip
|
298
|
-
- test/data/gpbit3stored.zip
|
299
|
-
- test/data/ntfs.zip
|
300
|
-
- test/data/notzippedruby.rb
|
301
|
-
- test/data/globTest.zip
|
302
|
-
- test/data/file1.txt.deflatedData
|
303
|
-
- test/data/test.xls
|
304
|
-
- test/data/zip64-sample.zip
|
305
|
-
- test/unicode_file_names_and_comments_test.rb
|
306
|
-
- test/entry_set_test.rb
|
307
|
-
- test/output_stream_test.rb
|
165
|
+
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
|