rubyzip 1.1.7 → 2.3.2

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.
Files changed (101) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +137 -54
  3. data/Rakefile +6 -4
  4. data/lib/zip/central_directory.rb +17 -13
  5. data/lib/zip/compressor.rb +1 -2
  6. data/lib/zip/constants.rb +57 -5
  7. data/lib/zip/crypto/decrypted_io.rb +40 -0
  8. data/lib/zip/crypto/null_encryption.rb +4 -6
  9. data/lib/zip/crypto/traditional_encryption.rb +14 -14
  10. data/lib/zip/decompressor.rb +22 -4
  11. data/lib/zip/deflater.rb +8 -6
  12. data/lib/zip/dos_time.rb +17 -13
  13. data/lib/zip/entry.rb +171 -148
  14. data/lib/zip/entry_set.rb +16 -14
  15. data/lib/zip/errors.rb +3 -0
  16. data/lib/zip/extra_field/generic.rb +14 -13
  17. data/lib/zip/extra_field/ntfs.rb +18 -16
  18. data/lib/zip/extra_field/old_unix.rb +12 -11
  19. data/lib/zip/extra_field/universal_time.rb +46 -16
  20. data/lib/zip/extra_field/unix.rb +10 -9
  21. data/lib/zip/extra_field/zip64.rb +15 -12
  22. data/lib/zip/extra_field/zip64_placeholder.rb +1 -2
  23. data/lib/zip/extra_field.rb +18 -16
  24. data/lib/zip/file.rb +147 -115
  25. data/lib/zip/filesystem.rb +289 -272
  26. data/lib/zip/inflater.rb +24 -36
  27. data/lib/zip/input_stream.rb +44 -28
  28. data/lib/zip/ioextras/abstract_input_stream.rb +24 -17
  29. data/lib/zip/ioextras/abstract_output_stream.rb +4 -6
  30. data/lib/zip/ioextras.rb +2 -4
  31. data/lib/zip/null_compressor.rb +2 -2
  32. data/lib/zip/null_decompressor.rb +3 -11
  33. data/lib/zip/null_input_stream.rb +0 -0
  34. data/lib/zip/output_stream.rb +25 -17
  35. data/lib/zip/pass_thru_compressor.rb +6 -6
  36. data/lib/zip/pass_thru_decompressor.rb +14 -24
  37. data/lib/zip/streamable_directory.rb +3 -3
  38. data/lib/zip/streamable_stream.rb +7 -11
  39. data/lib/zip/version.rb +1 -1
  40. data/lib/zip.rb +15 -6
  41. data/samples/example.rb +29 -39
  42. data/samples/example_filesystem.rb +16 -18
  43. data/samples/example_recursive.rb +31 -25
  44. data/samples/gtk_ruby_zip.rb +84 -0
  45. data/samples/qtzip.rb +23 -32
  46. data/samples/write_simple.rb +10 -13
  47. data/samples/zipfind.rb +33 -40
  48. metadata +50 -141
  49. data/samples/gtkRubyzip.rb +0 -86
  50. data/test/basic_zip_file_test.rb +0 -64
  51. data/test/central_directory_entry_test.rb +0 -73
  52. data/test/central_directory_test.rb +0 -104
  53. data/test/crypto/null_encryption_test.rb +0 -53
  54. data/test/crypto/traditional_encryption_test.rb +0 -80
  55. data/test/data/WarnInvalidDate.zip +0 -0
  56. data/test/data/file1.txt +0 -46
  57. data/test/data/file1.txt.deflatedData +0 -0
  58. data/test/data/file2.txt +0 -1504
  59. data/test/data/globTest/foo/bar/baz/foo.txt +0 -0
  60. data/test/data/globTest/foo.txt +0 -0
  61. data/test/data/globTest/food.txt +0 -0
  62. data/test/data/globTest.zip +0 -0
  63. data/test/data/mimetype +0 -1
  64. data/test/data/notzippedruby.rb +0 -7
  65. data/test/data/ntfs.zip +0 -0
  66. data/test/data/rubycode.zip +0 -0
  67. data/test/data/rubycode2.zip +0 -0
  68. data/test/data/testDirectory.bin +0 -0
  69. data/test/data/zip64-sample.zip +0 -0
  70. data/test/data/zipWithDirs.zip +0 -0
  71. data/test/data/zipWithEncryption.zip +0 -0
  72. data/test/deflater_test.rb +0 -67
  73. data/test/encryption_test.rb +0 -42
  74. data/test/entry_set_test.rb +0 -138
  75. data/test/entry_test.rb +0 -165
  76. data/test/errors_test.rb +0 -36
  77. data/test/extra_field_test.rb +0 -78
  78. data/test/file_extract_directory_test.rb +0 -56
  79. data/test/file_extract_test.rb +0 -90
  80. data/test/file_split_test.rb +0 -60
  81. data/test/file_test.rb +0 -559
  82. data/test/filesystem/dir_iterator_test.rb +0 -62
  83. data/test/filesystem/directory_test.rb +0 -131
  84. data/test/filesystem/file_mutating_test.rb +0 -100
  85. data/test/filesystem/file_nonmutating_test.rb +0 -514
  86. data/test/filesystem/file_stat_test.rb +0 -66
  87. data/test/gentestfiles.rb +0 -134
  88. data/test/inflater_test.rb +0 -14
  89. data/test/input_stream_test.rb +0 -170
  90. data/test/ioextras/abstract_input_stream_test.rb +0 -103
  91. data/test/ioextras/abstract_output_stream_test.rb +0 -106
  92. data/test/ioextras/fake_io_test.rb +0 -18
  93. data/test/local_entry_test.rb +0 -156
  94. data/test/output_stream_test.rb +0 -129
  95. data/test/pass_thru_compressor_test.rb +0 -31
  96. data/test/pass_thru_decompressor_test.rb +0 -15
  97. data/test/settings_test.rb +0 -92
  98. data/test/test_helper.rb +0 -228
  99. data/test/unicode_file_names_and_comments_test.rb +0 -52
  100. data/test/zip64_full_test.rb +0 -53
  101. data/test/zip64_support_test.rb +0 -15
