rubyzip 1.0.0 → 1.2.0
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 +6 -14
- data/README.md +173 -42
- data/Rakefile +10 -5
- data/TODO +0 -1
- data/lib/zip/central_directory.rb +55 -24
- data/lib/zip/compressor.rb +0 -0
- data/lib/zip/constants.rb +4 -2
- data/lib/zip/crypto/encryption.rb +11 -0
- data/lib/zip/crypto/null_encryption.rb +45 -0
- data/lib/zip/crypto/traditional_encryption.rb +99 -0
- data/lib/zip/decompressor.rb +2 -2
- data/lib/zip/deflater.rb +11 -6
- data/lib/zip/dos_time.rb +4 -5
- data/lib/zip/entry.rb +159 -97
- data/lib/zip/entry_set.rb +18 -18
- data/lib/zip/errors.rb +15 -6
- data/lib/zip/extra_field/generic.rb +8 -8
- 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 +14 -14
- data/lib/zip/extra_field/unix.rb +8 -9
- data/lib/zip/extra_field/zip64.rb +44 -6
- data/lib/zip/extra_field/zip64_placeholder.rb +16 -0
- data/lib/zip/extra_field.rb +20 -8
- data/lib/zip/file.rb +126 -114
- data/lib/zip/filesystem.rb +140 -139
- data/lib/zip/inflater.rb +10 -9
- data/lib/zip/input_stream.rb +105 -80
- data/lib/zip/ioextras/abstract_input_stream.rb +15 -12
- data/lib/zip/ioextras/abstract_output_stream.rb +0 -2
- data/lib/zip/ioextras.rb +1 -3
- data/lib/zip/null_compressor.rb +2 -2
- data/lib/zip/null_decompressor.rb +4 -4
- data/lib/zip/null_input_stream.rb +2 -1
- data/lib/zip/output_stream.rb +57 -43
- data/lib/zip/pass_thru_compressor.rb +4 -4
- data/lib/zip/pass_thru_decompressor.rb +4 -5
- data/lib/zip/streamable_directory.rb +2 -2
- data/lib/zip/streamable_stream.rb +22 -13
- data/lib/zip/version.rb +1 -1
- data/lib/zip.rb +11 -2
- data/samples/example.rb +30 -40
- data/samples/example_filesystem.rb +16 -18
- data/samples/example_recursive.rb +35 -27
- data/samples/{gtkRubyzip.rb → gtk_ruby_zip.rb} +25 -27
- data/samples/qtzip.rb +19 -28
- data/samples/write_simple.rb +12 -13
- data/samples/zipfind.rb +29 -37
- 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 +53 -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/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/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 +152 -0
- data/test/entry_test.rb +163 -0
- data/test/errors_test.rb +34 -0
- data/test/extra_field_test.rb +76 -0
- data/test/file_extract_directory_test.rb +54 -0
- data/test/file_extract_test.rb +83 -0
- data/test/file_permissions_test.rb +69 -0
- data/test/file_split_test.rb +57 -0
- data/test/file_test.rb +563 -0
- data/test/filesystem/dir_iterator_test.rb +58 -0
- data/test/filesystem/directory_test.rb +121 -0
- data/test/filesystem/file_mutating_test.rb +88 -0
- data/test/filesystem/file_nonmutating_test.rb +508 -0
- data/test/filesystem/file_stat_test.rb +64 -0
- data/test/gentestfiles.rb +122 -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/samples/example_recursive_test.rb +37 -0
- data/test/settings_test.rb +95 -0
- data/test/test_helper.rb +221 -0
- data/test/unicode_file_names_and_comments_test.rb +50 -0
- data/test/zip64_full_test.rb +51 -0
- data/test/zip64_support_test.rb +14 -0
- metadata +198 -22
- data/NEWS +0 -182
@@ -0,0 +1,83 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ZipFileExtractTest < MiniTest::Test
|
4
|
+
include CommonZipFileFixture
|
5
|
+
EXTRACTED_FILENAME = 'test/data/generated/extEntry'
|
6
|
+
ENTRY_TO_EXTRACT, *REMAINING_ENTRIES = TEST_ZIP.entry_names.reverse
|
7
|
+
|
8
|
+
def setup
|
9
|
+
super
|
10
|
+
::File.delete(EXTRACTED_FILENAME) if ::File.exist?(EXTRACTED_FILENAME)
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_extract
|
14
|
+
::Zip::File.open(TEST_ZIP.zip_name) do |zf|
|
15
|
+
zf.extract(ENTRY_TO_EXTRACT, EXTRACTED_FILENAME)
|
16
|
+
|
17
|
+
assert(File.exist?(EXTRACTED_FILENAME))
|
18
|
+
AssertEntry.assert_contents(EXTRACTED_FILENAME,
|
19
|
+
zf.get_input_stream(ENTRY_TO_EXTRACT) { |is| is.read })
|
20
|
+
|
21
|
+
::File.unlink(EXTRACTED_FILENAME)
|
22
|
+
|
23
|
+
entry = zf.get_entry(ENTRY_TO_EXTRACT)
|
24
|
+
entry.extract(EXTRACTED_FILENAME)
|
25
|
+
|
26
|
+
assert(File.exist?(EXTRACTED_FILENAME))
|
27
|
+
AssertEntry.assert_contents(EXTRACTED_FILENAME,
|
28
|
+
entry.get_input_stream { |is| is.read })
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_extract_exists
|
33
|
+
writtenText = 'written text'
|
34
|
+
::File.open(EXTRACTED_FILENAME, 'w') { |f| f.write(writtenText) }
|
35
|
+
|
36
|
+
assert_raises(::Zip::DestinationFileExistsError) do
|
37
|
+
::Zip::File.open(TEST_ZIP.zip_name) do |zf|
|
38
|
+
zf.extract(zf.entries.first, EXTRACTED_FILENAME)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
File.open(EXTRACTED_FILENAME, 'r') do |f|
|
42
|
+
assert_equal(writtenText, f.read)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_extract_exists_overwrite
|
47
|
+
writtenText = 'written text'
|
48
|
+
::File.open(EXTRACTED_FILENAME, 'w') { |f| f.write(writtenText) }
|
49
|
+
|
50
|
+
gotCalledCorrectly = false
|
51
|
+
::Zip::File.open(TEST_ZIP.zip_name) do |zf|
|
52
|
+
zf.extract(zf.entries.first, EXTRACTED_FILENAME) do |entry, extractLoc|
|
53
|
+
gotCalledCorrectly = zf.entries.first == entry &&
|
54
|
+
extractLoc == EXTRACTED_FILENAME
|
55
|
+
true
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
assert(gotCalledCorrectly)
|
60
|
+
::File.open(EXTRACTED_FILENAME, 'r') do |f|
|
61
|
+
assert(writtenText != f.read)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_extract_non_entry
|
66
|
+
zf = ::Zip::File.new(TEST_ZIP.zip_name)
|
67
|
+
assert_raises(Errno::ENOENT) { zf.extract('nonExistingEntry', 'nonExistingEntry') }
|
68
|
+
ensure
|
69
|
+
zf.close if zf
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_extract_non_entry_2
|
73
|
+
outFile = 'outfile'
|
74
|
+
assert_raises(Errno::ENOENT) do
|
75
|
+
zf = ::Zip::File.new(TEST_ZIP.zip_name)
|
76
|
+
nonEntry = 'hotdog-diddelidoo'
|
77
|
+
assert(!zf.entries.include?(nonEntry))
|
78
|
+
zf.extract(nonEntry, outFile)
|
79
|
+
zf.close
|
80
|
+
end
|
81
|
+
assert(!File.exist?(outFile))
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class FilePermissionsTest < MiniTest::Test
|
4
|
+
|
5
|
+
FILENAME = File.join(File.dirname(__FILE__), "umask.zip")
|
6
|
+
|
7
|
+
def teardown
|
8
|
+
::File.unlink(FILENAME)
|
9
|
+
end
|
10
|
+
|
11
|
+
if ::Zip::RUNNING_ON_WINDOWS
|
12
|
+
# Windows tests
|
13
|
+
|
14
|
+
DEFAULT_PERMS = 0644
|
15
|
+
|
16
|
+
def test_windows_perms
|
17
|
+
create_file
|
18
|
+
|
19
|
+
assert_equal DEFAULT_PERMS, ::File.stat(FILENAME).mode
|
20
|
+
end
|
21
|
+
|
22
|
+
else
|
23
|
+
# Unix tests
|
24
|
+
|
25
|
+
DEFAULT_PERMS = 0100666
|
26
|
+
|
27
|
+
def test_current_umask
|
28
|
+
umask = DEFAULT_PERMS - ::File.umask
|
29
|
+
create_file
|
30
|
+
|
31
|
+
assert_equal umask, ::File.stat(FILENAME).mode
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_umask_000
|
35
|
+
set_umask(0000) do
|
36
|
+
create_file
|
37
|
+
end
|
38
|
+
|
39
|
+
assert_equal DEFAULT_PERMS, ::File.stat(FILENAME).mode
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_umask_066
|
43
|
+
umask = 0066
|
44
|
+
set_umask(umask) do
|
45
|
+
create_file
|
46
|
+
end
|
47
|
+
|
48
|
+
assert_equal((DEFAULT_PERMS - umask), ::File.stat(FILENAME).mode)
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
def create_file
|
54
|
+
::Zip::File.open(FILENAME, ::Zip::File::CREATE) do |zip|
|
55
|
+
zip.comment = "test"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
# If anything goes wrong, make sure the umask is restored.
|
60
|
+
def set_umask(umask, &block)
|
61
|
+
begin
|
62
|
+
saved_umask = ::File.umask(umask)
|
63
|
+
yield
|
64
|
+
ensure
|
65
|
+
::File.umask(saved_umask)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ZipFileSplitTest < MiniTest::Test
|
4
|
+
TEST_ZIP = TestZipFile::TEST_ZIP2.clone
|
5
|
+
TEST_ZIP.zip_name = 'large_zip_file.zip'
|
6
|
+
EXTRACTED_FILENAME = 'test/data/generated/extEntrySplit'
|
7
|
+
UNSPLITTED_FILENAME = 'test/data/generated/unsplitted.zip'
|
8
|
+
ENTRY_TO_EXTRACT = TEST_ZIP.entry_names.first
|
9
|
+
|
10
|
+
def setup
|
11
|
+
FileUtils.cp(TestZipFile::TEST_ZIP2.zip_name, TEST_ZIP.zip_name)
|
12
|
+
end
|
13
|
+
|
14
|
+
def teardown
|
15
|
+
File.delete(TEST_ZIP.zip_name)
|
16
|
+
File.delete(UNSPLITTED_FILENAME) if File.exist?(UNSPLITTED_FILENAME)
|
17
|
+
|
18
|
+
Dir["#{TEST_ZIP.zip_name}.*"].each do |zip_file_name|
|
19
|
+
File.delete(zip_file_name) if File.exist?(zip_file_name)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_split_method_respond
|
24
|
+
assert_respond_to ::Zip::File, :split, 'Does not have split class method'
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_split
|
28
|
+
result = ::Zip::File.split(TEST_ZIP.zip_name, 65_536, false)
|
29
|
+
|
30
|
+
return if result.nil?
|
31
|
+
Dir["#{TEST_ZIP.zip_name}.*"].sort.each_with_index do |zip_file_name, index|
|
32
|
+
File.open(zip_file_name, 'rb') do |zip_file|
|
33
|
+
zip_file.read([::Zip::File::SPLIT_SIGNATURE].pack('V').size) if index == 0
|
34
|
+
File.open(UNSPLITTED_FILENAME, 'ab') do |file|
|
35
|
+
file << zip_file.read
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
::Zip::File.open(UNSPLITTED_FILENAME) do |zf|
|
41
|
+
zf.extract(ENTRY_TO_EXTRACT, EXTRACTED_FILENAME)
|
42
|
+
|
43
|
+
assert(File.exist?(EXTRACTED_FILENAME))
|
44
|
+
AssertEntry.assert_contents(EXTRACTED_FILENAME,
|
45
|
+
zf.get_input_stream(ENTRY_TO_EXTRACT) { |is| is.read })
|
46
|
+
|
47
|
+
File.unlink(EXTRACTED_FILENAME)
|
48
|
+
|
49
|
+
entry = zf.get_entry(ENTRY_TO_EXTRACT)
|
50
|
+
entry.extract(EXTRACTED_FILENAME)
|
51
|
+
|
52
|
+
assert(File.exist?(EXTRACTED_FILENAME))
|
53
|
+
AssertEntry.assert_contents(EXTRACTED_FILENAME,
|
54
|
+
entry.get_input_stream { |is| is.read })
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|