rubyzip 1.1.7 → 1.2.1

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 (88) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +75 -40
  3. data/Rakefile +3 -4
  4. data/lib/zip.rb +3 -5
  5. data/lib/zip/central_directory.rb +7 -7
  6. data/lib/zip/compressor.rb +0 -0
  7. data/lib/zip/constants.rb +2 -2
  8. data/lib/zip/crypto/null_encryption.rb +3 -3
  9. data/lib/zip/crypto/traditional_encryption.rb +5 -5
  10. data/lib/zip/decompressor.rb +2 -2
  11. data/lib/zip/deflater.rb +8 -6
  12. data/lib/zip/dos_time.rb +4 -5
  13. data/lib/zip/entry.rb +75 -81
  14. data/lib/zip/entry_set.rb +11 -11
  15. data/lib/zip/errors.rb +1 -0
  16. data/lib/zip/extra_field.rb +6 -6
  17. data/lib/zip/extra_field/generic.rb +7 -7
  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 -1
  24. data/lib/zip/file.rb +47 -60
  25. data/lib/zip/filesystem.rb +132 -135
  26. data/lib/zip/inflater.rb +3 -3
  27. data/lib/zip/input_stream.rb +13 -7
  28. data/lib/zip/ioextras.rb +1 -3
  29. data/lib/zip/ioextras/abstract_input_stream.rb +5 -9
  30. data/lib/zip/ioextras/abstract_output_stream.rb +2 -4
  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 +8 -9
  35. data/lib/zip/pass_thru_compressor.rb +4 -4
  36. data/lib/zip/pass_thru_decompressor.rb +2 -3
  37. data/lib/zip/streamable_directory.rb +2 -2
  38. data/lib/zip/streamable_stream.rb +2 -2
  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 +32 -25
  43. data/samples/{gtkRubyzip.rb → gtk_ruby_zip.rb} +23 -25
  44. data/samples/qtzip.rb +17 -26
  45. data/samples/write_simple.rb +12 -13
  46. data/samples/zipfind.rb +24 -32
  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/notzippedruby.rb +1 -1
  54. data/test/data/oddExtraField.zip +0 -0
  55. data/test/data/test.xls +0 -0
  56. data/test/deflater_test.rb +10 -12
  57. data/test/encryption_test.rb +2 -2
  58. data/test/entry_set_test.rb +50 -25
  59. data/test/entry_test.rb +76 -87
  60. data/test/errors_test.rb +0 -2
  61. data/test/extra_field_test.rb +19 -21
  62. data/test/file_extract_directory_test.rb +12 -14
  63. data/test/file_extract_test.rb +33 -40
  64. data/test/file_permissions_test.rb +69 -0
  65. data/test/file_split_test.rb +24 -27
  66. data/test/file_test.rb +196 -172
  67. data/test/filesystem/dir_iterator_test.rb +13 -17
  68. data/test/filesystem/directory_test.rb +80 -90
  69. data/test/filesystem/file_mutating_test.rb +51 -63
  70. data/test/filesystem/file_nonmutating_test.rb +222 -228
  71. data/test/filesystem/file_stat_test.rb +17 -19
  72. data/test/gentestfiles.rb +47 -55
  73. data/test/inflater_test.rb +1 -1
  74. data/test/input_stream_test.rb +46 -34
  75. data/test/ioextras/abstract_input_stream_test.rb +22 -23
  76. data/test/ioextras/abstract_output_stream_test.rb +32 -32
  77. data/test/ioextras/fake_io_test.rb +1 -1
  78. data/test/local_entry_test.rb +36 -38
  79. data/test/output_stream_test.rb +20 -21
  80. data/test/pass_thru_compressor_test.rb +5 -6
  81. data/test/pass_thru_decompressor_test.rb +0 -1
  82. data/test/samples/example_recursive_test.rb +37 -0
  83. data/test/settings_test.rb +18 -15
  84. data/test/test_helper.rb +50 -44
  85. data/test/unicode_file_names_and_comments_test.rb +5 -7
  86. data/test/zip64_full_test.rb +9 -11
  87. data/test/zip64_support_test.rb +0 -1
  88. metadata +14 -32