data/samples/zipfind.rb CHANGED
@@ -2,72 +2,65 @@
2
2
 
3
3
  $VERBOSE = true
4
4
 
5
- $: << "../lib"
5
+ $LOAD_PATH << '../lib'
6
6
 
7
7
  require 'zip'
8
8
  require 'find'
9
9
 
10
10
  module Zip
11
11
  module ZipFind
12
- def self.find(path, zipFilePattern = /\.zip$/i)
13
- Find.find(path) {
14
- |fileName|
15
- yield(fileName)
16
- if zipFilePattern.match(fileName) && File.file?(fileName)
17
- begin
18
- Zip::File.foreach(fileName) {
19
- |zipEntry|
20
- yield(fileName + File::SEPARATOR + zipEntry.to_s)
21
- }
22
- rescue Errno::EACCES => ex
23
- puts ex
24
- end
25
- end
26
- }
27
- end
12
+ def self.find(path, zip_file_pattern = /\.zip$/i)
13
+ Find.find(path) do |filename|
14
+ yield(filename)
15
+ next unless zip_file_pattern.match(filename) && File.file?(filename)
28
16
 
29
- def self.find_file(path, fileNamePattern, zipFilePattern = /\.zip$/i)
30
- self.find(path, zipFilePattern) {
31
- |fileName|
32
- yield(fileName) if fileNamePattern.match(fileName)
33
- }
17
+ begin
18
+ Zip::File.foreach(filename) do |entry|
19
+ yield(filename + File::SEPARATOR + entry.to_s)
20
+ end
21
+ rescue Errno::EACCES => e
22
+ puts e
23
+ end
24
+ end
34
25
  end
35
26
 
27
+ def self.find_file(path, filename_pattern, zip_file_pattern = /\.zip$/i)
28
+ find(path, zip_file_pattern) do |filename|
29
+ yield(filename) if filename_pattern.match(filename)
30
+ end
31
+ end
36
32
  end
37
33
  end
38
34
 
39
- if __FILE__ == $0
35
+ if $PROGRAM_NAME == __FILE__
40
36
  module ZipFindConsoleRunner
