archive-zip 0.11.0 → 0.13.0.pre1

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.
Files changed (133) hide show
  1. checksums.yaml +5 -5
  2. data/LICENSE +1 -1
  3. data/NEWS.md +12 -0
  4. data/README.md +2 -1
  5. data/lib/archive/support/ioextensions.rb +5 -7
  6. data/lib/archive/support/iowindow.rb +34 -87
  7. data/lib/archive/support/stringio.rb +27 -0
  8. data/lib/archive/support/zlib.rb +0 -435
  9. data/lib/archive/zip/codec/deflate/reader.rb +187 -0
  10. data/lib/archive/zip/codec/deflate/writer.rb +209 -0
  11. data/lib/archive/zip/codec/deflate.rb +92 -244
  12. data/lib/archive/zip/codec/null_encryption.rb +4 -184
  13. data/lib/archive/zip/codec/store/reader.rb +97 -0
  14. data/lib/archive/zip/codec/store/writer.rb +78 -0
  15. data/lib/archive/zip/codec/store.rb +6 -231
  16. data/lib/archive/zip/codec/traditional_encryption/base.rb +85 -0
  17. data/lib/archive/zip/codec/traditional_encryption/reader.rb +65 -0
  18. data/lib/archive/zip/codec/traditional_encryption/writer.rb +71 -0
  19. data/lib/archive/zip/codec/traditional_encryption.rb +6 -360
  20. data/lib/archive/zip/codec.rb +2 -2
  21. data/lib/archive/zip/dos_time.rb +103 -0
  22. data/lib/archive/zip/entry.rb +86 -70
  23. data/lib/archive/zip.rb +2 -5
  24. metadata +37 -227
  25. data/.yardopts +0 -1
  26. data/Rakefile +0 -247
  27. data/lib/archive/support/binary_stringio.rb +0 -30
  28. data/lib/archive/support/integer.rb +0 -13
  29. data/lib/archive/support/io-like.rb +0 -14
  30. data/lib/archive/support/time.rb +0 -119
  31. data/lib/archive/zip/version.rb +0 -6
  32. data/spec/archive/dos_time_spec.rb +0 -113
  33. data/spec/archive/zip/archive_spec.rb +0 -54
  34. data/spec/archive/zip/codec/deflate/compress/checksum_spec.rb +0 -44
  35. data/spec/archive/zip/codec/deflate/compress/close_spec.rb +0 -45
  36. data/spec/archive/zip/codec/deflate/compress/crc32_spec.rb +0 -23
  37. data/spec/archive/zip/codec/deflate/compress/data_descriptor_spec.rb +0 -74
  38. data/spec/archive/zip/codec/deflate/compress/new_spec.rb +0 -39
  39. data/spec/archive/zip/codec/deflate/compress/open_spec.rb +0 -48
  40. data/spec/archive/zip/codec/deflate/compress/write_spec.rb +0 -111
  41. data/spec/archive/zip/codec/deflate/decompress/checksum_spec.rb +0 -20
  42. data/spec/archive/zip/codec/deflate/decompress/close_spec.rb +0 -34
  43. data/spec/archive/zip/codec/deflate/decompress/crc32_spec.rb +0 -20
  44. data/spec/archive/zip/codec/deflate/decompress/data_descriptor_spec.rb +0 -74
  45. data/spec/archive/zip/codec/deflate/decompress/new_spec.rb +0 -16
  46. data/spec/archive/zip/codec/deflate/decompress/open_spec.rb +0 -29
  47. data/spec/archive/zip/codec/deflate/fixtures/classes.rb +0 -25
  48. data/spec/archive/zip/codec/deflate/fixtures/compressed_file.bin +0 -1
  49. data/spec/archive/zip/codec/deflate/fixtures/compressed_file_nocomp.bin +0 -0
  50. data/spec/archive/zip/codec/deflate/fixtures/raw_file.txt +0 -10
  51. data/spec/archive/zip/codec/null_encryption/decrypt/close_spec.rb +0 -34
  52. data/spec/archive/zip/codec/null_encryption/decrypt/new_spec.rb +0 -16
  53. data/spec/archive/zip/codec/null_encryption/decrypt/open_spec.rb +0 -29
  54. data/spec/archive/zip/codec/null_encryption/decrypt/read_spec.rb +0 -26
  55. data/spec/archive/zip/codec/null_encryption/decrypt/rewind_spec.rb +0 -27
  56. data/spec/archive/zip/codec/null_encryption/decrypt/seek_spec.rb +0 -59
  57. data/spec/archive/zip/codec/null_encryption/decrypt/tell_spec.rb +0 -23
  58. data/spec/archive/zip/codec/null_encryption/encrypt/close_spec.rb +0 -34
  59. data/spec/archive/zip/codec/null_encryption/encrypt/new_spec.rb +0 -16
  60. data/spec/archive/zip/codec/null_encryption/encrypt/open_spec.rb +0 -31
  61. data/spec/archive/zip/codec/null_encryption/encrypt/rewind_spec.rb +0 -28
  62. data/spec/archive/zip/codec/null_encryption/encrypt/seek_spec.rb +0 -52
  63. data/spec/archive/zip/codec/null_encryption/encrypt/tell_spec.rb +0 -31
  64. data/spec/archive/zip/codec/null_encryption/encrypt/write_spec.rb +0 -31
  65. data/spec/archive/zip/codec/null_encryption/fixtures/classes.rb +0 -12
  66. data/spec/archive/zip/codec/null_encryption/fixtures/raw_file.txt +0 -10
  67. data/spec/archive/zip/codec/store/compress/close_spec.rb +0 -34
  68. data/spec/archive/zip/codec/store/compress/data_descriptor_spec.rb +0 -77
  69. data/spec/archive/zip/codec/store/compress/new_spec.rb +0 -16
  70. data/spec/archive/zip/codec/store/compress/open_spec.rb +0 -29
  71. data/spec/archive/zip/codec/store/compress/rewind_spec.rb +0 -28
  72. data/spec/archive/zip/codec/store/compress/seek_spec.rb +0 -52
  73. data/spec/archive/zip/codec/store/compress/tell_spec.rb +0 -31
  74. data/spec/archive/zip/codec/store/compress/write_spec.rb +0 -29
  75. data/spec/archive/zip/codec/store/decompress/close_spec.rb +0 -34
  76. data/spec/archive/zip/codec/store/decompress/data_descriptor_spec.rb +0 -75
  77. data/spec/archive/zip/codec/store/decompress/new_spec.rb +0 -16
  78. data/spec/archive/zip/codec/store/decompress/open_spec.rb +0 -29
  79. data/spec/archive/zip/codec/store/decompress/read_spec.rb +0 -26
  80. data/spec/archive/zip/codec/store/decompress/rewind_spec.rb +0 -27
  81. data/spec/archive/zip/codec/store/decompress/seek_spec.rb +0 -59
  82. data/spec/archive/zip/codec/store/decompress/tell_spec.rb +0 -23
  83. data/spec/archive/zip/codec/store/fixtures/classes.rb +0 -12
  84. data/spec/archive/zip/codec/store/fixtures/raw_file.txt +0 -10
  85. data/spec/archive/zip/codec/traditional_encryption/decrypt/close_spec.rb +0 -53
  86. data/spec/archive/zip/codec/traditional_encryption/decrypt/new_spec.rb +0 -20
  87. data/spec/archive/zip/codec/traditional_encryption/decrypt/open_spec.rb +0 -43
  88. data/spec/archive/zip/codec/traditional_encryption/decrypt/read_spec.rb +0 -127
  89. data/spec/archive/zip/codec/traditional_encryption/decrypt/rewind_spec.rb +0 -36
  90. data/spec/archive/zip/codec/traditional_encryption/decrypt/seek_spec.rb +0 -80
  91. data/spec/archive/zip/codec/traditional_encryption/decrypt/tell_spec.rb +0 -27
  92. data/spec/archive/zip/codec/traditional_encryption/encrypt/close_spec.rb +0 -53
  93. data/spec/archive/zip/codec/traditional_encryption/encrypt/new_spec.rb +0 -20
  94. data/spec/archive/zip/codec/traditional_encryption/encrypt/open_spec.rb +0 -41
  95. data/spec/archive/zip/codec/traditional_encryption/encrypt/rewind_spec.rb +0 -39
  96. data/spec/archive/zip/codec/traditional_encryption/encrypt/seek_spec.rb +0 -73
  97. data/spec/archive/zip/codec/traditional_encryption/encrypt/tell_spec.rb +0 -40
  98. data/spec/archive/zip/codec/traditional_encryption/encrypt/write_spec.rb +0 -114
  99. data/spec/archive/zip/codec/traditional_encryption/fixtures/classes.rb +0 -27
  100. data/spec/archive/zip/codec/traditional_encryption/fixtures/encrypted_file.bin +0 -0
  101. data/spec/archive/zip/codec/traditional_encryption/fixtures/raw_file.txt +0 -10
  102. data/spec/binary_stringio/new_spec.rb +0 -40
  103. data/spec/binary_stringio/set_encoding_spec.rb +0 -17
  104. data/spec/ioextensions/read_exactly_spec.rb +0 -52
  105. data/spec/zlib/fixtures/classes.rb +0 -65
  106. data/spec/zlib/fixtures/compressed_file.bin +0 -1
  107. data/spec/zlib/fixtures/compressed_file_gzip.bin +0 -0
  108. data/spec/zlib/fixtures/compressed_file_huffman.bin +0 -2
  109. data/spec/zlib/fixtures/compressed_file_minmem.bin +0 -0
  110. data/spec/zlib/fixtures/compressed_file_minwin.bin +0 -1
  111. data/spec/zlib/fixtures/compressed_file_nocomp.bin +0 -0
  112. data/spec/zlib/fixtures/compressed_file_raw.bin +0 -1
  113. data/spec/zlib/fixtures/raw_file.txt +0 -10
  114. data/spec/zlib/zreader/checksum_spec.rb +0 -42
  115. data/spec/zlib/zreader/close_spec.rb +0 -16
  116. data/spec/zlib/zreader/compressed_size_spec.rb +0 -20
  117. data/spec/zlib/zreader/new_spec.rb +0 -43
  118. data/spec/zlib/zreader/open_spec.rb +0 -51
  119. data/spec/zlib/zreader/read_spec.rb +0 -58
  120. data/spec/zlib/zreader/rewind_spec.rb +0 -25
  121. data/spec/zlib/zreader/seek_spec.rb +0 -57
  122. data/spec/zlib/zreader/tell_spec.rb +0 -23
  123. data/spec/zlib/zreader/uncompressed_size_spec.rb +0 -20
  124. data/spec/zlib/zwriter/checksum_spec.rb +0 -43
  125. data/spec/zlib/zwriter/close_spec.rb +0 -16
  126. data/spec/zlib/zwriter/compressed_size_spec.rb +0 -21
  127. data/spec/zlib/zwriter/new_spec.rb +0 -66
  128. data/spec/zlib/zwriter/open_spec.rb +0 -70
  129. data/spec/zlib/zwriter/rewind_spec.rb +0 -28
  130. data/spec/zlib/zwriter/seek_spec.rb +0 -52
  131. data/spec/zlib/zwriter/tell_spec.rb +0 -31
  132. data/spec/zlib/zwriter/uncompressed_size_spec.rb +0 -21
  133. data/spec/zlib/zwriter/write_spec.rb +0 -28
