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.

Files changed (106) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +87 -45
  3. data/Rakefile +3 -4
  4. data/lib/zip.rb +11 -5
  5. data/lib/zip/central_directory.rb +8 -8
  6. data/lib/zip/compressor.rb +1 -2
  7. data/lib/zip/constants.rb +5 -5
  8. data/lib/zip/crypto/null_encryption.rb +4 -6
  9. data/lib/zip/crypto/traditional_encryption.rb +5 -5
  10. data/lib/zip/decompressor.rb +3 -3
  11. data/lib/zip/deflater.rb +8 -6
  12. data/lib/zip/dos_time.rb +5 -6
  13. data/lib/zip/entry.rb +120 -128
  14. data/lib/zip/entry_set.rb +14 -14
  15. data/lib/zip/errors.rb +1 -0
  16. data/lib/zip/extra_field.rb +8 -8
  17. data/lib/zip/extra_field/generic.rb +8 -8
  18. data/lib/zip/extra_field/ntfs.rb +14 -16
  19. data/lib/zip/extra_field/old_unix.rb +9 -10
  20. data/lib/zip/extra_field/universal_time.rb +14 -14
  21. data/lib/zip/extra_field/unix.rb +8 -9
  22. data/lib/zip/extra_field/zip64.rb +12 -11
  23. data/lib/zip/extra_field/zip64_placeholder.rb +1 -2
  24. data/lib/zip/file.rb +81 -81
  25. data/lib/zip/filesystem.rb +144 -143
  26. data/lib/zip/inflater.rb +5 -5
  27. data/lib/zip/input_stream.rb +22 -13
  28. data/lib/zip/ioextras.rb +1 -3
  29. data/lib/zip/ioextras/abstract_input_stream.rb +6 -10
  30. data/lib/zip/ioextras/abstract_output_stream.rb +3 -5
  31. data/lib/zip/null_compressor.rb +2 -2
  32. data/lib/zip/null_decompressor.rb +3 -3
  33. data/lib/zip/null_input_stream.rb +0 -0
  34. data/lib/zip/output_stream.rb +13 -14
  35. data/lib/zip/pass_thru_compressor.rb +4 -4
  36. data/lib/zip/pass_thru_decompressor.rb +3 -4
  37. data/lib/zip/streamable_directory.rb +2 -2
  38. data/lib/zip/streamable_stream.rb +3 -3
  39. data/lib/zip/version.rb +1 -1
  40. data/samples/example.rb +29 -39
  41. data/samples/example_filesystem.rb +16 -18
  42. data/samples/example_recursive.rb +31 -25
  43. data/samples/{gtkRubyzip.rb → gtk_ruby_zip.rb} +23 -25
  44. data/samples/qtzip.rb +18 -27
  45. data/samples/write_simple.rb +12 -13
  46. data/samples/zipfind.rb +26 -34
  47. data/test/basic_zip_file_test.rb +11 -15
  48. data/test/case_sensitivity_test.rb +69 -0
  49. data/test/central_directory_entry_test.rb +32 -36
  50. data/test/central_directory_test.rb +46 -50
  51. data/test/crypto/null_encryption_test.rb +8 -4
  52. data/test/crypto/traditional_encryption_test.rb +5 -5
  53. data/test/data/gpbit3stored.zip +0 -0
  54. data/test/data/notzippedruby.rb +1 -1
  55. data/test/data/oddExtraField.zip +0 -0
  56. data/test/data/path_traversal/Makefile +10 -0
  57. data/test/data/path_traversal/jwilk/README.md +5 -0
  58. data/test/data/path_traversal/jwilk/absolute1.zip +0 -0
  59. data/test/data/path_traversal/jwilk/absolute2.zip +0 -0
  60. data/test/data/path_traversal/jwilk/dirsymlink.zip +0 -0
  61. data/test/data/path_traversal/jwilk/dirsymlink2a.zip +0 -0
  62. data/test/data/path_traversal/jwilk/dirsymlink2b.zip +0 -0
  63. data/test/data/path_traversal/jwilk/relative0.zip +0 -0
  64. data/test/data/path_traversal/jwilk/relative2.zip +0 -0
  65. data/test/data/path_traversal/jwilk/symlink.zip +0 -0
  66. data/test/data/path_traversal/relative1.zip +0 -0
  67. data/test/data/path_traversal/tilde.zip +0 -0
  68. data/test/data/path_traversal/tuzovakaoff/README.md +3 -0
  69. data/test/data/path_traversal/tuzovakaoff/absolutepath.zip +0 -0
  70. data/test/data/path_traversal/tuzovakaoff/symlink.zip +0 -0
  71. data/test/data/rubycode.zip +0 -0
  72. data/test/data/test.xls +0 -0
  73. data/test/deflater_test.rb +10 -12
  74. data/test/encryption_test.rb +2 -2
  75. data/test/entry_set_test.rb +50 -25
  76. data/test/entry_test.rb +76 -87
  77. data/test/errors_test.rb +1 -2
  78. data/test/extra_field_test.rb +19 -21
  79. data/test/file_extract_directory_test.rb +12 -14
  80. data/test/file_extract_test.rb +33 -40
  81. data/test/file_permissions_test.rb +65 -0
  82. data/test/file_split_test.rb +24 -27
  83. data/test/file_test.rb +266 -179
  84. data/test/filesystem/dir_iterator_test.rb +13 -17
  85. data/test/filesystem/directory_test.rb +101 -93
  86. data/test/filesystem/file_mutating_test.rb +52 -65
  87. data/test/filesystem/file_nonmutating_test.rb +223 -229
  88. data/test/filesystem/file_stat_test.rb +17 -19
  89. data/test/gentestfiles.rb +54 -62
  90. data/test/inflater_test.rb +1 -1
  91. data/test/input_stream_test.rb +52 -40
  92. data/test/ioextras/abstract_input_stream_test.rb +22 -23
  93. data/test/ioextras/abstract_output_stream_test.rb +33 -33
  94. data/test/ioextras/fake_io_test.rb +1 -1
  95. data/test/local_entry_test.rb +36 -38
  96. data/test/output_stream_test.rb +20 -21
  97. data/test/pass_thru_compressor_test.rb +5 -6
  98. data/test/pass_thru_decompressor_test.rb +0 -1
  99. data/test/path_traversal_test.rb +141 -0
  100. data/test/samples/example_recursive_test.rb +37 -0
  101. data/test/settings_test.rb +18 -15
  102. data/test/test_helper.rb +52 -46
  103. data/test/unicode_file_names_and_comments_test.rb +17 -7
  104. data/test/zip64_full_test.rb +10 -12
  105. data/test/zip64_support_test.rb +0 -1
  106. metadata +94 -65