@@ -0,0 +1,69 @@
1
+ require 'test_helper'
2
+
3
+ class ZipCaseSensitivityTest < MiniTest::Test
4
+ include CommonZipFileFixture
5
+
6
+ SRC_FILES = [['test/data/file1.txt', 'testfile.rb'],
7
+ ['test/data/file2.txt', 'testFILE.rb']]
8
+
9
+ def teardown
10
+ ::Zip.case_insensitive_match = false
11
+ end
12
+
13
+ # Ensure that everything functions normally when +case_insensitive_match = false+
14
+ def test_add_case_sensitive
15
+ ::Zip.case_insensitive_match = false
16
+
17
+ SRC_FILES.each { |fn, _en| assert(::File.exist?(fn)) }
18
+ zf = ::Zip::File.new(EMPTY_FILENAME, ::Zip::File::CREATE)
19
+
20
+ SRC_FILES.each { |fn, en| zf.add(en, fn) }
21
+ zf.close
22
+
23
+ zfRead = ::Zip::File.new(EMPTY_FILENAME)
24
+ assert_equal(SRC_FILES.size, zfRead.entries.length)
25
+ SRC_FILES.each_with_index { |a, i|
26
+ assert_equal(a.last, zfRead.entries[i].name)
27
+ AssertEntry.assert_contents(a.first,
28
+ zfRead.get_input_stream(a.last) { |zis| zis.read })
29
+ }
30
+ end
31
+
32
+ # Ensure that names are treated case insensitively when adding files and +case_insensitive_match = false+
33
+ def test_add_case_insensitive
34
+ ::Zip.case_insensitive_match = true
35
+
36
+ SRC_FILES.each { |fn, _en| assert(::File.exist?(fn)) }
37
+ zf = ::Zip::File.new(EMPTY_FILENAME, ::Zip::File::CREATE)
38
+
39
+ assert_raises Zip::EntryExistsError do
40
+ SRC_FILES.each { |fn, en| zf.add(en, fn) }
41
+ end
42
+ end
43
+
44
+ # Ensure that names are treated case insensitively when reading files and +case_insensitive_match = true+
45
+ def test_add_case_sensitive_read_case_insensitive
46
+ ::Zip.case_insensitive_match = false
47
+
48
+ SRC_FILES.each { |fn, _en| assert(::File.exist?(fn)) }
49
+ zf = ::Zip::File.new(EMPTY_FILENAME, ::Zip::File::CREATE)
50
+
51
+ SRC_FILES.each { |fn, en| zf.add(en, fn) }
52
+ zf.close
53
+
54
+ ::Zip.case_insensitive_match = true
55
+
56
+ zfRead = ::Zip::File.new(EMPTY_FILENAME)
57
+ assert_equal(SRC_FILES.collect { |_fn, en| en.downcase }.uniq.size, zfRead.entries.length)
58
+ assert_equal(SRC_FILES.last.last.downcase, zfRead.entries.first.name.downcase)
59
+ AssertEntry.assert_contents(SRC_FILES.last.first,
60
+ zfRead.get_input_stream(SRC_FILES.last.last) { |zis| zis.read })
61
+ end
62
+
63
+ private
64
+
65
+ def assert_contains(zf, entryName, filename = entryName)
66
+ assert(zf.entries.detect { |e| e.name == entryName } != nil, "entry #{entryName} not in #{zf.entries.join(', ')} in zip file #{zf}")
67
+ assert_entry_contents(zf, entryName, filename) if File.exist?(filename)
68
+ end
69
+ end
@@ -1,73 +1,69 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class ZipCentralDirectoryEntryTest < MiniTest::Test
4
-
5
4
  def test_read_from_stream