@@ -1,114 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- require 'minitest/autorun'
4
-
5
- require File.expand_path('../../fixtures/classes', __FILE__)
6
-
7
- require 'archive/zip/codec/traditional_encryption'
8
- require 'archive/support/binary_stringio'
9
-
10
- describe "Archive::Zip::Codec::TraditionalEncryption::Encrypt#write" do
11
- it "writes encrypted data to the delegate" do
12
- # Ensure repeatable test data is used for encryption header.
13
- srand(0)
14
- encrypted_data = BinaryStringIO.new
15
- Archive::Zip::Codec::TraditionalEncryption::Encrypt.open(
16
- encrypted_data,
17
- TraditionalEncryptionSpecs.password,
18
- TraditionalEncryptionSpecs.mtime
19
- ) do |e|
20
- e.write(TraditionalEncryptionSpecs.test_data)
21
- end
22
- encrypted_data.string.must_equal(TraditionalEncryptionSpecs.encrypted_data)
23
- end
24
-
25
- it "writes encrypted data to a delegate that only performs partial writes" do
26
- # Ensure repeatable test data is used for encryption header.
27
- srand(0)
28
- encrypted_data = BinaryStringIO.new
29
- # Override encrypted_data.write to perform writes 1 byte at a time.
30
- class << encrypted_data
31
- alias :write_orig :write
32
- def write(buffer)
33
- write_orig(buffer.slice(0, 1))
34
- end
35
- end
36
-
37
- Archive::Zip::Codec::TraditionalEncryption::Encrypt.open(
38
- encrypted_data,
39
- TraditionalEncryptionSpecs.password,
40
- TraditionalEncryptionSpecs.mtime
41
- ) do |e|
42
- e.write(TraditionalEncryptionSpecs.test_data)
43
- end
44
- encrypted_data.string.must_equal(TraditionalEncryptionSpecs.encrypted_data)
45
- end
46
-
47
- it "writes encrypted data to a delegate that raises Errno::EAGAIN" do
48
- # Ensure repeatable test data is used for encryption header.
49
- srand(0)
50
- encrypted_data = BinaryStringIO.new
51
- # Override encrypted_data.write to raise Errno::EAGAIN every other time it's
52
- # called.
53
- class << encrypted_data
54
- alias :write_orig :write
55
- def write(buffer)
56
- @error_raised ||= false
57
- if @error_raised then
58
- @error_raised = false
59
- write_orig(buffer)
60
- else
61
- @error_raised = true
62
- raise Errno::EAGAIN
63
- end
64
- end
65
- end
66
-
67
- Archive::Zip::Codec::TraditionalEncryption::Encrypt.open(
68
- encrypted_data,
69
- TraditionalEncryptionSpecs.password,
70
- TraditionalEncryptionSpecs.mtime
71
- ) do |e|
72
- begin
73
- e.write(TraditionalEncryptionSpecs.test_data)
74
- rescue Errno::EAGAIN
75
- retry
76
- end
77
- end
78
- encrypted_data.string.must_equal(TraditionalEncryptionSpecs.encrypted_data)
79
- end
80
-
81
- it "writes encrypted data to a delegate that raises Errno::EINTR" do
82
- # Ensure repeatable test data is used for encryption header.
83
- srand(0)
84
- encrypted_data = BinaryStringIO.new
85
- # Override encrypted_data.write to raise Errno::EINTR every other time it's
86
- # called.
87
- class << encrypted_data
88
- alias :write_orig :write
89
- def write(buffer)
90
- @error_raised ||= false
91
- if @error_raised then
92
- @error_raised = false
93
- write_orig(buffer)
94
- else
95
- @error_raised = true
96
- raise Errno::EINTR
97
- end
98
- end
99
- end
100
-
101
- Archive::Zip::Codec::TraditionalEncryption::Encrypt.open(
102
- encrypted_data,
103
- TraditionalEncryptionSpecs.password,
104
- TraditionalEncryptionSpecs.mtime
105
- ) do |e|
106
- begin
107
- e.write(TraditionalEncryptionSpecs.test_data)
108
- rescue Errno::EINTR
109
- retry
110
- end
111
- end
112
- encrypted_data.string.must_equal(TraditionalEncryptionSpecs.encrypted_data)
113
- end
114
- end
@@ -1,27 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- class TraditionalEncryptionSpecs
4
- class << self
5
- def password
6
- 'p455w0rd'
7
- end
8
-
9
- def mtime
10
- Time.local(1979, 12, 31, 18, 0, 0)
11
- end
12
-
13
- def encrypted_data
14
- File.open(
15
- File.join(File.dirname(__FILE__), 'encrypted_file.bin'), 'rb'
16
- ) do |f|
17
- block_given? ? yield(f) : f.read
18
- end
19
- end
20
-
21
- def test_data
22
- File.open(File.join(File.dirname(__FILE__), 'raw_file.txt'), 'rb') do |f|
23
- block_given? ? yield(f) : f.read
24
- end
25
- end
26
- end
27
- end
@@ -1,10 +0,0 @@
1
- test
2
- This is a file with test data.
3
- The quick brown fox jumps over the lazy dog.
4
-
5
- Mary had a little lamb
6
- Whose fleece was white as snow
7
- And everywhere that Mary went
8
- The lamb was sure to go
9
-
10
- She sells sea shells down by the sea shore.
@@ -1,40 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- require 'minitest/autorun'
4
-
5
- require 'archive/support/binary_stringio'
6
-
7
- describe "BinaryStringIO.new" do
8
- it "returns a new instance" do
9
- io = BinaryStringIO.new
10
- io.must_be_instance_of BinaryStringIO
11
- io.close
12
- end
13
-
14
- it "creates a decendent of StringIO" do
15
- io = BinaryStringIO.new
16
- io.must_be_kind_of StringIO
17
- io.close
18
- end
19
-
20
- # TODO:
21
- # This is lame. Break this out as augmentation for the "returns a new
22
- # instance" test.
23
- it "takes the same arguments as StringIO.new" do
24
- BinaryStringIO.new.must_be_instance_of BinaryStringIO
25
- BinaryStringIO.new('').must_be_instance_of BinaryStringIO
26
- BinaryStringIO.new('', 'r').must_be_instance_of BinaryStringIO
27
- BinaryStringIO.new('', 'w').must_be_instance_of BinaryStringIO
28
-
29
- lambda { BinaryStringIO.new('', 'w', 42) }.must_raise ArgumentError
30
- end
31
-
32
- it "sets the external encoding to binary" do
33
- unless Object.const_defined?(:Encoding)
34
- skip("Encoding methods are not supported on current Ruby (#{RUBY_DESCRIPTION})")
35
- end
36
-
37
- io = BinaryStringIO.new
38
- io.external_encoding.must_equal Encoding::ASCII_8BIT
39
- end
40
- end
@@ -1,17 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- require 'minitest/autorun'
4
-
5
- require 'archive/support/binary_stringio'
6
-
7
- describe "BinaryStringIO#set_encoding" do
8
- it "raises an exception when called" do
9
- unless Object.const_defined?(:Encoding)
10
- skip("Encoding methods are not supported on current Ruby (#{RUBY_DESCRIPTION})")
11
- end
12
-
13
- lambda do
14
- BinaryStringIO.new.set_encoding('utf-8')
15
- end.must_raise RuntimeError
16
- end
17
- end
@@ -1,52 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- require 'minitest/autorun'
4
-
5
- require 'archive/support/ioextensions.rb'
6
- require 'archive/support/binary_stringio'
7
-
8
- describe "IOExtensions.read_exactly" do
9
- it "reads and returns length bytes from a given IO object" do
10
- io = BinaryStringIO.new('This is test data')
11
- IOExtensions.read_exactly(io, 4).must_equal 'This'
12
- IOExtensions.read_exactly(io, 13).must_equal ' is test data'
13
- end
14
-
15
- it "raises an error when too little data is available" do
16
- io = BinaryStringIO.new('This is test data')
17
- lambda do
18
- IOExtensions.read_exactly(io, 18)
19
- end.must_raise EOFError
20
- end
21
-
22
- it "takes an optional buffer argument and fills it" do
23
- io = BinaryStringIO.new('This is test data')
24
- buffer = ''
25
- IOExtensions.read_exactly(io, 4, buffer)
26
- buffer.must_equal 'This'
27
- buffer = ''
28
- IOExtensions.read_exactly(io, 13, buffer)
29
- buffer.must_equal ' is test data'
30
- end
31
-
32
- it "empties the optional buffer before filling it" do
33
- io = BinaryStringIO.new('This is test data')
34
- buffer = ''
35
- IOExtensions.read_exactly(io, 4, buffer)
36
- buffer.must_equal 'This'
37
- IOExtensions.read_exactly(io, 13, buffer)
38
- buffer.must_equal ' is test data'
39
- end
40
-
41
- it "can read 0 bytes" do
42
- io = BinaryStringIO.new('This is test data')
43
- IOExtensions.read_exactly(io, 0).must_equal ''
44
- end
45
-
46
- it "retries partial reads" do
47
- io = MiniTest::Mock.new
48
- io.expect(:read, 'hello', [10])
49
- io.expect(:read, 'hello', [5])
50
- IOExtensions.read_exactly(io, 10).must_equal 'hellohello'
51
- end
52
- end
@@ -1,65 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- class ZlibSpecs
4
- def self.compressed_data
5
- File.open(
6
- File.join(File.dirname(__FILE__), 'compressed_file.bin'), 'rb'
7
- ) do |f|
8
- block_given? ? yield(f) : f.read
9
- end
10
- end
11
-
12
- def self.compressed_data_nocomp
13
- File.open(
14
- File.join(File.dirname(__FILE__), 'compressed_file_nocomp.bin'), 'rb'
15
- ) do |f|
16
- block_given? ? yield(f) : f.read
17
- end
18
- end
19
-
20
- def self.compressed_data_minwin
21
- File.open(
22
- File.join(File.dirname(__FILE__), 'compressed_file_minwin.bin'), 'rb'
23
- ) do |f|
24
- block_given? ? yield(f) : f.read
25
- end
26
- end
27
-
28
- def self.compressed_data_minmem
29
- File.open(
30
- File.join(File.dirname(__FILE__), 'compressed_file_minmem.bin'), 'rb'
31
- ) do |f|
32
- block_given? ? yield(f) : f.read
33
- end
34
- end
35
-
36
- def self.compressed_data_huffman
37
- File.open(
38
- File.join(File.dirname(__FILE__), 'compressed_file_huffman.bin'), 'rb'
39
- ) do |f|
40
- block_given? ? yield(f) : f.read
41
- end
42
- end
43
-
44
- def self.compressed_data_gzip
45
- File.open(
46
- File.join(File.dirname(__FILE__), 'compressed_file_gzip.bin'), 'rb'
47
- ) do |f|
48
- block_given? ? yield(f) : f.read
49
- end
50
- end
51
-
52
- def self.compressed_data_raw
53
- File.open(
54
- File.join(File.dirname(__FILE__), 'compressed_file_raw.bin'), 'rb'
55
- ) do |f|
56
- block_given? ? yield(f) : f.read
57
- end
58
- end
59
-
60
- def self.test_data
61
- File.open(File.join(File.dirname(__FILE__), 'raw_file.txt'), 'rb') do |f|
62
- f.read
63
- end
64
- end
65
- end
@@ -1 +0,0 @@
1
- x�%�A�0E�9�?A��\�kj���E5��K� ��o��)+�S.��-� �����Z����J[0��u~*����wC��‘�D�m%���c�$Q�T����-ecx���pX"�m[K\ٝd�Ƌ����/n�Ɂr)>e����=��`��T��CQ�
@@ -1,2 +0,0 @@
1
- x��q�0 �?��
2
- ԃ �+���Nc�H� S}v��e���Q�5�H쒲�U���>^غ����u���#�0������r�>��C`5��s+��AF>�!��5 D�Qnm��s(;�*�����eU���0$W'���R>����P�v
@@ -1 +0,0 @@
1
- �%�A�0E�9�?A��\�kj���E5��K� ��o��)+�S.��-� �����Z����J[0��u~*����wC��‘�D�m%���c�$Q�T����-ecx���pX"�m[K\ٝd�Ƌ����/n�Ɂr)>e����=��`��T��CQ�
@@ -1 +0,0 @@
1
- %�A�0E�9�?A��\�kj���E5��K� ��o��)+�S.��-� �����Z����J[0��u~*����wC��‘�D�m%���c�$Q�T����-ecx���pX"�m[K\ٝd�Ƌ����/n�Ɂr)>e����=��`��T�
@@ -1,10 +0,0 @@
1
- test
2
- This is a file with test data.
3
- The quick brown fox jumps over the lazy dog.
4
-
5
- Mary had a little lamb
6
- Whose fleece was white as snow
7
- And everywhere that Mary went
8
- The lamb was sure to go
9
-
10
- She sells sea shells down by the sea shore.
@@ -1,42 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- require 'minitest/autorun'
4
-
5
- require File.expand_path('../../fixtures/classes', __FILE__)
6
-
7
- require 'archive/support/zlib'
8
-
9
- describe "Zlib::ZReader#checksum" do
10
- it "computes the ADLER32 checksum of zlib formatted data" do
11
- closed_zr = ZlibSpecs.compressed_data do |f|
12
- Zlib::ZReader.open(f, 15) do |zr|
13
- zr.read
14
- zr.checksum.must_equal Zlib.adler32(ZlibSpecs.test_data)
15
- zr
16
- end
17
- end
18
- closed_zr.checksum.must_equal Zlib.adler32(ZlibSpecs.test_data)
19
- end
20
-
21
- it "computes the CRC32 checksum of gzip formatted data" do
22
- closed_zr = ZlibSpecs.compressed_data_gzip do |f|
23
- Zlib::ZReader.open(f, 31) do |zr|
24
- zr.read
25
- zr.checksum.must_equal Zlib.crc32(ZlibSpecs.test_data)
26
- zr
27
- end
28
- end
29
- closed_zr.checksum.must_equal Zlib.crc32(ZlibSpecs.test_data)
30
- end
31
-
32
- it "does not compute a checksum for raw zlib data" do
33
- closed_zr = ZlibSpecs.compressed_data_raw do |f|
34
- Zlib::ZReader.open(f, -15) do |zr|
35
- zr.read
36
- zr.checksum.must_be_nil
37
- zr
38
- end
39
- end
40
- closed_zr.checksum.must_be_nil
41
- end
42
- end
@@ -1,16 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- require 'minitest/autorun'
4
-
5
- require File.expand_path('../../fixtures/classes', __FILE__)
6
-
7
- require 'archive/support/zlib'
8
- require 'archive/support/binary_stringio'
9
-
10
- describe "Zlib::ZReader.close" do
11
- it "closes the stream" do
12
- zr = Zlib::ZReader.new(BinaryStringIO.new)
13
- zr.close
14
- zr.closed?.must_equal true
15
- end
16
- end
@@ -1,20 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- require 'minitest/autorun'
4
-
5
- require File.expand_path('../../fixtures/classes', __FILE__)
6
-
7
- require 'archive/support/zlib'
8
-
9
- describe "Zlib::ZReader#compressed_size" do
10
- it "returns the number of bytes of compressed data" do
11
- closed_zr = ZlibSpecs.compressed_data_raw do |compressed_data|
12
- Zlib::ZReader.open(compressed_data, -15) do |zr|
13
- zr.read
14
- zr.compressed_size.must_equal 160
15
- zr
16
- end
17
- end
18
- closed_zr.compressed_size.must_equal 160
19
- end
20
- end
@@ -1,43 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- require 'minitest/autorun'
4
-
5
- require File.expand_path('../../fixtures/classes', __FILE__)
6
-
7
- require 'archive/support/zlib'
8
- require 'archive/support/binary_stringio'
9
-
10
- describe "Zlib::ZReader.new" do
11
- it "returns a new instance" do
12
- Zlib::ZReader.new(BinaryStringIO.new).class.must_equal Zlib::ZReader
13
- end
14
-
15
- it "does not require window_bits to be set" do
16
- data = ZlibSpecs.test_data
17
- compressed_data = BinaryStringIO.new
18
- Zlib::ZWriter.open(compressed_data) do |zw|
19
- zw.write(data)
20
- end
21
- compressed_data.rewind
22
-
23
- zr = Zlib::ZReader.new(compressed_data)
24
- zr.read.must_equal data
25
- zr.close
26
- end
27
-
28
- it "allows window_bits to be set" do
29
- data = ZlibSpecs.test_data
30
- compressed_data = BinaryStringIO.new
31
- window_bits = -Zlib::MAX_WBITS
32
- Zlib::ZWriter.open(
33
- compressed_data, Zlib::DEFAULT_COMPRESSION, window_bits
34
- ) do |zw|
35
- zw.write(data)
36
- end
37
- compressed_data.rewind
38
-
39
- zr = Zlib::ZReader.new(compressed_data, window_bits)
40
- zr.read.must_equal data
41
- zr.close
42
- end
43
- end
@@ -1,51 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- require 'minitest/autorun'
4
-
5
- require File.expand_path('../../fixtures/classes', __FILE__)
6
-
7
- require 'archive/support/zlib'
8
- require 'archive/support/binary_stringio'
9
-
10
- describe "Zlib::ZReader.open" do
11
- it "returns a new instance when run without a block" do
12
- Zlib::ZReader.open(BinaryStringIO.new).class.must_equal Zlib::ZReader
13
- end
14
-
15
- it "executes a block with a new instance as an argument" do
16
- Zlib::ZReader.open(BinaryStringIO.new) { |zr| zr.class.must_equal Zlib::ZReader }
17
- end
18
-
19
- it "closes the object after executing a block" do
20
- Zlib::ZReader.open(BinaryStringIO.new) { |zr| zr }.closed?.must_equal true
21
- end
22
-
23
- it "does not require window_bits to be set" do
24
- data = ZlibSpecs.test_data
25
- compressed_data = BinaryStringIO.new
26
- Zlib::ZWriter.open(compressed_data) do |zw|
27
- zw.write(data)
28
- end
29
- compressed_data.rewind
30
-
31
- Zlib::ZReader.open(compressed_data) do |zr|
32
- zr.read.must_equal data
33
- end
34
- end
35
-
36
- it "allows window_bits to be set" do
37
- data = ZlibSpecs.test_data
38
- compressed_data = BinaryStringIO.new
39
- window_bits = -Zlib::MAX_WBITS
40
- Zlib::ZWriter.open(
41
- compressed_data, Zlib::DEFAULT_COMPRESSION, window_bits
42
- ) do |zw|
43
- zw.write(data)
44
- end
45
- compressed_data.rewind
46
-
47
- Zlib::ZReader.open(compressed_data, window_bits) do |zr|
48
- zr.read.must_equal data
49
- end
50
- end
51
- end
@@ -1,58 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- require 'minitest/autorun'
4
-
5
- require File.expand_path('../../fixtures/classes', __FILE__)
6
-
7
- require 'archive/support/zlib'
8
- require 'archive/support/binary_stringio'
9
-
10
- describe "Zlib::ZReader#read" do
11
- it "calls the read method of the delegate" do
12
- delegate = MiniTest::Mock.new
13
- delegate.expect(:read, nil, [Integer])
14
- Zlib::ZReader.open(delegate) do |zr|
15
- # Capture and ignore the Zlib::BufError which is generated due to mocking.
16
- begin
17
- zr.read
18
- rescue Zlib::BufError
19
- end
20
-
21
- # Avoid warnings from zlib caused by closing the un-finished inflater.
22
- def zr.close; end
23
- end
24
- end
25
-
26
- it "decompresses compressed data" do
27
- ZlibSpecs.compressed_data do |cd|
28
- Zlib::ZReader.open(cd) do |zr|
29
- zr.read.must_equal ZlibSpecs.test_data
30
- end
31
- end
32
- end
33
-
34
- it "raises Zlib::DataError when reading invalid data" do
35
- Zlib::ZReader.open(BinaryStringIO.new('This is not compressed data')) do |zr|
36
- lambda { zr.read }.must_raise Zlib::DataError
37
- end
38
- end
39
-
40
- it "raises Zlib::BufError when reading truncated data" do
41
- truncated_data = ZlibSpecs.compressed_data { |cd| cd.read(100) }
42
- Zlib::ZReader.open(BinaryStringIO.new(truncated_data)) do |zr|
43
- lambda { zr.read }.must_raise Zlib::BufError
44
-
45
- # Avoid warnings from zlib caused by closing the un-finished inflater.
46
- def zr.close; end
47
- end
48
- end
49
-
50
- it "raises Zlib::BufError when reading empty data" do
51
- Zlib::ZReader.open(BinaryStringIO.new()) do |zr|
52
- lambda { zr.read }.must_raise Zlib::BufError
53
-
54
- # Avoid warnings from zlib caused by closing the un-finished inflater.
55
- def zr.close; end
56
- end
57
- end
58
- end
@@ -1,25 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- require 'minitest/autorun'
4
-
5
- require File.expand_path('../../fixtures/classes', __FILE__)
6
-
7
- require 'archive/support/zlib'
8
-
9
- describe "Zlib::ZReader#rewind" do
10
- it "can rewind the stream when the delegate responds to rewind" do
11
- ZlibSpecs.compressed_data do |cd|
12
- Zlib::ZReader.open(cd) do |zr|
13
- zr.read(4)
14
- zr.rewind
15
- zr.read.must_equal ZlibSpecs.test_data
16
- end
17
- end
18
- end
19
-
20
- it "raises Errno::EINVAL when attempting to rewind the stream when the delegate does not respond to rewind" do
21
- Zlib::ZReader.open(Object.new) do |zr|
22
- lambda { zr.rewind }.must_raise Errno::EINVAL
23
- end
24
- end
25
- end
@@ -1,57 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- require 'minitest/autorun'
4
-
5
- require File.expand_path('../../fixtures/classes', __FILE__)
6
-
7
- require 'archive/support/zlib'
8
-
9
- describe "Zlib::ZReader#seek" do
10
- it "can seek to the beginning of the stream when the delegate responds to rewind" do
11
- ZlibSpecs.compressed_data do |cd|
12
- Zlib::ZReader.open(cd) do |zr|
13
- zr.read(4)
14
- zr.seek(0).must_equal 0
15
- end
16
- end
17
- end
18
-
19
- it "raises Errno::EINVAL when attempting to seek to the beginning of the stream when the delegate does not respond to rewind" do
20
- Zlib::ZReader.open(Object.new) do |zr|
21
- lambda { zr.seek(0) }.must_raise Errno::EINVAL
22
- end
23
- end
24
-
25
- it "raises Errno::EINVAL when seeking forward or backward from the current position of the stream" do
26
- ZlibSpecs.compressed_data do |cd|
27
- Zlib::ZReader.open(cd) do |zr|
28
- # Disable read buffering to avoid some seeking optimizations implemented
29
- # by IO::Like which allow seeking forward within the buffer.
30
- zr.fill_size = 0
31
-
32
- zr.read(4)
33
- lambda { zr.seek(1, IO::SEEK_CUR) }.must_raise Errno::EINVAL
34
- lambda { zr.seek(-1, IO::SEEK_CUR) }.must_raise Errno::EINVAL
35
- end
36
- end
37
- end
38
-
39
- it "raises Errno::EINVAL when seeking a non-zero offset relative to the beginning of the stream" do
40
- ZlibSpecs.compressed_data do |cd|
41
- Zlib::ZReader.open(cd) do |zr|
42
- lambda { zr.seek(-1, IO::SEEK_SET) }.must_raise Errno::EINVAL
43
- lambda { zr.seek(1, IO::SEEK_SET) }.must_raise Errno::EINVAL
44
- end
45
- end
46
- end
47
-
48
- it "raises Errno::EINVAL when seeking relative to the end of the stream" do
49
- ZlibSpecs.compressed_data do |cd|
50
- Zlib::ZReader.open(cd) do |zr|
51
- lambda { zr.seek(0, IO::SEEK_END) }.must_raise Errno::EINVAL
52
- lambda { zr.seek(-1, IO::SEEK_END) }.must_raise Errno::EINVAL
53
- lambda { zr.seek(1, IO::SEEK_END) }.must_raise Errno::EINVAL
54
- end
55
- end
56
- end
57
- end