You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
223
229
224
230
```ruby
@@ -233,18 +239,57 @@ Additionally, if you want to configure rubyzip to overwrite existing files while
233
239
Zip.continue_on_exists_proc =true
234
240
```
235
241
242
+
### Non-ASCII Names
243
+
236
244
If you want to store non-english names and want to open them on Windows(pre 7) you need to set this option:
237
245
238
246
```ruby
239
247
Zip.unicode_names =true
240
248
```
241
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
+
242
260
Some zip files might have an invalid date format, which will raise a warning. You can hide this warning with the following setting:
243
261
244
262
```ruby
245
263
Zip.warn_invalid_date =false
246
264
```
247
265
266
+
### Size Validation
267
+
268
+
By default, `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 +=1if 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
+
248
293
You can set the default compression level like so:
It defaults to `Zlib::DEFAULT_COMPRESSION`. Possible values are `Zlib::BEST_COMPRESSION`, `Zlib::DEFAULT_COMPRESSION` and `Zlib::NO_COMPRESSION`
255
300
256
-
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:
301
+
### Zip64 Support
302
+
303
+
By default, Zip64 support is disabled for writing. To enable it do this:
257
304
258
305
```ruby
259
-
Zip.force_entry_names_encoding='UTF-8'
306
+
Zip.write_zip64_support=true
260
307
```
261
308
262
-
Allowed encoding names are the same as accepted by `String#force_encoding`
309
+
_NOTE_: If you will enable Zip64 writing then you will need zip extractor with Zip64 support to extract archive.
310
+
311
+
### Block Form
263
312
264
313
You can set multiple settings at the same time by using a block:
265
314
@@ -272,14 +321,6 @@ You can set multiple settings at the same time by using a block:
272
321
end
273
322
```
274
323
275
-
By default, Zip64 support is disabled for writing. To enable it do this:
276
-
277
-
```ruby
278
-
Zip.write_zip64_support =true
279
-
```
280
-
281
-
_NOTE_: If you will enable Zip64 writing then you will need zip extractor with Zip64 support to extract archive.
0 commit comments