6
- File.open("test/data/testDirectory.bin", "rb") {
7
- |file|
5
+ File.open('test/data/testDirectory.bin', 'rb') do |file|
8
6
  entry = ::Zip::Entry.read_c_dir_entry(file)
9
7
 
10
- assert_equal("longAscii.txt", entry.name)
8
+ assert_equal('longAscii.txt', entry.name)
11
9
  assert_equal(::Zip::Entry::DEFLATED, entry.compression_method)
12
- assert_equal(106490, entry.size)
10
+ assert_equal(106_490, entry.size)
13
11
  assert_equal(3784, entry.compressed_size)
14
12
  assert_equal(0xfcd1799c, entry.crc)
15
- assert_equal("", entry.comment)
13
+ assert_equal('', entry.comment)
16
14
 
17
15
  entry = ::Zip::Entry.read_c_dir_entry(file)
18
- assert_equal("empty.txt", entry.name)
16
+ assert_equal('empty.txt', entry.name)
19
17
  assert_equal(::Zip::Entry::STORED, entry.compression_method)
20
18
  assert_equal(0, entry.size)
21
19
  assert_equal(0, entry.compressed_size)
22
20
  assert_equal(0x0, entry.crc)
23
- assert_equal("", entry.comment)
21
+ assert_equal('', entry.comment)
24
22
 
25
23
  entry = ::Zip::Entry.read_c_dir_entry(file)
26
- assert_equal("short.txt", entry.name)
24
+ assert_equal('short.txt', entry.name)
27
25
  assert_equal(::Zip::Entry::STORED, entry.compression_method)
28
26
  assert_equal(6, entry.size)
29
27
  assert_equal(6, entry.compressed_size)
30
28
  assert_equal(0xbb76fe69, entry.crc)
31
- assert_equal("", entry.comment)
29
+ assert_equal('', entry.comment)
32
30
 
33
31
  entry = ::Zip::Entry.read_c_dir_entry(file)
34
- assert_equal("longBinary.bin", entry.name)
32
+ assert_equal('longBinary.bin', entry.name)
35
33
  assert_equal(::Zip::Entry::DEFLATED, entry.compression_method)
36
- assert_equal(1000024, entry.size)
37
- assert_equal(70847, entry.compressed_size)
34
+ assert_equal(1_000_024, entry.size)
35
+ assert_equal(70_847, entry.compressed_size)
38
36
  assert_equal(0x10da7d59, entry.crc)
39
37
  assert_equal('', entry.comment)
40
38
 
41
39
  entry = ::Zip::Entry.read_c_dir_entry(file)
42
- assert_equal(nil, entry)
43
- # Fields that are not check by this test:
44
- # version made by 2 bytes
45
- # version needed to extract 2 bytes
46
- # general purpose bit flag 2 bytes
47
- # last mod file time 2 bytes
48
- # last mod file date 2 bytes
49
- # compressed size 4 bytes
50
- # uncompressed size 4 bytes
51
- # disk number start 2 bytes
52
- # internal file attributes 2 bytes
53
- # external file attributes 4 bytes
54
- # relative offset of local header 4 bytes
55
-
56
- # file name (variable size)
57
- # extra field (variable size)
58
- # file comment (variable size)
40
+ assert_nil(entry)
41
+ # Fields that are not check by this test:
42
+ # version made by 2 bytes
43
+ # version needed to extract 2 bytes
44
+ # general purpose bit flag 2 bytes
45
+ # last mod file time 2 bytes
46
+ # last mod file date 2 bytes
47
+ # compressed size 4 bytes
48
+ # uncompressed size 4 bytes
49
+ # disk number start 2 bytes
50
+ # internal file attributes 2 bytes
51
+ # external file attributes 4 bytes
52
+ # relative offset of local header 4 bytes
59
53
 
60
- }
54
+ # file name (variable size)
55
+ # extra field (variable size)
56
+ # file comment (variable size)
57
+ end
61
58
  end
62
59
 
63
- def test_ReadEntryFromTruncatedZipFile
64
- fragment=""
65
- File.open("test/data/testDirectory.bin") { |f| fragment = f.read(12) } # cdir entry header is at least 46 bytes
60
+ def test_read_entry_from_truncated_zip_file
61
+ fragment = ''
62
+ File.open('test/data/testDirectory.bin') { |f| fragment = f.read(12) } # cdir entry header is at least 46 bytes
66
63
  fragment.extend(IOizeString)
67
64
  entry = ::Zip::Entry.new
68
65
  entry.read_c_dir_entry(fragment)
69
- fail "ZipError expected"
66
+ fail 'ZipError expected'
70
67
  rescue ::Zip::Error
71
68
  end
72
-
73
69
  end
@@ -1,96 +1,92 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class ZipCentralDirectoryTest < MiniTest::Test
4
-
5
4
  def teardown
6
5
  ::Zip.reset!
7
6
  end
8
7
 
