rubyzip 1.2.0 → 2.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 +89 -43
- data/Rakefile +3 -0
- data/lib/zip.rb +14 -3
- data/lib/zip/central_directory.rb +12 -8
- data/lib/zip/compressor.rb +1 -2
- data/lib/zip/constants.rb +55 -3
- data/lib/zip/crypto/decrypted_io.rb +40 -0
- data/lib/zip/crypto/null_encryption.rb +2 -4
- data/lib/zip/crypto/traditional_encryption.rb +9 -9
- data/lib/zip/decompressor.rb +20 -2
- data/lib/zip/dos_time.rb +13 -8
- data/lib/zip/entry.rb +115 -80
- data/lib/zip/entry_set.rb +6 -4
- data/lib/zip/errors.rb +2 -0
- data/lib/zip/extra_field.rb +12 -10
- data/lib/zip/extra_field/generic.rb +10 -9
- data/lib/zip/extra_field/ntfs.rb +4 -0
- data/lib/zip/extra_field/old_unix.rb +3 -1
- data/lib/zip/extra_field/universal_time.rb +42 -12
- data/lib/zip/extra_field/unix.rb +3 -1
- data/lib/zip/extra_field/zip64.rb +4 -2
- data/lib/zip/extra_field/zip64_placeholder.rb +1 -2
- data/lib/zip/file.rb +136 -100
- data/lib/zip/filesystem.rb +199 -179
- data/lib/zip/inflater.rb +24 -36
- data/lib/zip/input_stream.rb +37 -27
- data/lib/zip/ioextras.rb +1 -1
- data/lib/zip/ioextras/abstract_input_stream.rb +20 -9
- data/lib/zip/ioextras/abstract_output_stream.rb +4 -4
- data/lib/zip/null_decompressor.rb +1 -9
- data/lib/zip/output_stream.rb +19 -10
- data/lib/zip/pass_thru_compressor.rb +2 -2
- data/lib/zip/pass_thru_decompressor.rb +14 -23
- data/lib/zip/streamable_directory.rb +3 -3
- data/lib/zip/streamable_stream.rb +6 -10
- data/lib/zip/version.rb +1 -1
- data/samples/example.rb +2 -2
- data/samples/example_filesystem.rb +1 -1
- data/samples/example_recursive.rb +15 -18
- data/samples/gtk_ruby_zip.rb +20 -20
- data/samples/qtzip.rb +7 -7
- data/samples/write_simple.rb +2 -4
- data/samples/zipfind.rb +23 -22
- metadata +41 -130
- 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 -53
- 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/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/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 -152
- data/test/entry_test.rb +0 -163
- data/test/errors_test.rb +0 -34
- 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 -69
- data/test/file_split_test.rb +0 -57
- data/test/file_test.rb +0 -563
- data/test/filesystem/dir_iterator_test.rb +0 -58
- data/test/filesystem/directory_test.rb +0 -121
- data/test/filesystem/file_mutating_test.rb +0 -88
- data/test/filesystem/file_nonmutating_test.rb +0 -508
- data/test/filesystem/file_stat_test.rb +0 -64
- data/test/gentestfiles.rb +0 -122
- 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/samples/example_recursive_test.rb +0 -37
- data/test/settings_test.rb +0 -95
- data/test/test_helper.rb +0 -221
- data/test/unicode_file_names_and_comments_test.rb +0 -50
- data/test/zip64_full_test.rb +0 -51
- data/test/zip64_support_test.rb +0 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8ffab0e42187d7bbd5b732ff0b9395a6215587a18ce5dd9d64da46d1c628a69c
|
4
|
+
data.tar.gz: 3032ae5d4f62644c1a19d5de25d515844ecb8da0f59c774fcaa6b16904f496b7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 218f77b0c4ae423f2baed702bf56bb598e2c3d22a01fc9af8c2fa33432580e2706a820474fa1222480370517a9f28bda692a2f296d89620459d9c6239fcfff37
|
7
|
+
data.tar.gz: a4ffa820bb2272b07bd918827d03751261f87d694966ef6c88f74f4ec569c94b0420c9288a92e5370653d00790478bdd85d3e89a9ef42ccd94834facb622c336
|
data/README.md
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# rubyzip
|
2
|
+
|
2
3
|
[![Gem Version](https://badge.fury.io/rb/rubyzip.svg)](http://badge.fury.io/rb/rubyzip)
|
3
4
|
[![Build Status](https://secure.travis-ci.org/rubyzip/rubyzip.svg)](http://travis-ci.org/rubyzip/rubyzip)
|
4
5
|
[![Code Climate](https://codeclimate.com/github/rubyzip/rubyzip.svg)](https://codeclimate.com/github/rubyzip/rubyzip)
|
@@ -19,9 +20,10 @@ gem 'zip-zip' # will load compatibility for old rubyzip API.
|
|
19
20
|
|
20
21
|
## Requirements
|
21
22
|
|
22
|
-
|
23
|
+
- Ruby 2.4 or greater (for rubyzip 2.0; use 1.x for older rubies)
|
23
24
|
|
24
25
|
## Installation
|
26
|
+
|
25
27
|
Rubyzip is available on RubyGems:
|
26
28
|
|
27
29
|
```
|
@@ -52,30 +54,29 @@ Zip::File.open(zipfile_name, Zip::File::CREATE) do |zipfile|
|
|
52
54
|
# Two arguments:
|
53
55
|
# - The name of the file as it will appear in the archive
|
54
56
|
# - The original file, including the path to find it
|
55
|
-
zipfile.add(filename, folder
|
57
|
+
zipfile.add(filename, File.join(folder, filename))
|
56
58
|
end
|
57
|
-
zipfile.get_output_stream("myFile") { |
|
59
|
+
zipfile.get_output_stream("myFile") { |f| f.write "myFile contains just this" }
|
58
60
|
end
|
59
61
|
```
|
60
62
|
|
61
63
|
### Zipping a directory recursively
|
62
|
-
|
64
|
+
|
65
|
+
Copy from [here](https://github.com/rubyzip/rubyzip/blob/9d891f7353e66052283562d3e252fe380bb4b199/samples/example_recursive.rb)
|
63
66
|
|
64
67
|
```ruby
|
65
|
-
require 'rubygems'
|
66
68
|
require 'zip'
|
69
|
+
|
67
70
|
# This is a simple example which uses rubyzip to
|
68
71
|
# recursively generate a zip file from the contents of
|
69
72
|
# a specified directory. The directory itself is not
|
70
73
|
# included in the archive, rather just its contents.
|
71
74
|
#
|
72
75
|
# Usage:
|
73
|
-
#
|
74
|
-
#
|
75
|
-
#
|
76
|
-
#
|
77
|
-
# zf.write()
|
78
|
-
|
76
|
+
# directory_to_zip = "/tmp/input"
|
77
|
+
# output_file = "/tmp/out.zip"
|
78
|
+
# zf = ZipFileGenerator.new(directory_to_zip, output_file)
|
79
|
+
# zf.write()
|
79
80
|
class ZipFileGenerator
|
80
81
|
# Initialize with the directory to zip and the location of the output archive.
|
81
82
|
def initialize(input_dir, output_file)
|
@@ -85,40 +86,37 @@ class ZipFileGenerator
|
|
85
86
|
|
86
87
|
# Zip the input directory.
|
87
88
|
def write
|
88
|
-
entries = Dir.entries(@input_dir) - %w
|
89
|
+
entries = Dir.entries(@input_dir) - %w[. ..]
|
89
90
|
|
90
|
-
::Zip::File.open(@output_file, ::Zip::File::CREATE) do |
|
91
|
-
write_entries entries, '',
|
91
|
+
::Zip::File.open(@output_file, ::Zip::File::CREATE) do |zipfile|
|
92
|
+
write_entries entries, '', zipfile
|
92
93
|
end
|
93
94
|
end
|
94
95
|
|
95
96
|
private
|
96
97
|
|
97
98
|
# A helper method to make the recursion work.
|
98
|
-
def write_entries(entries, path,
|
99
|
+
def write_entries(entries, path, zipfile)
|
99
100
|
entries.each do |e|
|
100
|
-
|
101
|
-
disk_file_path = File.join(@input_dir,
|
102
|
-
puts "Deflating #{disk_file_path}"
|
101
|
+
zipfile_path = path == '' ? e : File.join(path, e)
|
102
|
+
disk_file_path = File.join(@input_dir, zipfile_path)
|
103
103
|
|
104
104
|
if File.directory? disk_file_path
|
105
|
-
recursively_deflate_directory(disk_file_path,
|
105
|
+
recursively_deflate_directory(disk_file_path, zipfile, zipfile_path)
|
106
106
|
else
|
107
|
-
put_into_archive(disk_file_path,
|
107
|
+
put_into_archive(disk_file_path, zipfile, zipfile_path)
|
108
108
|
end
|
109
109
|
end
|
110
110
|
end
|
111
111
|
|
112
|
-
def recursively_deflate_directory(disk_file_path,
|
113
|
-
|
114
|
-
subdir = Dir.entries(disk_file_path) - %w
|
115
|
-
write_entries subdir,
|
112
|
+
def recursively_deflate_directory(disk_file_path, zipfile, zipfile_path)
|
113
|
+
zipfile.mkdir zipfile_path
|
114
|
+
subdir = Dir.entries(disk_file_path) - %w[. ..]
|
115
|
+
write_entries subdir, zipfile_path, zipfile
|
116
116
|
end
|
117
117
|
|
118
|
-
def put_into_archive(disk_file_path,
|
119
|
-
|
120
|
-
f.puts(File.open(disk_file_path, 'rb').read)
|
121
|
-
end
|
118
|
+
def put_into_archive(disk_file_path, zipfile, zipfile_path)
|
119
|
+
zipfile.add(zipfile_path, disk_file_path)
|
122
120
|
end
|
123
121
|
end
|
124
122
|
```
|
@@ -154,12 +152,15 @@ When modifying a zip archive the file permissions of the archive are preserved.
|
|
154
152
|
### Reading a Zip file
|
155
153
|
|
156
154
|
```ruby
|
155
|
+
MAX_SIZE = 1024**2 # 1MiB (but of course you can increase this)
|
157
156
|
Zip::File.open('foo.zip') do |zip_file|
|
158
157
|
# Handle entries one by one
|
159
158
|
zip_file.each do |entry|
|
160
|
-
# Extract to file/directory/symlink
|
161
159
|
puts "Extracting #{entry.name}"
|
162
|
-
entry.
|
160
|
+
raise 'File too large when extracted' if entry.size > MAX_SIZE
|
161
|
+
|
162
|
+
# Extract to file or directory based on name in the archive
|
163
|
+
entry.extract
|
163
164
|
|
164
165
|
# Read into memory
|
165
166
|
content = entry.get_input_stream.read
|
@@ -167,6 +168,7 @@ Zip::File.open('foo.zip') do |zip_file|
|
|
167
168
|
|
168
169
|
# Find specific entry
|
169
170
|
entry = zip_file.glob('*.csv').first
|
171
|
+
raise 'File too large when extracted' if entry.size > MAX_SIZE
|
170
172
|
puts entry.get_input_stream.read
|
171
173
|
end
|
172
174
|
```
|
@@ -177,9 +179,7 @@ end
|
|
177
179
|
|
178
180
|
But there is one exception when it is not working - General Purpose Flag Bit 3.
|
179
181
|
|
180
|
-
|
181
|
-
If bit 3 (0x08) of the general-purpose flags field is set, then the CRC-32 and file sizes are not known when the header is written. The fields in the local header are filled with zero, and the CRC-32 and size are appended in a 12-byte structure (optionally preceded by a 4-byte signature) immediately after the compressed data
|
182
|
-
```
|
182
|
+
> If bit 3 (0x08) of the general-purpose flags field is set, then the CRC-32 and file sizes are not known when the header is written. The fields in the local header are filled with zero, and the CRC-32 and size are appended in a 12-byte structure (optionally preceded by a 4-byte signature) immediately after the compressed data
|
183
183
|
|
184
184
|
If `::Zip::InputStream` finds such entry in the zip archive it will raise an exception.
|
185
185
|
|
@@ -218,12 +218,14 @@ buffer = Zip::OutputStream.write_buffer do |out|
|
|
218
218
|
out.write rels.to_xml(:indent => 0).gsub("\n","")
|
219
219
|
end
|
220
220
|
|
221
|
-
File.open(new_path, "
|
221
|
+
File.open(new_path, "wb") {|f| f.write(buffer.string) }
|
222
222
|
```
|
223
223
|
|
224
224
|
## Configuration
|
225
225
|
|
226
|
-
|
226
|
+
### Existing Files
|
227
|
+
|
228
|
+
By default, rubyzip will not overwrite files if they already exist inside of the extracted path. To change this behavior, you may specify a configuration option like so:
|
227
229
|
|
228
230
|
```ruby
|
229
231
|
Zip.on_exists_proc = true
|
@@ -237,25 +239,77 @@ Additionally, if you want to configure rubyzip to overwrite existing files while
|
|
237
239
|
Zip.continue_on_exists_proc = true
|
238
240
|
```
|
239
241
|
|
242
|
+
### Non-ASCII Names
|
243
|
+
|
240
244
|
If you want to store non-english names and want to open them on Windows(pre 7) you need to set this option:
|
241
245
|
|
242
246
|
```ruby
|
243
247
|
Zip.unicode_names = true
|
244
248
|
```
|
245
249
|
|
250
|
+
Sometimes file names inside zip contain non-ASCII characters. If you can assume which encoding was used for such names and want to be able to find such entries using `find_entry` then you can force assumed encoding like so:
|
251
|
+
|
252
|
+
```ruby
|
253
|
+
Zip.force_entry_names_encoding = 'UTF-8'
|
254
|
+
```
|
255
|
+
|
256
|
+
Allowed encoding names are the same as accepted by `String#force_encoding`
|
257
|
+
|
258
|
+
### Date Validation
|
259
|
+
|
246
260
|
Some zip files might have an invalid date format, which will raise a warning. You can hide this warning with the following setting:
|
247
261
|
|
248
262
|
```ruby
|
249
263
|
Zip.warn_invalid_date = false
|
250
264
|
```
|
251
265
|
|
266
|
+
### Size Validation
|
267
|
+
|
268
|
+
By default (in rubyzip >= 2.0), rubyzip's `extract` method checks that an entry's reported uncompressed size is not (significantly) smaller than its actual size. This is to help you protect your application against [zip bombs](https://en.wikipedia.org/wiki/Zip_bomb). Before `extract`ing an entry, you should check that its size is in the range you expect. For example, if your application supports processing up to 100 files at once, each up to 10MiB, your zip extraction code might look like:
|
269
|
+
|
270
|
+
```ruby
|
271
|
+
MAX_FILE_SIZE = 10 * 1024**2 # 10MiB
|
272
|
+
MAX_FILES = 100
|
273
|
+
Zip::File.open('foo.zip') do |zip_file|
|
274
|
+
num_files = 0
|
275
|
+
zip_file.each do |entry|
|
276
|
+
num_files += 1 if entry.file?
|
277
|
+
raise 'Too many extracted files' if num_files > MAX_FILES
|
278
|
+
raise 'File too large when extracted' if entry.size > MAX_FILE_SIZE
|
279
|
+
entry.extract
|
280
|
+
end
|
281
|
+
end
|
282
|
+
```
|
283
|
+
|
284
|
+
If you need to extract zip files that report incorrect uncompressed sizes and you really trust them not too be too large, you can disable this setting with
|
285
|
+
```ruby
|
286
|
+
Zip.validate_entry_sizes = false
|
287
|
+
```
|
288
|
+
|
289
|
+
Note that if you use the lower level `Zip::InputStream` interface, `rubyzip` does *not* check the entry `size`s. In this case, the caller is responsible for making sure it does not read more data than expected from the input stream.
|
290
|
+
|
291
|
+
### Default Compression
|
292
|
+
|
252
293
|
You can set the default compression level like so:
|
253
294
|
|
254
295
|
```ruby
|
255
296
|
Zip.default_compression = Zlib::DEFAULT_COMPRESSION
|
256
297
|
```
|
298
|
+
|
257
299
|
It defaults to `Zlib::DEFAULT_COMPRESSION`. Possible values are `Zlib::BEST_COMPRESSION`, `Zlib::DEFAULT_COMPRESSION` and `Zlib::NO_COMPRESSION`
|
258
300
|
|
301
|
+
### Zip64 Support
|
302
|
+
|
303
|
+
By default, Zip64 support is disabled for writing. To enable it do this:
|
304
|
+
|
305
|
+
```ruby
|
306
|
+
Zip.write_zip64_support = true
|
307
|
+
```
|
308
|
+
|
309
|
+
_NOTE_: If you will enable Zip64 writing then you will need zip extractor with Zip64 support to extract archive.
|
310
|
+
|
311
|
+
### Block Form
|
312
|
+
|
259
313
|
You can set multiple settings at the same time by using a block:
|
260
314
|
|
261
315
|
```ruby
|
@@ -267,14 +321,6 @@ You can set multiple settings at the same time by using a block:
|
|
267
321
|
end
|
268
322
|
```
|
269
323
|
|
270
|
-
By default, Zip64 support is disabled for writing. To enable it do this:
|
271
|
-
|
272
|
-
```ruby
|
273
|
-
Zip.write_zip64_support = true
|
274
|
-
```
|
275
|
-
|
276
|
-
_NOTE_: If you will enable Zip64 writing then you will need zip extractor with Zip64 support to extract archive.
|
277
|
-
|
278
324
|
## Developing
|
279
325
|
|
280
326
|
To run the test you need to do this:
|
data/Rakefile
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'bundler/gem_tasks'
|
2
2
|
require 'rake/testtask'
|
3
|
+
require 'rubocop/rake_task'
|
3
4
|
|
4
5
|
task default: :test
|
5
6
|
|
@@ -10,6 +11,8 @@ Rake::TestTask.new(:test) do |test|
|
|
10
11
|
test.verbose = true
|
11
12
|
end
|
12
13
|
|
14
|
+
RuboCop::RakeTask.new
|
15
|
+
|
13
16
|
# Rake::TestTask.new(:zip64_full_test) do |test|
|
14
17
|
# test.libs << File.join(File.dirname(__FILE__), 'lib')
|
15
18
|
# test.libs << File.join(File.dirname(__FILE__), 'test')
|
data/lib/zip.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
|
+
require 'English'
|
1
2
|
require 'delegate'
|
2
3
|
require 'singleton'
|
3
4
|
require 'tempfile'
|
4
|
-
require 'tmpdir'
|
5
5
|
require 'fileutils'
|
6
6
|
require 'stringio'
|
7
7
|
require 'zlib'
|
8
|
+
require 'zip/constants'
|
8
9
|
require 'zip/dos_time'
|
9
10
|
require 'zip/ioextras'
|
10
11
|
require 'rbconfig'
|
@@ -22,6 +23,7 @@ require 'zip/null_compressor'
|
|
22
23
|
require 'zip/null_input_stream'
|
23
24
|
require 'zip/pass_thru_compressor'
|
24
25
|
require 'zip/pass_thru_decompressor'
|
26
|
+
require 'zip/crypto/decrypted_io'
|
25
27
|
require 'zip/crypto/encryption'
|
26
28
|
require 'zip/crypto/null_encryption'
|
27
29
|
require 'zip/crypto/traditional_encryption'
|
@@ -29,12 +31,20 @@ require 'zip/inflater'
|
|
29
31
|
require 'zip/deflater'
|
30
32
|
require 'zip/streamable_stream'
|
31
33
|
require 'zip/streamable_directory'
|
32
|
-
require 'zip/constants'
|
33
34
|
require 'zip/errors'
|
34
35
|
|
35
36
|
module Zip
|
36
37
|
extend self
|
37
|
-
attr_accessor :unicode_names,
|
38
|
+
attr_accessor :unicode_names,
|
39
|
+
:on_exists_proc,
|
40
|
+
:continue_on_exists_proc,
|
41
|
+
:sort_entries,
|
42
|
+
:default_compression,
|
43
|
+
:write_zip64_support,
|
44
|
+
:warn_invalid_date,
|
45
|
+
:case_insensitive_match,
|
46
|
+
:force_entry_names_encoding,
|
47
|
+
:validate_entry_sizes
|
38
48
|
|
39
49
|
def reset!
|
40
50
|
@_ran_once = false
|
@@ -46,6 +56,7 @@ module Zip
|
|
46
56
|
@write_zip64_support = false
|
47
57
|
@warn_invalid_date = true
|
48
58
|
@case_insensitive_match = false
|
59
|
+
@validate_entry_sizes = true
|
49
60
|
end
|
50
61
|
|
51
62
|
def setup
|
@@ -65,7 +65,7 @@ module Zip
|
|
65
65
|
@entry_set ? @entry_set.size : 0, # number of entries on this disk
|
66
66
|
@entry_set ? @entry_set.size : 0, # number of entries total
|
67
67
|
cdir_size, # size of central directory
|
68
|
-
offset
|
68
|
+
offset # offset of start of central directory in its disk
|
69
69
|
]
|
70
70
|
io << tmp.pack('VQ<vvVVQ<Q<Q<Q<')
|
71
71
|
end
|
@@ -96,7 +96,7 @@ module Zip
|
|
96
96
|
@size_in_bytes = Entry.read_zip_64_long(buf)
|
97
97
|
@cdir_offset = Entry.read_zip_64_long(buf)
|
98
98
|
@zip_64_extensible = buf.slice!(0, buf.bytesize)
|
99
|
-
raise Error, 'Zip consistency problem while reading eocd structure' unless buf.
|
99
|
+
raise Error, 'Zip consistency problem while reading eocd structure' unless buf.empty?
|
100
100
|
end
|
101
101
|
|
102
102
|
def read_e_o_c_d(buf) #:nodoc:
|
@@ -113,7 +113,7 @@ module Zip
|
|
113
113
|
else
|
114
114
|
buf.read(comment_length)
|
115
115
|
end
|
116
|
-
raise Error, 'Zip consistency problem while reading eocd structure' unless buf.
|
116
|
+
raise Error, 'Zip consistency problem while reading eocd structure' unless buf.empty?
|
117
117
|
end
|
118
118
|
|
119
119
|
def read_central_directory_entries(io) #:nodoc:
|
@@ -130,7 +130,7 @@ module Zip
|
|
130
130
|
|
131
131
|
def read_from_stream(io) #:nodoc:
|
132
132
|
buf = start_buf(io)
|
133
|
-
if
|
133
|
+
if zip64_file?(buf)
|
134
134
|
read_64_e_o_c_d(buf)
|
135
135
|
else
|
136
136
|
read_e_o_c_d(buf)
|
@@ -141,6 +141,7 @@ module Zip
|
|
141
141
|
def get_e_o_c_d(buf) #:nodoc:
|
142
142
|
sig_index = buf.rindex([END_OF_CDS].pack('V'))
|
143
143
|
raise Error, 'Zip end of central directory signature not found' unless sig_index
|
144
|
+
|
144
145
|
buf = buf.slice!((sig_index + 4)..(buf.bytesize))
|
145
146
|
|
146
147
|
def buf.read(count)
|
@@ -166,8 +167,10 @@ module Zip
|
|
166
167
|
def get_64_e_o_c_d(buf) #:nodoc:
|
167
168
|
zip_64_start = buf.rindex([ZIP64_END_OF_CDS].pack('V'))
|
168
169
|
raise Error, 'Zip64 end of central directory signature not found' unless zip_64_start
|
170
|
+
|
169
171
|
zip_64_locator = buf.rindex([ZIP64_EOCD_LOCATOR].pack('V'))
|
170
172
|
raise Error, 'Zip64 end of central directory signature locator not found' unless zip_64_locator
|
173
|
+
|
171
174
|
buf = buf.slice!((zip_64_start + 4)..zip_64_locator)
|
172
175
|
|
173
176
|
def buf.read(count)
|
@@ -178,8 +181,8 @@ module Zip
|
|
178
181
|
end
|
179
182
|
|
180
183
|
# For iterating over the entries.
|
181
|
-
def each(&
|
182
|
-
@entry_set.each(&
|
184
|
+
def each(&a_proc)
|
185
|
+
@entry_set.each(&a_proc)
|
183
186
|
end
|
184
187
|
|
185
188
|
# Returns the number of entries in the central directory (and
|
@@ -191,13 +194,14 @@ module Zip
|
|
191
194
|
def self.read_from_stream(io) #:nodoc:
|
192
195
|
cdir = new
|
193
196
|
cdir.read_from_stream(io)
|
194
|
-
|
197
|
+
cdir
|
195
198
|
rescue Error
|
196
|
-
|
199
|
+
nil
|
197
200
|
end
|
198
201
|
|
199
202
|
def ==(other) #:nodoc:
|
200
203
|
return false unless other.kind_of?(CentralDirectory)
|
204
|
+
|
201
205
|
@entry_set.entries.sort == other.entries.sort && comment == other.comment
|
202
206
|
end
|
203
207
|
end
|
data/lib/zip/compressor.rb
CHANGED
data/lib/zip/constants.rb
CHANGED
@@ -11,9 +11,9 @@ module Zip
|
|
11
11
|
VERSION_NEEDED_TO_EXTRACT = 20
|
12
12
|
VERSION_NEEDED_TO_EXTRACT_ZIP64 = 45
|
13
13
|
|
14
|
-
FILE_TYPE_FILE =
|
15
|
-
FILE_TYPE_DIR =
|
16
|
-
FILE_TYPE_SYMLINK =
|
14
|
+
FILE_TYPE_FILE = 0o10
|
15
|
+
FILE_TYPE_DIR = 0o04
|
16
|
+
FILE_TYPE_SYMLINK = 0o12
|
17
17
|
|
18
18
|
FSTYPE_FAT = 0
|
19
19
|
FSTYPE_AMIGA = 1
|
@@ -60,4 +60,56 @@ module Zip
|
|
60
60
|
FSTYPE_MAC_OSX => 'Mac OS/X (Darwin)'.freeze,
|
61
61
|
FSTYPE_ATHEOS => 'AtheOS'.freeze
|
62
62
|
}.freeze
|
63
|
+
|
64
|
+
COMPRESSION_METHOD_STORE = 0
|
65
|
+
COMPRESSION_METHOD_SHRINK = 1
|
66
|
+
COMPRESSION_METHOD_REDUCE_1 = 2
|
67
|
+
COMPRESSION_METHOD_REDUCE_2 = 3
|
68
|
+
COMPRESSION_METHOD_REDUCE_3 = 4
|
69
|
+
COMPRESSION_METHOD_REDUCE_4 = 5
|
70
|
+
COMPRESSION_METHOD_IMPLODE = 6
|
71
|
+
# RESERVED = 7
|
72
|
+
COMPRESSION_METHOD_DEFLATE = 8
|
73
|
+
COMPRESSION_METHOD_DEFLATE_64 = 9
|
74
|
+
COMPRESSION_METHOD_PKWARE_DCLI = 10
|
75
|
+
# RESERVED = 11
|
76
|
+
COMPRESSION_METHOD_BZIP2 = 12
|
77
|
+
# RESERVED = 13
|
78
|
+
COMPRESSION_METHOD_LZMA = 14
|
79
|
+
# RESERVED = 15
|
80
|
+
COMPRESSION_METHOD_IBM_CMPSC = 16
|
81
|
+
# RESERVED = 17
|
82
|
+
COMPRESSION_METHOD_IBM_TERSE = 18
|
83
|
+
COMPRESSION_METHOD_IBM_LZ77 = 19
|
84
|
+
COMPRESSION_METHOD_JPEG = 96
|
85
|
+
COMPRESSION_METHOD_WAVPACK = 97
|
86
|
+
COMPRESSION_METHOD_PPMD = 98
|
87
|
+
COMPRESSION_METHOD_AES = 99
|
88
|
+
|
89
|
+
COMPRESSION_METHODS = {
|
90
|
+
COMPRESSION_METHOD_STORE => 'Store (no compression)',
|
91
|
+
COMPRESSION_METHOD_SHRINK => 'Shrink',
|
92
|
+
COMPRESSION_METHOD_REDUCE_1 => 'Reduce with compression factor 1',
|
93
|
+
COMPRESSION_METHOD_REDUCE_2 => 'Reduce with compression factor 2',
|
94
|
+
COMPRESSION_METHOD_REDUCE_3 => 'Reduce with compression factor 3',
|
95
|
+
COMPRESSION_METHOD_REDUCE_4 => 'Reduce with compression factor 4',
|
96
|
+
COMPRESSION_METHOD_IMPLODE => 'Implode',
|
97
|
+
# RESERVED = 7
|
98
|
+
COMPRESSION_METHOD_DEFLATE => 'Deflate',
|
99
|
+
COMPRESSION_METHOD_DEFLATE_64 => 'Deflate64(tm)',
|
100
|
+
COMPRESSION_METHOD_PKWARE_DCLI => 'PKWARE Data Compression Library Imploding (old IBM TERSE)',
|
101
|
+
# RESERVED = 11
|
102
|
+
COMPRESSION_METHOD_BZIP2 => 'BZIP2',
|
103
|
+
# RESERVED = 13
|
104
|
+
COMPRESSION_METHOD_LZMA => 'LZMA',
|
105
|
+
# RESERVED = 15
|
106
|
+
COMPRESSION_METHOD_IBM_CMPSC => 'IBM z/OS CMPSC Compression',
|
107
|
+
# RESERVED = 17
|
108
|
+
COMPRESSION_METHOD_IBM_TERSE => 'IBM TERSE (new)',
|
109
|
+
COMPRESSION_METHOD_IBM_LZ77 => 'IBM LZ77 z Architecture (PFS)',
|
110
|
+
COMPRESSION_METHOD_JPEG => 'JPEG variant',
|
111
|
+
COMPRESSION_METHOD_WAVPACK => 'WavPack compressed data',
|
112
|
+
COMPRESSION_METHOD_PPMD => 'PPMd version I, Rev 1',
|
113
|
+
COMPRESSION_METHOD_AES => 'AES encryption'
|
114
|
+
}.freeze
|
63
115
|
end
|