rubyzip 1.2.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +83 -35
  3. data/lib/zip.rb +11 -1
  4. data/lib/zip/central_directory.rb +3 -3
  5. data/lib/zip/compressor.rb +1 -2
  6. data/lib/zip/constants.rb +3 -3
  7. data/lib/zip/crypto/null_encryption.rb +2 -4
  8. data/lib/zip/decompressor.rb +1 -1
  9. data/lib/zip/dos_time.rb +1 -1
  10. data/lib/zip/entry.rb +67 -57
  11. data/lib/zip/entry_set.rb +3 -3
  12. data/lib/zip/errors.rb +1 -0
  13. data/lib/zip/extra_field.rb +2 -2
  14. data/lib/zip/extra_field/generic.rb +1 -1
  15. data/lib/zip/extra_field/zip64_placeholder.rb +1 -2
  16. data/lib/zip/file.rb +47 -27
  17. data/lib/zip/filesystem.rb +17 -13
  18. data/lib/zip/inflater.rb +2 -2
  19. data/lib/zip/input_stream.rb +10 -7
  20. data/lib/zip/ioextras/abstract_input_stream.rb +1 -1
  21. data/lib/zip/ioextras/abstract_output_stream.rb +1 -1
  22. data/lib/zip/output_stream.rb +5 -5
  23. data/lib/zip/pass_thru_decompressor.rb +1 -1
  24. data/lib/zip/streamable_stream.rb +1 -1
  25. data/lib/zip/version.rb +1 -1
  26. data/samples/example_recursive.rb +14 -15
  27. data/samples/gtk_ruby_zip.rb +1 -1
  28. data/samples/qtzip.rb +1 -1
  29. data/samples/zipfind.rb +2 -2
  30. metadata +25 -121
  31. data/test/basic_zip_file_test.rb +0 -60
  32. data/test/case_sensitivity_test.rb +0 -69
  33. data/test/central_directory_entry_test.rb +0 -69
  34. data/test/central_directory_test.rb +0 -100
  35. data/test/crypto/null_encryption_test.rb +0 -57
  36. data/test/crypto/traditional_encryption_test.rb +0 -80
  37. data/test/data/WarnInvalidDate.zip +0 -0
  38. data/test/data/file1.txt +0 -46
  39. data/test/data/file1.txt.deflatedData +0 -0
  40. data/test/data/file2.txt +0 -1504
  41. data/test/data/globTest.zip +0 -0
  42. data/test/data/globTest/foo.txt +0 -0
  43. data/test/data/globTest/foo/bar/baz/foo.txt +0 -0
  44. data/test/data/globTest/food.txt +0 -0
  45. data/test/data/mimetype +0 -1
  46. data/test/data/notzippedruby.rb +0 -7
  47. data/test/data/ntfs.zip +0 -0
  48. data/test/data/oddExtraField.zip +0 -0
  49. data/test/data/rubycode.zip +0 -0
  50. data/test/data/rubycode2.zip +0 -0
  51. data/test/data/test.xls +0 -0
  52. data/test/data/testDirectory.bin +0 -0
  53. data/test/data/zip64-sample.zip +0 -0
  54. data/test/data/zipWithDirs.zip +0 -0
  55. data/test/data/zipWithEncryption.zip +0 -0
  56. data/test/deflater_test.rb +0 -65
  57. data/test/encryption_test.rb +0 -42
  58. data/test/entry_set_test.rb +0 -163
  59. data/test/entry_test.rb +0 -154
  60. data/test/errors_test.rb +0 -34
  61. data/test/extra_field_test.rb +0 -76
  62. data/test/file_extract_directory_test.rb +0 -54
  63. data/test/file_extract_test.rb +0 -83
  64. data/test/file_permissions_test.rb +0 -69
  65. data/test/file_split_test.rb +0 -57
  66. data/test/file_test.rb +0 -583
  67. data/test/filesystem/dir_iterator_test.rb +0 -58
  68. data/test/filesystem/directory_test.rb +0 -121
  69. data/test/filesystem/file_mutating_test.rb +0 -88
  70. data/test/filesystem/file_nonmutating_test.rb +0 -508
  71. data/test/filesystem/file_stat_test.rb +0 -64
  72. data/test/gentestfiles.rb +0 -126
  73. data/test/inflater_test.rb +0 -14
  74. data/test/input_stream_test.rb +0 -182
  75. data/test/ioextras/abstract_input_stream_test.rb +0 -102
  76. data/test/ioextras/abstract_output_stream_test.rb +0 -106
  77. data/test/ioextras/fake_io_test.rb +0 -18
  78. data/test/local_entry_test.rb +0 -154
  79. data/test/output_stream_test.rb +0 -128
  80. data/test/pass_thru_compressor_test.rb +0 -30
  81. data/test/pass_thru_decompressor_test.rb +0 -14
  82. data/test/samples/example_recursive_test.rb +0 -37
  83. data/test/settings_test.rb +0 -95
  84. data/test/test_helper.rb +0 -234
  85. data/test/unicode_file_names_and_comments_test.rb +0 -50
  86. data/test/zip64_full_test.rb +0 -51
  87. data/test/zip64_support_test.rb +0 -14