9
8
  def test_read_from_stream
10
- ::File.open(TestZipFile::TEST_ZIP2.zip_name, "rb") {
11
- |zipFile|
9
+ ::File.open(TestZipFile::TEST_ZIP2.zip_name, 'rb') do |zipFile|
12
10
  cdir = ::Zip::CentralDirectory.read_from_stream(zipFile)
13
11
 
14
12
  assert_equal(TestZipFile::TEST_ZIP2.entry_names.size, cdir.size)
15
- assert(cdir.entries.sort.compare_enumerables(TestZipFile::TEST_ZIP2.entry_names.sort) {
16
- |cdirEntry, testEntryName|
13
+ assert(cdir.entries.sort.compare_enumerables(TestZipFile::TEST_ZIP2.entry_names.sort) do |cdirEntry, testEntryName|
17
14
  cdirEntry.name == testEntryName
18
- })
15
+ end)
19
16
  assert_equal(TestZipFile::TEST_ZIP2.comment, cdir.comment)
20
- }
17
+ end
21
18
  end
22
19
 
23
- def test_readFromInvalidStream
24
- File.open("test/data/file2.txt", "rb") {
25
- |zipFile|
20
+ def test_read_from_invalid_stream
21
+ File.open('test/data/file2.txt', 'rb') do |zipFile|
26
22
  cdir = ::Zip::CentralDirectory.new
27
23
  cdir.read_from_stream(zipFile)
28
- }
29
- fail "ZipError expected!"
24
+ end
25
+ fail 'ZipError expected!'
30
26
  rescue ::Zip::Error
31
27
  end
32
28
 
33
- def test_ReadFromTruncatedZipFile
34
- fragment=""
35
- File.open("test/data/testDirectory.bin", "rb") { |f| fragment = f.read }
29
+ def test_read_from_truncated_zip_file
30
+ fragment = ''
31
+ File.open('test/data/testDirectory.bin', 'rb') { |f| fragment = f.read }
36
32
  fragment.slice!(12) # removed part of first cdir entry. eocd structure still complete
37
33
  fragment.extend(IOizeString)
38
34
  entry = ::Zip::CentralDirectory.new
39
35
  entry.read_from_stream(fragment)
40
- fail "ZipError expected"
36
+ fail 'ZipError expected'
41
37
  rescue ::Zip::Error
42
38
  end
43
39
 
44
40
  def test_write_to_stream
45
- entries = [::Zip::Entry.new("file.zip", "flimse", "myComment", "somethingExtra"),
46
- ::Zip::Entry.new("file.zip", "secondEntryName"),
47
- ::Zip::Entry.new("file.zip", "lastEntry.txt", "Has a comment too")]
48
- cdir = ::Zip::CentralDirectory.new(entries, "my zip comment")
49
- File.open("test/data/generated/cdirtest.bin", "wb") { |f| cdir.write_to_stream(f) }
41
+ entries = [::Zip::Entry.new('file.zip', 'flimse', 'myComment', 'somethingExtra'),
42
+ ::Zip::Entry.new('file.zip', 'secondEntryName'),
43
+ ::Zip::Entry.new('file.zip', 'lastEntry.txt', 'Has a comment too')]
44
+ cdir = ::Zip::CentralDirectory.new(entries, 'my zip comment')
45
+ File.open('test/data/generated/cdirtest.bin', 'wb') { |f| cdir.write_to_stream(f) }
50
46
  cdirReadback = ::Zip::CentralDirectory.new
51
- File.open("test/data/generated/cdirtest.bin", "rb") { |f| cdirReadback.read_from_stream(f) }
47
+ File.open('test/data/generated/cdirtest.bin', 'rb') { |f| cdirReadback.read_from_stream(f) }
52
48
 
53
49
  assert_equal(cdir.entries.sort, cdirReadback.entries.sort)
54
50
  end
55
51
 
56
52
  def test_write64_to_stream
57
53
  ::Zip.write_zip64_support = true