@@ -2,9 +2,8 @@ require 'test_helper'
2
2
  require 'zip/filesystem'
3
3
 
4
4
  class ZipFsFileStatTest < MiniTest::Test
5
-
6
5
  def setup
7
- @zip_file = ::Zip::File.new("test/data/zipWithDirs.zip")
6
+ @zip_file = ::Zip::File.new('test/data/zipWithDirs.zip')
8
7
  end
9
8
 
10
9
  def teardown
@@ -12,55 +11,54 @@ class ZipFsFileStatTest < MiniTest::Test
12
11
  end
13
12
 
14
13
  def test_blocks
15
- assert_equal(nil, @zip_file.file.stat("file1").blocks)
14
+ assert_nil(@zip_file.file.stat('file1').blocks)
16
15
  end
17
16
 
18
17
  def test_ino
19
- assert_equal(0, @zip_file.file.stat("file1").ino)
18
+ assert_equal(0, @zip_file.file.stat('file1').ino)
20
19
  end
21
20
 
22
21
  def test_uid
23
- assert_equal(0, @zip_file.file.stat("file1").uid)
22
+ assert_equal(0, @zip_file.file.stat('file1').uid)
24
23
  end
25
24
 
26
25
  def test_gid
27
- assert_equal(0, @zip_file.file.stat("file1").gid)
26
+ assert_equal(0, @zip_file.file.stat('file1').gid)
28
27
  end
29
28
 
30
29
  def test_ftype