@@ -31,7 +31,7 @@ class MainApp < Gtk::Window
31
31
  sw.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC)
32
32
  box.pack_start(sw, true, true, 0)
33
33
 
34
- @clist = Gtk::CList.new(%w(Name Size Compression))
34
+ @clist = Gtk::CList.new(%w[Name Size Compression])
35
35
  @clist.set_selection_mode(Gtk::SELECTION_BROWSE)
36
36
  @clist.set_column_width(0, 120)
37
37
  @clist.set_column_width(1, 120)
@@ -65,7 +65,7 @@ class ZipDialog < ZipDialogUI
65
65
  end
66
66
  puts "selected_items.size = #{selected_items.size}"
67
67
  puts "unselected_items.size = #{unselected_items.size}"
68
- items = selected_items.size > 0 ? selected_items : unselected_items
68
+ items = !selected_items.empty? ? selected_items : unselected_items
69
69
  puts "items.size = #{items.size}"
70
70
 
71
71
  d = Qt::FileDialog.get_existing_directory(nil, self)
@@ -31,7 +31,7 @@ module Zip
31
31
  end
32
32
  end
33
33
 
34
- if __FILE__ == $0
34
+ if $0 == __FILE__
35
35
  module ZipFindConsoleRunner
36
36
  PATH_ARG_INDEX = 0
37
37
  FILENAME_PATTERN_ARG_INDEX = 1
@@ -47,7 +47,7 @@ if __FILE__ == $0
47
47
  end
48
48
 
49
49
  def self.check_args(args)
50
- if (args.size != 3)
50
+ if args.size != 3
51
51
  usage
52
52
  exit
53
53
  end
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.2.1
4
+ version: 2.0.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: 2017-02-08 00:00:00.000000000 Z
11
+ date: 2019-09-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0.7'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.49.1
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.49.1
69
83
  description:
70
84
  email:
71
85
  - alex@simonov.me
@@ -120,67 +134,15 @@ files:
120
134
  - samples/qtzip.rb
121
135
  - samples/write_simple.rb
122
136
  - samples/zipfind.rb