58
- entries = [::Zip::Entry.new("file.zip", "file1-little", "comment1", "", 200, 101, ::Zip::Entry::STORED, 200),
59
- ::Zip::Entry.new("file.zip", "file2-big", "comment2", "", 18000000000, 102, ::Zip::Entry::DEFLATED, 20000000000),
60
- ::Zip::Entry.new("file.zip", "file3-alsobig", "comment3", "", 15000000000, 103, ::Zip::Entry::DEFLATED, 21000000000),
61
- ::Zip::Entry.new("file.zip", "file4-little", "comment4", "", 100, 104, ::Zip::Entry::DEFLATED, 121)]
62
- [0, 250, 18000000300, 33000000350].each_with_index do |offset, index|
54
+ entries = [::Zip::Entry.new('file.zip', 'file1-little', 'comment1', '', 200, 101, ::Zip::Entry::STORED, 200),
55
+ ::Zip::Entry.new('file.zip', 'file2-big', 'comment2', '', 18_000_000_000, 102, ::Zip::Entry::DEFLATED, 20_000_000_000),
56
+ ::Zip::Entry.new('file.zip', 'file3-alsobig', 'comment3', '', 15_000_000_000, 103, ::Zip::Entry::DEFLATED, 21_000_000_000),
57
+ ::Zip::Entry.new('file.zip', 'file4-little', 'comment4', '', 100, 104, ::Zip::Entry::DEFLATED, 121)]
58
+ [0, 250, 18_000_000_300, 33_000_000_350].each_with_index do |offset, index|
63
59
  entries[index].local_header_offset = offset
64
60
  end
65
- cdir = ::Zip::CentralDirectory.new(entries, "zip comment")
66
- File.open("test/data/generated/cdir64test.bin", "wb") { |f| cdir.write_to_stream(f) }
61
+ cdir = ::Zip::CentralDirectory.new(entries, 'zip comment')
62
+ File.open('test/data/generated/cdir64test.bin', 'wb') { |f| cdir.write_to_stream(f) }
67
63
  cdirReadback = ::Zip::CentralDirectory.new
68
- File.open("test/data/generated/cdir64test.bin", "rb") { |f| cdirReadback.read_from_stream(f) }
64
+ File.open('test/data/generated/cdir64test.bin', 'rb') { |f| cdirReadback.read_from_stream(f) }
69
65
 
70
66
  assert_equal(cdir.entries.sort, cdirReadback.entries.sort)
71
67
  assert_equal(::Zip::VERSION_NEEDED_TO_EXTRACT_ZIP64, cdirReadback.instance_variable_get(:@version_needed_for_extract))
72
68
  end
73
69
 
74
70
  def test_equality
75
- cdir1 = ::Zip::CentralDirectory.new([::Zip::Entry.new("file.zip", "flimse", nil,
76
- "somethingExtra"),
77
- ::Zip::Entry.new("file.zip", "secondEntryName"),
78
- ::Zip::Entry.new("file.zip", "lastEntry.txt")],
79
- "my zip comment")
80
- cdir2 = ::Zip::CentralDirectory.new([::Zip::Entry.new("file.zip", "flimse", nil,
81
- "somethingExtra"),
82
- ::Zip::Entry.new("file.zip", "secondEntryName"),
83
- ::Zip::Entry.new("file.zip", "lastEntry.txt")],
84
- "my zip comment")
85
- cdir3 = ::Zip::CentralDirectory.new([::Zip::Entry.new("file.zip", "flimse", nil,
86
- "somethingExtra"),
87
- ::Zip::Entry.new("file.zip", "secondEntryName"),
88
- ::Zip::Entry.new("file.zip", "lastEntry.txt")],
89
- "comment?")
90
- cdir4 = ::Zip::CentralDirectory.new([::Zip::Entry.new("file.zip", "flimse", nil,
91
- "somethingExtra"),
92
- ::Zip::Entry.new("file.zip", "lastEntry.txt")],
93
- "comment?")
71
+ cdir1 = ::Zip::CentralDirectory.new([::Zip::Entry.new('file.zip', 'flimse', nil,
72
+ 'somethingExtra'),
73
+ ::Zip::Entry.new('file.zip', 'secondEntryName'),
74
+ ::Zip::Entry.new('file.zip', 'lastEntry.txt')],
75
+ 'my zip comment')
76
+ cdir2 = ::Zip::CentralDirectory.new([::Zip::Entry.new('file.zip', 'flimse', nil,
77
+ 'somethingExtra'),
78
+ ::Zip::Entry.new('file.zip', 'secondEntryName'),
79
+ ::Zip::Entry.new('file.zip', 'lastEntry.txt')],
80
+ 'my zip comment')
81
+ cdir3 = ::Zip::CentralDirectory.new([::Zip::Entry.new('file.zip', 'flimse', nil,
82
+ 'somethingExtra'),
83
+ ::Zip::Entry.new('file.zip', 'secondEntryName'),
84
+ ::Zip::Entry.new('file.zip', 'lastEntry.txt')],
85
+ 'comment?')
86
+ cdir4 = ::Zip::CentralDirectory.new([::Zip::Entry.new('file.zip', 'flimse', nil,
87
+ 'somethingExtra'),
88
+ ::Zip::Entry.new('file.zip', 'lastEntry.txt')],
89
+ 'comment?')
94
90
  assert_equal(cdir1, cdir1)
