rubyzip 1.2.0 → 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 +7 -9
- data/lib/zip/entry.rb +7 -1
- data/lib/zip/entry_set.rb +1 -1
- data/lib/zip/file.rb +17 -26
- data/lib/zip/ioextras/abstract_output_stream.rb +2 -2
- data/lib/zip/version.rb +1 -1
- data/samples/example_recursive.rb +2 -4
- data/test/central_directory_entry_test.rb +1 -1
- data/test/crypto/null_encryption_test.rb +6 -2
- data/test/entry_set_test.rb +13 -2
- data/test/entry_test.rb +3 -12
- data/test/file_permissions_test.rb +33 -33
- data/test/file_test.rb +23 -3
- data/test/filesystem/file_nonmutating_test.rb +3 -3
- data/test/filesystem/file_stat_test.rb +1 -1
- data/test/gentestfiles.rb +4 -0
- data/test/input_stream_test.rb +4 -4
- data/test/ioextras/abstract_input_stream_test.rb +1 -1
- data/test/ioextras/fake_io_test.rb +1 -1
- data/test/local_entry_test.rb +1 -1
- data/test/test_helper.rb +14 -1
- metadata +3 -3
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
@@ -62,20 +62,18 @@ 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
79
|
def initialize(input_dir, output_file)
|
@@ -117,7 +115,7 @@ class ZipFileGenerator
|
|
117
115
|
|
118
116
|
def put_into_archive(disk_file_path, io, zip_file_path)
|
119
117
|
io.get_output_stream(zip_file_path) do |f|
|
120
|
-
f.
|
118
|
+
f.write(File.open(disk_file_path, 'rb').read)
|
121
119
|
end
|
122
120
|
end
|
123
121
|
end
|
@@ -218,7 +216,7 @@ buffer = Zip::OutputStream.write_buffer do |out|
|
|
218
216
|
out.write rels.to_xml(:indent => 0).gsub("\n","")
|
219
217
|
end
|
220
218
|
|
221
|
-
File.open(new_path, "
|
219
|
+
File.open(new_path, "wb") {|f| f.write(buffer.string) }
|
222
220
|
```
|
223
221
|
|
224
222
|
## Configuration
|
data/lib/zip/entry.rb
CHANGED
@@ -7,6 +7,7 @@ module Zip
|
|
7
7
|
|
8
8
|
attr_accessor :comment, :compressed_size, :crc, :extra, :compression_method,
|
9
9
|
:name, :size, :local_header_offset, :zipfile, :fstype, :external_file_attributes,
|
10
|
+
:internal_file_attributes,
|
10
11
|
:gp_flags, :header_signature, :follow_symlinks,
|
11
12
|
:restore_times, :restore_permissions, :restore_ownership,
|
12
13
|
:unix_uid, :unix_gid, :unix_perms,
|
@@ -149,6 +150,11 @@ module Zip
|
|
149
150
|
def extract(dest_path = @name, &block)
|
150
151
|
block ||= proc { ::Zip.on_exists_proc }
|
151
152
|
|
153
|
+
if @name.squeeze('/') =~ /\.{2}(?:\/|\z)/
|
154
|
+
puts "WARNING: skipped \"../\" path component(s) in #{@name}"
|
155
|
+
return self
|
156
|
+
end
|
157
|
+
|
152
158
|
if directory? || file? || symlink?
|
153
159
|
__send__("create_#{@ftype}", dest_path, &block)
|
154
160
|
else
|
@@ -357,7 +363,7 @@ module Zip
|
|
357
363
|
unpack_c_dir_entry(static_sized_fields_buf)
|
358
364
|
check_c_dir_entry_signature
|
359
365
|
set_time(@last_mod_date, @last_mod_time)
|
360
|
-
@name = io.read(@name_length)
|
366
|
+
@name = io.read(@name_length)
|
361
367
|
read_c_dir_extra_field(io)
|
362
368
|
@comment = io.read(@comment_length)
|
363
369
|
check_c_dir_entry_comment_size
|
data/lib/zip/entry_set.rb
CHANGED
@@ -57,7 +57,7 @@ module Zip
|
|
57
57
|
@entry_set[to_key(entry.parent_as_string)]
|
58
58
|
end
|
59
59
|
|
60
|
-
def glob(pattern, flags = ::File::FNM_PATHNAME | ::File::FNM_DOTMATCH)
|
60
|
+
def glob(pattern, flags = ::File::FNM_PATHNAME | ::File::FNM_DOTMATCH | ::File::FNM_EXTGLOB)
|
61
61
|
entries.map do |entry|
|
62
62
|
next nil unless ::File.fnmatch(pattern, entry.name.chomp('/'), flags)
|
63
63
|
yield(entry) if block_given?
|
data/lib/zip/file.rb
CHANGED
@@ -43,7 +43,7 @@ module Zip
|
|
43
43
|
# interface for accessing the filesystem, ie. the File and Dir classes.
|
44
44
|
|
45
45
|
class File < CentralDirectory
|
46
|
-
CREATE =
|
46
|
+
CREATE = true
|
47
47
|
SPLIT_SIGNATURE = 0x08074b50
|
48
48
|
ZIP64_EOCD_SIGNATURE = 0x06064b50
|
49
49
|
MAX_SEGMENT_SIZE = 3_221_225_472
|
@@ -64,20 +64,19 @@ module Zip
|
|
64
64
|
|
65
65
|
# Opens a zip archive. Pass true as the second parameter to create
|
66
66
|
# a new archive if it doesn't exist already.
|
67
|
-
def initialize(file_name, create =
|
67
|
+
def initialize(file_name, create = false, buffer = false, options = {})
|
68
68
|
super()
|
69
69
|
@name = file_name
|
70
70
|
@comment = ''
|
71
|
-
@create = create
|
71
|
+
@create = create ? true : false # allow any truthy value to mean true
|
72
72
|
case
|
73
73
|
when !buffer && ::File.size?(file_name)
|
74
|
-
@create =
|
74
|
+
@create = false
|
75
75
|
@file_permissions = ::File.stat(file_name).mode
|
76
76
|
::File.open(name, 'rb') do |f|
|
77
77
|
read_from_stream(f)
|
78
78
|
end
|
79
|
-
when create
|
80
|
-
@file_permissions = create_file_permissions
|
79
|
+
when @create
|
81
80
|
@entry_set = EntrySet.new
|
82
81
|
when ::File.zero?(file_name)
|
83
82
|
raise Error, "File #{file_name} has zero size. Did you mean to pass the create flag?"
|
@@ -95,7 +94,7 @@ module Zip
|
|
95
94
|
# Same as #new. If a block is passed the ZipFile object is passed
|
96
95
|
# to the block and is automatically closed afterwards just as with
|
97
96
|
# ruby's builtin File.open method.
|
98
|
-
def open(file_name, create =
|
97
|
+
def open(file_name, create = false)
|
99
98
|
zf = ::Zip::File.new(file_name, create)
|
100
99
|
return zf unless block_given?
|
101
100
|
begin
|
@@ -130,6 +129,7 @@ module Zip
|
|
130
129
|
end
|
131
130
|
zf = ::Zip::File.new(io, true, true, options)
|
132
131
|
zf.read_from_stream(io)
|
132
|
+
return zf unless block_given?
|
133
133
|
yield zf
|
134
134
|
begin
|
135
135
|
zf.write_buffer(io)
|
@@ -340,7 +340,7 @@ module Zip
|
|
340
340
|
@entry_set.each do |e|
|
341
341
|
return true if e.dirty
|
342
342
|
end
|
343
|
-
@comment != @stored_comment || @entry_set != @stored_entries || @create
|
343
|
+
@comment != @stored_comment || @entry_set != @stored_entries || @create
|
344
344
|
end
|
345
345
|
|
346
346
|
# Searches for entry with the specified name. Returns nil if
|
@@ -403,27 +403,18 @@ module Zip
|
|
403
403
|
end
|
404
404
|
|
405
405
|
def on_success_replace
|
406
|
-
tmp_filename = create_tmpname
|
407
|
-
if yield tmp_filename
|
408
|
-
::File.rename(tmp_filename, name)
|
409
|
-
::File.chmod(@file_permissions, name) if defined?(@file_permissions)
|
410
|
-
end
|
411
|
-
ensure
|
412
|
-
::File.unlink(tmp_filename) if ::File.exist?(tmp_filename)
|
413
|
-
end
|
414
|
-
|
415
|
-
def create_tmpname
|
416
406
|
dirname, basename = ::File.split(name)
|
417
|
-
::Dir::Tmpname.create(basename, dirname) do |
|
418
|
-
|
419
|
-
|
420
|
-
|
407
|
+
::Dir::Tmpname.create(basename, dirname) do |tmp_filename|
|
408
|
+
begin
|
409
|
+
if yield tmp_filename
|
410
|
+
::File.rename(tmp_filename, name)
|
411
|
+
::File.chmod(@file_permissions, name) unless @create
|
412
|
+
end
|
413
|
+
ensure
|
414
|
+
::File.unlink(tmp_filename) if ::File.exist?(tmp_filename)
|
415
|
+
end
|
421
416
|
end
|
422
417
|
end
|
423
|
-
|
424
|
-
def create_file_permissions
|
425
|
-
::Zip::RUNNING_ON_WINDOWS ? 0644 : 0666 - ::File.umask
|
426
|
-
end
|
427
418
|
end
|
428
419
|
end
|
429
420
|
|
@@ -20,12 +20,12 @@ module Zip
|
|
20
20
|
|
21
21
|
def putc(an_object)
|
22
22
|
self << case an_object
|
23
|
-
when
|
23
|
+
when Integer
|
24
24
|
an_object.chr
|
25
25
|
when String
|
26
26
|
an_object
|
27
27
|
else
|
28
|
-
raise TypeError, 'putc: Only
|
28
|
+
raise TypeError, 'putc: Only Integer and String supported'
|
29
29
|
end
|
30
30
|
an_object
|
31
31
|
end
|
data/lib/zip/version.rb
CHANGED
@@ -6,7 +6,7 @@ require 'zip'
|
|
6
6
|
# included in the archive, rather just its contents.
|
7
7
|
#
|
8
8
|
# Usage:
|
9
|
-
#
|
9
|
+
# directory_to_zip = "/tmp/input"
|
10
10
|
# output_file = "/tmp/out.zip"
|
11
11
|
# zf = ZipFileGenerator.new(directory_to_zip, output_file)
|
12
12
|
# zf.write()
|
@@ -50,8 +50,6 @@ class ZipFileGenerator
|
|
50
50
|
end
|
51
51
|
|
52
52
|
def put_into_archive(disk_file_path, io, zip_file_path)
|
53
|
-
io.
|
54
|
-
f.write(File.open(disk_file_path, 'rb').read)
|
55
|
-
end
|
53
|
+
io.add(zip_file_path, disk_file_path)
|
56
54
|
end
|
57
55
|
end
|
@@ -37,7 +37,7 @@ class ZipCentralDirectoryEntryTest < MiniTest::Test
|
|
37
37
|
assert_equal('', entry.comment)
|
38
38
|
|
39
39
|
entry = ::Zip::Entry.read_c_dir_entry(file)
|
40
|
-
|
40
|
+
assert_nil(entry)
|
41
41
|
# Fields that are not check by this test:
|
42
42
|
# version made by 2 bytes
|
43
43
|
# version needed to extract 2 bytes
|
@@ -18,7 +18,9 @@ class NullEncrypterTest < MiniTest::Test
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def test_encrypt
|
21
|
-
|
21
|
+
assert_nil @encrypter.encrypt(nil)
|
22
|
+
|
23
|
+
['', 'a' * 10, 0xffffffff].each do |data|
|
22
24
|
assert_equal data, @encrypter.encrypt(data)
|
23
25
|
end
|
24
26
|
end
|
@@ -42,7 +44,9 @@ class NullDecrypterTest < MiniTest::Test
|
|
42
44
|
end
|
43
45
|
|
44
46
|
def test_decrypt
|
45
|
-
|
47
|
+
assert_nil @decrypter.decrypt(nil)
|
48
|
+
|
49
|
+
['', 'a' * 10, 0xffffffff].each do |data|
|
46
50
|
assert_equal data, @decrypter.decrypt(data)
|
47
51
|
end
|
48
52
|
end
|
data/test/entry_set_test.rb
CHANGED
@@ -76,7 +76,7 @@ class ZipEntrySetTest < MiniTest::Test
|
|
76
76
|
::Zip.case_insensitive_match = false
|
77
77
|
zipEntrySet = ::Zip::EntrySet.new(entries)
|
78
78
|
assert_equal(entries[0], zipEntrySet.find_entry('MiXeDcAsEnAmE'))
|
79
|
-
|
79
|
+
assert_nil(zipEntrySet.find_entry('mixedcasename'))
|
80
80
|
end
|
81
81
|
|
82
82
|
def test_entries_with_sort
|
@@ -123,7 +123,7 @@ class ZipEntrySetTest < MiniTest::Test
|
|
123
123
|
]
|
124
124
|
entrySet = ::Zip::EntrySet.new(entries)
|
125
125
|
|
126
|
-
|
126
|
+
assert_nil(entrySet.parent(entries[0]))
|
127
127
|
assert_equal(entries[0], entrySet.parent(entries[1]))
|
128
128
|
assert_equal(entries[1], entrySet.parent(entries[2]))
|
129
129
|
end
|
@@ -149,4 +149,15 @@ class ZipEntrySetTest < MiniTest::Test
|
|
149
149
|
# assert_equal(entries.size, res.size)
|
150
150
|
# assert_equal(entrySet.map { |e| e.name }, res.map { |e| e.name })
|
151
151
|
end
|
152
|
+
|
153
|
+
def test_glob3
|
154
|
+
entries = [
|
155
|
+
::Zip::Entry.new('zf.zip', 'a/a'),
|
156
|
+
::Zip::Entry.new('zf.zip', 'a/b'),
|
157
|
+
::Zip::Entry.new('zf.zip', 'a/c')
|
158
|
+
]
|
159
|
+
entrySet = ::Zip::EntrySet.new(entries)
|
160
|
+
|
161
|
+
assert_equal(entries[0, 2].sort, entrySet.glob('a/{a,b}').sort)
|
162
|
+
end
|
152
163
|
end
|
data/test/entry_test.rb
CHANGED
@@ -1,16 +1,7 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
3
|
class ZipEntryTest < MiniTest::Test
|
4
|
-
|
5
|
-
TEST_COMMENT = 'a comment'
|
6
|
-
TEST_COMPRESSED_SIZE = 1234
|
7
|
-
TEST_CRC = 325_324
|
8
|
-
TEST_EXTRA = 'Some data here'
|
9
|
-
TEST_COMPRESSIONMETHOD = ::Zip::Entry::DEFLATED
|
10
|
-
TEST_NAME = 'entry name'
|
11
|
-
TEST_SIZE = 8432
|
12
|
-
TEST_ISDIRECTORY = false
|
13
|
-
TEST_TIME = Time.now
|
4
|
+
include ZipEntryData
|
14
5
|
|
15
6
|
def test_constructor_and_getters
|
16
7
|
entry = ::Zip::Entry.new(TEST_ZIPFILE,
|
@@ -118,8 +109,8 @@ class ZipEntryTest < MiniTest::Test
|
|
118
109
|
entry5 = ::Zip::Entry.new('zf.zip', 'aa/bb/cc')
|
119
110
|
entry6 = ::Zip::Entry.new('zf.zip', 'aa/bb/cc/')
|
120
111
|
|
121
|
-
|
122
|
-
|
112
|
+
assert_nil(entry1.parent_as_string)
|
113
|
+
assert_nil(entry2.parent_as_string)
|
123
114
|
assert_equal('aa/', entry3.parent_as_string)
|
124
115
|
assert_equal('aa/', entry4.parent_as_string)
|
125
116
|
assert_equal('aa/bb/', entry5.parent_as_string)
|
@@ -2,58 +2,58 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
class FilePermissionsTest < MiniTest::Test
|
4
4
|
|
5
|
-
|
5
|
+
ZIPNAME = File.join(File.dirname(__FILE__), "umask.zip")
|
6
|
+
FILENAME = File.join(File.dirname(__FILE__), "umask.txt")
|
6
7
|
|
7
8
|
def teardown
|
9
|
+
::File.unlink(ZIPNAME)
|
8
10
|
::File.unlink(FILENAME)
|
9
11
|
end
|
10
12
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
def test_windows_perms
|
17
|
-
create_file
|
13
|
+
def test_current_umask
|
14
|
+
create_files
|
15
|
+
assert_matching_permissions FILENAME, ZIPNAME
|
16
|
+
end
|
18
17
|
|
19
|
-
|
18
|
+
def test_umask_000
|
19
|
+
set_umask(0000) do
|
20
|
+
create_files
|
20
21
|
end
|
21
22
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
DEFAULT_PERMS = 0100666
|
26
|
-
|
27
|
-
def test_current_umask
|
28
|
-
umask = DEFAULT_PERMS - ::File.umask
|
29
|
-
create_file
|
23
|
+
assert_matching_permissions FILENAME, ZIPNAME
|
24
|
+
end
|
30
25
|
|
31
|
-
|
26
|
+
def test_umask_066
|
27
|
+
set_umask(0066) do
|
28
|
+
create_files
|
32
29
|
end
|
33
30
|
|
34
|
-
|
35
|
-
|
36
|
-
create_file
|
37
|
-
end
|
31
|
+
assert_matching_permissions FILENAME, ZIPNAME
|
32
|
+
end
|
38
33
|
|
39
|
-
|
34
|
+
def test_umask_027
|
35
|
+
set_umask(0027) do
|
36
|
+
create_files
|
40
37
|
end
|
41
38
|
|
42
|
-
|
43
|
-
|
44
|
-
set_umask(umask) do
|
45
|
-
create_file
|
46
|
-
end
|
47
|
-
|
48
|
-
assert_equal((DEFAULT_PERMS - umask), ::File.stat(FILENAME).mode)
|
49
|
-
end
|
39
|
+
assert_matching_permissions FILENAME, ZIPNAME
|
40
|
+
end
|
50
41
|
|
42
|
+
def assert_matching_permissions(expected_file, actual_file)
|
43
|
+
assert_equal(
|
44
|
+
::File.stat(expected_file).mode.to_s(8).rjust(4, '0'),
|
45
|
+
::File.stat(actual_file).mode.to_s(8).rjust(4, '0')
|
46
|
+
)
|
51
47
|
end
|
52
48
|
|
53
|
-
def
|
54
|
-
::Zip::File.open(
|
49
|
+
def create_files
|
50
|
+
::Zip::File.open(ZIPNAME, ::Zip::File::CREATE) do |zip|
|
55
51
|
zip.comment = "test"
|
56
52
|
end
|
53
|
+
|
54
|
+
::File.open(FILENAME, 'w') do |file|
|
55
|
+
file << 'test'
|
56
|
+
end
|
57
57
|
end
|
58
58
|
|
59
59
|
# If anything goes wrong, make sure the umask is restored.
|
data/test/file_test.rb
CHANGED
@@ -2,6 +2,7 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
class ZipFileTest < MiniTest::Test
|
4
4
|
include CommonZipFileFixture
|
5
|
+
include ZipEntryData
|
5
6
|
|
6
7
|
OK_DELETE_FILE = 'test/data/generated/okToDelete.txt'
|
7
8
|
OK_DELETE_MOVED_FILE = 'test/data/generated/okToDeleteMoved.txt'
|
@@ -40,6 +41,20 @@ class ZipFileTest < MiniTest::Test
|
|
40
41
|
assert_equal(2, zfRead.entries.length)
|
41
42
|
end
|
42
43
|
|
44
|
+
def test_create_from_scratch_with_old_create_parameter
|
45
|
+
comment = 'a short comment'
|
46
|
+
|
47
|
+
zf = ::Zip::File.new(EMPTY_FILENAME, 1)
|
48
|
+
zf.get_output_stream('myFile') { |os| os.write 'myFile contains just this' }
|
49
|
+
zf.mkdir('dir1')
|
50
|
+
zf.comment = comment
|
51
|
+
zf.close
|
52
|
+
|
53
|
+
zfRead = ::Zip::File.new(EMPTY_FILENAME)
|
54
|
+
assert_equal(comment, zfRead.comment)
|
55
|
+
assert_equal(2, zfRead.entries.length)
|
56
|
+
end
|
57
|
+
|
43
58
|
def test_get_output_stream
|
44
59
|
entryCount = nil
|
45
60
|
::Zip::File.open(TEST_ZIP.zip_name) do |zf|
|
@@ -56,7 +71,7 @@ class ZipFileTest < MiniTest::Test
|
|
56
71
|
assert_equal(entryCount + 1, zf.size)
|
57
72
|
assert_equal('Putting stuff in data/generated/empty.txt', zf.read('test/data/generated/empty.txt'))
|
58
73
|
|
59
|
-
custom_entry_args = [
|
74
|
+
custom_entry_args = [TEST_COMMENT, TEST_EXTRA, TEST_COMPRESSED_SIZE, TEST_CRC, ::Zip::Entry::STORED, TEST_SIZE, TEST_TIME]
|
60
75
|
zf.get_output_stream('entry_with_custom_args.txt', nil, *custom_entry_args) do |os|
|
61
76
|
os.write 'Some data'
|
62
77
|
end
|
@@ -89,6 +104,12 @@ class ZipFileTest < MiniTest::Test
|
|
89
104
|
end
|
90
105
|
end
|
91
106
|
|
107
|
+
def test_open_buffer_without_block
|
108
|
+
string_io = StringIO.new File.read('test/data/rubycode.zip')
|
109
|
+
zf = ::Zip::File.open_buffer string_io
|
110
|
+
assert zf.entries.map { |e| e.name }.include?('zippedruby1.rb')
|
111
|
+
end
|
112
|
+
|
92
113
|
def test_cleans_up_tempfiles_after_close
|
93
114
|
zf = ::Zip::File.new(EMPTY_FILENAME, ::Zip::File::CREATE)
|
94
115
|
zf.get_output_stream('myFile') do |os|
|
@@ -528,9 +549,8 @@ class ZipFileTest < MiniTest::Test
|
|
528
549
|
end
|
529
550
|
|
530
551
|
def test_empty_zip
|
531
|
-
puts `touch empty.zip`
|
532
552
|
assert_raises(::Zip::Error) do
|
533
|
-
::Zip::File.open(
|
553
|
+
::Zip::File.open(TestFiles::NULL_FILE)
|
534
554
|
end
|
535
555
|
end
|
536
556
|
|
@@ -103,12 +103,12 @@ class ZipFsFileNonmutatingTest < MiniTest::Test
|
|
103
103
|
end
|
104
104
|
|
105
105
|
def test_size?
|
106
|
-
|
106
|
+
assert_nil(@zip_file.file.size?('notAFile'))
|
107
107
|
assert_equal(72, @zip_file.file.size?('file1'))
|
108
|
-
|
108
|
+
assert_nil(@zip_file.file.size?('dir2/dir21'))
|
109
109
|
|
110
110
|
assert_equal(72, @zip_file.file.stat('file1').size?)
|
111
|
-
|
111
|
+
assert_nil(@zip_file.file.stat('dir2/dir21').size?)
|
112
112
|
end
|
113
113
|
|
114
114
|
def test_file?
|
data/test/gentestfiles.rb
CHANGED
@@ -9,6 +9,8 @@ class TestFiles
|
|
9
9
|
RANDOM_BINARY_FILE1 = 'test/data/generated/randomBinary1.bin'
|
10
10
|
RANDOM_BINARY_FILE2 = 'test/data/generated/randomBinary2.bin'
|
11
11
|
|
12
|
+
NULL_FILE = 'test/data/generated/null.zip' # Zero length, so not a zip file.
|
13
|
+
|
12
14
|
EMPTY_TEST_DIR = 'test/data/generated/emptytestdir'
|
13
15
|
|
14
16
|
ASCII_TEST_FILES = [RANDOM_ASCII_FILE1, RANDOM_ASCII_FILE2, RANDOM_ASCII_FILE3]
|
@@ -28,6 +30,8 @@ class TestFiles
|
|
28
30
|
create_random_binary(filename, 1E4 * (index + 1))
|
29
31
|
end
|
30
32
|
|
33
|
+
system("touch #{NULL_FILE}")
|
34
|
+
|
31
35
|
ensure_dir(EMPTY_TEST_DIR)
|
32
36
|
end
|
33
37
|
|
data/test/input_stream_test.rb
CHANGED
@@ -75,12 +75,12 @@ class ZipInputStreamTest < MiniTest::Test
|
|
75
75
|
entry = zis.get_next_entry # empty.txt
|
76
76
|
assert_equal(TestZipFile::TEST_ZIP2.entry_names[1], entry.name)
|
77
77
|
assert_equal(0, entry.size)
|
78
|
-
|
78
|
+
assert_nil(zis.gets)
|
79
79
|
assert_equal(true, zis.eof?)
|
80
80
|
entry = zis.get_next_entry # empty_chmod640.txt
|
81
81
|
assert_equal(TestZipFile::TEST_ZIP2.entry_names[2], entry.name)
|
82
82
|
assert_equal(0, entry.size)
|
83
|
-
|
83
|
+
assert_nil(zis.gets)
|
84
84
|
assert_equal(true, zis.eof?)
|
85
85
|
entry = zis.get_next_entry # short.txt
|
86
86
|
assert_equal(TestZipFile::TEST_ZIP2.entry_names[3], entry.name)
|
@@ -102,12 +102,12 @@ class ZipInputStreamTest < MiniTest::Test
|
|
102
102
|
entry = zis.get_next_entry # empty.txt
|
103
103
|
assert_equal(TestZipFile::TEST_ZIP2.entry_names[1], entry.name)
|
104
104
|
assert_equal(0, entry.size)
|
105
|
-
|
105
|
+
assert_nil(zis.gets)
|
106
106
|
assert_equal(true, zis.eof?)
|
107
107
|
entry = zis.get_next_entry # empty_chmod640.txt
|
108
108
|
assert_equal(TestZipFile::TEST_ZIP2.entry_names[2], entry.name)
|
109
109
|
assert_equal(0, entry.size)
|
110
|
-
|
110
|
+
assert_nil(zis.gets)
|
111
111
|
assert_equal(true, zis.eof?)
|
112
112
|
entry = zis.get_next_entry # short.txt
|
113
113
|
assert_equal(TestZipFile::TEST_ZIP2.entry_names[3], entry.name)
|
data/test/local_entry_test.rb
CHANGED
@@ -36,7 +36,7 @@ class ZipLocalEntryTest < MiniTest::Test
|
|
36
36
|
|
37
37
|
def test_read_local_entry_from_non_zip_file
|
38
38
|
::File.open('test/data/file2.txt') do |file|
|
39
|
-
|
39
|
+
assert_nil(::Zip::Entry.read_local_entry(file))
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
data/test/test_helper.rb
CHANGED
@@ -134,7 +134,7 @@ module AssertEntry
|
|
134
134
|
testZipFile.entry_names.each do |entryName|
|
135
135
|
assert_next_entry(entryName, zis)
|
136
136
|
end
|
137
|
-
|
137
|
+
assert_nil(zis.get_next_entry)
|
138
138
|
end
|
139
139
|
|
140
140
|
def assert_test_zip_contents(testZipFile)
|
@@ -219,3 +219,16 @@ module ExtraAssertions
|
|
219
219
|
anObject.instance_eval "undef #{method}; alias #{method} #{method}_org"
|
220
220
|
end
|
221
221
|
end
|
222
|
+
|
223
|
+
module ZipEntryData
|
224
|
+
TEST_ZIPFILE = 'someZipFile.zip'
|
225
|
+
TEST_COMMENT = 'a comment'
|
226
|
+
TEST_COMPRESSED_SIZE = 1234
|
227
|
+
TEST_CRC = 325_324
|
228
|
+
TEST_EXTRA = 'Some data here'
|
229
|
+
TEST_COMPRESSIONMETHOD = ::Zip::Entry::DEFLATED
|
230
|
+
TEST_NAME = 'entry name'
|
231
|
+
TEST_SIZE = 8432
|
232
|
+
TEST_ISDIRECTORY = false
|
233
|
+
TEST_TIME = Time.now
|
234
|
+
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.
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Simonov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-02-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -197,7 +197,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
197
197
|
version: '0'
|
198
198
|
requirements: []
|
199
199
|
rubyforge_project:
|
200
|
-
rubygems_version: 2.
|
200
|
+
rubygems_version: 2.5.1
|
201
201
|
signing_key:
|
202
202
|
specification_version: 4
|
203
203
|
summary: rubyzip is a ruby module for reading and writing zip files
|