rubyzip 1.1.7 → 1.2.4
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 +5 -5
- data/README.md +87 -45
- data/Rakefile +3 -4
- data/lib/zip.rb +11 -5
- data/lib/zip/central_directory.rb +8 -8
- data/lib/zip/compressor.rb +1 -2
- data/lib/zip/constants.rb +5 -5
- data/lib/zip/crypto/null_encryption.rb +4 -6
- data/lib/zip/crypto/traditional_encryption.rb +5 -5
- data/lib/zip/decompressor.rb +3 -3
- data/lib/zip/deflater.rb +8 -6
- data/lib/zip/dos_time.rb +5 -6
- data/lib/zip/entry.rb +120 -128
- data/lib/zip/entry_set.rb +14 -14
- data/lib/zip/errors.rb +1 -0
- data/lib/zip/extra_field.rb +8 -8
- data/lib/zip/extra_field/generic.rb +8 -8
- 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 -2
- data/lib/zip/file.rb +81 -81
- data/lib/zip/filesystem.rb +144 -143
- data/lib/zip/inflater.rb +5 -5
- data/lib/zip/input_stream.rb +22 -13
- data/lib/zip/ioextras.rb +1 -3
- data/lib/zip/ioextras/abstract_input_stream.rb +6 -10
- data/lib/zip/ioextras/abstract_output_stream.rb +3 -5
- 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 +13 -14
- data/lib/zip/pass_thru_compressor.rb +4 -4
- data/lib/zip/pass_thru_decompressor.rb +3 -4
- data/lib/zip/streamable_directory.rb +2 -2
- data/lib/zip/streamable_stream.rb +3 -3
- 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 +31 -25
- data/samples/{gtkRubyzip.rb → gtk_ruby_zip.rb} +23 -25
- data/samples/qtzip.rb +18 -27
- data/samples/write_simple.rb +12 -13
- data/samples/zipfind.rb +26 -34
- 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/gpbit3stored.zip +0 -0
- data/test/data/notzippedruby.rb +1 -1
- 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/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 +1 -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 +65 -0
- data/test/file_split_test.rb +24 -27
- data/test/file_test.rb +266 -179
- data/test/filesystem/dir_iterator_test.rb +13 -17
- data/test/filesystem/directory_test.rb +101 -93
- data/test/filesystem/file_mutating_test.rb +52 -65
- data/test/filesystem/file_nonmutating_test.rb +223 -229
- data/test/filesystem/file_stat_test.rb +17 -19
- data/test/gentestfiles.rb +54 -62
- data/test/inflater_test.rb +1 -1
- data/test/input_stream_test.rb +52 -40
- data/test/ioextras/abstract_input_stream_test.rb +22 -23
- data/test/ioextras/abstract_output_stream_test.rb +33 -33
- 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/path_traversal_test.rb +141 -0
- data/test/samples/example_recursive_test.rb +37 -0
- data/test/settings_test.rb +18 -15
- data/test/test_helper.rb +52 -46
- data/test/unicode_file_names_and_comments_test.rb +17 -7
- data/test/zip64_full_test.rb +10 -12
- data/test/zip64_support_test.rb +0 -1
- metadata +94 -65
@@ -6,7 +6,7 @@ class AbstractInputStreamTest < MiniTest::Test
|
|
6
6
|
|
7
7
|
TEST_LINES = ["Hello world#{$/}",
|
8
8
|
"this is the second line#{$/}",
|
9
|
-
|
9
|
+
'this is the last line']
|
10
10
|
TEST_STRING = TEST_LINES.join
|
11
11
|
class TestAbstractInputStream
|
12
12
|
include ::Zip::IOExtras::AbstractInputStream
|
@@ -17,10 +17,10 @@ class AbstractInputStreamTest < MiniTest::Test
|
|
17
17
|
@readPointer = 0
|
18
18
|
end
|
19
19
|
|
20
|
-
def sysread(charsToRead,
|
21
|
-
retVal
|
22
|
-
@readPointer+=charsToRead
|
23
|
-
|
20
|
+
def sysread(charsToRead, _buf = nil)
|
21
|
+
retVal = @contents[@readPointer, charsToRead]
|
22
|
+
@readPointer += charsToRead
|
23
|
+
retVal
|
24
24
|
end
|
25
25
|
|
26
26
|
def produce_input
|
@@ -28,7 +28,7 @@ class AbstractInputStreamTest < MiniTest::Test
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def input_finished?
|
31
|
-
@contents[@readPointer]
|
31
|
+
@contents[@readPointer].nil?
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
@@ -44,48 +44,47 @@ class AbstractInputStreamTest < MiniTest::Test
|
|
44
44
|
assert_equal(2, @io.lineno)
|
45
45
|
assert_equal(TEST_LINES[2], @io.gets)
|
46
46
|
assert_equal(3, @io.lineno)
|
47
|
-
|
47
|
+
assert_nil(@io.gets)
|
48
48
|
assert_equal(4, @io.lineno)
|
49
49
|
end
|
50
50
|
|
51
|
-
def
|
52
|
-
assert_equal(
|
53
|
-
assert_equal("o world#{$/}this is the second l", @io.gets(
|
51
|
+
def test_gets_multi_char_seperator
|
52
|
+
assert_equal('Hell', @io.gets('ll'))
|
53
|
+
assert_equal("o world#{$/}this is the second l", @io.gets('d l'))
|
54
54
|
end
|
55
55
|
|
56
56
|
LONG_LINES = [
|
57
|
-
|
58
|
-
|
59
|
-
|
57
|
+
'x' * 48 + "\r\n",
|
58
|
+
'y' * 49 + "\r\n",
|
59
|
+
'rest'
|
60
60
|
]
|
61
61
|
|
62
|
-
def
|
62
|
+
def test_gets_mulit_char_seperator_split
|
63
63
|
io = TestAbstractInputStream.new(LONG_LINES.join)
|
64
64
|
assert_equal(LONG_LINES[0], io.gets("\r\n"))
|
65
65
|
assert_equal(LONG_LINES[1], io.gets("\r\n"))
|
66
66
|
assert_equal(LONG_LINES[2], io.gets("\r\n"))
|
67
67
|
end
|
68
68
|
|
69
|
-
def
|
69
|
+
def test_gets_with_sep_and_index
|
70
70
|
io = TestAbstractInputStream.new(LONG_LINES.join)
|
71
71
|
assert_equal('x', io.gets("\r\n", 1))
|
72
|
-
assert_equal('x'*47 + "\r", io.gets("\r\n", 48))
|
72
|
+
assert_equal('x' * 47 + "\r", io.gets("\r\n", 48))
|
73
73
|
assert_equal("\n", io.gets(nil, 1))
|
74
74
|
assert_equal('yy', io.gets(nil, 2))
|
75
75
|
end
|
76
76
|
|
77
|
-
def
|
77
|
+
def test_gets_with_index
|
78
78
|
assert_equal(TEST_LINES[0], @io.gets(100))
|
79
79
|
assert_equal('this', @io.gets(4))
|
80
80
|
end
|
81
81
|
|
82
82
|
def test_each_line
|
83
|
-
lineNumber=0
|
84
|
-
@io.each_line
|
85
|
-
|line|
|
83
|
+
lineNumber = 0
|
84
|
+
@io.each_line do |line|
|
86
85
|
assert_equal(TEST_LINES[lineNumber], line)
|
87
|
-
lineNumber+=1
|
88
|
-
|
86
|
+
lineNumber += 1
|
87
|
+
end
|
89
88
|
end
|
90
89
|
|
91
90
|
def test_readlines
|
@@ -96,7 +95,7 @@ class AbstractInputStreamTest < MiniTest::Test
|
|
96
95
|
test_gets
|
97
96
|
begin
|
98
97
|
@io.readline
|
99
|
-
fail
|
98
|
+
fail 'EOFError expected'
|
100
99
|
rescue EOFError
|
101
100
|
end
|
102
101
|
end
|
@@ -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 =
|
95
|
-
@output_stream.puts([
|
94
|
+
@output_stream.buffer = ''
|
95
|
+
@output_stream.puts(%W[hello\n world\n])
|
96
96
|
assert_equal("hello\nworld\n", @output_stream.buffer)
|
97
97
|
|
98
|
-
@output_stream.buffer =
|
99
|
-
@output_stream.puts([
|
98
|
+
@output_stream.buffer = ''
|
99
|
+
@output_stream.puts(%W[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
|
-
|
42
|
-
|
43
|
-
}
|
37
|
+
def test_read_local_entry_from_non_zip_file
|
38
|
+
::File.open('test/data/file2.txt') do |file|
|
39
|
+
assert_nil(::Zip::Entry.read_local_entry(file))
|
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
|