31
- assert_equal("file", @zip_file.file.stat("file1").ftype)
32
- assert_equal("directory", @zip_file.file.stat("dir1").ftype)
30
+ assert_equal('file', @zip_file.file.stat('file1').ftype)
31
+ assert_equal('directory', @zip_file.file.stat('dir1').ftype)
33
32
  end
34
33
 
35
34
  def test_mode
36
- assert_equal(0600, @zip_file.file.stat("file1").mode & 0777)
37
- assert_equal(0600, @zip_file.file.stat("file1").mode & 0777)
38
- assert_equal(0755, @zip_file.file.stat("dir1").mode & 0777)
39
- assert_equal(0755, @zip_file.file.stat("dir1").mode & 0777)
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)
40
39
  end
41
40
 
42
41
  def test_dev
43
- assert_equal(0, @zip_file.file.stat("file1").dev)
42
+ assert_equal(0, @zip_file.file.stat('file1').dev)
44
43
  end
45
44
 
46
45
  def test_rdev
47
- assert_equal(0, @zip_file.file.stat("file1").rdev)
46
+ assert_equal(0, @zip_file.file.stat('file1').rdev)
48
47
  end
49
48
 
50
49
  def test_rdev_major
51
- assert_equal(0, @zip_file.file.stat("file1").rdev_major)
50
+ assert_equal(0, @zip_file.file.stat('file1').rdev_major)
52
51
  end
53
52
 
54
53
  def test_rdev_minor
55
- assert_equal(0, @zip_file.file.stat("file1").rdev_minor)
54
+ assert_equal(0, @zip_file.file.stat('file1').rdev_minor)
56
55
  end
57
56
 
58
57
  def test_nlink
59
- assert_equal(1, @zip_file.file.stat("file1").nlink)
58
+ assert_equal(1, @zip_file.file.stat('file1').nlink)
60
59
  end
61
60
 
62
61
  def test_blksize
63
- assert_nil(@zip_file.file.stat("file1").blksize)
62
+ assert_nil(@zip_file.file.stat('file1').blksize)
64
63
  end
65
-
66
64
  end
@@ -3,13 +3,15 @@
3
3
  $VERBOSE = true
4
4
 
5
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"
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
11
 
12
- EMPTY_TEST_DIR = "test/data/generated/emptytestdir"
12
+ NULL_FILE = 'test/data/generated/null.zip' # Zero length, so not a zip file.
13
+
14
+ EMPTY_TEST_DIR = 'test/data/generated/emptytestdir'
13
15
 
14
16
  ASCII_TEST_FILES = [RANDOM_ASCII_FILE1, RANDOM_ASCII_FILE2, RANDOM_ASCII_FILE3]
15
17
  BINARY_TEST_FILES = [RANDOM_BINARY_FILE1, RANDOM_BINARY_FILE2]
@@ -18,34 +20,32 @@ class TestFiles
18
20
 
19
21
  class << self
20
22
  def create_test_files
21
- Dir.mkdir "test/data/generated" unless Dir.exist?('test/data/generated')
23
+ Dir.mkdir 'test/data/generated' unless Dir.exist?('test/data/generated')
22
24
 
23
- ASCII_TEST_FILES.each_with_index do |filename, index|
24
- create_random_ascii(filename, 1E4 * (index+1))
25
- end
25
+ ASCII_TEST_FILES.each_with_index do |filename, index|
26
+ create_random_ascii(filename, 1E4 * (index + 1))
27
+ end
26
28
 
27
- BINARY_TEST_FILES.each_with_index do |filename, index|
28
- create_random_binary(filename, 1E4 * (index+1))
29
- end
29
+ BINARY_TEST_FILES.each_with_index do |filename, index|
30
+ create_random_binary(filename, 1E4 * (index + 1))
31
+ end
30
32
 
31
- ensure_dir(EMPTY_TEST_DIR)
33
+ system("touch #{NULL_FILE}")
34
+
35
+ ensure_dir(EMPTY_TEST_DIR)
32
36
  end
33
37
 
34
38
  private
35
39
 
36
40
  def create_random_ascii(filename, size)