41
-
42
- PATH_ARG_INDEX = 0;
43
- FILENAME_PATTERN_ARG_INDEX = 1;
44
- ZIPFILE_PATTERN_ARG_INDEX = 2;
37
+ PATH_ARG_INDEX = 0
38
+ FILENAME_PATTERN_ARG_INDEX = 1
39
+ ZIPFILE_PATTERN_ARG_INDEX = 2
45
40
 
46
41
  def self.run(args)
47
42
  check_args(args)
48
43
  Zip::ZipFind.find_file(args[PATH_ARG_INDEX],
49
- args[FILENAME_PATTERN_ARG_INDEX],
50
- args[ZIPFILE_PATTERN_ARG_INDEX]) {
51
- |fileName|
52
- report_entry_found fileName
53
- }
44
+ args[FILENAME_PATTERN_ARG_INDEX],
45
+ args[ZIPFILE_PATTERN_ARG_INDEX]) do |filename|
46
+ report_entry_found filename
47
+ end
54
48
  end
55
49
 
56
50
  def self.check_args(args)
57
- if (args.size != 3)
58
- usage
59
- exit
60
- end
51
+ return if args.size == 3
52
+
53
+ usage
54
+ exit
61
55
  end
62
56
 
63
57
  def self.usage
64
- puts "Usage: #{$0} PATH ZIPFILENAME_PATTERN FILNAME_PATTERN"
58
+ puts "Usage: #{$PROGRAM_NAME} PATH ZIPFILENAME_PATTERN FILNAME_PATTERN"
65
59
  end
66
60
 
67
- def self.report_entry_found(fileName)
68
- puts fileName
61
+ def self.report_entry_found(filename)
62
+ puts filename
69
63
  end
70
-
71
64
  end
72
65
 
73
66
  ZipFindConsoleRunner.run(ARGV)
metadata CHANGED
@@ -1,43 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubyzip
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.7
4
+ version: 2.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Simonov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-02 00:00:00.000000000 Z
11
+ date: 2021-07-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rake
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '10.3'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '10.3'
27
- - !ruby/object:Gem::Dependency
28
- name: pry
14
+ name: coveralls
29
15
  requirement: !ruby/object:Gem::Requirement
30
16
  requirements:
31
17
  - - "~>"
32
18
  - !ruby/object:Gem::Version
33
- version: '0.10'
19
+ version: '0.7'
34
20
  type: :development
35
21
  prerelease: false
36
22
  version_requirements: !ruby/object:Gem::Requirement
37
23
  requirements:
38
24
  - - "~>"
39
25
  - !ruby/object:Gem::Version
40
- version: '0.10'
26
+ version: '0.7'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: minitest
43
29
  requirement: !ruby/object:Gem::Requirement
@@ -53,47 +39,53 @@ dependencies:
53
39
  - !ruby/object:Gem::Version
54
40
  version: '5.4'
55
41
  - !ruby/object:Gem::Dependency
56
- name: coveralls
42
+ name: pry
57
43
  requirement: !ruby/object:Gem::Requirement
58
44
  requirements:
59
45
  - - "~>"
60
46
  - !ruby/object:Gem::Version
61
- version: '0.7'
47
+ version: '0.10'
62
48
  type: :development
63
49
  prerelease: false
64
50
  version_requirements: !ruby/object:Gem::Requirement
65
51
  requirements:
66
52
  - - "~>"
67
53
  - !ruby/object:Gem::Version
68
- version: '0.7'
54
+ version: '0.10'
69
55
  - !ruby/object:Gem::Dependency
70
- name: guard
56
+ name: rake
71
57
  requirement: !ruby/object:Gem::Requirement
72
58
  requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '12.3'
73
62
  - - ">="
74
63
  - !ruby/object:Gem::Version
75
- version: '0'
64
+ version: 12.3.3
76
65
  type: :development
77
66
  prerelease: false
78
67
  version_requirements: !ruby/object:Gem::Requirement
79
68
  requirements:
69
+ - - "~>"
70
+ - !ruby/object:Gem::Version
71
+ version: '12.3'
80
72
  - - ">="
81
73
  - !ruby/object:Gem::Version
