rubyzip 1.1.7 → 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 +4 -4
- data/README.md +69 -32
- 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 +68 -80
- 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 +45 -49
- 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 +0 -2
- 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 +33 -24
- 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 +31 -35
- data/test/central_directory_test.rb +46 -50
- data/test/crypto/null_encryption_test.rb +2 -2
- 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 +38 -24
- data/test/entry_test.rb +76 -78
- 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 +174 -170
- 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 +43 -55
- data/test/inflater_test.rb +1 -1
- data/test/input_stream_test.rb +42 -30
- data/test/ioextras/abstract_input_stream_test.rb +21 -22
- data/test/ioextras/abstract_output_stream_test.rb +32 -32
- data/test/local_entry_test.rb +35 -37
- 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 +37 -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
@@ -8,10 +8,10 @@ class AbstractOutputStreamTest < MiniTest::Test
|
|
8
8
|
attr_accessor :buffer
|
9
9
|
|
10
10
|
def initialize
|
11
|
-
@buffer =
|
11
|
+
@buffer = ''
|
12
12
|
end
|
13
13
|
|
14
|
-
def <<
|
14
|
+
def <<(data)
|
15
15
|
@buffer << data
|
16
16
|
self
|
17
17
|
end
|
@@ -30,77 +30,77 @@ class AbstractOutputStreamTest < MiniTest::Test
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def test_write
|
33
|
-
count = @output_stream.write(
|
34
|
-
assert_equal(
|
35
|
-
assert_equal(
|
33
|
+
count = @output_stream.write('a little string')
|
34
|
+
assert_equal('a little string', @output_stream.buffer)
|
35
|
+
assert_equal('a little string'.length, count)
|
36
36
|
|
37
|
-
count = @output_stream.write(
|
38
|
-
assert_equal(
|
39
|
-
assert_equal(
|
37
|
+
count = @output_stream.write('. a little more')
|
38
|
+
assert_equal('a little string. a little more', @output_stream.buffer)
|
39
|
+
assert_equal('. a little more'.length, count)
|
40
40
|
end
|
41
41
|
|
42
42
|
def test_print
|
43
43
|
$\ = nil # record separator set to nil
|
44
|
-
@output_stream.print(
|
45
|
-
assert_equal(
|
44
|
+
@output_stream.print('hello')
|
45
|
+
assert_equal('hello', @output_stream.buffer)
|
46
46
|
|
47
|
-
@output_stream.print(
|
48
|
-
assert_equal(
|
47
|
+
@output_stream.print(' world.')
|
48
|
+
assert_equal('hello world.', @output_stream.buffer)
|
49
49
|
|
50
|
-
@output_stream.print(
|
51
|
-
assert_equal(
|
50
|
+
@output_stream.print(' You ok ', 'out ', 'there?')
|
51
|
+
assert_equal('hello world. You ok out there?', @output_stream.buffer)
|
52
52
|
|
53
53
|
$\ = "\n"
|
54
54
|
@output_stream.print
|
55
55
|
assert_equal("hello world. You ok out there?\n", @output_stream.buffer)
|
56
56
|
|
57
|
-
@output_stream.print(
|
57
|
+
@output_stream.print('I sure hope so!')
|
58
58
|
assert_equal("hello world. You ok out there?\nI sure hope so!\n", @output_stream.buffer)
|
59
59
|
|
60
|
-
$, =
|
61
|
-
@output_stream.buffer =
|
62
|
-
@output_stream.print(
|
60
|
+
$, = 'X'
|
61
|
+
@output_stream.buffer = ''
|
62
|
+
@output_stream.print('monkey', 'duck', 'zebra')
|
63
63
|
assert_equal("monkeyXduckXzebra\n", @output_stream.buffer)
|
64
64
|
|
65
65
|
$\ = nil
|
66
|
-
@output_stream.buffer =
|
66
|
+
@output_stream.buffer = ''
|
67
67
|
@output_stream.print(20)
|
68
|
-
assert_equal(
|
68
|
+
assert_equal('20', @output_stream.buffer)
|
69
69
|
end
|
70
70
|
|
71
71
|
def test_printf
|
72
|
-
@output_stream.printf(
|
73
|
-
assert_equal(
|
72
|
+
@output_stream.printf('%d %04x', 123, 123)
|
73
|
+
assert_equal('123 007b', @output_stream.buffer)
|
74
74
|
end
|
75
75
|
|
76
76
|
def test_putc
|
77
|
-
@output_stream.putc(
|
78
|
-
assert_equal(
|
77
|
+
@output_stream.putc('A')
|
78
|
+
assert_equal('A', @output_stream.buffer)
|
79
79
|
@output_stream.putc(65)
|
80
|
-
assert_equal(
|
80
|
+
assert_equal('AA', @output_stream.buffer)
|
81
81
|
end
|
82
82
|
|
83
83
|
def test_puts
|
84
84
|
@output_stream.puts
|
85
85
|
assert_equal("\n", @output_stream.buffer)
|
86
86
|
|
87
|
-
@output_stream.puts(
|
87
|
+
@output_stream.puts('hello', 'world')
|
88
88
|
assert_equal("\nhello\nworld\n", @output_stream.buffer)
|
89
89
|
|
90
|
-
@output_stream.buffer =
|
90
|
+
@output_stream.buffer = ''
|
91
91
|
@output_stream.puts("hello\n", "world\n")
|
92
92
|
assert_equal("hello\nworld\n", @output_stream.buffer)
|
93
93
|
|
94
|
-
@output_stream.buffer =
|
94
|
+
@output_stream.buffer = ''
|
95
95
|
@output_stream.puts(["hello\n", "world\n"])
|
96
96
|
assert_equal("hello\nworld\n", @output_stream.buffer)
|
97
97
|
|
98
|
-
@output_stream.buffer =
|
99
|
-
@output_stream.puts(["hello\n", "world\n"],
|
98
|
+
@output_stream.buffer = ''
|
99
|
+
@output_stream.puts(["hello\n", "world\n"], 'bingo')
|
100
100
|
assert_equal("hello\nworld\nbingo\n", @output_stream.buffer)
|
101
101
|
|
102
|
-
@output_stream.buffer =
|
103
|
-
@output_stream.puts(16, 20, 50,
|
102
|
+
@output_stream.buffer = ''
|
103
|
+
@output_stream.puts(16, 20, 50, 'hello')
|
104
104
|
assert_equal("16\n20\n50\nhello\n", @output_stream.buffer)
|
105
105
|
end
|
106
106
|
end
|
data/test/local_entry_test.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
3
|
class ZipLocalEntryTest < MiniTest::Test
|
4
|
-
|
5
4
|
CEH_FILE = 'test/data/generated/centralEntryHeader.bin'
|
6
5
|
LEH_FILE = 'test/data/generated/localEntryHeader.bin'
|
7
6
|
|
@@ -9,8 +8,8 @@ class ZipLocalEntryTest < MiniTest::Test
|
|
9
8
|
::Zip.write_zip64_support = false
|
10
9
|
end
|
11
10
|
|
12
|
-
def
|
13
|
-
::File.open(TestZipFile::TEST_ZIP3.zip_name,
|
11
|
+
def test_read_local_entry_header_of_first_test_zip_entry
|
12
|
+
::File.open(TestZipFile::TEST_ZIP3.zip_name, 'rb') do |file|
|
14
13
|
entry = ::Zip::Entry.read_local_entry(file)
|
15
14
|
|
16
15
|
assert_equal('', entry.comment)
|
@@ -27,35 +26,33 @@ class ZipLocalEntryTest < MiniTest::Test
|
|
27
26
|
end
|
28
27
|
end
|
29
28
|
|
30
|
-
def
|
31
|
-
::File.open(
|
32
|
-
|file|
|
29
|
+
def test_read_date_time
|
30
|
+
::File.open('test/data/rubycode.zip', 'rb') do |file|
|
33
31
|
entry = ::Zip::Entry.read_local_entry(file)
|
34
|
-
assert_equal(
|
35
|
-
assert_equal(::Zip::DOSTime.at(
|
36
|
-
|
32
|
+
assert_equal('zippedruby1.rb', entry.name)
|
33
|
+
assert_equal(::Zip::DOSTime.at(1_019_261_638), entry.time)
|
34
|
+
end
|
37
35
|
end
|
38
36
|
|
39
|
-
def
|
40
|
-
::File.open(
|
41
|
-
|file|
|
37
|
+
def test_read_local_entry_from_non_zip_file
|
38
|
+
::File.open('test/data/file2.txt') do |file|
|
42
39
|
assert_equal(nil, ::Zip::Entry.read_local_entry(file))
|
43
|
-
|
40
|
+
end
|
44
41
|
end
|
45
42
|
|
46
|
-
def
|
47
|
-
zipFragment=
|
43
|
+
def test_read_local_entry_from_truncated_zip_file
|
44
|
+
zipFragment = ''
|
48
45
|
::File.open(TestZipFile::TEST_ZIP2.zip_name) { |f| zipFragment = f.read(12) } # local header is at least 30 bytes
|
49
46
|
zipFragment.extend(IOizeString).reset
|
50
47
|
entry = ::Zip::Entry.new
|
51
48
|
entry.read_local_entry(zipFragment)
|
52
|
-
fail
|
49
|
+
fail 'ZipError expected'
|
53
50
|
rescue ::Zip::Error
|
54
51
|
end
|
55
52
|
|
56
|
-
def
|
57
|
-
entry = ::Zip::Entry.new(
|
58
|
-
|
53
|
+
def test_write_entry
|
54
|
+
entry = ::Zip::Entry.new('file.zip', 'entryName', 'my little comment',
|
55
|
+
'thisIsSomeExtraInformation', 100, 987_654,
|
59
56
|
::Zip::Entry::DEFLATED, 400)
|
60
57
|
write_to_file(LEH_FILE, CEH_FILE, entry)
|
61
58
|
entryReadLocal, entryReadCentral = read_from_file(LEH_FILE, CEH_FILE)
|
@@ -64,10 +61,10 @@ class ZipLocalEntryTest < MiniTest::Test
|
|
64
61
|
compare_c_dir_entry_headers(entry, entryReadCentral)
|
65
62
|
end
|
66
63
|
|
67
|
-
def
|
64
|
+
def test_write_entry_with_zip64
|
68
65
|
::Zip.write_zip64_support = true
|
69
|
-
entry = ::Zip::Entry.new(
|
70
|
-
|
66
|
+
entry = ::Zip::Entry.new('file.zip', 'entryName', 'my little comment',
|
67
|
+
'thisIsSomeExtraInformation', 100, 987_654,
|
71
68
|
::Zip::Entry::DEFLATED, 400)
|
72
69
|
write_to_file(LEH_FILE, CEH_FILE, entry)
|
73
70
|
entryReadLocal, entryReadCentral = read_from_file(LEH_FILE, CEH_FILE)
|
@@ -78,10 +75,10 @@ class ZipLocalEntryTest < MiniTest::Test
|
|
78
75
|
compare_c_dir_entry_headers(entry, entryReadCentral)
|
79
76
|
end
|
80
77
|
|
81
|
-
def
|
78
|
+
def test_write_64entry
|
82
79
|
::Zip.write_zip64_support = true
|
83
|
-
entry = ::Zip::Entry.new(
|
84
|
-
|
80
|
+
entry = ::Zip::Entry.new('bigfile.zip', 'entryName', 'my little equine',
|
81
|
+
'malformed extra field because why not',
|
85
82
|
0x7766554433221100, 0xDEADBEEF, ::Zip::Entry::DEFLATED,
|
86
83
|
0x9988776655443322)
|
87
84
|
write_to_file(LEH_FILE, CEH_FILE, entry)
|
@@ -90,12 +87,12 @@ class ZipLocalEntryTest < MiniTest::Test
|
|
90
87
|
compare_c_dir_entry_headers(entry, entryReadCentral)
|
91
88
|
end
|
92
89
|
|
93
|
-
def
|
90
|
+
def test_rewrite_local_header64
|
94
91
|
::Zip.write_zip64_support = true
|
95
92
|
buf1 = StringIO.new
|
96
|
-
entry = ::Zip::Entry.new(
|
93
|
+
entry = ::Zip::Entry.new('file.zip', 'entryName')
|
97
94
|
entry.write_local_entry(buf1)
|
98
|
-
assert(entry.extra['Zip64'].nil?,
|
95
|
+
assert(entry.extra['Zip64'].nil?, 'zip64 extra is unnecessarily present')
|
99
96
|
|
100
97
|
buf2 = StringIO.new
|
101
98
|
entry.size = 0x123456789ABCDEF0
|
@@ -106,18 +103,18 @@ class ZipLocalEntryTest < MiniTest::Test
|
|
106
103
|
assert_equal(buf1.size, buf2.size) # it can't grow, or we'd clobber file data
|
107
104
|
end
|
108
105
|
|
109
|
-
def
|
110
|
-
entry = ::Zip::Entry.new(
|
111
|
-
entry.local_header_offset =
|
106
|
+
def test_read_local_offset
|
107
|
+
entry = ::Zip::Entry.new('file.zip', 'entryName')
|
108
|
+
entry.local_header_offset = 12_345
|
112
109
|
::File.open(CEH_FILE, 'wb') { |f| entry.write_c_dir_entry(f) }
|
113
110
|
read_entry = nil
|
114
111
|
::File.open(CEH_FILE, 'rb') { |f| read_entry = ::Zip::Entry.read_c_dir_entry(f) }
|
115
112
|
compare_c_dir_entry_headers(entry, read_entry)
|
116
113
|
end
|
117
114
|
|
118
|
-
def
|
115
|
+
def test_read64_local_offset
|
119
116
|
::Zip.write_zip64_support = true
|
120
|
-
entry = ::Zip::Entry.new(
|
117
|
+
entry = ::Zip::Entry.new('file.zip', 'entryName')
|
121
118
|
entry.local_header_offset = 0x0123456789ABCDEF
|
122
119
|
::File.open(CEH_FILE, 'wb') { |f| entry.write_c_dir_entry(f) }
|
123
120
|
read_entry = nil
|
@@ -126,6 +123,7 @@ class ZipLocalEntryTest < MiniTest::Test
|
|
126
123
|
end
|
127
124
|
|
128
125
|
private
|
126
|
+
|
129
127
|
def compare_local_entry_headers(entry1, entry2)
|
130
128
|
assert_equal(entry1.compressed_size, entry2.compressed_size)
|
131
129
|
assert_equal(entry1.crc, entry2.crc)
|
@@ -142,15 +140,15 @@ class ZipLocalEntryTest < MiniTest::Test
|
|
142
140
|
end
|
143
141
|
|
144
142
|
def write_to_file(localFileName, centralFileName, entry)
|
145
|
-
::File.open(localFileName,
|
146
|
-
::File.open(centralFileName,
|
143
|
+
::File.open(localFileName, 'wb') { |f| entry.write_local_entry(f) }
|
144
|
+
::File.open(centralFileName, 'wb') { |f| entry.write_c_dir_entry(f) }
|
147
145
|
end
|
148
146
|
|
149
147
|
def read_from_file(localFileName, centralFileName)
|
150
148
|
localEntry = nil
|
151
149
|
cdirEntry = nil
|
152
|
-
::File.open(localFileName,
|
153
|
-
::File.open(centralFileName,
|
150
|
+
::File.open(localFileName, 'rb') { |f| localEntry = ::Zip::Entry.read_local_entry(f) }
|
151
|
+
::File.open(centralFileName, 'rb') { |f| cdirEntry = ::Zip::Entry.read_c_dir_entry(f) }
|
154
152
|
[localEntry, cdirEntry]
|
155
153
|
end
|
156
154
|
end
|
data/test/output_stream_test.rb
CHANGED
@@ -4,7 +4,7 @@ class ZipOutputStreamTest < MiniTest::Test
|
|
4
4
|
include AssertEntry
|
5
5
|
|
6
6
|
TEST_ZIP = TestZipFile::TEST_ZIP2.clone
|
7
|
-
TEST_ZIP.zip_name =
|
7
|
+
TEST_ZIP.zip_name = 'test/data/generated/output.zip'
|
8
8
|
|
9
9
|
def test_new
|
10
10
|
zos = ::Zip::OutputStream.new(TEST_ZIP.zip_name)
|
@@ -47,13 +47,13 @@ class ZipOutputStreamTest < MiniTest::Test
|
|
47
47
|
assert_test_zip_contents(TEST_ZIP)
|
48
48
|
end
|
49
49
|
|
50
|
-
def
|
51
|
-
assert_i_o_error_in_closed_stream { |zos| zos <<
|
52
|
-
assert_i_o_error_in_closed_stream { |zos| zos.puts
|
53
|
-
assert_i_o_error_in_closed_stream { |zos| zos.write
|
50
|
+
def test_writing_to_closed_stream
|
51
|
+
assert_i_o_error_in_closed_stream { |zos| zos << 'hello world' }
|
52
|
+
assert_i_o_error_in_closed_stream { |zos| zos.puts 'hello world' }
|
53
|
+
assert_i_o_error_in_closed_stream { |zos| zos.write 'hello world' }
|
54
54
|
end
|
55
55
|
|
56
|
-
def
|
56
|
+
def test_cannot_open_file
|
57
57
|
name = TestFiles::EMPTY_TEST_DIR
|
58
58
|
begin
|
59
59
|
::Zip::OutputStream.open(name)
|
@@ -66,9 +66,9 @@ class ZipOutputStreamTest < MiniTest::Test
|
|
66
66
|
end
|
67
67
|
|
68
68
|
def test_put_next_entry
|
69
|
-
stored_text =
|
70
|
-
entry_name =
|
71
|
-
comment =
|
69
|
+
stored_text = 'hello world in stored text'
|
70
|
+
entry_name = 'file1'
|
71
|
+
comment = 'my comment'
|
72
72
|
::Zip::OutputStream.open(TEST_ZIP.zip_name) do |zos|
|
73
73
|
zos.put_next_entry(entry_name, comment, nil, ::Zip::Entry::STORED)
|
74
74
|
zos << stored_text
|
@@ -81,14 +81,14 @@ class ZipOutputStreamTest < MiniTest::Test
|
|
81
81
|
end
|
82
82
|
|
83
83
|
def test_put_next_entry_using_zip_entry_creates_entries_with_correct_timestamps
|
84
|
-
file = ::File.open(
|
84
|
+
file = ::File.open('test/data/file2.txt', 'rb')
|
85
85
|
::Zip::OutputStream.open(TEST_ZIP.zip_name) do |zos|
|
86
|
-
zip_entry = ::Zip::Entry.new(zos, file.path,
|
86
|
+
zip_entry = ::Zip::Entry.new(zos, file.path, '', '', 0, 0, ::Zip::Entry::DEFLATED, 0, ::Zip::DOSTime.at(file.mtime))
|
87
87
|
zos.put_next_entry(zip_entry)
|
88
88
|
zos << file.read
|
89
89
|
end
|
90
90
|
|
91
|
-
::Zip::InputStream
|
91
|
+
::Zip::InputStream.open(TEST_ZIP.zip_name) do |io|
|
92
92
|
while (entry = io.get_next_entry)
|
93
93
|
assert(::Zip::DOSTime.at(file.mtime).dos_equals(::Zip::DOSTime.at(entry.mtime))) # Compare DOS Times, since they are stored with two seconds accuracy
|
94
94
|
end
|
@@ -96,10 +96,10 @@ class ZipOutputStreamTest < MiniTest::Test
|
|
96
96
|
end
|
97
97
|
|
98
98
|
def test_chained_put_into_next_entry
|
99
|
-
stored_text =
|
100
|
-
stored_text2 =
|
101
|
-
entry_name =
|
102
|
-
comment =
|
99
|
+
stored_text = 'hello world in stored text'
|
100
|
+
stored_text2 = 'with chain'
|
101
|
+
entry_name = 'file1'
|
102
|
+
comment = 'my comment'
|
103
103
|
::Zip::OutputStream.open(TEST_ZIP.zip_name) do |zos|
|
104
104
|
zos.put_next_entry(entry_name, comment, nil, ::Zip::Entry::STORED)
|
105
105
|
zos << stored_text << stored_text2
|
@@ -109,21 +109,20 @@ class ZipOutputStreamTest < MiniTest::Test
|
|
109
109
|
::Zip::File.open(TEST_ZIP.zip_name) do |zf|
|
110
110
|
assert_equal(stored_text + stored_text2, zf.read(entry_name))
|
111
111
|
end
|
112
|
-
|
113
112
|
end
|
114
113
|
|
115
114
|
def assert_i_o_error_in_closed_stream
|
116
|
-
assert_raises(IOError)
|
117
|
-
zos = ::Zip::OutputStream.new(
|
115
|
+
assert_raises(IOError) do
|
116
|
+
zos = ::Zip::OutputStream.new('test/data/generated/test_putOnClosedStream.zip')
|
118
117
|
zos.close
|
119
118
|
yield zos
|
120
|
-
|
119
|
+
end
|
121
120
|
end
|
122
121
|
|
123
122
|
def write_test_zip(zos)
|
124
123
|
TEST_ZIP.entry_names.each do |entryName|
|
125
124
|
zos.put_next_entry(entryName)
|
126
|
-
File.open(entryName,
|
125
|
+
File.open(entryName, 'rb') { |f| zos.write(f.read) }
|
127
126
|
end
|
128
127
|
end
|
129
128
|
end
|
@@ -4,15 +4,14 @@ class PassThruCompressorTest < MiniTest::Test
|
|
4
4
|
include CrcTest
|
5
5
|
|
6
6
|
def test_size
|
7
|
-
File.open(
|
8
|
-
|file|
|
7
|
+
File.open('test/data/generated/dummy.txt', 'wb') do |file|
|
9
8
|
compressor = ::Zip::PassThruCompressor.new(file)
|
10
9
|
|
11
10
|
assert_equal(0, compressor.size)
|
12
11
|
|
13
|
-
t1 =
|
14
|
-
t2 =
|
15
|
-
t3 =
|
12
|
+
t1 = 'hello world'
|
13
|
+
t2 = ''
|
14
|
+
t3 = 'bingo'
|
16
15
|
|
17
16
|
compressor << t1
|
18
17
|
assert_equal(compressor.size, t1.size)
|
@@ -22,7 +21,7 @@ class PassThruCompressorTest < MiniTest::Test
|
|
22
21
|
|
23
22
|
compressor << t3
|
24
23
|
assert_equal(compressor.size, t1.size + t2.size + t3.size)
|
25
|
-
|
24
|
+
end
|
26
25
|
end
|
27
26
|
|
28
27
|
def test_crc
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'fileutils'
|
3
|
+
require_relative '../../samples/example_recursive'
|
4
|
+
|
5
|
+
class ExampleRecursiveTest < MiniTest::Test
|
6
|
+
DIRECTORY_TO_ZIP = 'test/data/globTest'
|
7
|
+
OUTPUT_DIRECTORY = 'test/data/example_recursive.zip'
|
8
|
+
TEMP_DIRECTORY = 'test/data/tmp'
|
9
|
+
|
10
|
+
def setup
|
11
|
+
@generator = ::ZipFileGenerator.new(DIRECTORY_TO_ZIP, OUTPUT_DIRECTORY)
|
12
|
+
end
|
13
|
+
|
14
|
+
def teardown
|
15
|
+
FileUtils.rm_rf TEMP_DIRECTORY
|
16
|
+
FileUtils.rm_f OUTPUT_DIRECTORY
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_write
|
20
|
+
@generator.write
|
21
|
+
unzip
|
22
|
+
assert_equal Dir.entries(DIRECTORY_TO_ZIP).sort, Dir.entries(TEMP_DIRECTORY).sort
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def unzip(file = OUTPUT_DIRECTORY)
|
28
|
+
Zip::File.open(file) do |zip_file|
|
29
|
+
zip_file.each do |f|
|
30
|
+
file_path = File.join(TEMP_DIRECTORY, f.name)
|
31
|
+
FileUtils.mkdir_p(File.dirname(file_path))
|
32
|
+
|
33
|
+
zip_file.extract(f, file_path) unless File.exist?(file_path)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|