37
- File.open(filename, "wb") do |file|
38
- while (file.tell < size)
39
- file << rand
40
- end
41
+ File.open(filename, 'wb') do |file|
42
+ file << rand while file.tell < size
41
43
  end
42
44
  end
43
45
 
44
46
  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
47
+ File.open(filename, 'wb') do |file|
48
+ file << [rand].pack('V') while file.tell < size
49
49
  end
50
50
  end
51
51
 
@@ -56,79 +56,71 @@ class TestFiles
56
56
  end
57
57
  Dir.mkdir(name)
58
58
  end
59
-
60
59
  end
61
60
  end
62
61
 
63
-
64
62
  # For representation and creation of
65
63
  # test data
66
64
  class TestZipFile
67
65
  attr_accessor :zip_name, :entry_names, :comment
68
66
 
69
- def initialize(zip_name, entry_names, comment = "")
70
- @zip_name=zip_name
71
- @entry_names=entry_names
67
+ def initialize(zip_name, entry_names, comment = '')
68
+ @zip_name = zip_name
69
+ @entry_names = entry_names
72
70
  @comment = comment
73
71
  end
74
72
 
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")
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")
78
76
 
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")
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')
82
80
 
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
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
90
86
  end
91
87
 
92
- testBinaryPattern=""
93
- File.open("test/data/generated/empty.zip") { |file| testBinaryPattern=file.read }
88
+ testBinaryPattern = ''
89
+ File.open('test/data/generated/empty.zip') { |file| testBinaryPattern = file.read }
94
90
  testBinaryPattern *= 4
95
91
 
96
- File.open("test/data/generated/longBinary.bin", "wb") do |file|
97
- while (file.tell < 6E5)
98
- file << testBinaryPattern << rand << "\0"
99
- end
92
+ File.open('test/data/generated/longBinary.bin', 'wb') do |file|
93
+ file << testBinaryPattern << rand << "\0" while file.tell < 6E5
100
94
  end
101
95
 
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(' ')}")
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(' ')}")
103
97
 
104
98
  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}\"")
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}\"")
106
100
  else
107
101
  # without bash system interprets everything after echo as parameters to
108
102
  # 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}\"")
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}\"")
110
104
  end
111
105
 
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(' ')}")
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(' ')}")
113
107
 
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(' ')}")
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(' ')}")
115
109
  rescue
116
110
  # If there are any Windows developers wanting to use a command line zip.exe
117
111
  # to help create the following files, there's a free one available from
118
112
  # http://stahlworks.com/dev/index.php?tool=zipunzip
119
113
  # that works with the above code
120
114
  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."
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.'
124
118
  end
125
119
 
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])
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])
132
126
  end
133
-
134
-
@@ -4,7 +4,7 @@ class InflaterTest < MiniTest::Test
4
4
 
5
5
  def setup
6
6
  super
7
- @file = File.new("test/data/file1.txt.deflatedData", "rb")
7
+ @file = File.new('test/data/file1.txt.deflatedData', 'rb')
8
8
  @decompressor = ::Zip::Inflater.new(@file)
9
9
  end
10
10
 
@@ -3,6 +3,16 @@ require 'test_helper'
3
3
  class ZipInputStreamTest < MiniTest::Test
4
4
  include AssertEntry
5
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
+
6
16
  def test_new
7
17
  zis = ::Zip::InputStream.new(TestZipFile::TEST_ZIP2.zip_name)
8
18
  assert_stream_contents(zis, TestZipFile::TEST_ZIP2)
@@ -10,21 +20,20 @@ class ZipInputStreamTest < MiniTest::Test
10
20
  zis.close
11
21
  end
12
22
 
13
- def test_openWithBlock
14
- ::Zip::InputStream.open(TestZipFile::TEST_ZIP2.zip_name) {
15
- |zis|
23
+ def test_open_with_block
24
+ ::Zip::InputStream.open(TestZipFile::TEST_ZIP2.zip_name) do |zis|
16
25
  assert_stream_contents(zis, TestZipFile::TEST_ZIP2)
17
26
  assert_equal(true, zis.eof?)
18
- }
27
+ end
19
28
  end