82
- version: '0'
74
+ version: 12.3.3
83
75
  - !ruby/object:Gem::Dependency
84
- name: guard-minitest
76
+ name: rubocop
85
77
  requirement: !ruby/object:Gem::Requirement
86
78
  requirements:
87
- - - ">="
79
+ - - "~>"
88
80
  - !ruby/object:Gem::Version
89
- version: '0'
81
+ version: '0.79'
90
82
  type: :development
91
83
  prerelease: false
92
84
  version_requirements: !ruby/object:Gem::Requirement
93
85
  requirements:
94
- - - ">="
86
+ - - "~>"
95
87
  - !ruby/object:Gem::Version
96
- version: '0'
88
+ version: '0.79'
97
89
  description:
98
90
  email:
99
91
  - alex@simonov.me
@@ -108,6 +100,7 @@ files:
108
100
  - lib/zip/central_directory.rb
109
101
  - lib/zip/compressor.rb
110
102
  - lib/zip/constants.rb
103
+ - lib/zip/crypto/decrypted_io.rb
111
104
  - lib/zip/crypto/encryption.rb
112
105
  - lib/zip/crypto/null_encryption.rb
113
106
  - lib/zip/crypto/traditional_encryption.rb
@@ -144,67 +137,36 @@ files:
144
137
  - samples/example.rb
145
138
  - samples/example_filesystem.rb
146
139
  - samples/example_recursive.rb
147
- - samples/gtkRubyzip.rb
140
+ - samples/gtk_ruby_zip.rb
148
141
  - samples/qtzip.rb
149
142
  - samples/write_simple.rb
150
143
  - samples/zipfind.rb
151
- - test/basic_zip_file_test.rb
152
- - test/central_directory_entry_test.rb
153
- - test/central_directory_test.rb
154
- - test/crypto/null_encryption_test.rb
155
- - test/crypto/traditional_encryption_test.rb
156
- - test/data/WarnInvalidDate.zip
157
- - test/data/file1.txt
158
- - test/data/file1.txt.deflatedData
159
- - test/data/file2.txt
160
- - test/data/globTest.zip
161
- - test/data/globTest/foo.txt
162
- - test/data/globTest/foo/bar/baz/foo.txt
163
- - test/data/globTest/food.txt
164
- - test/data/mimetype
165
- - test/data/notzippedruby.rb
166
- - test/data/ntfs.zip
167
- - test/data/rubycode.zip
168
- - test/data/rubycode2.zip
169
- - test/data/testDirectory.bin
170
- - test/data/zip64-sample.zip
171
- - test/data/zipWithDirs.zip
172
- - test/data/zipWithEncryption.zip
173
- - test/deflater_test.rb
174
- - test/encryption_test.rb
175
- - test/entry_set_test.rb
176
- - test/entry_test.rb
177
- - test/errors_test.rb
178
- - test/extra_field_test.rb
179
- - test/file_extract_directory_test.rb
180
- - test/file_extract_test.rb
181
- - test/file_split_test.rb
182
- - test/file_test.rb
183
- - test/filesystem/dir_iterator_test.rb
184
- - test/filesystem/directory_test.rb
185
- - test/filesystem/file_mutating_test.rb
186
- - test/filesystem/file_nonmutating_test.rb
187
- - test/filesystem/file_stat_test.rb
188
- - test/gentestfiles.rb
189
- - test/inflater_test.rb
190
- - test/input_stream_test.rb
191
- - test/ioextras/abstract_input_stream_test.rb
192
- - test/ioextras/abstract_output_stream_test.rb
193
- - test/ioextras/fake_io_test.rb
194
- - test/local_entry_test.rb
195
- - test/output_stream_test.rb
196
- - test/pass_thru_compressor_test.rb
197
- - test/pass_thru_decompressor_test.rb
198
- - test/settings_test.rb
199
- - test/test_helper.rb
200
- - test/unicode_file_names_and_comments_test.rb
201
- - test/zip64_full_test.rb
202
- - test/zip64_support_test.rb
203
144
  homepage: http://github.com/rubyzip/rubyzip
204
145
  licenses:
205
146
  - BSD 2-Clause