123
- - test/basic_zip_file_test.rb
124
- - test/case_sensitivity_test.rb
125
- - test/central_directory_entry_test.rb
126
- - test/central_directory_test.rb
127
- - test/crypto/null_encryption_test.rb
128
- - test/crypto/traditional_encryption_test.rb
129
- - test/data/WarnInvalidDate.zip
130
- - test/data/file1.txt
131
- - test/data/file1.txt.deflatedData
132
- - test/data/file2.txt
133
- - test/data/globTest.zip
134
- - test/data/globTest/foo.txt
135
- - test/data/globTest/foo/bar/baz/foo.txt
136
- - test/data/globTest/food.txt
137
- - test/data/mimetype
138
- - test/data/notzippedruby.rb
139
- - test/data/ntfs.zip
140
- - test/data/oddExtraField.zip
141
- - test/data/rubycode.zip
142
- - test/data/rubycode2.zip
143
- - test/data/test.xls
144
- - test/data/testDirectory.bin
145
- - test/data/zip64-sample.zip
146
- - test/data/zipWithDirs.zip
147
- - test/data/zipWithEncryption.zip
148
- - test/deflater_test.rb
149
- - test/encryption_test.rb
150
- - test/entry_set_test.rb
151
- - test/entry_test.rb
152
- - test/errors_test.rb
153
- - test/extra_field_test.rb
154
- - test/file_extract_directory_test.rb
155
- - test/file_extract_test.rb
156
- - test/file_permissions_test.rb
157
- - test/file_split_test.rb
158
- - test/file_test.rb
159
- - test/filesystem/dir_iterator_test.rb
160
- - test/filesystem/directory_test.rb
161
- - test/filesystem/file_mutating_test.rb
162
- - test/filesystem/file_nonmutating_test.rb
163
- - test/filesystem/file_stat_test.rb
164
- - test/gentestfiles.rb
165
- - test/inflater_test.rb
166
- - test/input_stream_test.rb
167
- - test/ioextras/abstract_input_stream_test.rb
168
- - test/ioextras/abstract_output_stream_test.rb
169
- - test/ioextras/fake_io_test.rb
170
- - test/local_entry_test.rb
171
- - test/output_stream_test.rb
172
- - test/pass_thru_compressor_test.rb
173
- - test/pass_thru_decompressor_test.rb
174
- - test/samples/example_recursive_test.rb
175
- - test/settings_test.rb
176
- - test/test_helper.rb
177
- - test/unicode_file_names_and_comments_test.rb
178
- - test/zip64_full_test.rb
179
- - test/zip64_support_test.rb
180
137
  homepage: http://github.com/rubyzip/rubyzip
181
138
  licenses:
182
139
  - BSD 2-Clause
183
- metadata: {}
140
+ metadata:
141
+ bug_tracker_uri: https://github.com/rubyzip/rubyzip/issues
142
+ changelog_uri: https://github.com/rubyzip/rubyzip/blob/v2.0.0/Changelog.md
143
+ documentation_uri: https://www.rubydoc.info/gems/rubyzip/2.0.0
144
+ source_code_uri: https://github.com/rubyzip/rubyzip/tree/v2.0.0
145
+ wiki_uri: https://github.com/rubyzip/rubyzip/wiki
184
146
  post_install_message:
185
147
  rdoc_options: []
186
148
  require_paths:
@@ -189,73 +151,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
189
151
  requirements:
190
152
  - - ">="
191
153
  - !ruby/object:Gem::Version
192
- version: 1.9.2
154
+ version: '2.4'
193
155
  required_rubygems_version: !ruby/object:Gem::Requirement
194
156
  requirements:
195
157
  - - ">="
196
158
  - !ruby/object:Gem::Version
197
159
  version: '0'
198
160
  requirements: []
199
- rubyforge_project:
200
- rubygems_version: 2.5.1
161
+ rubygems_version: 3.0.3
201
162
  signing_key:
202
163
  specification_version: 4
203
164
  summary: rubyzip is a ruby module for reading and writing zip files
