rubyzip 1.1.7 → 2.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/README.md +137 -54
- data/Rakefile +6 -4
- data/lib/zip/central_directory.rb +17 -13
- data/lib/zip/compressor.rb +1 -2
- data/lib/zip/constants.rb +57 -5
- data/lib/zip/crypto/decrypted_io.rb +40 -0
- data/lib/zip/crypto/null_encryption.rb +4 -6
- data/lib/zip/crypto/traditional_encryption.rb +14 -14
- data/lib/zip/decompressor.rb +22 -4
- data/lib/zip/deflater.rb +8 -6
- data/lib/zip/dos_time.rb +17 -13
- data/lib/zip/entry.rb +171 -148
- data/lib/zip/entry_set.rb +16 -14
- data/lib/zip/errors.rb +3 -0
- data/lib/zip/extra_field/generic.rb +14 -13
- data/lib/zip/extra_field/ntfs.rb +18 -16
- data/lib/zip/extra_field/old_unix.rb +12 -11
- data/lib/zip/extra_field/universal_time.rb +46 -16
- data/lib/zip/extra_field/unix.rb +10 -9
- data/lib/zip/extra_field/zip64.rb +15 -12
- data/lib/zip/extra_field/zip64_placeholder.rb +1 -2
- data/lib/zip/extra_field.rb +18 -16
- data/lib/zip/file.rb +147 -115
- data/lib/zip/filesystem.rb +289 -272
- data/lib/zip/inflater.rb +24 -36
- data/lib/zip/input_stream.rb +44 -28
- data/lib/zip/ioextras/abstract_input_stream.rb +24 -17
- data/lib/zip/ioextras/abstract_output_stream.rb +4 -6
- data/lib/zip/ioextras.rb +2 -4
- data/lib/zip/null_compressor.rb +2 -2
- data/lib/zip/null_decompressor.rb +3 -11
- data/lib/zip/null_input_stream.rb +0 -0
- data/lib/zip/output_stream.rb +25 -17
- data/lib/zip/pass_thru_compressor.rb +6 -6
- data/lib/zip/pass_thru_decompressor.rb +14 -24
- data/lib/zip/streamable_directory.rb +3 -3
- data/lib/zip/streamable_stream.rb +7 -11
- data/lib/zip/version.rb +1 -1
- data/lib/zip.rb +15 -6
- data/samples/example.rb +29 -39
- data/samples/example_filesystem.rb +16 -18
- data/samples/example_recursive.rb +31 -25
- data/samples/gtk_ruby_zip.rb +84 -0
- data/samples/qtzip.rb +23 -32
- data/samples/write_simple.rb +10 -13
- data/samples/zipfind.rb +33 -40
- metadata +50 -141
- data/samples/gtkRubyzip.rb +0 -86
- data/test/basic_zip_file_test.rb +0 -64
- data/test/central_directory_entry_test.rb +0 -73
- data/test/central_directory_test.rb +0 -104
- data/test/crypto/null_encryption_test.rb +0 -53
- 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/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 +0 -1
- data/test/data/notzippedruby.rb +0 -7
- data/test/data/ntfs.zip +0 -0
- data/test/data/rubycode.zip +0 -0
- data/test/data/rubycode2.zip +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 -67
- data/test/encryption_test.rb +0 -42
- data/test/entry_set_test.rb +0 -138
- data/test/entry_test.rb +0 -165
- data/test/errors_test.rb +0 -36
- data/test/extra_field_test.rb +0 -78
- data/test/file_extract_directory_test.rb +0 -56
- data/test/file_extract_test.rb +0 -90
- data/test/file_split_test.rb +0 -60
- data/test/file_test.rb +0 -559
- data/test/filesystem/dir_iterator_test.rb +0 -62
- data/test/filesystem/directory_test.rb +0 -131
- data/test/filesystem/file_mutating_test.rb +0 -100
- data/test/filesystem/file_nonmutating_test.rb +0 -514
- data/test/filesystem/file_stat_test.rb +0 -66
- data/test/gentestfiles.rb +0 -134
- data/test/inflater_test.rb +0 -14
- data/test/input_stream_test.rb +0 -170
- data/test/ioextras/abstract_input_stream_test.rb +0 -103
- 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 -156
- data/test/output_stream_test.rb +0 -129
- data/test/pass_thru_compressor_test.rb +0 -31
- data/test/pass_thru_decompressor_test.rb +0 -15
- data/test/settings_test.rb +0 -92
- data/test/test_helper.rb +0 -228
- data/test/unicode_file_names_and_comments_test.rb +0 -52
- data/test/zip64_full_test.rb +0 -53
- data/test/zip64_support_test.rb +0 -15
data/test/gentestfiles.rb
DELETED
@@ -1,134 +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
|
-
EMPTY_TEST_DIR = "test/data/generated/emptytestdir"
|
13
|
-
|
14
|
-
ASCII_TEST_FILES = [RANDOM_ASCII_FILE1, RANDOM_ASCII_FILE2, RANDOM_ASCII_FILE3]
|
15
|
-
BINARY_TEST_FILES = [RANDOM_BINARY_FILE1, RANDOM_BINARY_FILE2]
|
16
|
-
TEST_DIRECTORIES = [EMPTY_TEST_DIR]
|
17
|
-
TEST_FILES = [ASCII_TEST_FILES, BINARY_TEST_FILES, EMPTY_TEST_DIR].flatten!
|
18
|
-
|
19
|
-
class << self
|
20
|
-
def create_test_files
|
21
|
-
Dir.mkdir "test/data/generated" unless Dir.exist?('test/data/generated')
|
22
|
-
|
23
|
-
ASCII_TEST_FILES.each_with_index do |filename, index|
|
24
|
-
create_random_ascii(filename, 1E4 * (index+1))
|
25
|
-
end
|
26
|
-
|
27
|
-
BINARY_TEST_FILES.each_with_index do |filename, index|
|
28
|
-
create_random_binary(filename, 1E4 * (index+1))
|
29
|
-
end
|
30
|
-
|
31
|
-
ensure_dir(EMPTY_TEST_DIR)
|
32
|
-
end
|
33
|
-
|
34
|
-
private
|
35
|
-
|
36
|
-
def create_random_ascii(filename, size)
|
37
|
-
File.open(filename, "wb") do |file|
|
38
|
-
while (file.tell < size)
|
39
|
-
file << rand
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
def create_random_binary(filename, size)
|
45
|
-
File.open(filename, "wb") do |file|
|
46
|
-
while (file.tell < size)
|
47
|
-
file << [rand].pack("V")
|
48
|
-
end
|
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
|
-
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
|
64
|
-
# For representation and creation of
|
65
|
-
# test data
|
66
|
-
class TestZipFile
|
67
|
-
attr_accessor :zip_name, :entry_names, :comment
|
68
|
-
|
69
|
-
def initialize(zip_name, entry_names, comment = "")
|
70
|
-
@zip_name=zip_name
|
71
|
-
@entry_names=entry_names
|
72
|
-
@comment = comment
|
73
|
-
end
|
74
|
-
|
75
|
-
def TestZipFile.create_test_zips
|
76
|
-
raise "failed to create test zip '#{TEST_ZIP1.zip_name}'" unless system("/usr/bin/zip #{TEST_ZIP1.zip_name} test/data/file2.txt")
|
77
|
-
raise "failed to remove entry from '#{TEST_ZIP1.zip_name}'" unless system("/usr/bin/zip #{TEST_ZIP1.zip_name} -d test/data/file2.txt")
|
78
|
-
|
79
|
-
File.open("test/data/generated/empty.txt", "w") {}
|
80
|
-
File.open("test/data/generated/empty_chmod640.txt", "w") {}
|
81
|
-
::File.chmod(0640, "test/data/generated/empty_chmod640.txt")
|
82
|
-
|
83
|
-
File.open("test/data/generated/short.txt", "w") { |file| file << "ABCDEF" }
|
84
|
-
ziptestTxt=""
|
85
|
-
File.open("test/data/file2.txt") { |file| ziptestTxt=file.read }
|
86
|
-
File.open("test/data/generated/longAscii.txt", "w") do |file|
|
87
|
-
while (file.tell < 1E5)
|
88
|
-
file << ziptestTxt
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
testBinaryPattern=""
|
93
|
-
File.open("test/data/generated/empty.zip") { |file| testBinaryPattern=file.read }
|
94
|
-
testBinaryPattern *= 4
|
95
|
-
|
96
|
-
File.open("test/data/generated/longBinary.bin", "wb") do |file|
|
97
|
-
while (file.tell < 6E5)
|
98
|
-
file << testBinaryPattern << rand << "\0"
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
raise "failed to create test zip '#{TEST_ZIP2.zip_name}'" unless system("/usr/bin/zip #{TEST_ZIP2.zip_name} #{TEST_ZIP2.entry_names.join(' ')}")
|
103
|
-
|
104
|
-
if RUBY_PLATFORM =~ /mswin|mingw|cygwin/
|
105
|
-
raise "failed to add comment to test zip '#{TEST_ZIP2.zip_name}'" unless system("echo #{TEST_ZIP2.comment}| /usr/bin/zip -z #{TEST_ZIP2.zip_name}\"")
|
106
|
-
else
|
107
|
-
# without bash system interprets everything after echo as parameters to
|
108
|
-
# echo including | zip -z ...
|
109
|
-
raise "failed to add comment to test zip '#{TEST_ZIP2.zip_name}'" unless system("bash -c \"echo #{TEST_ZIP2.comment} | /usr/bin/zip -z #{TEST_ZIP2.zip_name}\"")
|
110
|
-
end
|
111
|
-
|
112
|
-
raise "failed to create test zip '#{TEST_ZIP3.zip_name}'" unless system("/usr/bin/zip #{TEST_ZIP3.zip_name} #{TEST_ZIP3.entry_names.join(' ')}")
|
113
|
-
|
114
|
-
raise "failed to create test zip '#{TEST_ZIP4.zip_name}'" unless system("/usr/bin/zip #{TEST_ZIP4.zip_name} #{TEST_ZIP4.entry_names.join(' ')}")
|
115
|
-
rescue
|
116
|
-
# If there are any Windows developers wanting to use a command line zip.exe
|
117
|
-
# to help create the following files, there's a free one available from
|
118
|
-
# http://stahlworks.com/dev/index.php?tool=zipunzip
|
119
|
-
# that works with the above code
|
120
|
-
raise $!.to_s +
|
121
|
-
"\n\nziptest.rb requires the Info-ZIP program 'zip' in the path\n" +
|
122
|
-
"to create test data. If you don't have it you can download\n" +
|
123
|
-
"the necessary test files at http://sf.net/projects/rubyzip."
|
124
|
-
end
|
125
|
-
|
126
|
-
TEST_ZIP1 = TestZipFile.new("test/data/generated/empty.zip", [])
|
127
|
-
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},
|
128
|
-
"my zip comment")
|
129
|
-
TEST_ZIP3 = TestZipFile.new("test/data/generated/test1.zip", %w{ test/data/file1.txt })
|
130
|
-
TEST_ZIP4 = TestZipFile.new("test/data/generated/zipWithDir.zip", ["test/data/file1.txt",
|
131
|
-
TestFiles::EMPTY_TEST_DIR])
|
132
|
-
end
|
133
|
-
|
134
|
-
|
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,170 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class ZipInputStreamTest < MiniTest::Test
|
4
|
-
include AssertEntry
|
5
|
-
|
6
|
-
def test_new
|
7
|
-
zis = ::Zip::InputStream.new(TestZipFile::TEST_ZIP2.zip_name)
|
8
|
-
assert_stream_contents(zis, TestZipFile::TEST_ZIP2)
|
9
|
-
assert_equal(true, zis.eof?)
|
10
|
-
zis.close
|
11
|
-
end
|
12
|
-
|
13
|
-
def test_openWithBlock
|
14
|
-
::Zip::InputStream.open(TestZipFile::TEST_ZIP2.zip_name) {
|
15
|
-
|zis|
|
16
|
-
assert_stream_contents(zis, TestZipFile::TEST_ZIP2)
|
17
|
-
assert_equal(true, zis.eof?)
|
18
|
-
}
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_openWithoutBlock
|
22
|
-
zis = ::Zip::InputStream.open(File.new(TestZipFile::TEST_ZIP2.zip_name, "rb"))
|
23
|
-
assert_stream_contents(zis, TestZipFile::TEST_ZIP2)
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_openBufferWithBlock
|
27
|
-
::Zip::InputStream.open(File.new(TestZipFile::TEST_ZIP2.zip_name, "rb")) do |zis|
|
28
|
-
assert_stream_contents(zis, TestZipFile::TEST_ZIP2)
|
29
|
-
assert_equal(true, zis.eof?)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_open_string_io_without_block
|
34
|
-
string_io = ::StringIO.new(::File.read(TestZipFile::TEST_ZIP2.zip_name))
|
35
|
-
zis = ::Zip::InputStream.open(string_io)
|
36
|
-
assert_stream_contents(zis, TestZipFile::TEST_ZIP2)
|
37
|
-
end
|
38
|
-
|
39
|
-
def test_open_string_io_with_block
|
40
|
-
string_io = ::StringIO.new(::File.read(TestZipFile::TEST_ZIP2.zip_name))
|
41
|
-
::Zip::InputStream.open(string_io) do |zis|
|
42
|
-
assert_stream_contents(zis, TestZipFile::TEST_ZIP2)
|
43
|
-
assert_equal(true, zis.eof?)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
def test_openBufferWithoutBlock
|
48
|
-
zis = ::Zip::InputStream.open(TestZipFile::TEST_ZIP2.zip_name)
|
49
|
-
assert_stream_contents(zis, TestZipFile::TEST_ZIP2)
|
50
|
-
end
|
51
|
-
|
52
|
-
def test_incompleteReads
|
53
|
-
::Zip::InputStream.open(TestZipFile::TEST_ZIP2.zip_name) {
|
54
|
-
|zis|
|
55
|
-
entry = zis.get_next_entry # longAscii.txt
|
56
|
-
assert_equal(false, zis.eof?)
|
57
|
-
assert_equal(TestZipFile::TEST_ZIP2.entry_names[0], entry.name)
|
58
|
-
assert zis.gets.length > 0
|
59
|
-
assert_equal(false, zis.eof?)
|
60
|
-
entry = zis.get_next_entry # empty.txt
|
61
|
-
assert_equal(TestZipFile::TEST_ZIP2.entry_names[1], entry.name)
|
62
|
-
assert_equal(0, entry.size)
|
63
|
-
assert_equal(nil, zis.gets)
|
64
|
-
assert_equal(true, zis.eof?)
|
65
|
-
entry = zis.get_next_entry # empty_chmod640.txt
|
66
|
-
assert_equal(TestZipFile::TEST_ZIP2.entry_names[2], entry.name)
|
67
|
-
assert_equal(0, entry.size)
|
68
|
-
assert_equal(nil, zis.gets)
|
69
|
-
assert_equal(true, zis.eof?)
|
70
|
-
entry = zis.get_next_entry # short.txt
|
71
|
-
assert_equal(TestZipFile::TEST_ZIP2.entry_names[3], entry.name)
|
72
|
-
assert zis.gets.length > 0
|
73
|
-
entry = zis.get_next_entry # longBinary.bin
|
74
|
-
assert_equal(TestZipFile::TEST_ZIP2.entry_names[4], entry.name)
|
75
|
-
assert zis.gets.length > 0
|
76
|
-
}
|
77
|
-
end
|
78
|
-
|
79
|
-
def test_incomplete_reads_from_string_io
|
80
|
-
string_io = ::StringIO.new(::File.read(TestZipFile::TEST_ZIP2.zip_name))
|
81
|
-
::Zip::InputStream.open(string_io) do |zis|
|
82
|
-
entry = zis.get_next_entry # longAscii.txt
|
83
|
-
assert_equal(false, zis.eof?)
|
84
|
-
assert_equal(TestZipFile::TEST_ZIP2.entry_names[0], entry.name)
|
85
|
-
assert zis.gets.length > 0
|
86
|
-
assert_equal(false, zis.eof?)
|
87
|
-
entry = zis.get_next_entry # empty.txt
|
88
|
-
assert_equal(TestZipFile::TEST_ZIP2.entry_names[1], entry.name)
|
89
|
-
assert_equal(0, entry.size)
|
90
|
-
assert_equal(nil, zis.gets)
|
91
|
-
assert_equal(true, zis.eof?)
|
92
|
-
entry = zis.get_next_entry # empty_chmod640.txt
|
93
|
-
assert_equal(TestZipFile::TEST_ZIP2.entry_names[2], entry.name)
|
94
|
-
assert_equal(0, entry.size)
|
95
|
-
assert_equal(nil, zis.gets)
|
96
|
-
assert_equal(true, zis.eof?)
|
97
|
-
entry = zis.get_next_entry # short.txt
|
98
|
-
assert_equal(TestZipFile::TEST_ZIP2.entry_names[3], entry.name)
|
99
|
-
assert zis.gets.length > 0
|
100
|
-
entry = zis.get_next_entry # longBinary.bin
|
101
|
-
assert_equal(TestZipFile::TEST_ZIP2.entry_names[4], entry.name)
|
102
|
-
assert zis.gets.length > 0
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
def test_read_with_number_of_bytes_returns_nil_at_eof
|
107
|
-
::Zip::InputStream.open(TestZipFile::TEST_ZIP2.zip_name) do |zis|
|
108
|
-
entry = zis.get_next_entry # longAscii.txt
|
109
|
-
zis.read(entry.size)
|
110
|
-
assert_equal(true, zis.eof?)
|
111
|
-
assert_nil(zis.read(1))
|
112
|
-
assert_nil(zis.read(1))
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
def test_rewind
|
117
|
-
::Zip::InputStream.open(TestZipFile::TEST_ZIP2.zip_name) {
|
118
|
-
|zis|
|
119
|
-
e = zis.get_next_entry
|
120
|
-
assert_equal(TestZipFile::TEST_ZIP2.entry_names[0], e.name)
|
121
|
-
|
122
|
-
# Do a little reading
|
123
|
-
buf = ""
|
124
|
-
buf << zis.read(100)
|
125
|
-
assert_equal(100, zis.pos)
|
126
|
-
buf << (zis.gets || "")
|
127
|
-
buf << (zis.gets || "")
|
128
|
-
assert_equal(false, zis.eof?)
|
129
|
-
|
130
|
-
zis.rewind
|
131
|
-
|
132
|
-
buf2 = ""
|
133
|
-
buf2 << zis.read(100)
|
134
|
-
buf2 << (zis.gets || "")
|
135
|
-
buf2 << (zis.gets || "")
|
136
|
-
|
137
|
-
assert_equal(buf, buf2)
|
138
|
-
|
139
|
-
zis.rewind
|
140
|
-
assert_equal(false, zis.eof?)
|
141
|
-
assert_equal(0, zis.pos)
|
142
|
-
|
143
|
-
assert_entry(e.name, zis, e.name)
|
144
|
-
}
|
145
|
-
end
|
146
|
-
|
147
|
-
def test_mix_read_and_gets
|
148
|
-
::Zip::InputStream.open(TestZipFile::TEST_ZIP2.zip_name) {
|
149
|
-
|zis|
|
150
|
-
zis.get_next_entry
|
151
|
-
assert_equal("#!/usr/bin/env ruby", zis.gets.chomp)
|
152
|
-
assert_equal(false, zis.eof?)
|
153
|
-
assert_equal("", zis.gets.chomp)
|
154
|
-
assert_equal(false, zis.eof?)
|
155
|
-
assert_equal("$VERBOSE =", zis.read(10))
|
156
|
-
assert_equal(false, zis.eof?)
|
157
|
-
}
|
158
|
-
end
|
159
|
-
|
160
|
-
def test_ungetc
|
161
|
-
::Zip::InputStream.open(TestZipFile::TEST_ZIP2.zip_name) do |zis|
|
162
|
-
zis.get_next_entry
|
163
|
-
first_line = zis.gets.chomp
|
164
|
-
first_line.reverse.bytes.each { |b| zis.ungetc(b) }
|
165
|
-
assert_equal('#!/usr/bin/env ruby', zis.gets.chomp)
|
166
|
-
assert_equal("$VERBOSE =", zis.read(10))
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
end
|
@@ -1,103 +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
|
-
return 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_equal(nil, @io.gets)
|
48
|
-
assert_equal(4, @io.lineno)
|
49
|
-
end
|
50
|
-
|
51
|
-
def test_getsMultiCharSeperator
|
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_getsMulitCharSeperator_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_getsWithSepAndIndex
|
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_getsWithIndex
|
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 {
|
85
|
-
|line|
|
86
|
-
assert_equal(TEST_LINES[lineNumber], line)
|
87
|
-
lineNumber+=1
|
88
|
-
}
|
89
|
-
end
|
90
|
-
|
91
|
-
def test_readlines
|
92
|
-
assert_equal(TEST_LINES, @io.readlines)
|
93
|
-
end
|
94
|
-
|
95
|
-
def test_readline
|
96
|
-
test_gets
|
97
|
-
begin
|
98
|
-
@io.readline
|
99
|
-
fail "EOFError expected"
|
100
|
-
rescue EOFError
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
@@ -1,106 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'zip/ioextras'
|
3
|
-
|
4
|
-
class AbstractOutputStreamTest < MiniTest::Test
|
5
|
-
class TestOutputStream
|
6
|
-
include ::Zip::IOExtras::AbstractOutputStream
|
7
|
-
|
8
|
-
attr_accessor :buffer
|
9
|
-
|
10
|
-
def initialize
|
11
|
-
@buffer = ""
|
12
|
-
end
|
13
|
-
|
14
|
-
def << (data)
|
15
|
-
@buffer << data
|
16
|
-
self
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def setup
|
21
|
-
@output_stream = TestOutputStream.new
|
22
|
-
|
23
|
-
@origCommaSep = $,
|
24
|
-
@origOutputSep = $\
|
25
|
-
end
|
26
|
-
|
27
|
-
def teardown
|
28
|
-
$, = @origCommaSep
|
29
|
-
$\ = @origOutputSep
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_write
|
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
|
-
|
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
|
-
end
|
41
|
-
|
42
|
-
def test_print
|
43
|
-
$\ = nil # record separator set to nil
|
44
|
-
@output_stream.print("hello")
|
45
|
-
assert_equal("hello", @output_stream.buffer)
|
46
|
-
|
47
|
-
@output_stream.print(" world.")
|
48
|
-
assert_equal("hello world.", @output_stream.buffer)
|
49
|
-
|
50
|
-
@output_stream.print(" You ok ", "out ", "there?")
|
51
|
-
assert_equal("hello world. You ok out there?", @output_stream.buffer)
|
52
|
-
|
53
|
-
$\ = "\n"
|
54
|
-
@output_stream.print
|
55
|
-
assert_equal("hello world. You ok out there?\n", @output_stream.buffer)
|
56
|
-
|
57
|
-
@output_stream.print("I sure hope so!")
|
58
|
-
assert_equal("hello world. You ok out there?\nI sure hope so!\n", @output_stream.buffer)
|
59
|
-
|
60
|
-
$, = "X"
|
61
|
-
@output_stream.buffer = ""
|
62
|
-
@output_stream.print("monkey", "duck", "zebra")
|
63
|
-
assert_equal("monkeyXduckXzebra\n", @output_stream.buffer)
|
64
|
-
|
65
|
-
$\ = nil
|
66
|
-
@output_stream.buffer = ""
|
67
|
-
@output_stream.print(20)
|
68
|
-
assert_equal("20", @output_stream.buffer)
|
69
|
-
end
|
70
|
-
|
71
|
-
def test_printf
|
72
|
-
@output_stream.printf("%d %04x", 123, 123)
|
73
|
-
assert_equal("123 007b", @output_stream.buffer)
|
74
|
-
end
|
75
|
-
|
76
|
-
def test_putc
|
77
|
-
@output_stream.putc("A")
|
78
|
-
assert_equal("A", @output_stream.buffer)
|
79
|
-
@output_stream.putc(65)
|
80
|
-
assert_equal("AA", @output_stream.buffer)
|
81
|
-
end
|
82
|
-
|
83
|
-
def test_puts
|
84
|
-
@output_stream.puts
|
85
|
-
assert_equal("\n", @output_stream.buffer)
|
86
|
-
|
87
|
-
@output_stream.puts("hello", "world")
|
88
|
-
assert_equal("\nhello\nworld\n", @output_stream.buffer)
|
89
|
-
|
90
|
-
@output_stream.buffer = ""
|
91
|
-
@output_stream.puts("hello\n", "world\n")
|
92
|
-
assert_equal("hello\nworld\n", @output_stream.buffer)
|
93
|
-
|
94
|
-
@output_stream.buffer = ""
|
95
|
-
@output_stream.puts(["hello\n", "world\n"])
|
96
|
-
assert_equal("hello\nworld\n", @output_stream.buffer)
|
97
|
-
|
98
|
-
@output_stream.buffer = ""
|
99
|
-
@output_stream.puts(["hello\n", "world\n"], "bingo")
|
100
|
-
assert_equal("hello\nworld\nbingo\n", @output_stream.buffer)
|
101
|
-
|
102
|
-
@output_stream.buffer = ""
|
103
|
-
@output_stream.puts(16, 20, 50, "hello")
|
104
|
-
assert_equal("16\n20\n50\nhello\n", @output_stream.buffer)
|
105
|
-
end
|
106
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'zip/ioextras'
|
3
|
-
|
4
|
-
class FakeIOTest < MiniTest::Test
|
5
|
-
class FakeIOUsingClass
|
6
|
-
include ::Zip::IOExtras::FakeIO
|
7
|
-
end
|
8
|
-
|
9
|
-
def test_kind_of?
|
10
|
-
obj = FakeIOUsingClass.new
|
11
|
-
|
12
|
-
assert(obj.kind_of?(Object))
|
13
|
-
assert(obj.kind_of?(FakeIOUsingClass))
|
14
|
-
assert(obj.kind_of?(IO))
|
15
|
-
assert(!obj.kind_of?(Fixnum))
|
16
|
-
assert(!obj.kind_of?(String))
|
17
|
-
end
|
18
|
-
end
|