rubyzip 1.3.0 → 2.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -8
- data/Rakefile +3 -0
- data/lib/zip.rb +4 -3
- data/lib/zip/central_directory.rb +9 -5
- data/lib/zip/constants.rb +52 -0
- data/lib/zip/crypto/decrypted_io.rb +40 -0
- data/lib/zip/crypto/traditional_encryption.rb +9 -9
- data/lib/zip/decompressor.rb +19 -1
- data/lib/zip/dos_time.rb +12 -7
- data/lib/zip/entry.rb +57 -38
- data/lib/zip/entry_set.rb +2 -0
- data/lib/zip/errors.rb +1 -0
- data/lib/zip/extra_field.rb +11 -9
- data/lib/zip/extra_field/generic.rb +10 -9
- data/lib/zip/extra_field/ntfs.rb +4 -0
- data/lib/zip/extra_field/old_unix.rb +3 -1
- data/lib/zip/extra_field/universal_time.rb +42 -12
- data/lib/zip/extra_field/unix.rb +3 -1
- data/lib/zip/extra_field/zip64.rb +4 -2
- data/lib/zip/file.rb +79 -54
- data/lib/zip/filesystem.rb +193 -177
- data/lib/zip/inflater.rb +24 -36
- data/lib/zip/input_stream.rb +33 -26
- data/lib/zip/ioextras.rb +1 -1
- data/lib/zip/ioextras/abstract_input_stream.rb +19 -8
- data/lib/zip/ioextras/abstract_output_stream.rb +1 -1
- data/lib/zip/null_decompressor.rb +1 -9
- data/lib/zip/output_stream.rb +14 -5
- data/lib/zip/pass_thru_compressor.rb +2 -2
- data/lib/zip/pass_thru_decompressor.rb +13 -22
- data/lib/zip/streamable_directory.rb +3 -3
- data/lib/zip/streamable_stream.rb +6 -10
- data/lib/zip/version.rb +1 -1
- data/samples/example.rb +2 -2
- data/samples/example_filesystem.rb +1 -1
- data/samples/gtk_ruby_zip.rb +19 -19
- data/samples/qtzip.rb +6 -6
- data/samples/write_simple.rb +2 -4
- data/samples/zipfind.rb +23 -22
- metadata +28 -169
- data/test/basic_zip_file_test.rb +0 -60
- data/test/case_sensitivity_test.rb +0 -69
- data/test/central_directory_entry_test.rb +0 -69
- data/test/central_directory_test.rb +0 -100
- data/test/crypto/null_encryption_test.rb +0 -57
- data/test/crypto/traditional_encryption_test.rb +0 -80
- data/test/data/WarnInvalidDate.zip +0 -0
- data/test/data/file1.txt +0 -46
- data/test/data/file1.txt.deflatedData +0 -0
- data/test/data/file2.txt +0 -1504
- data/test/data/globTest.zip +0 -0
- data/test/data/globTest/foo.txt +0 -0
- data/test/data/globTest/foo/bar/baz/foo.txt +0 -0
- data/test/data/globTest/food.txt +0 -0
- data/test/data/gpbit3stored.zip +0 -0
- data/test/data/mimetype +0 -1
- data/test/data/notzippedruby.rb +0 -7
- data/test/data/ntfs.zip +0 -0
- data/test/data/oddExtraField.zip +0 -0
- data/test/data/path_traversal/Makefile +0 -10
- data/test/data/path_traversal/jwilk/README.md +0 -5
- 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 +0 -3
- 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 +0 -65
- data/test/encryption_test.rb +0 -42
- data/test/entry_set_test.rb +0 -163
- data/test/entry_test.rb +0 -154
- data/test/errors_test.rb +0 -35
- data/test/extra_field_test.rb +0 -76
- data/test/file_extract_directory_test.rb +0 -54
- data/test/file_extract_test.rb +0 -145
- data/test/file_permissions_test.rb +0 -65
- data/test/file_split_test.rb +0 -57
- data/test/file_test.rb +0 -666
- data/test/filesystem/dir_iterator_test.rb +0 -58
- data/test/filesystem/directory_test.rb +0 -139
- data/test/filesystem/file_mutating_test.rb +0 -87
- data/test/filesystem/file_nonmutating_test.rb +0 -508
- data/test/filesystem/file_stat_test.rb +0 -64
- data/test/gentestfiles.rb +0 -126
- data/test/inflater_test.rb +0 -14
- data/test/input_stream_test.rb +0 -182
- data/test/ioextras/abstract_input_stream_test.rb +0 -102
- data/test/ioextras/abstract_output_stream_test.rb +0 -106
- data/test/ioextras/fake_io_test.rb +0 -18
- data/test/local_entry_test.rb +0 -154
- data/test/output_stream_test.rb +0 -128
- data/test/pass_thru_compressor_test.rb +0 -30
- data/test/pass_thru_decompressor_test.rb +0 -14
- data/test/path_traversal_test.rb +0 -141
- data/test/samples/example_recursive_test.rb +0 -37
- data/test/settings_test.rb +0 -95
- data/test/test_helper.rb +0 -234
- data/test/unicode_file_names_and_comments_test.rb +0 -62
- data/test/zip64_full_test.rb +0 -51
- data/test/zip64_support_test.rb +0 -14
@@ -1,64 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'zip/filesystem'
|
3
|
-
|
4
|
-
class ZipFsFileStatTest < MiniTest::Test
|
5
|
-
def setup
|
6
|
-
@zip_file = ::Zip::File.new('test/data/zipWithDirs.zip')
|
7
|
-
end
|
8
|
-
|
9
|
-
def teardown
|
10
|
-
@zip_file.close if @zip_file
|
11
|
-
end
|
12
|
-
|
13
|
-
def test_blocks
|
14
|
-
assert_nil(@zip_file.file.stat('file1').blocks)
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_ino
|
18
|
-
assert_equal(0, @zip_file.file.stat('file1').ino)
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_uid
|
22
|
-
assert_equal(0, @zip_file.file.stat('file1').uid)
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_gid
|
26
|
-
assert_equal(0, @zip_file.file.stat('file1').gid)
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_ftype
|
30
|
-
assert_equal('file', @zip_file.file.stat('file1').ftype)
|
31
|
-
assert_equal('directory', @zip_file.file.stat('dir1').ftype)
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_mode
|
35
|
-
assert_equal(0o600, @zip_file.file.stat('file1').mode & 0o777)
|
36
|
-
assert_equal(0o600, @zip_file.file.stat('file1').mode & 0o777)
|
37
|
-
assert_equal(0o755, @zip_file.file.stat('dir1').mode & 0o777)
|
38
|
-
assert_equal(0o755, @zip_file.file.stat('dir1').mode & 0o777)
|
39
|
-
end
|
40
|
-
|
41
|
-
def test_dev
|
42
|
-
assert_equal(0, @zip_file.file.stat('file1').dev)
|
43
|
-
end
|
44
|
-
|
45
|
-
def test_rdev
|
46
|
-
assert_equal(0, @zip_file.file.stat('file1').rdev)
|
47
|
-
end
|
48
|
-
|
49
|
-
def test_rdev_major
|
50
|
-
assert_equal(0, @zip_file.file.stat('file1').rdev_major)
|
51
|
-
end
|
52
|
-
|
53
|
-
def test_rdev_minor
|
54
|
-
assert_equal(0, @zip_file.file.stat('file1').rdev_minor)
|
55
|
-
end
|
56
|
-
|
57
|
-
def test_nlink
|
58
|
-
assert_equal(1, @zip_file.file.stat('file1').nlink)
|
59
|
-
end
|
60
|
-
|
61
|
-
def test_blksize
|
62
|
-
assert_nil(@zip_file.file.stat('file1').blksize)
|
63
|
-
end
|
64
|
-
end
|
data/test/gentestfiles.rb
DELETED
@@ -1,126 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
$VERBOSE = true
|
4
|
-
|
5
|
-
class TestFiles
|
6
|
-
RANDOM_ASCII_FILE1 = 'test/data/generated/randomAscii1.txt'
|
7
|
-
RANDOM_ASCII_FILE2 = 'test/data/generated/randomAscii2.txt'
|
8
|
-
RANDOM_ASCII_FILE3 = 'test/data/generated/randomAscii3.txt'
|
9
|
-
RANDOM_BINARY_FILE1 = 'test/data/generated/randomBinary1.bin'
|
10
|
-
RANDOM_BINARY_FILE2 = 'test/data/generated/randomBinary2.bin'
|
11
|
-
|
12
|
-
NULL_FILE = 'test/data/generated/null.zip' # Zero length, so not a zip file.
|
13
|
-
|
14
|
-
EMPTY_TEST_DIR = 'test/data/generated/emptytestdir'
|
15
|
-
|
16
|
-
ASCII_TEST_FILES = [RANDOM_ASCII_FILE1, RANDOM_ASCII_FILE2, RANDOM_ASCII_FILE3]
|
17
|
-
BINARY_TEST_FILES = [RANDOM_BINARY_FILE1, RANDOM_BINARY_FILE2]
|
18
|
-
TEST_DIRECTORIES = [EMPTY_TEST_DIR]
|
19
|
-
TEST_FILES = [ASCII_TEST_FILES, BINARY_TEST_FILES, EMPTY_TEST_DIR].flatten!
|
20
|
-
|
21
|
-
class << self
|
22
|
-
def create_test_files
|
23
|
-
Dir.mkdir 'test/data/generated' unless Dir.exist?('test/data/generated')
|
24
|
-
|
25
|
-
ASCII_TEST_FILES.each_with_index do |filename, index|
|
26
|
-
create_random_ascii(filename, 1E4 * (index + 1))
|
27
|
-
end
|
28
|
-
|
29
|
-
BINARY_TEST_FILES.each_with_index do |filename, index|
|
30
|
-
create_random_binary(filename, 1E4 * (index + 1))
|
31
|
-
end
|
32
|
-
|
33
|
-
system("touch #{NULL_FILE}")
|
34
|
-
|
35
|
-
ensure_dir(EMPTY_TEST_DIR)
|
36
|
-
end
|
37
|
-
|
38
|
-
private
|
39
|
-
|
40
|
-
def create_random_ascii(filename, size)
|
41
|
-
File.open(filename, 'wb') do |file|
|
42
|
-
file << rand while file.tell < size
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
def create_random_binary(filename, size)
|
47
|
-
File.open(filename, 'wb') do |file|
|
48
|
-
file << [rand].pack('V') while file.tell < size
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
def ensure_dir(name)
|
53
|
-
if File.exist?(name)
|
54
|
-
return if File.stat(name).directory?
|
55
|
-
File.delete(name)
|
56
|
-
end
|
57
|
-
Dir.mkdir(name)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
# For representation and creation of
|
63
|
-
# test data
|
64
|
-
class TestZipFile
|
65
|
-
attr_accessor :zip_name, :entry_names, :comment
|
66
|
-
|
67
|
-
def initialize(zip_name, entry_names, comment = '')
|
68
|
-
@zip_name = zip_name
|
69
|
-
@entry_names = entry_names
|
70
|
-
@comment = comment
|
71
|
-
end
|
72
|
-
|
73
|
-
def self.create_test_zips
|
74
|
-
raise "failed to create test zip '#{TEST_ZIP1.zip_name}'" unless system("/usr/bin/zip -q #{TEST_ZIP1.zip_name} test/data/file2.txt")
|
75
|
-
raise "failed to remove entry from '#{TEST_ZIP1.zip_name}'" unless system("/usr/bin/zip -q #{TEST_ZIP1.zip_name} -d test/data/file2.txt")
|
76
|
-
|
77
|
-
File.open('test/data/generated/empty.txt', 'w') {}
|
78
|
-
File.open('test/data/generated/empty_chmod640.txt', 'w') {}
|
79
|
-
::File.chmod(0o640, 'test/data/generated/empty_chmod640.txt')
|
80
|
-
|
81
|
-
File.open('test/data/generated/short.txt', 'w') { |file| file << 'ABCDEF' }
|
82
|
-
ziptestTxt = ''
|
83
|
-
File.open('test/data/file2.txt') { |file| ziptestTxt = file.read }
|
84
|
-
File.open('test/data/generated/longAscii.txt', 'w') do |file|
|
85
|
-
file << ziptestTxt while file.tell < 1E5
|
86
|
-
end
|
87
|
-
|
88
|
-
testBinaryPattern = ''
|
89
|
-
File.open('test/data/generated/empty.zip') { |file| testBinaryPattern = file.read }
|
90
|
-
testBinaryPattern *= 4
|
91
|
-
|
92
|
-
File.open('test/data/generated/longBinary.bin', 'wb') do |file|
|
93
|
-
file << testBinaryPattern << rand << "\0" while file.tell < 6E5
|
94
|
-
end
|
95
|
-
|
96
|
-
raise "failed to create test zip '#{TEST_ZIP2.zip_name}'" unless system("/usr/bin/zip -q #{TEST_ZIP2.zip_name} #{TEST_ZIP2.entry_names.join(' ')}")
|
97
|
-
|
98
|
-
if RUBY_PLATFORM =~ /mswin|mingw|cygwin/
|
99
|
-
raise "failed to add comment to test zip '#{TEST_ZIP2.zip_name}'" unless system("echo #{TEST_ZIP2.comment}| /usr/bin/zip -zq #{TEST_ZIP2.zip_name}\"")
|
100
|
-
else
|
101
|
-
# without bash system interprets everything after echo as parameters to
|
102
|
-
# echo including | zip -z ...
|
103
|
-
raise "failed to add comment to test zip '#{TEST_ZIP2.zip_name}'" unless system("bash -c \"echo #{TEST_ZIP2.comment} | /usr/bin/zip -zq #{TEST_ZIP2.zip_name}\"")
|
104
|
-
end
|
105
|
-
|
106
|
-
raise "failed to create test zip '#{TEST_ZIP3.zip_name}'" unless system("/usr/bin/zip -q #{TEST_ZIP3.zip_name} #{TEST_ZIP3.entry_names.join(' ')}")
|
107
|
-
|
108
|
-
raise "failed to create test zip '#{TEST_ZIP4.zip_name}'" unless system("/usr/bin/zip -q #{TEST_ZIP4.zip_name} #{TEST_ZIP4.entry_names.join(' ')}")
|
109
|
-
rescue
|
110
|
-
# If there are any Windows developers wanting to use a command line zip.exe
|
111
|
-
# to help create the following files, there's a free one available from
|
112
|
-
# http://stahlworks.com/dev/index.php?tool=zipunzip
|
113
|
-
# that works with the above code
|
114
|
-
raise $!.to_s +
|
115
|
-
"\n\nziptest.rb requires the Info-ZIP program 'zip' in the path\n" \
|
116
|
-
"to create test data. If you don't have it you can download\n" \
|
117
|
-
'the necessary test files at http://sf.net/projects/rubyzip.'
|
118
|
-
end
|
119
|
-
|
120
|
-
TEST_ZIP1 = TestZipFile.new('test/data/generated/empty.zip', [])
|
121
|
-
TEST_ZIP2 = TestZipFile.new('test/data/generated/5entry.zip', %w[test/data/generated/longAscii.txt test/data/generated/empty.txt test/data/generated/empty_chmod640.txt test/data/generated/short.txt test/data/generated/longBinary.bin],
|
122
|
-
'my zip comment')
|
123
|
-
TEST_ZIP3 = TestZipFile.new('test/data/generated/test1.zip', %w[test/data/file1.txt])
|
124
|
-
TEST_ZIP4 = TestZipFile.new('test/data/generated/zipWithDir.zip', ['test/data/file1.txt',
|
125
|
-
TestFiles::EMPTY_TEST_DIR])
|
126
|
-
end
|
data/test/inflater_test.rb
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
class InflaterTest < MiniTest::Test
|
3
|
-
include DecompressorTests
|
4
|
-
|
5
|
-
def setup
|
6
|
-
super
|
7
|
-
@file = File.new('test/data/file1.txt.deflatedData', 'rb')
|
8
|
-
@decompressor = ::Zip::Inflater.new(@file)
|
9
|
-
end
|
10
|
-
|
11
|
-
def teardown
|
12
|
-
@file.close
|
13
|
-
end
|
14
|
-
end
|
data/test/input_stream_test.rb
DELETED
@@ -1,182 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class ZipInputStreamTest < MiniTest::Test
|
4
|
-
include AssertEntry
|
5
|
-
|
6
|
-
class IOLike
|
7
|
-
extend Forwardable
|
8
|
-
|
9
|
-
def initialize(path, mode)
|
10
|
-
@file = File.new(path, mode)
|
11
|
-
end
|
12
|
-
|
13
|
-
delegate ::Zip::File::IO_METHODS => :@file
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_new
|
17
|
-
zis = ::Zip::InputStream.new(TestZipFile::TEST_ZIP2.zip_name)
|
18
|
-
assert_stream_contents(zis, TestZipFile::TEST_ZIP2)
|
19
|
-
assert_equal(true, zis.eof?)
|
20
|
-
zis.close
|
21
|
-
end
|
22
|
-
|
23
|
-
def test_open_with_block
|
24
|
-
::Zip::InputStream.open(TestZipFile::TEST_ZIP2.zip_name) do |zis|
|
25
|
-
assert_stream_contents(zis, TestZipFile::TEST_ZIP2)
|
26
|
-
assert_equal(true, zis.eof?)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_open_without_block
|
31
|
-
zis = ::Zip::InputStream.open(File.new(TestZipFile::TEST_ZIP2.zip_name, 'rb'))
|
32
|
-
assert_stream_contents(zis, TestZipFile::TEST_ZIP2)
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_open_buffer_with_block
|
36
|
-
::Zip::InputStream.open(File.new(TestZipFile::TEST_ZIP2.zip_name, 'rb')) do |zis|
|
37
|
-
assert_stream_contents(zis, TestZipFile::TEST_ZIP2)
|
38
|
-
assert_equal(true, zis.eof?)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_open_string_io_without_block
|
43
|
-
string_io = ::StringIO.new(::File.read(TestZipFile::TEST_ZIP2.zip_name))
|
44
|
-
zis = ::Zip::InputStream.open(string_io)
|
45
|
-
assert_stream_contents(zis, TestZipFile::TEST_ZIP2)
|
46
|
-
end
|
47
|
-
|
48
|
-
def test_open_string_io_with_block
|
49
|
-
string_io = ::StringIO.new(::File.read(TestZipFile::TEST_ZIP2.zip_name))
|
50
|
-
::Zip::InputStream.open(string_io) do |zis|
|
51
|
-
assert_stream_contents(zis, TestZipFile::TEST_ZIP2)
|
52
|
-
assert_equal(true, zis.eof?)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
def test_open_buffer_without_block
|
57
|
-
zis = ::Zip::InputStream.open(TestZipFile::TEST_ZIP2.zip_name)
|
58
|
-
assert_stream_contents(zis, TestZipFile::TEST_ZIP2)
|
59
|
-
end
|
60
|
-
|
61
|
-
def test_open_io_like_with_block
|
62
|
-
::Zip::InputStream.open(IOLike.new(TestZipFile::TEST_ZIP2.zip_name, 'rb')) do |zis|
|
63
|
-
assert_stream_contents(zis, TestZipFile::TEST_ZIP2)
|
64
|
-
assert_equal(true, zis.eof?)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
def test_incomplete_reads
|
69
|
-
::Zip::InputStream.open(TestZipFile::TEST_ZIP2.zip_name) do |zis|
|
70
|
-
entry = zis.get_next_entry # longAscii.txt
|
71
|
-
assert_equal(false, zis.eof?)
|
72
|
-
assert_equal(TestZipFile::TEST_ZIP2.entry_names[0], entry.name)
|
73
|
-
assert !zis.gets.empty?
|
74
|
-
assert_equal(false, zis.eof?)
|
75
|
-
entry = zis.get_next_entry # empty.txt
|
76
|
-
assert_equal(TestZipFile::TEST_ZIP2.entry_names[1], entry.name)
|
77
|
-
assert_equal(0, entry.size)
|
78
|
-
assert_nil(zis.gets)
|
79
|
-
assert_equal(true, zis.eof?)
|
80
|
-
entry = zis.get_next_entry # empty_chmod640.txt
|
81
|
-
assert_equal(TestZipFile::TEST_ZIP2.entry_names[2], entry.name)
|
82
|
-
assert_equal(0, entry.size)
|
83
|
-
assert_nil(zis.gets)
|
84
|
-
assert_equal(true, zis.eof?)
|
85
|
-
entry = zis.get_next_entry # short.txt
|
86
|
-
assert_equal(TestZipFile::TEST_ZIP2.entry_names[3], entry.name)
|
87
|
-
assert !zis.gets.empty?
|
88
|
-
entry = zis.get_next_entry # longBinary.bin
|
89
|
-
assert_equal(TestZipFile::TEST_ZIP2.entry_names[4], entry.name)
|
90
|
-
assert !zis.gets.empty?
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
def test_incomplete_reads_from_string_io
|
95
|
-
string_io = ::StringIO.new(::File.read(TestZipFile::TEST_ZIP2.zip_name))
|
96
|
-
::Zip::InputStream.open(string_io) do |zis|
|
97
|
-
entry = zis.get_next_entry # longAscii.txt
|
98
|
-
assert_equal(false, zis.eof?)
|
99
|
-
assert_equal(TestZipFile::TEST_ZIP2.entry_names[0], entry.name)
|
100
|
-
assert !zis.gets.empty?
|
101
|
-
assert_equal(false, zis.eof?)
|
102
|
-
entry = zis.get_next_entry # empty.txt
|
103
|
-
assert_equal(TestZipFile::TEST_ZIP2.entry_names[1], entry.name)
|
104
|
-
assert_equal(0, entry.size)
|
105
|
-
assert_nil(zis.gets)
|
106
|
-
assert_equal(true, zis.eof?)
|
107
|
-
entry = zis.get_next_entry # empty_chmod640.txt
|
108
|
-
assert_equal(TestZipFile::TEST_ZIP2.entry_names[2], entry.name)
|
109
|
-
assert_equal(0, entry.size)
|
110
|
-
assert_nil(zis.gets)
|
111
|
-
assert_equal(true, zis.eof?)
|
112
|
-
entry = zis.get_next_entry # short.txt
|
113
|
-
assert_equal(TestZipFile::TEST_ZIP2.entry_names[3], entry.name)
|
114
|
-
assert !zis.gets.empty?
|
115
|
-
entry = zis.get_next_entry # longBinary.bin
|
116
|
-
assert_equal(TestZipFile::TEST_ZIP2.entry_names[4], entry.name)
|
117
|
-
assert !zis.gets.empty?
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
def test_read_with_number_of_bytes_returns_nil_at_eof
|
122
|
-
::Zip::InputStream.open(TestZipFile::TEST_ZIP2.zip_name) do |zis|
|
123
|
-
entry = zis.get_next_entry # longAscii.txt
|
124
|
-
zis.read(entry.size)
|
125
|
-
assert_equal(true, zis.eof?)
|
126
|
-
assert_nil(zis.read(1))
|
127
|
-
assert_nil(zis.read(1))
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
def test_rewind
|
132
|
-
::Zip::InputStream.open(TestZipFile::TEST_ZIP2.zip_name) do |zis|
|
133
|
-
e = zis.get_next_entry
|
134
|
-
assert_equal(TestZipFile::TEST_ZIP2.entry_names[0], e.name)
|
135
|
-
|
136
|
-
# Do a little reading
|
137
|
-
buf = ''
|
138
|
-
buf << zis.read(100)
|
139
|
-
assert_equal(100, zis.pos)
|
140
|
-
buf << (zis.gets || '')
|
141
|
-
buf << (zis.gets || '')
|
142
|
-
assert_equal(false, zis.eof?)
|
143
|
-
|
144
|
-
zis.rewind
|
145
|
-
|
146
|
-
buf2 = ''
|
147
|
-
buf2 << zis.read(100)
|
148
|
-
buf2 << (zis.gets || '')
|
149
|
-
buf2 << (zis.gets || '')
|
150
|
-
|
151
|
-
assert_equal(buf, buf2)
|
152
|
-
|
153
|
-
zis.rewind
|
154
|
-
assert_equal(false, zis.eof?)
|
155
|
-
assert_equal(0, zis.pos)
|
156
|
-
|
157
|
-
assert_entry(e.name, zis, e.name)
|
158
|
-
end
|
159
|
-
end
|
160
|
-
|
161
|
-
def test_mix_read_and_gets
|
162
|
-
::Zip::InputStream.open(TestZipFile::TEST_ZIP2.zip_name) do |zis|
|
163
|
-
zis.get_next_entry
|
164
|
-
assert_equal('#!/usr/bin/env ruby', zis.gets.chomp)
|
165
|
-
assert_equal(false, zis.eof?)
|
166
|
-
assert_equal('', zis.gets.chomp)
|
167
|
-
assert_equal(false, zis.eof?)
|
168
|
-
assert_equal('$VERBOSE =', zis.read(10))
|
169
|
-
assert_equal(false, zis.eof?)
|
170
|
-
end
|
171
|
-
end
|
172
|
-
|
173
|
-
def test_ungetc
|
174
|
-
::Zip::InputStream.open(TestZipFile::TEST_ZIP2.zip_name) do |zis|
|
175
|
-
zis.get_next_entry
|
176
|
-
first_line = zis.gets.chomp
|
177
|
-
first_line.reverse.bytes.each { |b| zis.ungetc(b) }
|
178
|
-
assert_equal('#!/usr/bin/env ruby', zis.gets.chomp)
|
179
|
-
assert_equal('$VERBOSE =', zis.read(10))
|
180
|
-
end
|
181
|
-
end
|
182
|
-
end
|
@@ -1,102 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'zip/ioextras'
|
3
|
-
|
4
|
-
class AbstractInputStreamTest < MiniTest::Test
|
5
|
-
# AbstractInputStream subclass that provides a read method
|
6
|
-
|
7
|
-
TEST_LINES = ["Hello world#{$/}",
|
8
|
-
"this is the second line#{$/}",
|
9
|
-
'this is the last line']
|
10
|
-
TEST_STRING = TEST_LINES.join
|
11
|
-
class TestAbstractInputStream
|
12
|
-
include ::Zip::IOExtras::AbstractInputStream
|
13
|
-
|
14
|
-
def initialize(aString)
|
15
|
-
super()
|
16
|
-
@contents = aString
|
17
|
-
@readPointer = 0
|
18
|
-
end
|
19
|
-
|
20
|
-
def sysread(charsToRead, _buf = nil)
|
21
|
-
retVal = @contents[@readPointer, charsToRead]
|
22
|
-
@readPointer += charsToRead
|
23
|
-
retVal
|
24
|
-
end
|
25
|
-
|
26
|
-
def produce_input
|
27
|
-
sysread(100)
|
28
|
-
end
|
29
|
-
|
30
|
-
def input_finished?
|
31
|
-
@contents[@readPointer].nil?
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def setup
|
36
|
-
@io = TestAbstractInputStream.new(TEST_STRING)
|
37
|
-
end
|
38
|
-
|
39
|
-
def test_gets
|
40
|
-
assert_equal(TEST_LINES[0], @io.gets)
|
41
|
-
assert_equal(1, @io.lineno)
|
42
|
-
assert_equal(TEST_LINES[0].length, @io.pos)
|
43
|
-
assert_equal(TEST_LINES[1], @io.gets)
|
44
|
-
assert_equal(2, @io.lineno)
|
45
|
-
assert_equal(TEST_LINES[2], @io.gets)
|
46
|
-
assert_equal(3, @io.lineno)
|
47
|
-
assert_nil(@io.gets)
|
48
|
-
assert_equal(4, @io.lineno)
|
49
|
-
end
|
50
|
-
|
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
|
-
end
|
55
|
-
|
56
|
-
LONG_LINES = [
|
57
|
-
'x' * 48 + "\r\n",
|
58
|
-
'y' * 49 + "\r\n",
|
59
|
-
'rest'
|
60
|
-
]
|
61
|
-
|
62
|
-
def test_gets_mulit_char_seperator_split
|
63
|
-
io = TestAbstractInputStream.new(LONG_LINES.join)
|
64
|
-
assert_equal(LONG_LINES[0], io.gets("\r\n"))
|
65
|
-
assert_equal(LONG_LINES[1], io.gets("\r\n"))
|
66
|
-
assert_equal(LONG_LINES[2], io.gets("\r\n"))
|
67
|
-
end
|
68
|
-
|
69
|
-
def test_gets_with_sep_and_index
|
70
|
-
io = TestAbstractInputStream.new(LONG_LINES.join)
|
71
|
-
assert_equal('x', io.gets("\r\n", 1))
|
72
|
-
assert_equal('x' * 47 + "\r", io.gets("\r\n", 48))
|
73
|
-
assert_equal("\n", io.gets(nil, 1))
|
74
|
-
assert_equal('yy', io.gets(nil, 2))
|
75
|
-
end
|
76
|
-
|
77
|
-
def test_gets_with_index
|
78
|
-
assert_equal(TEST_LINES[0], @io.gets(100))
|
79
|
-
assert_equal('this', @io.gets(4))
|
80
|
-
end
|
81
|
-
|
82
|
-
def test_each_line
|
83
|
-
lineNumber = 0
|
84
|
-
@io.each_line do |line|
|
85
|
-
assert_equal(TEST_LINES[lineNumber], line)
|
86
|
-
lineNumber += 1
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
def test_readlines
|
91
|
-
assert_equal(TEST_LINES, @io.readlines)
|
92
|
-
end
|
93
|
-
|
94
|
-
def test_readline
|
95
|
-
test_gets
|
96
|
-
begin
|
97
|
-
@io.readline
|
98
|
-
fail 'EOFError expected'
|
99
|
-
rescue EOFError
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|