20
29
 
21
- def test_openWithoutBlock
22
- zis = ::Zip::InputStream.open(File.new(TestZipFile::TEST_ZIP2.zip_name, "rb"))
30
+ def test_open_without_block
31
+ zis = ::Zip::InputStream.open(File.new(TestZipFile::TEST_ZIP2.zip_name, 'rb'))
23
32
  assert_stream_contents(zis, TestZipFile::TEST_ZIP2)
24
33
  end
25
34
 
26
- def test_openBufferWithBlock
27
- ::Zip::InputStream.open(File.new(TestZipFile::TEST_ZIP2.zip_name, "rb")) do |zis|
35
+ def test_open_buffer_with_block
36
+ ::Zip::InputStream.open(File.new(TestZipFile::TEST_ZIP2.zip_name, 'rb')) do |zis|
28
37
  assert_stream_contents(zis, TestZipFile::TEST_ZIP2)
29
38
  assert_equal(true, zis.eof?)
30
39
  end
@@ -44,36 +53,42 @@ class ZipInputStreamTest < MiniTest::Test
44
53
  end
45
54
  end
46
55
 
47
- def test_openBufferWithoutBlock
56
+ def test_open_buffer_without_block
48
57
  zis = ::Zip::InputStream.open(TestZipFile::TEST_ZIP2.zip_name)
49
58
  assert_stream_contents(zis, TestZipFile::TEST_ZIP2)
50
59
  end
51
60
 
52
- def test_incompleteReads
53
- ::Zip::InputStream.open(TestZipFile::TEST_ZIP2.zip_name) {
54
- |zis|
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|
55
70
  entry = zis.get_next_entry # longAscii.txt
56
71
  assert_equal(false, zis.eof?)
57
72
  assert_equal(TestZipFile::TEST_ZIP2.entry_names[0], entry.name)
58
- assert zis.gets.length > 0
73
+ assert !zis.gets.empty?
59
74
  assert_equal(false, zis.eof?)
60
75
  entry = zis.get_next_entry # empty.txt
61
76
  assert_equal(TestZipFile::TEST_ZIP2.entry_names[1], entry.name)
62
77
  assert_equal(0, entry.size)
63
- assert_equal(nil, zis.gets)
78
+ assert_nil(zis.gets)
64
79
  assert_equal(true, zis.eof?)
65
80
  entry = zis.get_next_entry # empty_chmod640.txt
66
81
  assert_equal(TestZipFile::TEST_ZIP2.entry_names[2], entry.name)
67
82
  assert_equal(0, entry.size)
68
- assert_equal(nil, zis.gets)
83
+ assert_nil(zis.gets)
69
84
  assert_equal(true, zis.eof?)
70
85
  entry = zis.get_next_entry # short.txt
71
86
  assert_equal(TestZipFile::TEST_ZIP2.entry_names[3], entry.name)
72
- assert zis.gets.length > 0
87
+ assert !zis.gets.empty?
73
88
  entry = zis.get_next_entry # longBinary.bin
74
89
  assert_equal(TestZipFile::TEST_ZIP2.entry_names[4], entry.name)
75
- assert zis.gets.length > 0
76
- }
90
+ assert !zis.gets.empty?
91
+ end
77
92
  end
78
93
 
79
94
  def test_incomplete_reads_from_string_io
@@ -82,24 +97,24 @@ class ZipInputStreamTest < MiniTest::Test
82
97
  entry = zis.get_next_entry # longAscii.txt
83
98
  assert_equal(false, zis.eof?)
84
99
  assert_equal(TestZipFile::TEST_ZIP2.entry_names[0], entry.name)
85
- assert zis.gets.length > 0
100
+ assert !zis.gets.empty?
86
101
  assert_equal(false, zis.eof?)
87
102
  entry = zis.get_next_entry # empty.txt
88
103
  assert_equal(TestZipFile::TEST_ZIP2.entry_names[1], entry.name)
89
104
  assert_equal(0, entry.size)
90
- assert_equal(nil, zis.gets)
105
+ assert_nil(zis.gets)
91
106
  assert_equal(true, zis.eof?)