95
91
  assert_equal(cdir1, cdir2)
96
92
 
@@ -99,6 +95,6 @@ class ZipCentralDirectoryTest < MiniTest::Test
99
95
  assert(cdir2 != cdir3)
100
96
  assert(cdir3 != cdir4)
101
97
 
102
- assert(cdir3 != "hello")
98
+ assert(cdir3 != 'hello')
103
99
  end
104
100
  end
@@ -4,7 +4,7 @@ class NullEncrypterTest < MiniTest::Test
4
4
  def setup
5
5
  @encrypter = ::Zip::NullEncrypter.new
6
6
  end
7
-
7
+
8
8
  def test_header_bytesize
9
9
  assert_equal 0, @encrypter.header_bytesize
10
10
  end
@@ -18,7 +18,9 @@ class NullEncrypterTest < MiniTest::Test
18
18
  end
19
19
 
20
20
  def test_encrypt
21
- [nil, '', 'a' * 10, 0xffffffff].each do |data|
21
+ assert_nil @encrypter.encrypt(nil)
22
+
23
+ ['', 'a' * 10, 0xffffffff].each do |data|
22
24
  assert_equal data, @encrypter.encrypt(data)
23
25
  end
24
26
  end
@@ -32,7 +34,7 @@ class NullDecrypterTest < MiniTest::Test
32
34
  def setup
33
35
  @decrypter = ::Zip::NullDecrypter.new
34
36
  end
35
-
37
+
36
38
  def test_header_bytesize
37
39
  assert_equal 0, @decrypter.header_bytesize
38
40
  end
@@ -42,7 +44,9 @@ class NullDecrypterTest < MiniTest::Test
42
44
  end
43
45
 
44
46
  def test_decrypt
45
- [nil, '', 'a' * 10, 0xffffffff].each do |data|
47
+ assert_nil @decrypter.decrypt(nil)
48
+
49
+ ['', 'a' * 10, 0xffffffff].each do |data|
46
50
  assert_equal data, @decrypter.decrypt(data)
47
51
  end
48
52
  end
@@ -16,7 +16,7 @@ class TraditionalEncrypterTest < MiniTest::Test
16
16
 
17
17
  def test_header
18
18
  @encrypter.reset!
19
- exepected = [239, 57, 234, 154, 246, 80, 83, 221, 74, 200, 121, 91].pack("C*")
19
+ exepected = [239, 57, 234, 154, 246, 80, 83, 221, 74, 200, 121, 91].pack('C*')
20
20
  Random.stub(:rand, 1) do
21
21
  assert_equal exepected, @encrypter.header(@mtime)
22
22
  end
@@ -28,7 +28,7 @@ class TraditionalEncrypterTest < MiniTest::Test
28
28
  assert_raises(NoMethodError) { @encrypter.encrypt(nil) }
29
29
  assert_raises(NoMethodError) { @encrypter.encrypt(1) }
30
30
  assert_equal '', @encrypter.encrypt('')
31
- assert_equal [100, 218, 7, 114, 226, 82, 62, 93, 224, 62].pack("C*"), @encrypter.encrypt('a' * 10)
31
+ assert_equal [100, 218, 7, 114, 226, 82, 62, 93, 224, 62].pack('C*'), @encrypter.encrypt('a' * 10)
32
32
  end
33
33
 
34
34
  def test_reset!
