rubyzip 0.9.9 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +284 -41
- data/Rakefile +11 -6
- data/TODO +0 -1
- data/lib/zip/central_directory.rb +208 -0
- data/lib/zip/compressor.rb +1 -2
- data/lib/zip/constants.rb +59 -7
- data/lib/zip/crypto/encryption.rb +11 -0
- data/lib/zip/crypto/null_encryption.rb +43 -0
- data/lib/zip/crypto/traditional_encryption.rb +99 -0
- data/lib/zip/decompressor.rb +4 -4
- data/lib/zip/deflater.rb +17 -13
- data/lib/zip/dos_time.rb +13 -14
- data/lib/zip/entry.rb +700 -0
- data/lib/zip/entry_set.rb +86 -0
- data/lib/zip/errors.rb +18 -0
- data/lib/zip/extra_field/generic.rb +43 -0
- data/lib/zip/extra_field/ntfs.rb +90 -0
- data/lib/zip/extra_field/old_unix.rb +44 -0
- data/lib/zip/extra_field/universal_time.rb +47 -0
- data/lib/zip/extra_field/unix.rb +37 -0
- data/lib/zip/extra_field/zip64.rb +68 -0
- data/lib/zip/extra_field/zip64_placeholder.rb +15 -0
- data/lib/zip/extra_field.rb +101 -0
- data/lib/zip/file.rb +443 -0
- data/lib/zip/{zipfilesystem.rb → filesystem.rb} +162 -157
- data/lib/zip/inflater.rb +29 -28
- data/lib/zip/input_stream.rb +173 -0
- data/lib/zip/ioextras/abstract_input_stream.rb +111 -0
- data/lib/zip/ioextras/abstract_output_stream.rb +43 -0
- data/lib/zip/ioextras.rb +21 -149
- data/lib/zip/null_compressor.rb +2 -2
- data/lib/zip/null_decompressor.rb +8 -6
- data/lib/zip/null_input_stream.rb +3 -2
- data/lib/zip/output_stream.rb +189 -0
- data/lib/zip/pass_thru_compressor.rb +6 -6
- data/lib/zip/pass_thru_decompressor.rb +19 -19
- data/lib/zip/{zip_streamable_directory.rb → streamable_directory.rb} +3 -3
- data/lib/zip/streamable_stream.rb +56 -0
- data/lib/zip/version.rb +3 -0
- data/lib/zip.rb +71 -0
- data/samples/example.rb +44 -32
- data/samples/example_filesystem.rb +16 -18
- data/samples/example_recursive.rb +33 -28
- data/samples/{gtkRubyzip.rb → gtk_ruby_zip.rb} +26 -28
- data/samples/qtzip.rb +22 -31
- data/samples/write_simple.rb +12 -13
- data/samples/zipfind.rb +31 -39
- data/test/basic_zip_file_test.rb +60 -0
- data/test/case_sensitivity_test.rb +69 -0
- data/test/central_directory_entry_test.rb +69 -0
- data/test/central_directory_test.rb +100 -0
- data/test/crypto/null_encryption_test.rb +57 -0
- data/test/crypto/traditional_encryption_test.rb +80 -0
- data/test/data/WarnInvalidDate.zip +0 -0
- data/test/data/file1.txt +46 -0
- data/test/data/file1.txt.deflatedData +0 -0
- data/test/data/file2.txt +1504 -0
- 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 +1 -0
- data/test/data/notzippedruby.rb +7 -0
- data/test/data/ntfs.zip +0 -0
- data/test/data/oddExtraField.zip +0 -0
- data/test/data/path_traversal/Makefile +10 -0
- data/test/data/path_traversal/jwilk/README.md +5 -0
- 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 +3 -0
- 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 +65 -0
- data/test/encryption_test.rb +42 -0
- data/test/entry_set_test.rb +163 -0
- data/test/entry_test.rb +154 -0
- data/test/errors_test.rb +35 -0
- data/test/extra_field_test.rb +76 -0
- data/test/file_extract_directory_test.rb +54 -0
- data/test/file_extract_test.rb +145 -0
- data/test/file_permissions_test.rb +65 -0
- data/test/file_split_test.rb +57 -0
- data/test/file_test.rb +666 -0
- data/test/filesystem/dir_iterator_test.rb +58 -0
- data/test/filesystem/directory_test.rb +139 -0
- data/test/filesystem/file_mutating_test.rb +87 -0
- data/test/filesystem/file_nonmutating_test.rb +508 -0
- data/test/filesystem/file_stat_test.rb +64 -0
- data/test/gentestfiles.rb +126 -0
- data/test/inflater_test.rb +14 -0
- data/test/input_stream_test.rb +182 -0
- data/test/ioextras/abstract_input_stream_test.rb +102 -0
- data/test/ioextras/abstract_output_stream_test.rb +106 -0
- data/test/ioextras/fake_io_test.rb +18 -0
- data/test/local_entry_test.rb +154 -0
- data/test/output_stream_test.rb +128 -0
- data/test/pass_thru_compressor_test.rb +30 -0
- data/test/pass_thru_decompressor_test.rb +14 -0
- data/test/path_traversal_test.rb +141 -0
- data/test/samples/example_recursive_test.rb +37 -0
- data/test/settings_test.rb +95 -0
- data/test/test_helper.rb +234 -0
- data/test/unicode_file_names_and_comments_test.rb +62 -0
- data/test/zip64_full_test.rb +51 -0
- data/test/zip64_support_test.rb +14 -0
- metadata +274 -41
- data/NEWS +0 -172
- data/lib/zip/settings.rb +0 -10
- data/lib/zip/tempfile_bugfixed.rb +0 -195
- data/lib/zip/zip.rb +0 -56
- data/lib/zip/zip_central_directory.rb +0 -135
- data/lib/zip/zip_entry.rb +0 -638
- data/lib/zip/zip_entry_set.rb +0 -77
- data/lib/zip/zip_extra_field.rb +0 -213
- data/lib/zip/zip_file.rb +0 -340
- data/lib/zip/zip_input_stream.rb +0 -144
- data/lib/zip/zip_output_stream.rb +0 -173
- data/lib/zip/zip_streamable_stream.rb +0 -47
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'zip/filesystem'
|
3
|
+
|
4
|
+
class ZipFsDirIteratorTest < MiniTest::Test
|
5
|
+
FILENAME_ARRAY = %w[f1 f2 f3 f4 f5 f6]
|
6
|
+
|
7
|
+
def setup
|
8
|
+
@dirIt = ::Zip::FileSystem::ZipFsDirIterator.new(FILENAME_ARRAY)
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_close
|
12
|
+
@dirIt.close
|
13
|
+
assert_raises(IOError, 'closed directory') do
|
14
|
+
@dirIt.each { |e| p e }
|
15
|
+
end
|
16
|
+
assert_raises(IOError, 'closed directory') do
|
17
|
+
@dirIt.read
|
18
|
+
end
|
19
|
+
assert_raises(IOError, 'closed directory') do
|
20
|
+
@dirIt.rewind
|
21
|
+
end
|
22
|
+
assert_raises(IOError, 'closed directory') do
|
23
|
+
@dirIt.seek(0)
|
24
|
+
end
|
25
|
+
assert_raises(IOError, 'closed directory') do
|
26
|
+
@dirIt.tell
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_each
|
31
|
+
# Tested through Enumerable.entries
|
32
|
+
assert_equal(FILENAME_ARRAY, @dirIt.entries)
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_read
|
36
|
+
FILENAME_ARRAY.size.times do |i|
|
37
|
+
assert_equal(FILENAME_ARRAY[i], @dirIt.read)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_rewind
|
42
|
+
@dirIt.read
|
43
|
+
@dirIt.read
|
44
|
+
assert_equal(FILENAME_ARRAY[2], @dirIt.read)
|
45
|
+
@dirIt.rewind
|
46
|
+
assert_equal(FILENAME_ARRAY[0], @dirIt.read)
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_tell_seek
|
50
|
+
@dirIt.read
|
51
|
+
@dirIt.read
|
52
|
+
pos = @dirIt.tell
|
53
|
+
valAtPos = @dirIt.read
|
54
|
+
@dirIt.read
|
55
|
+
@dirIt.seek(pos)
|
56
|
+
assert_equal(valAtPos, @dirIt.read)
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,139 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'zip/filesystem'
|
3
|
+
|
4
|
+
class ZipFsDirectoryTest < MiniTest::Test
|
5
|
+
TEST_ZIP = 'test/data/generated/zipWithDirs_copy.zip'
|
6
|
+
GLOB_TEST_ZIP = 'test/data/globTest.zip'
|
7
|
+
|
8
|
+
def setup
|
9
|
+
FileUtils.cp('test/data/zipWithDirs.zip', TEST_ZIP)
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_delete
|
13
|
+
::Zip::File.open(TEST_ZIP) do |zf|
|
14
|
+
assert_raises(Errno::ENOENT, 'No such file or directory - NoSuchFile.txt') do
|
15
|
+
zf.dir.delete('NoSuchFile.txt')
|
16
|
+
end
|
17
|
+
assert_raises(Errno::EINVAL, 'Invalid argument - file1') do
|
18
|
+
zf.dir.delete('file1')
|
19
|
+
end
|
20
|
+
assert(zf.file.exists?('dir1'))
|
21
|
+
zf.dir.delete('dir1')
|
22
|
+
assert(!zf.file.exists?('dir1'))
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_mkdir
|
27
|
+
::Zip::File.open(TEST_ZIP) do |zf|
|
28
|
+
assert_raises(Errno::EEXIST, 'File exists - dir1') do
|
29
|
+
zf.dir.mkdir('file1')
|
30
|
+
end
|
31
|
+
assert_raises(Errno::EEXIST, 'File exists - dir1') do
|
32
|
+
zf.dir.mkdir('dir1')
|
33
|
+
end
|
34
|
+
assert(!zf.file.exists?('newDir'))
|
35
|
+
zf.dir.mkdir('newDir')
|
36
|
+
assert(zf.file.directory?('newDir'))
|
37
|
+
assert(!zf.file.exists?('newDir2'))
|
38
|
+
zf.dir.mkdir('newDir2', 3485)
|
39
|
+
assert(zf.file.directory?('newDir2'))
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_pwd_chdir_entries
|
44
|
+
::Zip::File.open(TEST_ZIP) do |zf|
|
45
|
+
assert_equal('/', zf.dir.pwd)
|
46
|
+
|
47
|
+
assert_raises(Errno::ENOENT, 'No such file or directory - no such dir') do
|
48
|
+
zf.dir.chdir 'no such dir'
|
49
|
+
end
|
50
|
+
|
51
|
+
assert_raises(Errno::EINVAL, 'Invalid argument - file1') do
|
52
|
+
zf.dir.chdir 'file1'
|
53
|
+
end
|
54
|
+
|
55
|
+
assert_equal(%w[dir1 dir2 file1].sort, zf.dir.entries('.').sort)
|
56
|
+
zf.dir.chdir 'dir1'
|
57
|
+
assert_equal('/dir1', zf.dir.pwd)
|
58
|
+
assert_equal(%w[dir11 file11 file12], zf.dir.entries('.').sort)
|
59
|
+
|
60
|
+
zf.dir.chdir '../dir2/dir21'
|
61
|
+
assert_equal('/dir2/dir21', zf.dir.pwd)
|
62
|
+
assert_equal(['dir221'].sort, zf.dir.entries('.').sort)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_foreach
|
67
|
+
::Zip::File.open(TEST_ZIP) do |zf|
|
68
|
+
blockCalled = false
|
69
|
+
assert_raises(Errno::ENOENT, 'No such file or directory - noSuchDir') do
|
70
|
+
zf.dir.foreach('noSuchDir') { |_e| blockCalled = true }
|
71
|
+
end
|
72
|
+
assert(!blockCalled)
|
73
|
+
|
74
|
+
assert_raises(Errno::ENOTDIR, 'Not a directory - file1') do
|
75
|
+
zf.dir.foreach('file1') { |_e| blockCalled = true }
|
76
|
+
end
|
77
|
+
assert(!blockCalled)
|
78
|
+
|
79
|
+
entries = []
|
80
|
+
zf.dir.foreach('.') { |e| entries << e }
|
81
|
+
assert_equal(%w[dir1 dir2 file1].sort, entries.sort)
|
82
|
+
|
83
|
+
entries = []
|
84
|
+
zf.dir.foreach('dir1') { |e| entries << e }
|
85
|
+
assert_equal(%w[dir11 file11 file12], entries.sort)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_chroot
|
90
|
+
::Zip::File.open(TEST_ZIP) do |zf|
|
91
|
+
assert_raises(NotImplementedError) do
|
92
|
+
zf.dir.chroot
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_glob
|
98
|
+
globbed_files = [
|
99
|
+
'globTest/foo/bar/baz/foo.txt',
|
100
|
+
'globTest/foo.txt',
|
101
|
+
'globTest/food.txt'
|
102
|
+
]
|
103
|
+
|
104
|
+
::Zip::File.open(GLOB_TEST_ZIP) do |zf|
|
105
|
+
zf.dir.glob('**/*.txt') do |f|
|
106
|
+
assert globbed_files.include?(f.name)
|
107
|
+
end
|
108
|
+
|
109
|
+
zf.dir.glob('globTest/foo/**/*.txt') do |f|
|
110
|
+
assert_equal globbed_files[0], f.name
|
111
|
+
end
|
112
|
+
|
113
|
+
zf.dir.chdir('globTest/foo')
|
114
|
+
zf.dir.glob('**/*.txt') do |f|
|
115
|
+
assert_equal globbed_files[0], f.name
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
def test_open_new
|
121
|
+
::Zip::File.open(TEST_ZIP) do |zf|
|
122
|
+
assert_raises(Errno::ENOTDIR, 'Not a directory - file1') do
|
123
|
+
zf.dir.new('file1')
|
124
|
+
end
|
125
|
+
|
126
|
+
assert_raises(Errno::ENOENT, 'No such file or directory - noSuchFile') do
|
127
|
+
zf.dir.new('noSuchFile')
|
128
|
+
end
|
129
|
+
|
130
|
+
d = zf.dir.new('.')
|
131
|
+
assert_equal(%w[file1 dir1 dir2].sort, d.entries.sort)
|
132
|
+
d.close
|
133
|
+
|
134
|
+
zf.dir.open('dir1') do |dir|
|
135
|
+
assert_equal(%w[dir11 file11 file12].sort, dir.entries.sort)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'zip/filesystem'
|
3
|
+
|
4
|
+
class ZipFsFileMutatingTest < MiniTest::Test
|
5
|
+
TEST_ZIP = 'test/data/generated/zipWithDirs_copy.zip'
|
6
|
+
def setup
|
7
|
+
FileUtils.cp('test/data/zipWithDirs.zip', TEST_ZIP)
|
8
|
+
end
|
9
|
+
|
10
|
+
def teardown; end
|
11
|
+
|
12
|
+
def test_delete
|
13
|
+
do_test_delete_or_unlink(:delete)
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_unlink
|
17
|
+
do_test_delete_or_unlink(:unlink)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_open_write
|
21
|
+
::Zip::File.open(TEST_ZIP) do |zf|
|
22
|
+
zf.file.open('test_open_write_entry', 'w') do |f|
|
23
|
+
f.write "This is what I'm writing"
|
24
|
+
end
|
25
|
+
assert_equal("This is what I'm writing",
|
26
|
+
zf.file.read('test_open_write_entry'))
|
27
|
+
|
28
|
+
# Test with existing entry
|
29
|
+
zf.file.open('file1', 'wb') do |f| # also check that 'b' option is ignored
|
30
|
+
f.write "This is what I'm writing too"
|
31
|
+
end
|
32
|
+
assert_equal("This is what I'm writing too",
|
33
|
+
zf.file.read('file1'))
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_rename
|
38
|
+
::Zip::File.open(TEST_ZIP) do |zf|
|
39
|
+
assert_raises(Errno::ENOENT, '') do
|
40
|
+
zf.file.rename('NoSuchFile', 'bimse')
|
41
|
+
end
|
42
|
+
zf.file.rename('file1', 'newNameForFile1')
|
43
|
+
end
|
44
|
+
|
45
|
+
::Zip::File.open(TEST_ZIP) do |zf|
|
46
|
+
assert(!zf.file.exists?('file1'))
|
47
|
+
assert(zf.file.exists?('newNameForFile1'))
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_chmod
|
52
|
+
::Zip::File.open(TEST_ZIP) do |zf|
|
53
|
+
zf.file.chmod(0o765, 'file1')
|
54
|
+
end
|
55
|
+
|
56
|
+
::Zip::File.open(TEST_ZIP) do |zf|
|
57
|
+
assert_equal(0o100765, zf.file.stat('file1').mode)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def do_test_delete_or_unlink(symbol)
|
62
|
+
::Zip::File.open(TEST_ZIP) do |zf|
|
63
|
+
assert(zf.file.exists?('dir2/dir21/dir221/file2221'))
|
64
|
+
zf.file.send(symbol, 'dir2/dir21/dir221/file2221')
|
65
|
+
assert(!zf.file.exists?('dir2/dir21/dir221/file2221'))
|
66
|
+
|
67
|
+
assert(zf.file.exists?('dir1/file11'))
|
68
|
+
assert(zf.file.exists?('dir1/file12'))
|
69
|
+
zf.file.send(symbol, 'dir1/file11', 'dir1/file12')
|
70
|
+
assert(!zf.file.exists?('dir1/file11'))
|
71
|
+
assert(!zf.file.exists?('dir1/file12'))
|
72
|
+
|
73
|
+
assert_raises(Errno::ENOENT) { zf.file.send(symbol, 'noSuchFile') }
|
74
|
+
assert_raises(Errno::EISDIR) { zf.file.send(symbol, 'dir1/dir11') }
|
75
|
+
assert_raises(Errno::EISDIR) { zf.file.send(symbol, 'dir1/dir11/') }
|
76
|
+
end
|
77
|
+
|
78
|
+
::Zip::File.open(TEST_ZIP) do |zf|
|
79
|
+
assert(!zf.file.exists?('dir2/dir21/dir221/file2221'))
|
80
|
+
assert(!zf.file.exists?('dir1/file11'))
|
81
|
+
assert(!zf.file.exists?('dir1/file12'))
|
82
|
+
|
83
|
+
assert(zf.file.exists?('dir1/dir11'))
|
84
|
+
assert(zf.file.exists?('dir1/dir11/'))
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|