92
107
  entry = zis.get_next_entry # empty_chmod640.txt
93
108
  assert_equal(TestZipFile::TEST_ZIP2.entry_names[2], entry.name)
94
109
  assert_equal(0, entry.size)
95
- assert_equal(nil, zis.gets)
110
+ assert_nil(zis.gets)
96
111
  assert_equal(true, zis.eof?)
97
112
  entry = zis.get_next_entry # short.txt
98
113
  assert_equal(TestZipFile::TEST_ZIP2.entry_names[3], entry.name)
99
- assert zis.gets.length > 0
114
+ assert !zis.gets.empty?
100
115
  entry = zis.get_next_entry # longBinary.bin
101
116
  assert_equal(TestZipFile::TEST_ZIP2.entry_names[4], entry.name)
102
- assert zis.gets.length > 0
117
+ assert !zis.gets.empty?
103
118
  end
104
119
  end
105
120
 
@@ -114,25 +129,24 @@ class ZipInputStreamTest < MiniTest::Test
114
129
  end
115
130
 
116
131
  def test_rewind
117
- ::Zip::InputStream.open(TestZipFile::TEST_ZIP2.zip_name) {
118
- |zis|
132
+ ::Zip::InputStream.open(TestZipFile::TEST_ZIP2.zip_name) do |zis|
119
133
  e = zis.get_next_entry
120
134
  assert_equal(TestZipFile::TEST_ZIP2.entry_names[0], e.name)
121
135
 
122
136
  # Do a little reading
123
- buf = ""
137
+ buf = ''
124
138
  buf << zis.read(100)
125
139
  assert_equal(100, zis.pos)
126
- buf << (zis.gets || "")
127
- buf << (zis.gets || "")
140
+ buf << (zis.gets || '')
141
+ buf << (zis.gets || '')
128
142
  assert_equal(false, zis.eof?)
129
143
 
130
144
  zis.rewind
131
145
 
132
- buf2 = ""
146
+ buf2 = ''
133
147
  buf2 << zis.read(100)
134
- buf2 << (zis.gets || "")
135
- buf2 << (zis.gets || "")
148
+ buf2 << (zis.gets || '')
149
+ buf2 << (zis.gets || '')
136
150
 
137
151
  assert_equal(buf, buf2)
138
152
 
@@ -141,20 +155,19 @@ class ZipInputStreamTest < MiniTest::Test
141
155
  assert_equal(0, zis.pos)
142
156
 
143
157
  assert_entry(e.name, zis, e.name)
144
- }
158
+ end
145
159
  end
146
160
 
147
161
  def test_mix_read_and_gets
148
- ::Zip::InputStream.open(TestZipFile::TEST_ZIP2.zip_name) {
149
- |zis|
162
+ ::Zip::InputStream.open(TestZipFile::TEST_ZIP2.zip_name) do |zis|
150
163
  zis.get_next_entry
151
- assert_equal("#!/usr/bin/env ruby", zis.gets.chomp)
164
+ assert_equal('#!/usr/bin/env ruby', zis.gets.chomp)
152
165
  assert_equal(false, zis.eof?)
153
- assert_equal("", zis.gets.chomp)
166
+ assert_equal('', zis.gets.chomp)
154
167
  assert_equal(false, zis.eof?)
155
- assert_equal("$VERBOSE =", zis.read(10))
168
+ assert_equal('$VERBOSE =', zis.read(10))
156
169
  assert_equal(false, zis.eof?)
157
- }
170
+ end
158
171
  end
159
172
 
160
173
  def test_ungetc
@@ -163,8 +176,7 @@ class ZipInputStreamTest < MiniTest::Test
163
176
  first_line = zis.gets.chomp
164
177
  first_line.reverse.bytes.each { |b| zis.ungetc(b) }
165
178
  assert_equal('#!/usr/bin/env ruby', zis.gets.chomp)
166
- assert_equal("$VERBOSE =", zis.read(10))
179
+ assert_equal('$VERBOSE =', zis.read(10))
167
180
  end
168
181
  end
169
-
170
182
  end