@@ -60,19 +60,19 @@ class TraditionalDecrypterTest < MiniTest::Test
60
60
  end
61
61
 
62
62
  def test_decrypt
63
- @decrypter.reset!([239, 57, 234, 154, 246, 80, 83, 221, 74, 200, 121, 91].pack("C*"))
63
+ @decrypter.reset!([239, 57, 234, 154, 246, 80, 83, 221, 74, 200, 121, 91].pack('C*'))
64
64
  [100, 218, 7, 114, 226, 82, 62, 93, 224, 62].map(&:chr).each do |c|
65
65
  assert_equal 'a', @decrypter.decrypt(c)
66
66
  end
67
67
  end
68
68
 
69
69
  def test_reset!
70
- @decrypter.reset!([239, 57, 234, 154, 246, 80, 83, 221, 74, 200, 121, 91].pack("C*"))
70
+ @decrypter.reset!([239, 57, 234, 154, 246, 80, 83, 221, 74, 200, 121, 91].pack('C*'))
71
71
  [100, 218, 7, 114, 226, 82, 62, 93, 224, 62].map(&:chr).each do |c|
72
72
  assert_equal 'a', @decrypter.decrypt(c)
73
73
  end
74
74
  assert_equal 91.chr, @decrypter.decrypt(2.chr)
75
- @decrypter.reset!([239, 57, 234, 154, 246, 80, 83, 221, 74, 200, 121, 91].pack("C*"))
75
+ @decrypter.reset!([239, 57, 234, 154, 246, 80, 83, 221, 74, 200, 121, 91].pack('C*'))
76
76
  [100, 218, 7, 114, 226, 82, 62, 93, 224, 62].map(&:chr).each do |c|
77
77
  assert_equal 'a', @decrypter.decrypt(c)
78
78
  end
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  class NotZippedRuby
4
- def returnTrue
4
+ def return_true
5
5
  true
6
6
  end
7
7
  end
Binary file
@@ -8,15 +8,15 @@ class DeflaterTest < MiniTest::Test
8
8
  DEFAULT_COMP_FILE = 'test/data/generated/compressiontest_default_compression.bin'
9
9
  NO_COMP_FILE = 'test/data/generated/compressiontest_no_compression.bin'
10
10
 
11
- def test_outputOperator
12
- txt = load_file("test/data/file2.txt")
11
+ def test_output_operator
12
+ txt = load_file('test/data/file2.txt')
13
13
  deflate(txt, DEFLATER_TEST_FILE)
14
14
  inflatedTxt = inflate(DEFLATER_TEST_FILE)
15
15
  assert_equal(txt, inflatedTxt)
16
16
  end
17
17
 
18
18
  def test_default_compression
19
- txt = load_file("test/data/file2.txt")
19
+ txt = load_file('test/data/file2.txt')
20
20
 
21
21
  Zip.default_compression = ::Zlib::BEST_COMPRESSION
22
22
  deflate(txt, BEST_COMP_FILE)
@@ -34,31 +34,29 @@ class DeflaterTest < MiniTest::Test
34
34
  assert(default < no)
35
35
  end
36
36
 
37
-
38
37
  private
38
+
39
39
  def load_file(fileName)
40
40
  txt = nil
41
- File.open(fileName, "rb") { |f| txt = f.read }
41
+ File.open(fileName, 'rb') { |f| txt = f.read }
42
42
  end
43
43
 
44
44
  def deflate(data, fileName)
45
- File.open(fileName, "wb") {
46
- |file|
45
+ File.open(fileName, 'wb') do |file|
47
46
  deflater = ::Zip::Deflater.new(file)
48
47
  deflater << data
49
48
  deflater.finish
50
49
  assert_equal(deflater.size, data.size)
51
- file << "trailing data for zlib with -MAX_WBITS"
52
- }
50
+ file << 'trailing data for zlib with -MAX_WBITS'
51
+ end
53
52
  end
54
53
 
55
54
  def inflate(fileName)
56
55
  txt = nil
57
- File.open(fileName, "rb") {
58
- |file|
56
+ File.open(fileName, 'rb') do |file|
59
57
  inflater = ::Zip::Inflater.new(file)
60
58
  txt = inflater.sysread
61
- }
59
+ end
62
60
  end
63
61
 
64
62
  def test_crc