204
- test_files:
205
- - test/basic_zip_file_test.rb
206
- - test/case_sensitivity_test.rb
207
- - test/central_directory_entry_test.rb
208
- - test/central_directory_test.rb
209
- - test/crypto/null_encryption_test.rb
210
- - test/crypto/traditional_encryption_test.rb
211
- - test/data/file1.txt
212
- - test/data/file1.txt.deflatedData
213
- - test/data/file2.txt
214
- - test/data/globTest/foo/bar/baz/foo.txt
215
- - test/data/globTest/foo.txt
216
- - test/data/globTest/food.txt
217
- - test/data/globTest.zip
218
- - test/data/mimetype
219
- - test/data/notzippedruby.rb
220
- - test/data/ntfs.zip
221
- - test/data/oddExtraField.zip
222
- - test/data/rubycode.zip
223
- - test/data/rubycode2.zip
224
- - test/data/test.xls
225
- - test/data/testDirectory.bin
226
- - test/data/WarnInvalidDate.zip
227
- - test/data/zip64-sample.zip
228
- - test/data/zipWithDirs.zip
229
- - test/data/zipWithEncryption.zip
230
- - test/deflater_test.rb
231
- - test/encryption_test.rb
232
- - test/entry_set_test.rb
233
- - test/entry_test.rb
234
- - test/errors_test.rb
235
- - test/extra_field_test.rb
236
- - test/file_extract_directory_test.rb
237
- - test/file_extract_test.rb
238
- - test/file_permissions_test.rb
239
- - test/file_split_test.rb
240
- - test/file_test.rb
241
- - test/filesystem/dir_iterator_test.rb
242
- - test/filesystem/directory_test.rb
243
- - test/filesystem/file_mutating_test.rb
244
- - test/filesystem/file_nonmutating_test.rb
245
- - test/filesystem/file_stat_test.rb
246
- - test/gentestfiles.rb
247
- - test/inflater_test.rb
248
- - test/input_stream_test.rb
249
- - test/ioextras/abstract_input_stream_test.rb
250
- - test/ioextras/abstract_output_stream_test.rb
251
- - test/ioextras/fake_io_test.rb
252
- - test/local_entry_test.rb
253
- - test/output_stream_test.rb
254
- - test/pass_thru_compressor_test.rb
255
- - test/pass_thru_decompressor_test.rb
256
- - test/samples/example_recursive_test.rb
257
- - test/settings_test.rb
258
- - test/test_helper.rb
259
- - test/unicode_file_names_and_comments_test.rb
260
- - test/zip64_full_test.rb
261
- - test/zip64_support_test.rb
165
+ test_files: []
@@ -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
@@ -1,100 +0,0 @@
1
- require 'test_helper'
2
-
3
- class ZipCentralDirectoryTest < MiniTest::Test
4
- def teardown
5
- ::Zip.reset!
6
- end
7
-
8
- def test_read_from_stream
9
- ::File.open(TestZipFile::TEST_ZIP2.zip_name, 'rb') do |zipFile|
10
- cdir = ::Zip::CentralDirectory.read_from_stream(zipFile)
11
-
12
- assert_equal(TestZipFile::TEST_ZIP2.entry_names.size, cdir.size)
13
- assert(cdir.entries.sort.compare_enumerables(TestZipFile::TEST_ZIP2.entry_names.sort) do |cdirEntry, testEntryName|
14
- cdirEntry.name == testEntryName
15
- end)
16
- assert_equal(TestZipFile::TEST_ZIP2.comment, cdir.comment)
17
- end
18
- end
19
-
20
- def test_read_from_invalid_stream
21
- File.open('test/data/file2.txt', 'rb') do |zipFile|
22
- cdir = ::Zip::CentralDirectory.new
23
- cdir.read_from_stream(zipFile)
24
- end
25
- fail 'ZipError expected!'
26
- rescue ::Zip::Error
27
- end
28
-
29
- def test_read_from_truncated_zip_file
30
- fragment = ''
31
- File.open('test/data/testDirectory.bin', 'rb') { |f| fragment = f.read }
32
- fragment.slice!(12) # removed part of first cdir entry. eocd structure still complete
33
- fragment.extend(IOizeString)
34
- entry = ::Zip::CentralDirectory.new
35
- entry.read_from_stream(fragment)
36
- fail 'ZipError expected'
37
- rescue ::Zip::Error
38
- end
39
-
40
- def test_write_to_stream
41
- entries = [::Zip::Entry.new('file.zip', 'flimse', 'myComment', 'somethingExtra'),
42
- ::Zip::Entry.new('file.zip', 'secondEntryName'),
43
- ::Zip::Entry.new('file.zip', 'lastEntry.txt', 'Has a comment too')]
44
- cdir = ::Zip::CentralDirectory.new(entries, 'my zip comment')
45
- File.open('test/data/generated/cdirtest.bin', 'wb') { |f| cdir.write_to_stream(f) }
46
- cdirReadback = ::Zip::CentralDirectory.new
47
- File.open('test/data/generated/cdirtest.bin', 'rb') { |f| cdirReadback.read_from_stream(f) }
48
-
49
- assert_equal(cdir.entries.sort, cdirReadback.entries.sort)
50
- end
51
-
52
- def test_write64_to_stream
53
- ::Zip.write_zip64_support = true
54
- entries = [::Zip::Entry.new('file.zip', 'file1-little', 'comment1', '', 200, 101, ::Zip::Entry::STORED, 200),
55
- ::Zip::Entry.new('file.zip', 'file2-big', 'comment2', '', 18_000_000_000, 102, ::Zip::Entry::DEFLATED, 20_000_000_000),
56
- ::Zip::Entry.new('file.zip', 'file3-alsobig', 'comment3', '', 15_000_000_000, 103, ::Zip::Entry::DEFLATED, 21_000_000_000),
57
- ::Zip::Entry.new('file.zip', 'file4-little', 'comment4', '', 100, 104, ::Zip::Entry::DEFLATED, 121)]
58
- [0, 250, 18_000_000_300, 33_000_000_350].each_with_index do |offset, index|
59
- entries[index].local_header_offset = offset
60
- end
61
- cdir = ::Zip::CentralDirectory.new(entries, 'zip comment')
62
- File.open('test/data/generated/cdir64test.bin', 'wb') { |f| cdir.write_to_stream(f) }
63
- cdirReadback = ::Zip::CentralDirectory.new
64
- File.open('test/data/generated/cdir64test.bin', 'rb') { |f| cdirReadback.read_from_stream(f) }
65
-
66
- assert_equal(cdir.entries.sort, cdirReadback.entries.sort)
67
- assert_equal(::Zip::VERSION_NEEDED_TO_EXTRACT_ZIP64, cdirReadback.instance_variable_get(:@version_needed_for_extract))
68
- end
69
-
70
- def test_equality
71
- cdir1 = ::Zip::CentralDirectory.new([::Zip::Entry.new('file.zip', 'flimse', nil,
72
- 'somethingExtra'),
73
- ::Zip::Entry.new('file.zip', 'secondEntryName'),
74
- ::Zip::Entry.new('file.zip', 'lastEntry.txt')],
75
- 'my zip comment')
76
- cdir2 = ::Zip::CentralDirectory.new([::Zip::Entry.new('file.zip', 'flimse', nil,
77
- 'somethingExtra'),
78
- ::Zip::Entry.new('file.zip', 'secondEntryName'),
79
- ::Zip::Entry.new('file.zip', 'lastEntry.txt')],
80
- 'my zip comment')
81
- cdir3 = ::Zip::CentralDirectory.new([::Zip::Entry.new('file.zip', 'flimse', nil,
82
- 'somethingExtra'),
83
- ::Zip::Entry.new('file.zip', 'secondEntryName'),
84
- ::Zip::Entry.new('file.zip', 'lastEntry.txt')],
85
- 'comment?')
86
- cdir4 = ::Zip::CentralDirectory.new([::Zip::Entry.new('file.zip', 'flimse', nil,
87
- 'somethingExtra'),
88
- ::Zip::Entry.new('file.zip', 'lastEntry.txt')],
89
- 'comment?')
90
- assert_equal(cdir1, cdir1)
91
- assert_equal(cdir1, cdir2)
92
-
93
- assert(cdir1 != cdir3)
94
- assert(cdir2 != cdir3)
95
- assert(cdir2 != cdir3)
96
- assert(cdir3 != cdir4)
97
-
98
- assert(cdir3 != 'hello')
99
- end
100
- end