rubyzip 1.1.7 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of rubyzip might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/README.md +75 -40
- data/Rakefile +3 -4
- data/lib/zip.rb +3 -5
- data/lib/zip/central_directory.rb +7 -7
- data/lib/zip/compressor.rb +0 -0
- data/lib/zip/constants.rb +2 -2
- data/lib/zip/crypto/null_encryption.rb +3 -3
- data/lib/zip/crypto/traditional_encryption.rb +5 -5
- data/lib/zip/decompressor.rb +2 -2
- data/lib/zip/deflater.rb +8 -6
- data/lib/zip/dos_time.rb +4 -5
- data/lib/zip/entry.rb +75 -81
- data/lib/zip/entry_set.rb +11 -11
- data/lib/zip/errors.rb +1 -0
- data/lib/zip/extra_field.rb +6 -6
- data/lib/zip/extra_field/generic.rb +7 -7
- data/lib/zip/extra_field/ntfs.rb +14 -16
- data/lib/zip/extra_field/old_unix.rb +9 -10
- data/lib/zip/extra_field/universal_time.rb +14 -14
- data/lib/zip/extra_field/unix.rb +8 -9
- data/lib/zip/extra_field/zip64.rb +12 -11
- data/lib/zip/extra_field/zip64_placeholder.rb +1 -1
- data/lib/zip/file.rb +47 -60
- data/lib/zip/filesystem.rb +132 -135
- data/lib/zip/inflater.rb +3 -3
- data/lib/zip/input_stream.rb +13 -7
- data/lib/zip/ioextras.rb +1 -3
- data/lib/zip/ioextras/abstract_input_stream.rb +5 -9
- data/lib/zip/ioextras/abstract_output_stream.rb +2 -4
- data/lib/zip/null_compressor.rb +2 -2
- data/lib/zip/null_decompressor.rb +3 -3
- data/lib/zip/null_input_stream.rb +0 -0
- data/lib/zip/output_stream.rb +8 -9
- data/lib/zip/pass_thru_compressor.rb +4 -4
- data/lib/zip/pass_thru_decompressor.rb +2 -3
- data/lib/zip/streamable_directory.rb +2 -2
- data/lib/zip/streamable_stream.rb +2 -2
- data/lib/zip/version.rb +1 -1
- data/samples/example.rb +29 -39
- data/samples/example_filesystem.rb +16 -18
- data/samples/example_recursive.rb +32 -25
- data/samples/{gtkRubyzip.rb → gtk_ruby_zip.rb} +23 -25
- data/samples/qtzip.rb +17 -26
- data/samples/write_simple.rb +12 -13
- data/samples/zipfind.rb +24 -32
- data/test/basic_zip_file_test.rb +11 -15
- data/test/case_sensitivity_test.rb +69 -0
- data/test/central_directory_entry_test.rb +32 -36
- data/test/central_directory_test.rb +46 -50
- data/test/crypto/null_encryption_test.rb +8 -4
- data/test/crypto/traditional_encryption_test.rb +5 -5
- data/test/data/notzippedruby.rb +1 -1
- data/test/data/oddExtraField.zip +0 -0
- data/test/data/test.xls +0 -0
- data/test/deflater_test.rb +10 -12
- data/test/encryption_test.rb +2 -2
- data/test/entry_set_test.rb +50 -25
- data/test/entry_test.rb +76 -87
- data/test/errors_test.rb +0 -2
- data/test/extra_field_test.rb +19 -21
- data/test/file_extract_directory_test.rb +12 -14
- data/test/file_extract_test.rb +33 -40
- data/test/file_permissions_test.rb +69 -0
- data/test/file_split_test.rb +24 -27
- data/test/file_test.rb +196 -172
- data/test/filesystem/dir_iterator_test.rb +13 -17
- data/test/filesystem/directory_test.rb +80 -90
- data/test/filesystem/file_mutating_test.rb +51 -63
- data/test/filesystem/file_nonmutating_test.rb +222 -228
- data/test/filesystem/file_stat_test.rb +17 -19
- data/test/gentestfiles.rb +47 -55
- data/test/inflater_test.rb +1 -1
- data/test/input_stream_test.rb +46 -34
- data/test/ioextras/abstract_input_stream_test.rb +22 -23
- data/test/ioextras/abstract_output_stream_test.rb +32 -32
- data/test/ioextras/fake_io_test.rb +1 -1
- data/test/local_entry_test.rb +36 -38
- data/test/output_stream_test.rb +20 -21
- data/test/pass_thru_compressor_test.rb +5 -6
- data/test/pass_thru_decompressor_test.rb +0 -1
- data/test/samples/example_recursive_test.rb +37 -0
- data/test/settings_test.rb +18 -15
- data/test/test_helper.rb +50 -44
- data/test/unicode_file_names_and_comments_test.rb +5 -7
- data/test/zip64_full_test.rb +9 -11
- data/test/zip64_support_test.rb +0 -1
- metadata +14 -32
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1b7ea085db9b27be420d541113214a73ee044c9f
|
4
|
+
data.tar.gz: ea28ff723bfd70f2e6f7a02f4fe28b805aa4a47e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 121d7129aa37b72da82b32882401b7837c9cface1edf1b8bfb911cd20a55b2ecdacd308de9b7ed0cb6bc0b45d9d974faf28826efe191ddc36d3eb8431f8fe6f0
|
7
|
+
data.tar.gz: b1ef9770bcd133de33f61642665d511a11aff21aba880cf1226df0c8e1b3602833679384d76bf6877b19567406f7bd9a60de8bd78aded3f303660fbb80b31bb7
|
data/README.md
CHANGED
@@ -4,11 +4,11 @@
|
|
4
4
|
[![Code Climate](https://codeclimate.com/github/rubyzip/rubyzip.svg)](https://codeclimate.com/github/rubyzip/rubyzip)
|
5
5
|
[![Coverage Status](https://img.shields.io/coveralls/rubyzip/rubyzip.svg)](https://coveralls.io/r/rubyzip/rubyzip?branch=master)
|
6
6
|
|
7
|
-
|
7
|
+
Rubyzip is a ruby library for reading and writing zip files.
|
8
8
|
|
9
9
|
## Important note
|
10
10
|
|
11
|
-
Rubyzip interface changed!!! No need to do `require "zip/zip"` and `Zip` prefix in class names removed.
|
11
|
+
The Rubyzip interface has changed!!! No need to do `require "zip/zip"` and `Zip` prefix in class names removed.
|
12
12
|
|
13
13
|
If you have issues with any third-party gems that require an old version of rubyzip, you can use this workaround:
|
14
14
|
|
@@ -22,7 +22,7 @@ gem 'zip-zip' # will load compatibility for old rubyzip API.
|
|
22
22
|
* Ruby 1.9.2 or greater
|
23
23
|
|
24
24
|
## Installation
|
25
|
-
|
25
|
+
Rubyzip is available on RubyGems:
|
26
26
|
|
27
27
|
```
|
28
28
|
gem install rubyzip
|
@@ -62,55 +62,68 @@ end
|
|
62
62
|
Copy from [here](https://github.com/rubyzip/rubyzip/blob/05916bf89181e1955118fd3ea059f18acac28cc8/samples/example_recursive.rb )
|
63
63
|
|
64
64
|
```ruby
|
65
|
-
require 'rubygems'
|
66
65
|
require 'zip'
|
66
|
+
|
67
67
|
# This is a simple example which uses rubyzip to
|
68
68
|
# recursively generate a zip file from the contents of
|
69
69
|
# a specified directory. The directory itself is not
|
70
70
|
# included in the archive, rather just its contents.
|
71
71
|
#
|
72
72
|
# Usage:
|
73
|
-
#
|
74
|
-
#
|
75
|
-
#
|
76
|
-
#
|
77
|
-
# zf.write()
|
78
|
-
|
73
|
+
# directory_to_zip = "/tmp/input"
|
74
|
+
# output_file = "/tmp/out.zip"
|
75
|
+
# zf = ZipFileGenerator.new(directory_to_zip, output_file)
|
76
|
+
# zf.write()
|
79
77
|
class ZipFileGenerator
|
80
78
|
# Initialize with the directory to zip and the location of the output archive.
|
81
|
-
def initialize(
|
82
|
-
@
|
83
|
-
@
|
79
|
+
def initialize(input_dir, output_file)
|
80
|
+
@input_dir = input_dir
|
81
|
+
@output_file = output_file
|
84
82
|
end
|
83
|
+
|
85
84
|
# Zip the input directory.
|
86
|
-
def write
|
87
|
-
entries = Dir.entries(@
|
88
|
-
|
89
|
-
|
90
|
-
|
85
|
+
def write
|
86
|
+
entries = Dir.entries(@input_dir) - %w(. ..)
|
87
|
+
|
88
|
+
::Zip::File.open(@output_file, ::Zip::File::CREATE) do |io|
|
89
|
+
write_entries entries, '', io
|
90
|
+
end
|
91
91
|
end
|
92
|
-
|
92
|
+
|
93
93
|
private
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
94
|
+
|
95
|
+
# A helper method to make the recursion work.
|
96
|
+
def write_entries(entries, path, io)
|
97
|
+
entries.each do |e|
|
98
|
+
zip_file_path = path == '' ? e : File.join(path, e)
|
99
|
+
disk_file_path = File.join(@input_dir, zip_file_path)
|
100
|
+
puts "Deflating #{disk_file_path}"
|
101
|
+
|
102
|
+
if File.directory? disk_file_path
|
103
|
+
recursively_deflate_directory(disk_file_path, io, zip_file_path)
|
103
104
|
else
|
104
|
-
|
105
|
+
put_into_archive(disk_file_path, io, zip_file_path)
|
105
106
|
end
|
106
|
-
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def recursively_deflate_directory(disk_file_path, io, zip_file_path)
|
111
|
+
io.mkdir zip_file_path
|
112
|
+
subdir = Dir.entries(disk_file_path) - %w(. ..)
|
113
|
+
write_entries subdir, zip_file_path, io
|
114
|
+
end
|
115
|
+
|
116
|
+
def put_into_archive(disk_file_path, io, zip_file_path)
|
117
|
+
io.get_output_stream(zip_file_path) do |f|
|
118
|
+
f.write(File.open(disk_file_path, 'rb').read)
|
119
|
+
end
|
107
120
|
end
|
108
121
|
end
|
109
122
|
```
|
110
123
|
|
111
124
|
### Save zip archive entries in sorted by name state
|
112
125
|
|
113
|
-
To
|
126
|
+
To save zip archives in sorted order like below, you need to set `::Zip.sort_entries` to `true`
|
114
127
|
|
115
128
|
```
|
116
129
|
Vegetable/
|
@@ -124,7 +137,17 @@ fruit/mango
|
|
124
137
|
fruit/orange
|
125
138
|
```
|
126
139
|
|
127
|
-
After this entries in zip archive will be saved in ordered state.
|
140
|
+
After this, entries in the zip archive will be saved in ordered state.
|
141
|
+
|
142
|
+
### Default permissions of zip archives
|
143
|
+
|
144
|
+
On Posix file systems the default file permissions applied to a new archive
|
145
|
+
are (0666 - umask), which mimics the behavior of standard tools such as `touch`.
|
146
|
+
|
147
|
+
On Windows the default file permissions are set to 0644 as suggested by the
|
148
|
+
[Ruby File documentation](http://ruby-doc.org/core-2.2.2/File.html).
|
149
|
+
|
150
|
+
When modifying a zip archive the file permissions of the archive are preserved.
|
128
151
|
|
129
152
|
### Reading a Zip file
|
130
153
|
|
@@ -146,9 +169,21 @@ Zip::File.open('foo.zip') do |zip_file|
|
|
146
169
|
end
|
147
170
|
```
|
148
171
|
|
172
|
+
#### Notice about ::Zip::InputStream
|
173
|
+
|
174
|
+
`::Zip::InputStream` usable for fast reading zip file content because it not read Central directory.
|
175
|
+
|
176
|
+
But there is one exception when it is not working - General Purpose Flag Bit 3.
|
177
|
+
|
178
|
+
```
|
179
|
+
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
|
180
|
+
```
|
181
|
+
|
182
|
+
If `::Zip::InputStream` finds such entry in the zip archive it will raise an exception.
|
183
|
+
|
149
184
|
### Password Protection (Experimental)
|
150
185
|
|
151
|
-
|
186
|
+
Rubyzip supports reading/writing zip files with traditional zip encryption (a.k.a. "ZipCrypto"). AES encryption is not yet supported. It can be used with buffer streams, e.g.:
|
152
187
|
|
153
188
|
```ruby
|
154
189
|
Zip::OutputStream.write_buffer(::StringIO.new(''), Zip::TraditionalEncrypter.new('password')) do |out|
|
@@ -181,7 +216,7 @@ buffer = Zip::OutputStream.write_buffer do |out|
|
|
181
216
|
out.write rels.to_xml(:indent => 0).gsub("\n","")
|
182
217
|
end
|
183
218
|
|
184
|
-
File.open(new_path, "
|
219
|
+
File.open(new_path, "wb") {|f| f.write(buffer.string) }
|
185
220
|
```
|
186
221
|
|
187
222
|
## Configuration
|
@@ -200,13 +235,13 @@ Additionally, if you want to configure rubyzip to overwrite existing files while
|
|
200
235
|
Zip.continue_on_exists_proc = true
|
201
236
|
```
|
202
237
|
|
203
|
-
If you want to store non
|
238
|
+
If you want to store non-english names and want to open them on Windows(pre 7) you need to set this option:
|
204
239
|
|
205
240
|
```ruby
|
206
241
|
Zip.unicode_names = true
|
207
242
|
```
|
208
243
|
|
209
|
-
|
244
|
+
Some zip files might have an invalid date format, which will raise a warning. You can hide this warning with the following setting:
|
210
245
|
|
211
246
|
```ruby
|
212
247
|
Zip.warn_invalid_date = false
|
@@ -219,7 +254,7 @@ Zip.default_compression = Zlib::DEFAULT_COMPRESSION
|
|
219
254
|
```
|
220
255
|
It defaults to `Zlib::DEFAULT_COMPRESSION`. Possible values are `Zlib::BEST_COMPRESSION`, `Zlib::DEFAULT_COMPRESSION` and `Zlib::NO_COMPRESSION`
|
221
256
|
|
222
|
-
|
257
|
+
You can set multiple settings at the same time by using a block:
|
223
258
|
|
224
259
|
```ruby
|
225
260
|
Zip.setup do |c|
|
@@ -230,7 +265,7 @@ All settings in same time
|
|
230
265
|
end
|
231
266
|
```
|
232
267
|
|
233
|
-
By default Zip64 support is disabled for writing. To enable it do
|
268
|
+
By default, Zip64 support is disabled for writing. To enable it do this:
|
234
269
|
|
235
270
|
```ruby
|
236
271
|
Zip.write_zip64_support = true
|
@@ -240,7 +275,7 @@ _NOTE_: If you will enable Zip64 writing then you will need zip extractor with Z
|
|
240
275
|
|
241
276
|
## Developing
|
242
277
|
|
243
|
-
To run
|
278
|
+
To run the test you need to do this:
|
244
279
|
|
245
280
|
```
|
246
281
|
bundle install
|
@@ -267,5 +302,5 @@ extra-field support contributed by Tatsuki Sugiura (sugi at nemui.org)
|
|
267
302
|
|
268
303
|
## License
|
269
304
|
|
270
|
-
|
305
|
+
Rubyzip is distributed under the same license as ruby. See
|
271
306
|
http://www.ruby-lang.org/en/LICENSE.txt
|
data/Rakefile
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'bundler/gem_tasks'
|
2
2
|
require 'rake/testtask'
|
3
3
|
|
4
|
-
task :
|
4
|
+
task default: :test
|
5
5
|
|
6
6
|
Rake::TestTask.new(:test) do |test|
|
7
7
|
test.libs << 'lib'
|
@@ -10,10 +10,9 @@ Rake::TestTask.new(:test) do |test|
|
|
10
10
|
test.verbose = true
|
11
11
|
end
|
12
12
|
|
13
|
-
#Rake::TestTask.new(:zip64_full_test) do |test|
|
13
|
+
# Rake::TestTask.new(:zip64_full_test) do |test|
|
14
14
|
# test.libs << File.join(File.dirname(__FILE__), 'lib')
|
15
15
|
# test.libs << File.join(File.dirname(__FILE__), 'test')
|
16
16
|
# test.pattern = File.join(File.dirname(__FILE__), 'test/zip64_full_test.rb')
|
17
17
|
# test.verbose = true
|
18
|
-
#end
|
19
|
-
|
18
|
+
# end
|
data/lib/zip.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'delegate'
|
2
2
|
require 'singleton'
|
3
3
|
require 'tempfile'
|
4
|
+
require 'tmpdir'
|
4
5
|
require 'fileutils'
|
5
6
|
require 'stringio'
|
6
7
|
require 'zlib'
|
@@ -30,14 +31,10 @@ require 'zip/streamable_stream'
|
|
30
31
|
require 'zip/streamable_directory'
|
31
32
|
require 'zip/constants'
|
32
33
|
require 'zip/errors'
|
33
|
-
if defined? JRUBY_VERSION
|
34
|
-
require 'jruby'
|
35
|
-
JRuby.objectspace = true
|
36
|
-
end
|
37
34
|
|
38
35
|
module Zip
|
39
36
|
extend self
|
40
|
-
attr_accessor :unicode_names, :on_exists_proc, :continue_on_exists_proc, :sort_entries, :default_compression, :write_zip64_support, :warn_invalid_date
|
37
|
+
attr_accessor :unicode_names, :on_exists_proc, :continue_on_exists_proc, :sort_entries, :default_compression, :write_zip64_support, :warn_invalid_date, :case_insensitive_match
|
41
38
|
|
42
39
|
def reset!
|
43
40
|
@_ran_once = false
|
@@ -48,6 +45,7 @@ module Zip
|
|
48
45
|
@default_compression = ::Zlib::DEFAULT_COMPRESSION
|
49
46
|
@write_zip64_support = false
|
50
47
|
@warn_invalid_date = true
|
48
|
+
@case_insensitive_match = false
|
51
49
|
end
|
52
50
|
|
53
51
|
def setup
|
@@ -5,7 +5,7 @@ module Zip
|
|
5
5
|
END_OF_CDS = 0x06054b50
|
6
6
|
ZIP64_END_OF_CDS = 0x06064b50
|
7
7
|
ZIP64_EOCD_LOCATOR = 0x07064b50
|
8
|
-
MAX_END_OF_CDS_SIZE =
|
8
|
+
MAX_END_OF_CDS_SIZE = 65_536 + 18
|
9
9
|
STATIC_EOCD_SIZE = 22
|
10
10
|
|
11
11
|
attr_reader :comment
|
@@ -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,
|
99
|
+
raise Error, 'Zip consistency problem while reading eocd structure' unless buf.size == 0
|
100
100
|
end
|
101
101
|
|
102
102
|
def read_e_o_c_d(buf) #:nodoc:
|
@@ -113,14 +113,14 @@ module Zip
|
|
113
113
|
else
|
114
114
|
buf.read(comment_length)
|
115
115
|
end
|
116
|
-
raise Error,
|
116
|
+
raise Error, 'Zip consistency problem while reading eocd structure' unless buf.size == 0
|
117
117
|
end
|
118
118
|
|
119
119
|
def read_central_directory_entries(io) #:nodoc:
|
120
120
|
begin
|
121
121
|
io.seek(@cdir_offset, IO::SEEK_SET)
|
122
122
|
rescue Errno::EINVAL
|
123
|
-
raise Error,
|
123
|
+
raise Error, 'Zip consistency problem while reading central directory entry'
|
124
124
|
end
|
125
125
|
@entry_set = EntrySet.new
|
126
126
|
@size.times do
|
@@ -140,7 +140,7 @@ module Zip
|
|
140
140
|
|
141
141
|
def get_e_o_c_d(buf) #:nodoc:
|
142
142
|
sig_index = buf.rindex([END_OF_CDS].pack('V'))
|
143
|
-
raise Error,
|
143
|
+
raise Error, 'Zip end of central directory signature not found' unless sig_index
|
144
144
|
buf = buf.slice!((sig_index + 4)..(buf.bytesize))
|
145
145
|
|
146
146
|
def buf.read(count)
|
@@ -165,9 +165,9 @@ module Zip
|
|
165
165
|
|
166
166
|
def get_64_e_o_c_d(buf) #:nodoc:
|
167
167
|
zip_64_start = buf.rindex([ZIP64_END_OF_CDS].pack('V'))
|
168
|
-
raise Error,
|
168
|
+
raise Error, 'Zip64 end of central directory signature not found' unless zip_64_start
|
169
169
|
zip_64_locator = buf.rindex([ZIP64_EOCD_LOCATOR].pack('V'))
|
170
|
-
raise Error,
|
170
|
+
raise Error, 'Zip64 end of central directory signature locator not found' unless zip_64_locator
|
171
171
|
buf = buf.slice!((zip_64_start + 4)..zip_64_locator)
|
172
172
|
|
173
173
|
def buf.read(count)
|
data/lib/zip/compressor.rb
CHANGED
File without changes
|
data/lib/zip/constants.rb
CHANGED
@@ -6,7 +6,7 @@ module Zip
|
|
6
6
|
|
7
7
|
LOCAL_ENTRY_SIGNATURE = 0x04034b50
|
8
8
|
LOCAL_ENTRY_STATIC_HEADER_LENGTH = 30
|
9
|
-
LOCAL_ENTRY_TRAILING_DESCRIPTOR_LENGTH = 4+4+4
|
9
|
+
LOCAL_ENTRY_TRAILING_DESCRIPTOR_LENGTH = 4 + 4 + 4
|
10
10
|
VERSION_MADE_BY = 52 # this library's version
|
11
11
|
VERSION_NEEDED_TO_EXTRACT = 20
|
12
12
|
VERSION_NEEDED_TO_EXTRACT_ZIP64 = 45
|
@@ -58,6 +58,6 @@ module Zip
|
|
58
58
|
FSTYPE_TANDEM => 'Tandem NSK'.freeze,
|
59
59
|
FSTYPE_THEOS => 'Theos'.freeze,
|
60
60
|
FSTYPE_MAC_OSX => 'Mac OS/X (Darwin)'.freeze,
|
61
|
-
FSTYPE_ATHEOS => 'AtheOS'.freeze
|
61
|
+
FSTYPE_ATHEOS => 'AtheOS'.freeze
|
62
62
|
}.freeze
|
63
63
|
end
|
@@ -12,7 +12,7 @@ module Zip
|
|
12
12
|
class NullEncrypter < Encrypter
|
13
13
|
include NullEncryption
|
14
14
|
|
15
|
-
def header(
|
15
|
+
def header(_mtime)
|
16
16
|
''
|
17
17
|
end
|
18
18
|
|
@@ -20,7 +20,7 @@ module Zip
|
|
20
20
|
data
|
21
21
|
end
|
22
22
|
|
23
|
-
def data_descriptor(
|
23
|
+
def data_descriptor(_crc32, _compressed_size, _uncomprssed_size)
|
24
24
|
''
|
25
25
|
end
|
26
26
|
|
@@ -35,7 +35,7 @@ module Zip
|
|
35
35
|
data
|
36
36
|
end
|
37
37
|
|
38
|
-
def reset!(
|
38
|
+
def reset!(_header)
|
39
39
|
end
|
40
40
|
end
|
41
41
|
end
|
@@ -26,7 +26,7 @@ module Zip
|
|
26
26
|
|
27
27
|
def update_keys(n)
|
28
28
|
@key0 = ~Zlib.crc32(n, ~@key0)
|
29
|
-
@key1 = ((@key1 + (@key0 & 0xff)) *
|
29
|
+
@key1 = ((@key1 + (@key0 & 0xff)) * 134_775_813 + 1) & 0xffffffff
|
30
30
|
@key2 = ~Zlib.crc32((@key1 >> 24).chr, ~@key2)
|
31
31
|
end
|
32
32
|
|
@@ -46,15 +46,15 @@ module Zip
|
|
46
46
|
end
|
47
47
|
header << (mtime.to_binary_dos_time & 0xff)
|
48
48
|
header << (mtime.to_binary_dos_time >> 8)
|
49
|
-
end.map{|x| encode x}.pack(
|
49
|
+
end.map { |x| encode x }.pack('C*')
|
50
50
|
end
|
51
51
|
|
52
52
|
def encrypt(data)
|
53
|
-
data.unpack(
|
53
|
+
data.unpack('C*').map { |x| encode x }.pack('C*')
|
54
54
|
end
|
55
55
|
|
56
56
|
def data_descriptor(crc32, compressed_size, uncomprssed_size)
|
57
|
-
[0x08074b50, crc32, compressed_size, uncomprssed_size].pack(
|
57
|
+
[0x08074b50, crc32, compressed_size, uncomprssed_size].pack('VVVV')
|
58
58
|
end
|
59
59
|
|
60
60
|
def reset!
|
@@ -74,7 +74,7 @@ module Zip
|
|
74
74
|
include TraditionalEncryption
|
75
75
|
|
76
76
|
def decrypt(data)
|
77
|
-
data.unpack(
|
77
|
+
data.unpack('C*').map { |x| decode x }.pack('C*')
|
78
78
|
end
|
79
79
|
|
80
80
|
def reset!(header)
|
data/lib/zip/decompressor.rb
CHANGED
data/lib/zip/deflater.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
module Zip
|
2
2
|
class Deflater < Compressor #:nodoc:all
|
3
|
-
|
4
3
|
def initialize(output_stream, level = Zip.default_compression, encrypter = NullEncrypter.new)
|
5
4
|
super()
|
6
5
|
@output_stream = output_stream
|
@@ -8,18 +7,21 @@ module Zip
|
|
8
7
|
@size = 0
|
9
8
|
@crc = ::Zlib.crc32
|
10
9
|
@encrypter = encrypter
|
11
|
-
@buffer_stream = ::StringIO.new('')
|
12
10
|
end
|
13
11
|
|
14
|
-
def <<
|
12
|
+
def <<(data)
|
15
13
|
val = data.to_s
|
16
|
-
@crc = Zlib
|
14
|
+
@crc = Zlib.crc32(val, @crc)
|
17
15
|
@size += val.bytesize
|
18
|
-
|
16
|
+
buffer = @zlib_deflater.deflate(data)
|
17
|
+
if buffer.empty?
|
18
|
+
@output_stream
|
19
|
+
else
|
20
|
+
@output_stream << @encrypter.encrypt(buffer)
|
21
|
+
end
|
19
22
|
end
|
20
23
|
|
21
24
|
def finish
|
22
|
-
@output_stream << @encrypter.encrypt(@buffer_stream.string)
|
23
25
|
@output_stream << @encrypter.encrypt(@zlib_deflater.finish) until @zlib_deflater.finished?
|
24
26
|
end
|
25
27
|
|