206
- metadata: {}
207
- post_install_message:
147
+ metadata:
148
+ bug_tracker_uri: https://github.com/rubyzip/rubyzip/issues
149
+ changelog_uri: https://github.com/rubyzip/rubyzip/blob/v2.3.2/Changelog.md
150
+ documentation_uri: https://www.rubydoc.info/gems/rubyzip/2.3.2
151
+ source_code_uri: https://github.com/rubyzip/rubyzip/tree/v2.3.2
152
+ wiki_uri: https://github.com/rubyzip/rubyzip/wiki
153
+ post_install_message: |
154
+ RubyZip 3.0 is coming!
155
+ **********************
156
+
157
+ The public API of some Rubyzip classes has been modernized to use named
158
+ parameters for optional arguments. Please check your usage of the
159
+ following classes:
160
+ * `Zip::File`
161
+ * `Zip::Entry`
162
+ * `Zip::InputStream`
163
+ * `Zip::OutputStream`
164
+
165
+ Please ensure that your Gemfiles and .gemspecs are suitably restrictive
166
+ to avoid an unexpected breakage when 3.0 is released (e.g. ~> 2.3.0).
167
+ See https://github.com/rubyzip/rubyzip for details. The Changelog also
168
+ lists other enhancements and bugfixes that have been implemented since
169
+ version 2.3.0.
208
170
  rdoc_options: []
209
171
  require_paths:
210
172
  - lib
@@ -212,68 +174,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
212
174
  requirements:
213
175
  - - ">="
214
176
  - !ruby/object:Gem::Version
215
- version: 1.9.2
177
+ version: '2.4'
216
178
  required_rubygems_version: !ruby/object:Gem::Requirement
217
179
  requirements:
218
180
  - - ">="
219
181
  - !ruby/object:Gem::Version
220
182
  version: '0'
221
183
  requirements: []
222
- rubyforge_project:
223
- rubygems_version: 2.4.5
184
+ rubygems_version: 3.1.4
224
185
  signing_key:
225
186
  specification_version: 4
226
187
  summary: rubyzip is a ruby module for reading and writing zip files
