rubyzip 1.3.0 → 3.4.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/Changelog.md +516 -0
- data/LICENSE.md +24 -0
- data/README.md +213 -51
- data/Rakefile +17 -12
- data/lib/rubyzip.rb +3 -0
- data/lib/zip/central_directory.rb +196 -123
- data/lib/zip/compressor.rb +3 -1
- data/lib/zip/constants.rb +81 -21
- data/lib/zip/crypto/aes_encryption.rb +120 -0
- data/lib/zip/crypto/decrypted_io.rb +46 -0
- data/lib/zip/crypto/encryption.rb +4 -2
- data/lib/zip/crypto/null_encryption.rb +5 -13
- data/lib/zip/crypto/traditional_encryption.rb +22 -16
- data/lib/zip/decompressor.rb +21 -2
- data/lib/zip/deflater.rb +12 -8
- data/lib/zip/dirtyable.rb +32 -0
- data/lib/zip/dos_time.rb +65 -13
- data/lib/zip/entry.rb +433 -249
- data/lib/zip/entry_set.rb +13 -9
- data/lib/zip/errors.rb +152 -15
- data/lib/zip/extra_field/aes.rb +50 -0
- data/lib/zip/extra_field/generic.rb +18 -18
- data/lib/zip/extra_field/ntfs.rb +10 -4
- data/lib/zip/extra_field/old_unix.rb +6 -2
- data/lib/zip/extra_field/universal_time.rb +45 -13
- data/lib/zip/extra_field/unix.rb +7 -3
- data/lib/zip/extra_field/unknown.rb +35 -0
- data/lib/zip/extra_field/zip64.rb +23 -7
- data/lib/zip/extra_field.rb +31 -27
- data/lib/zip/file.rb +225 -241
- data/lib/zip/file_split.rb +91 -0
- data/lib/zip/filesystem/dir.rb +86 -0
- data/lib/zip/filesystem/directory_iterator.rb +48 -0
- data/lib/zip/filesystem/file.rb +263 -0
- data/lib/zip/filesystem/file_stat.rb +110 -0
- data/lib/zip/filesystem/zip_file_name_mapper.rb +81 -0
- data/lib/zip/filesystem.rb +32 -585
- data/lib/zip/inflater.rb +28 -37
- data/lib/zip/input_stream.rb +113 -54
- data/lib/zip/ioextras/abstract_input_stream.rb +154 -55
- data/lib/zip/ioextras/abstract_output_stream.rb +13 -3
- data/lib/zip/ioextras.rb +8 -8
- data/lib/zip/null_compressor.rb +3 -1
- data/lib/zip/null_decompressor.rb +7 -12
- data/lib/zip/null_input_stream.rb +3 -1
- data/lib/zip/output_stream.rb +69 -50
- data/lib/zip/pass_thru_compressor.rb +5 -3
- data/lib/zip/pass_thru_decompressor.rb +17 -23
- data/lib/zip/streamable_directory.rb +6 -4
- data/lib/zip/streamable_stream.rb +10 -11
- data/lib/zip/version.rb +4 -1
- data/lib/zip.rb +32 -7
- data/rubyzip.gemspec +39 -0
- data/samples/example.rb +9 -4
- data/samples/example_filesystem.rb +4 -3
- data/samples/example_recursive.rb +3 -1
- data/samples/gtk_ruby_zip.rb +23 -21
- data/samples/qtzip.rb +13 -12
- data/samples/write_simple.rb +3 -4
- data/samples/zipfind.rb +24 -22
- metadata +85 -177
- data/TODO +0 -15
- data/lib/zip/extra_field/zip64_placeholder.rb +0 -15
- 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/foo/bar/baz/foo.txt +0 -0
- data/test/data/globTest/foo.txt +0 -0
- data/test/data/globTest/food.txt +0 -0
- data/test/data/globTest.zip +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 -145
- data/test/file_permissions_test.rb +0 -65
- data/test/file_split_test.rb +0 -57
- data/test/file_test.rb +0 -666
- 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
data/README.md
CHANGED
|
@@ -1,26 +1,37 @@
|
|
|
1
1
|
# rubyzip
|
|
2
2
|
|
|
3
3
|
[](http://badge.fury.io/rb/rubyzip)
|
|
4
|
-
[](https://github.com/rubyzip/rubyzip/actions/workflows/tests.yml)
|
|
5
|
+
[](https://github.com/rubyzip/rubyzip/actions/workflows/lint.yml)
|
|
6
|
+
[](https://github.com/rubocop/rubocop)
|
|
7
|
+
[](https://qlty.sh/gh/rubyzip/projects/rubyzip)
|
|
6
8
|
[](https://coveralls.io/r/rubyzip/rubyzip?branch=master)
|
|
7
9
|
|
|
8
10
|
Rubyzip is a ruby library for reading and writing zip files.
|
|
9
11
|
|
|
10
|
-
## Important
|
|
12
|
+
## Important notes
|
|
11
13
|
|
|
12
|
-
|
|
14
|
+
### Reporting security issues with this library
|
|
13
15
|
|
|
14
|
-
If you have
|
|
16
|
+
If you think you have found a security issue with this library, please don't submit a public issue or PR. Email me directly at hainesr@gmail.com with as much information as you can provide - steps for replication are particularly helpful if you can - and we'll get it sorted ASAP. Thank you.
|
|
15
17
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
### Updating to version 3.0
|
|
19
|
+
|
|
20
|
+
The public API of some classes has been modernized to use named parameters for optional arguments. Please check your usage of the following Rubyzip classes:
|
|
21
|
+
* `File`
|
|
22
|
+
* `Entry`
|
|
23
|
+
* `InputStream`
|
|
24
|
+
* `OutputStream`
|
|
25
|
+
|
|
26
|
+
**Please see [Updating to version 3.x](https://github.com/rubyzip/rubyzip/wiki/Updating-to-version-3.x) in the wiki for details.**
|
|
20
27
|
|
|
21
28
|
## Requirements
|
|
22
29
|
|
|
23
|
-
|
|
30
|
+
Version 3.x requires at least Ruby 3.0.
|
|
31
|
+
|
|
32
|
+
Version 2.x requires at least Ruby 2.4, and is known to work on Ruby 3.x.
|
|
33
|
+
|
|
34
|
+
It is not recommended to use any versions of Rubyzip earlier than 2.3 due to security issues.
|
|
24
35
|
|
|
25
36
|
## Installation
|
|
26
37
|
|
|
@@ -33,9 +44,12 @@ gem install rubyzip
|
|
|
33
44
|
Or in your Gemfile:
|
|
34
45
|
|
|
35
46
|
```ruby
|
|
36
|
-
gem 'rubyzip'
|
|
47
|
+
gem 'rubyzip', require: 'zip' # For versions before 3.4.
|
|
48
|
+
gem 'rubyzip' # For version 3.4 and after.
|
|
37
49
|
```
|
|
38
50
|
|
|
51
|
+
From version 3.4 onwards, you can `require` either 'zip' or 'rubyzip' to use this library. Before version 3.4 you need to `require 'zip'` explicitly.
|
|
52
|
+
|
|
39
53
|
## Usage
|
|
40
54
|
|
|
41
55
|
### Basic zip archive creation
|
|
@@ -49,7 +63,7 @@ input_filenames = ['image.jpg', 'description.txt', 'stats.csv']
|
|
|
49
63
|
|
|
50
64
|
zipfile_name = "/Users/me/Desktop/archive.zip"
|
|
51
65
|
|
|
52
|
-
Zip::File.open(zipfile_name,
|
|
66
|
+
Zip::File.open(zipfile_name, create: true) do |zipfile|
|
|
53
67
|
input_filenames.each do |filename|
|
|
54
68
|
# Two arguments:
|
|
55
69
|
# - The name of the file as it will appear in the archive
|
|
@@ -60,6 +74,48 @@ Zip::File.open(zipfile_name, Zip::File::CREATE) do |zipfile|
|
|
|
60
74
|
end
|
|
61
75
|
```
|
|
62
76
|
|
|
77
|
+
### Creating a Zip file with `Zip::OutputStream`
|
|
78
|
+
|
|
79
|
+
```ruby
|
|
80
|
+
require 'rubygems'
|
|
81
|
+
require 'zip'
|
|
82
|
+
|
|
83
|
+
Zip::OutputStream.open('archive.zip') do |zos|
|
|
84
|
+
# Quick.
|
|
85
|
+
zos.put_next_entry('greeting.txt')
|
|
86
|
+
zos << 'Hello, World!'
|
|
87
|
+
|
|
88
|
+
# More control.
|
|
89
|
+
# You MUST NOT make any calls on your `Entry` after calling `put_next_entry`.
|
|
90
|
+
entry = Zip::Entry.new(nil, 'parting.txt')
|
|
91
|
+
entry.atime = Time.now
|
|
92
|
+
zos.put_next_entry(entry)
|
|
93
|
+
zos.write('TTFN')
|
|
94
|
+
end
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
You can generate a Zip archive in memory using `Zip::OutputStream.write_buffer`.
|
|
98
|
+
|
|
99
|
+
### Suppressing extra fields
|
|
100
|
+
|
|
101
|
+
If you wish to suppress extra fields from being added to your entries, you can do so by passing the `suppress_extra_fields` parameter to any of the archive opening calls within `Zip::File` or `Zip::OutputStream`, e.g.:
|
|
102
|
+
|
|
103
|
+
```ruby
|
|
104
|
+
# Suppress all extra fields.
|
|
105
|
+
Zip::File.open('archive.zip', create: true, suppress_extra_fields: true)
|
|
106
|
+
Zip::OutputStream.open('archive.zip', suppress_extra_fields: true)
|
|
107
|
+
|
|
108
|
+
# Suppress an individual extra field.
|
|
109
|
+
Zip::File.open('archive.zip', create: true, suppress_extra_fields: :zip64)
|
|
110
|
+
Zip::OutputStream.open('archive.zip', suppress_extra_fields: :zip64)
|
|
111
|
+
|
|
112
|
+
# Suppress multiple extra fields.
|
|
113
|
+
Zip::File.open('archive.zip', create: true, suppress_extra_fields: [:ntfs, :zip64])
|
|
114
|
+
Zip::OutputStream.open('archive.zip', suppress_extra_fields: [:ntfs, :zip64])
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Note that there are some extra fields that cannot be suppressed at all (e.g. `:aes`), and some which will only be suppressed if it is safe to do so (e.g. `:zip64`).
|
|
118
|
+
|
|
63
119
|
### Zipping a directory recursively
|
|
64
120
|
|
|
65
121
|
Copy from [here](https://github.com/rubyzip/rubyzip/blob/9d891f7353e66052283562d3e252fe380bb4b199/samples/example_recursive.rb)
|
|
@@ -88,7 +144,7 @@ class ZipFileGenerator
|
|
|
88
144
|
def write
|
|
89
145
|
entries = Dir.entries(@input_dir) - %w[. ..]
|
|
90
146
|
|
|
91
|
-
::Zip::File.open(@output_file,
|
|
147
|
+
::Zip::File.open(@output_file, create: true) do |zipfile|
|
|
92
148
|
write_entries entries, '', zipfile
|
|
93
149
|
end
|
|
94
150
|
end
|
|
@@ -121,9 +177,9 @@ class ZipFileGenerator
|
|
|
121
177
|
end
|
|
122
178
|
```
|
|
123
179
|
|
|
124
|
-
### Save zip archive entries
|
|
180
|
+
### Save zip archive entries sorted by name
|
|
125
181
|
|
|
126
|
-
To save zip archives
|
|
182
|
+
To save zip archives with their entries sorted by name (see below), set `::Zip.sort_entries` to `true`
|
|
127
183
|
|
|
128
184
|
```
|
|
129
185
|
Vegetable/
|
|
@@ -137,7 +193,7 @@ fruit/mango
|
|
|
137
193
|
fruit/orange
|
|
138
194
|
```
|
|
139
195
|
|
|
140
|
-
|
|
196
|
+
Opening an existing zip file with this option set will not change the order of the entries automatically. Altering the zip file - adding an entry, renaming an entry, adding or changing the archive comment, etc - will cause the ordering to be applied when closing the file.
|
|
141
197
|
|
|
142
198
|
### Default permissions of zip archives
|
|
143
199
|
|
|
@@ -173,28 +229,79 @@ Zip::File.open('foo.zip') do |zip_file|
|
|
|
173
229
|
end
|
|
174
230
|
```
|
|
175
231
|
|
|
176
|
-
|
|
232
|
+
### Reading a Zip file with `Zip::InputStream`
|
|
233
|
+
|
|
234
|
+
`Zip::InputStream` can be used for faster reading of zip file content because it does not read the Central directory up front.
|
|
235
|
+
|
|
236
|
+
There is one exception where it can not work however, and this is if the file does not contain enough information in the local entry headers to extract an entry. This is indicated in an entry by the General Purpose Flag bit 3 being set.
|
|
237
|
+
|
|
238
|
+
> 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.
|
|
239
|
+
|
|
240
|
+
If `Zip::InputStream` finds such an entry in the zip archive it will raise an exception (`Zip::StreamingError`).
|
|
241
|
+
|
|
242
|
+
`Zip::InputStream` is not designed to be used for random access in a zip file. When performing any operations on an entry that you are accessing via `Zip::InputStream#get_next_entry` then you should complete any such operations before the next call to `get_next_entry`.
|
|
243
|
+
|
|
244
|
+
```ruby
|
|
245
|
+
Zip::InputStream.open('file.zip') do |zip_stream|
|
|
246
|
+
while entry = zip_stream.get_next_entry
|
|
247
|
+
# All required operations on `entry` go here.
|
|
248
|
+
end
|
|
249
|
+
end # The `InputStream` is closed at the end of the block.
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
Any attempt to move about in a zip file opened with `Zip::InputStream` could result in the incorrect entry being accessed and/or Zlib buffer errors. If you need random access in a zip file, use `Zip::File`.
|
|
177
253
|
|
|
178
|
-
|
|
254
|
+
### Password Protection (experimental)
|
|
179
255
|
|
|
180
|
-
|
|
256
|
+
Rubyzip supports reading zip files with AES encryption (version 3.1 and later), and reading and writing zip files with traditional zip encryption (a.k.a. "ZipCrypto"). Encryption is currently only available with the stream API, with either files or buffers, e.g.:
|
|
181
257
|
|
|
182
|
-
|
|
258
|
+
#### Version 2.x (ZipCrypto only)
|
|
183
259
|
|
|
184
|
-
|
|
260
|
+
```ruby
|
|
261
|
+
# Writing.
|
|
262
|
+
enc = Zip::TraditionalEncrypter.new('password')
|
|
263
|
+
buffer = Zip::OutputStream.write_buffer(::StringIO.new(''), enc) do |output|
|
|
264
|
+
output.put_next_entry("my_file.txt")
|
|
265
|
+
output.write my_data
|
|
266
|
+
end
|
|
185
267
|
|
|
186
|
-
|
|
268
|
+
# Reading.
|
|
269
|
+
dec = Zip::TraditionalDecrypter.new('password')
|
|
270
|
+
Zip::InputStream.open(buffer, 0, dec) do |input|
|
|
271
|
+
entry = input.get_next_entry
|
|
272
|
+
puts "Contents of '#{entry.name}':"
|
|
273
|
+
puts input.read
|
|
274
|
+
end
|
|
275
|
+
```
|
|
187
276
|
|
|
188
|
-
|
|
277
|
+
#### Version 3.x (AES reading and ZipCrypto read/write)
|
|
189
278
|
|
|
190
279
|
```ruby
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
280
|
+
# Reading AES, version 3.1 and later.
|
|
281
|
+
dec = Zip::AESDecrypter.new('password', Zip::AESEncryption::STRENGTH_256_BIT)
|
|
282
|
+
Zip::InputStream.open('aes-encrypted-file.zip', decrypter: dec) do |input|
|
|
283
|
+
entry = input.get_next_entry
|
|
284
|
+
puts "Contents of '#{entry.name}':"
|
|
285
|
+
puts input.read
|
|
286
|
+
end
|
|
287
|
+
|
|
288
|
+
# Writing.
|
|
289
|
+
enc = Zip::TraditionalEncrypter.new('password')
|
|
290
|
+
buffer = Zip::OutputStream.write_buffer(encrypter: enc) do |output|
|
|
291
|
+
output.put_next_entry("my_file.txt")
|
|
292
|
+
output.write my_data
|
|
293
|
+
end
|
|
294
|
+
|
|
295
|
+
# Reading.
|
|
296
|
+
dec = Zip::TraditionalDecrypter.new('password')
|
|
297
|
+
Zip::InputStream.open(buffer, decrypter: dec) do |input|
|
|
298
|
+
entry = input.get_next_entry
|
|
299
|
+
puts "Contents of '#{entry.name}':"
|
|
300
|
+
puts input.read
|
|
301
|
+
end
|
|
195
302
|
```
|
|
196
303
|
|
|
197
|
-
|
|
304
|
+
_This is an evolving feature and the interface for encryption may change in future versions._
|
|
198
305
|
|
|
199
306
|
## Known issues
|
|
200
307
|
|
|
@@ -208,7 +315,7 @@ buffer = Zip::OutputStream.write_buffer do |out|
|
|
|
208
315
|
unless [DOCUMENT_FILE_PATH, RELS_FILE_PATH].include?(e.name)
|
|
209
316
|
out.put_next_entry(e.name)
|
|
210
317
|
out.write e.get_input_stream.read
|
|
211
|
-
|
|
318
|
+
end
|
|
212
319
|
end
|
|
213
320
|
|
|
214
321
|
out.put_next_entry(DOCUMENT_FILE_PATH)
|
|
@@ -263,15 +370,21 @@ Some zip files might have an invalid date format, which will raise a warning. Yo
|
|
|
263
370
|
Zip.warn_invalid_date = false
|
|
264
371
|
```
|
|
265
372
|
|
|
266
|
-
###
|
|
373
|
+
### Validating Declared Number of Entries
|
|
267
374
|
|
|
268
|
-
|
|
375
|
+
When reading a zip file it is potentially dangerous to trust what it tells you about how many entries it contains. A malformed zip file could claim a high number of entries in an attempt to waste internal resources, or crash the processing application.
|
|
269
376
|
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
377
|
+
By default rubyzip will warn if the number of declared entries is impossible based on the actual size of the Central Directory headers. You can set this check to raise an error:
|
|
378
|
+
|
|
379
|
+
```ruby
|
|
380
|
+
Zip.validate_declared_number_of_entries = true
|
|
273
381
|
```
|
|
274
|
-
|
|
382
|
+
|
|
383
|
+
It is likely that the default behaviour for this check will be changed to raise an error in version 4.
|
|
384
|
+
|
|
385
|
+
### Entry Size Validation
|
|
386
|
+
|
|
387
|
+
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:
|
|
275
388
|
|
|
276
389
|
```ruby
|
|
277
390
|
MAX_FILE_SIZE = 10 * 1024**2 # 10MiB
|
|
@@ -294,25 +407,37 @@ Zip.validate_entry_sizes = false
|
|
|
294
407
|
|
|
295
408
|
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.
|
|
296
409
|
|
|
297
|
-
###
|
|
410
|
+
### Compression level
|
|
298
411
|
|
|
299
|
-
|
|
412
|
+
When adding entries to a zip archive you can set the compression level to trade-off compressed size against compression speed. By default this is set to the same as the underlying Zlib library's default (`Zlib::DEFAULT_COMPRESSION`), which is somewhere in the middle.
|
|
413
|
+
|
|
414
|
+
You can configure the default compression level with:
|
|
300
415
|
|
|
301
416
|
```ruby
|
|
302
|
-
Zip.default_compression =
|
|
417
|
+
Zip.default_compression = X
|
|
303
418
|
```
|
|
304
419
|
|
|
305
|
-
|
|
420
|
+
Where X is an integer between 0 and 9, inclusive. If this option is set to 0 (`Zlib::NO_COMPRESSION`) then entries will be stored in the zip archive uncompressed. A value of 1 (`Zlib::BEST_SPEED`) gives the fastest compression and 9 (`Zlib::BEST_COMPRESSION`) gives the smallest compressed file size.
|
|
421
|
+
|
|
422
|
+
This can also be set for each archive as an option to `Zip::File`:
|
|
423
|
+
|
|
424
|
+
```ruby
|
|
425
|
+
Zip::File.open('foo.zip', create:true, compression_level: 9) do |zip|
|
|
426
|
+
zip.add ...
|
|
427
|
+
end
|
|
428
|
+
```
|
|
306
429
|
|
|
307
430
|
### Zip64 Support
|
|
308
431
|
|
|
309
|
-
|
|
432
|
+
Since version 3.0, Zip64 support is enabled for writing by default. To disable it do this:
|
|
310
433
|
|
|
311
434
|
```ruby
|
|
312
|
-
Zip.write_zip64_support =
|
|
435
|
+
Zip.write_zip64_support = false
|
|
313
436
|
```
|
|
314
437
|
|
|
315
|
-
|
|
438
|
+
Prior to version 3.0, Zip64 support is disabled for writing by default.
|
|
439
|
+
|
|
440
|
+
_NOTE_: If Zip64 write support is enabled then any extractor subsequently used may also require Zip64 support to read from the resultant archive.
|
|
316
441
|
|
|
317
442
|
### Block Form
|
|
318
443
|
|
|
@@ -327,15 +452,51 @@ You can set multiple settings at the same time by using a block:
|
|
|
327
452
|
end
|
|
328
453
|
```
|
|
329
454
|
|
|
455
|
+
## Compatibility
|
|
456
|
+
|
|
457
|
+
Rubyzip is known to run on a number of platforms and under a number of different Ruby versions.
|
|
458
|
+
|
|
459
|
+
### Version 2.4.x
|
|
460
|
+
|
|
461
|
+
Rubyzip 2.4 is known to work on MRI 2.4 to 3.4 on Linux and Mac, and JRuby and Truffleruby on Linux. There are known issues with Windows which have been fixed on the development branch. Please [let us know](https://github.com/rubyzip/rubyzip/pulls) if you know Rubyzip 2.4 works on a platform/Ruby combination not listed here, or [raise an issue](https://github.com/rubyzip/rubyzip/issues) if you see a failure where we think it should work.
|
|
462
|
+
|
|
463
|
+
### Version 3.x
|
|
464
|
+
|
|
465
|
+
Please see the table below for what we think the current situation is. Note: an empty cell means "unknown", not "does not work".
|
|
466
|
+
|
|
467
|
+
| OS/Ruby | 3.0 | 3.1 | 3.2 | 3.3 | 3.4 | 4.0 | Head | JRuby 10.0.1.0 | JRuby Head | Truffleruby 34.0.1 | Truffleruby Head |
|
|
468
|
+
|---------|-----|-----|-----|-----|-----|-----|------|----------------|------------|-------------------|------------------|
|
|
469
|
+
|Ubuntu 24.04| CI | CI | CI | CI | CI | CI | ci | CI | ci | CI | ci |
|
|
470
|
+
|Mac OS 15.7.7| CI | x | x | CI | CI | CI | ci | x | | x | |
|
|
471
|
+
|Windows Server 2022| CI | | | | | | | | | | |
|
|
472
|
+
|Windows Server 2025| | | | CI | | CI | CI mswin</br>CI ucrt | | | | |
|
|
473
|
+
|
|
474
|
+
Key: `CI` - tested in CI, should work; `ci` - tested in CI, might fail; `x` - known working; `o` - known failing.
|
|
475
|
+
|
|
476
|
+
Rubies 3.1+ are also tested separately with YJIT turned on (Ubuntu and Mac OS).
|
|
477
|
+
|
|
478
|
+
See [the Actions tab](https://github.com/rubyzip/rubyzip/actions) in GitHub for full details.
|
|
479
|
+
|
|
480
|
+
Please [raise a PR](https://github.com/rubyzip/rubyzip/pulls) if you know Rubyzip works on a platform/Ruby combination not listed here, or [raise an issue](https://github.com/rubyzip/rubyzip/issues) if you see a failure where we think it should work.
|
|
481
|
+
|
|
330
482
|
## Developing
|
|
331
483
|
|
|
332
|
-
|
|
484
|
+
Install the dependencies:
|
|
333
485
|
|
|
334
|
-
```
|
|
486
|
+
```shell
|
|
335
487
|
bundle install
|
|
488
|
+
```
|
|
489
|
+
|
|
490
|
+
Run the tests with `rake`:
|
|
491
|
+
|
|
492
|
+
```shell
|
|
336
493
|
rake
|
|
337
494
|
```
|
|
338
495
|
|
|
496
|
+
Please also run `rubocop` over your changes.
|
|
497
|
+
|
|
498
|
+
Our CI runs on [GitHub Actions](https://github.com/rubyzip/rubyzip/actions). Please note that `rubocop` is run as part of the CI configuration and will fail a build if errors are found.
|
|
499
|
+
|
|
339
500
|
## Website and Project Home
|
|
340
501
|
|
|
341
502
|
http://github.com/rubyzip/rubyzip
|
|
@@ -344,17 +505,18 @@ http://rdoc.info/github/rubyzip/rubyzip/master/frames
|
|
|
344
505
|
|
|
345
506
|
## Authors
|
|
346
507
|
|
|
347
|
-
|
|
508
|
+
See https://github.com/rubyzip/rubyzip/graphs/contributors for a comprehensive list.
|
|
348
509
|
|
|
349
|
-
|
|
510
|
+
### Current maintainers
|
|
350
511
|
|
|
351
|
-
|
|
512
|
+
* Robert Haines (@hainesr)
|
|
513
|
+
* John Lees-Miller (@jdleesmiller)
|
|
514
|
+
* Oleksandr Simonov (@simonoff)
|
|
352
515
|
|
|
353
|
-
|
|
516
|
+
### Original author
|
|
354
517
|
|
|
355
|
-
|
|
518
|
+
* Thomas Sondergaard
|
|
356
519
|
|
|
357
520
|
## License
|
|
358
521
|
|
|
359
|
-
Rubyzip is distributed under the same license as ruby.
|
|
360
|
-
http://www.ruby-lang.org/en/LICENSE.txt
|
|
522
|
+
Rubyzip is distributed under the same license as Ruby. In practice this means you can use it under the terms of the Ruby License or the 2-Clause BSD License. See https://www.ruby-lang.org/en/about/license.txt and LICENSE.md for details.
|
data/Rakefile
CHANGED
|
@@ -1,18 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'bundler/gem_tasks'
|
|
2
|
-
require '
|
|
4
|
+
require 'minitest/test_task'
|
|
5
|
+
require 'rdoc/task'
|
|
6
|
+
require 'rubocop/rake_task'
|
|
3
7
|
|
|
4
8
|
task default: :test
|
|
5
9
|
|
|
6
|
-
|
|
7
|
-
test.
|
|
8
|
-
test.
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
Minitest::TestTask.create do |test|
|
|
11
|
+
test.framework = 'require "simplecov"'
|
|
12
|
+
test.test_globs = 'test/**/*_test.rb'
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
RDoc::Task.new do |rdoc|
|
|
16
|
+
rdoc.main = 'README.md'
|
|
17
|
+
rdoc.rdoc_files.include('README.md', 'lib/**/*.rb')
|
|
18
|
+
rdoc.options << '--markup=markdown'
|
|
19
|
+
rdoc.options << '--tab-width=2'
|
|
20
|
+
rdoc.options << "-t Rubyzip version #{Zip::VERSION}"
|
|
11
21
|
end
|
|
12
22
|
|
|
13
|
-
|
|
14
|
-
# test.libs << File.join(File.dirname(__FILE__), 'lib')
|
|
15
|
-
# test.libs << File.join(File.dirname(__FILE__), 'test')
|
|
16
|
-
# test.pattern = File.join(File.dirname(__FILE__), 'test/zip64_full_test.rb')
|
|
17
|
-
# test.verbose = true
|
|
18
|
-
# end
|
|
23
|
+
RuboCop::RakeTask.new
|
data/lib/rubyzip.rb
ADDED