227
- test_files:
228
- - test/basic_zip_file_test.rb
229
- - test/central_directory_entry_test.rb
230
- - test/central_directory_test.rb
231
- - test/crypto/null_encryption_test.rb
232
- - test/crypto/traditional_encryption_test.rb
233
- - test/data/file1.txt
234
- - test/data/file1.txt.deflatedData
235
- - test/data/file2.txt
236
- - test/data/globTest/foo/bar/baz/foo.txt
237
- - test/data/globTest/foo.txt
238
- - test/data/globTest/food.txt
239
- - test/data/globTest.zip
240
- - test/data/mimetype
241
- - test/data/notzippedruby.rb
242
- - test/data/ntfs.zip
243
- - test/data/rubycode.zip
244
- - test/data/rubycode2.zip
245
- - test/data/testDirectory.bin
246
- - test/data/WarnInvalidDate.zip
247
- - test/data/zip64-sample.zip
248
- - test/data/zipWithDirs.zip
249
- - test/data/zipWithEncryption.zip
250
- - test/deflater_test.rb
251
- - test/encryption_test.rb
252
- - test/entry_set_test.rb
253
- - test/entry_test.rb
254
- - test/errors_test.rb
255
- - test/extra_field_test.rb
256
- - test/file_extract_directory_test.rb
257
- - test/file_extract_test.rb
258
- - test/file_split_test.rb
259
- - test/file_test.rb
260
- - test/filesystem/dir_iterator_test.rb
261
- - test/filesystem/directory_test.rb
262
- - test/filesystem/file_mutating_test.rb
263
- - test/filesystem/file_nonmutating_test.rb
264
- - test/filesystem/file_stat_test.rb
265
- - test/gentestfiles.rb
266
- - test/inflater_test.rb
267
- - test/input_stream_test.rb
268
- - test/ioextras/abstract_input_stream_test.rb
269
- - test/ioextras/abstract_output_stream_test.rb
270
- - test/ioextras/fake_io_test.rb
271
- - test/local_entry_test.rb
272
- - test/output_stream_test.rb
273
- - test/pass_thru_compressor_test.rb
274
- - test/pass_thru_decompressor_test.rb
275
- - test/settings_test.rb
276
- - test/test_helper.rb
277
- - test/unicode_file_names_and_comments_test.rb
278
- - test/zip64_full_test.rb
279
- - test/zip64_support_test.rb
188
+ test_files: []
@@ -1,86 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- $: << "../lib"
4
-
5
- $VERBOSE = true
6
-
7
- require 'gtk'
8
- require 'zip'
9
-
10
- class MainApp < Gtk::Window
11
- def initialize
12
- super()
13
- set_usize(400, 256)
14
- set_title("rubyzip")
15
- signal_connect(Gtk::Window::SIGNAL_DESTROY) { Gtk.main_quit }
16
-
17
- box = Gtk::VBox.new(false, 0)
18
- add(box)
19
-
20
- @zipfile = nil
21
- @buttonPanel = ButtonPanel.new
22
- @buttonPanel.openButton.signal_connect(Gtk::Button::SIGNAL_CLICKED) {
23
- show_file_selector
24
- }
25
- @buttonPanel.extractButton.signal_connect(Gtk::Button::SIGNAL_CLICKED) {
26
- puts "Not implemented!"
27
- }
28
- box.pack_start(@buttonPanel, false, false, 0)
29
-
30
- sw = Gtk::ScrolledWindow.new
31
- sw.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC)
32
- box.pack_start(sw, true, true, 0)
33
-
34
- @clist = Gtk::CList.new(["Name", "Size", "Compression"])
35
- @clist.set_selection_mode(Gtk::SELECTION_BROWSE)
36
- @clist.set_column_width(0, 120)
37
- @clist.set_column_width(1, 120)
38
- @clist.signal_connect(Gtk::CList::SIGNAL_SELECT_ROW) {
39
- |w, row, column, event|
40
- @selected_row = row
41
- }
42
- sw.add(@clist)
43
- end
44
-
45
- class ButtonPanel < Gtk::HButtonBox
46
- attr_reader :openButton, :extractButton
47
- def initialize
48
- super
49
- set_layout(Gtk::BUTTONBOX_START)
50
- set_spacing(0)
51
- @openButton = Gtk::Button.new("Open archive")
52
- @extractButton = Gtk::Button.new("Extract entry")
53
- pack_start(@openButton)
54
- pack_start(@extractButton)
55
- end
56
- end
57
-
58
- def show_file_selector
59
- @fileSelector = Gtk::FileSelection.new("Open zip file")
60
- @fileSelector.show
61
- @fileSelector.ok_button.signal_connect(Gtk::Button::SIGNAL_CLICKED) {
62
- open_zip(@fileSelector.filename)
63
- @fileSelector.destroy
64
- }
65
- @fileSelector.cancel_button.signal_connect(Gtk::Button::SIGNAL_CLICKED) {
66
- @fileSelector.destroy
67
- }
68
- end
69
-
70
- def open_zip(filename)
71
- @zipfile = Zip::File.open(filename)
72
- @clist.clear
73
- @zipfile.each {
74
- |entry|
75
- @clist.append([ entry.name,
76
- entry.size.to_s,
77
- (100.0*entry.compressedSize/entry.size).to_s+"%" ])
78
- }
79
- end
80
- end
81
-
82
- mainApp = MainApp.new()
83
-
84
- mainApp.show_all
85
-
86
- Gtk.main
@@ -1,64 +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 {
20
- |entry|
21
- assert(TestZipFile::TEST_ZIP2.entry_names.include?(entry.name))
22
- assert(!visited.include?(entry.name))
23
- visited[entry.name] = nil
24
- count = count.succ
25
- }
26
- assert_equal(TestZipFile::TEST_ZIP2.entry_names.length, count)
27
- end
28
-
29
- def test_foreach
30
- count = 0
31
- visited = {}
32
- ::Zip::File.foreach(TestZipFile::TEST_ZIP2.zip_name) {
33
- |entry|
34
- assert(TestZipFile::TEST_ZIP2.entry_names.include?(entry.name))
35
- assert(!visited.include?(entry.name))
36
- visited[entry.name] = nil
37
- count = count.succ
38
- }
39
- assert_equal(TestZipFile::TEST_ZIP2.entry_names.length, count)
40
- end
41
-
42
- def test_get_input_stream
43
- count = 0
44
- visited = {}
45
- @zip_file.each do |entry|
46
- assert_entry(entry.name, @zip_file.get_input_stream(entry), entry.name)
47
- assert(!visited.include?(entry.name))
48
- visited[entry.name] = nil
49
- count = count.succ
50
- end
51
- assert_equal(TestZipFile::TEST_ZIP2.entry_names.length, count)
52
- end
53
-
54
- def test_get_input_streamBlock
55
- fileAndEntryName = @zip_file.entries.first.name
56
- @zip_file.get_input_stream(fileAndEntryName) {
57
- |zis|
58
- assert_entryContentsForStream(fileAndEntryName,
59
- zis,
60
- fileAndEntryName)
61
- }
62
- end
63
-
64
- end
@@ -1,73 +0,0 @@
1
- require 'test_helper'
2
-
3
- class ZipCentralDirectoryEntryTest < MiniTest::Test
4
-
5
- def test_read_from_stream
6
- File.open("test/data/testDirectory.bin", "rb") {
7
- |file|
8
- entry = ::Zip::Entry.read_c_dir_entry(file)
9
-
10
- assert_equal("longAscii.txt", entry.name)
11
- assert_equal(::Zip::Entry::DEFLATED, entry.compression_method)
12
- assert_equal(106490, entry.size)
13
- assert_equal(3784, entry.compressed_size)
14
- assert_equal(0xfcd1799c, entry.crc)
15
- assert_equal("", entry.comment)
16
-
17
- entry = ::Zip::Entry.read_c_dir_entry(file)
18
- assert_equal("empty.txt", entry.name)
19
- assert_equal(::Zip::Entry::STORED, entry.compression_method)
20
- assert_equal(0, entry.size)
21
- assert_equal(0, entry.compressed_size)
22
- assert_equal(0x0, entry.crc)
23
- assert_equal("", entry.comment)
24
-
25
- entry = ::Zip::Entry.read_c_dir_entry(file)
26
- assert_equal("short.txt", entry.name)
27
- assert_equal(::Zip::Entry::STORED, entry.compression_method)
28
- assert_equal(6, entry.size)
29
- assert_equal(6, entry.compressed_size)
30
- assert_equal(0xbb76fe69, entry.crc)
31
- assert_equal("", entry.comment)
32
-
33
- entry = ::Zip::Entry.read_c_dir_entry(file)
34
- assert_equal("longBinary.bin", entry.name)
35
- assert_equal(::Zip::Entry::DEFLATED, entry.compression_method)
36
- assert_equal(1000024, entry.size)
37
- assert_equal(70847, entry.compressed_size)
38
- assert_equal(0x10da7d59, entry.crc)
39
- assert_equal('', entry.comment)
40
-
41
- entry = ::Zip::Entry.read_c_dir_entry(file)
42
- assert_equal(nil, entry)
43
- # Fields that are not check by this test:
44
- # version made by 2 bytes
45
- # version needed to extract 2 bytes
46
- # general purpose bit flag 2 bytes
47
- # last mod file time 2 bytes
48
- # last mod file date 2 bytes
49
- # compressed size 4 bytes
50
- # uncompressed size 4 bytes
51
- # disk number start 2 bytes
52
- # internal file attributes 2 bytes
53
- # external file attributes 4 bytes
54
- # relative offset of local header 4 bytes
55
-
56
- # file name (variable size)
57
- # extra field (variable size)
58
- # file comment (variable size)
59
-
60
- }
61
- end
62
-
63
- def test_ReadEntryFromTruncatedZipFile
64
- fragment=""
65
- File.open("test/data/testDirectory.bin") { |f| fragment = f.read(12) } # cdir entry header is at least 46 bytes
66
- fragment.extend(IOizeString)
67
- entry = ::Zip::Entry.new
68
- entry.read_c_dir_entry(fragment)
69
- fail "ZipError expected"
70
- rescue ::Zip::Error
71
- end
72
-
73
- end