archive-zip 0.12.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 (132) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +1 -1
  3. data/NEWS.md +5 -0
  4. data/README.md +1 -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/dos_time.rb +103 -0
  21. data/lib/archive/zip/entry.rb +86 -70
  22. data/lib/archive/zip.rb +2 -5
  23. metadata +35 -227
  24. data/.yardopts +0 -1
  25. data/Rakefile +0 -247
  26. data/lib/archive/support/binary_stringio.rb +0 -30
  27. data/lib/archive/support/integer.rb +0 -13
  28. data/lib/archive/support/io-like.rb +0 -14
  29. data/lib/archive/support/time.rb +0 -119
  30. data/lib/archive/zip/version.rb +0 -6
  31. data/spec/archive/dos_time_spec.rb +0 -113
  32. data/spec/archive/zip/archive_spec.rb +0 -54
  33. data/spec/archive/zip/codec/deflate/compress/checksum_spec.rb +0 -44
  34. data/spec/archive/zip/codec/deflate/compress/close_spec.rb +0 -45
  35. data/spec/archive/zip/codec/deflate/compress/crc32_spec.rb +0 -23
  36. data/spec/archive/zip/codec/deflate/compress/data_descriptor_spec.rb +0 -74
  37. data/spec/archive/zip/codec/deflate/compress/new_spec.rb +0 -39
  38. data/spec/archive/zip/codec/deflate/compress/open_spec.rb +0 -48
  39. data/spec/archive/zip/codec/deflate/compress/write_spec.rb +0 -111
  40. data/spec/archive/zip/codec/deflate/decompress/checksum_spec.rb +0 -20
  41. data/spec/archive/zip/codec/deflate/decompress/close_spec.rb +0 -34
  42. data/spec/archive/zip/codec/deflate/decompress/crc32_spec.rb +0 -20
  43. data/spec/archive/zip/codec/deflate/decompress/data_descriptor_spec.rb +0 -74
  44. data/spec/archive/zip/codec/deflate/decompress/new_spec.rb +0 -16
  45. data/spec/archive/zip/codec/deflate/decompress/open_spec.rb +0 -29
  46. data/spec/archive/zip/codec/deflate/fixtures/classes.rb +0 -25
  47. data/spec/archive/zip/codec/deflate/fixtures/compressed_file.bin +0 -1
  48. data/spec/archive/zip/codec/deflate/fixtures/compressed_file_nocomp.bin +0 -0
  49. data/spec/archive/zip/codec/deflate/fixtures/raw_file.txt +0 -10
  50. data/spec/archive/zip/codec/null_encryption/decrypt/close_spec.rb +0 -34
  51. data/spec/archive/zip/codec/null_encryption/decrypt/new_spec.rb +0 -16
  52. data/spec/archive/zip/codec/null_encryption/decrypt/open_spec.rb +0 -29
  53. data/spec/archive/zip/codec/null_encryption/decrypt/read_spec.rb +0 -26
  54. data/spec/archive/zip/codec/null_encryption/decrypt/rewind_spec.rb +0 -27
  55. data/spec/archive/zip/codec/null_encryption/decrypt/seek_spec.rb +0 -59
  56. data/spec/archive/zip/codec/null_encryption/decrypt/tell_spec.rb +0 -23
  57. data/spec/archive/zip/codec/null_encryption/encrypt/close_spec.rb +0 -34
  58. data/spec/archive/zip/codec/null_encryption/encrypt/new_spec.rb +0 -16
  59. data/spec/archive/zip/codec/null_encryption/encrypt/open_spec.rb +0 -31
  60. data/spec/archive/zip/codec/null_encryption/encrypt/rewind_spec.rb +0 -28
  61. data/spec/archive/zip/codec/null_encryption/encrypt/seek_spec.rb +0 -52
  62. data/spec/archive/zip/codec/null_encryption/encrypt/tell_spec.rb +0 -31
  63. data/spec/archive/zip/codec/null_encryption/encrypt/write_spec.rb +0 -31
  64. data/spec/archive/zip/codec/null_encryption/fixtures/classes.rb +0 -12
  65. data/spec/archive/zip/codec/null_encryption/fixtures/raw_file.txt +0 -10
  66. data/spec/archive/zip/codec/store/compress/close_spec.rb +0 -34
  67. data/spec/archive/zip/codec/store/compress/data_descriptor_spec.rb +0 -77
  68. data/spec/archive/zip/codec/store/compress/new_spec.rb +0 -16
  69. data/spec/archive/zip/codec/store/compress/open_spec.rb +0 -29
  70. data/spec/archive/zip/codec/store/compress/rewind_spec.rb +0 -28
  71. data/spec/archive/zip/codec/store/compress/seek_spec.rb +0 -52
  72. data/spec/archive/zip/codec/store/compress/tell_spec.rb +0 -31
  73. data/spec/archive/zip/codec/store/compress/write_spec.rb +0 -29
  74. data/spec/archive/zip/codec/store/decompress/close_spec.rb +0 -34
  75. data/spec/archive/zip/codec/store/decompress/data_descriptor_spec.rb +0 -75
  76. data/spec/archive/zip/codec/store/decompress/new_spec.rb +0 -16
  77. data/spec/archive/zip/codec/store/decompress/open_spec.rb +0 -29
  78. data/spec/archive/zip/codec/store/decompress/read_spec.rb +0 -26
  79. data/spec/archive/zip/codec/store/decompress/rewind_spec.rb +0 -27
  80. data/spec/archive/zip/codec/store/decompress/seek_spec.rb +0 -59
  81. data/spec/archive/zip/codec/store/decompress/tell_spec.rb +0 -23
  82. data/spec/archive/zip/codec/store/fixtures/classes.rb +0 -12
  83. data/spec/archive/zip/codec/store/fixtures/raw_file.txt +0 -10
  84. data/spec/archive/zip/codec/traditional_encryption/decrypt/close_spec.rb +0 -53
  85. data/spec/archive/zip/codec/traditional_encryption/decrypt/new_spec.rb +0 -20
  86. data/spec/archive/zip/codec/traditional_encryption/decrypt/open_spec.rb +0 -43
  87. data/spec/archive/zip/codec/traditional_encryption/decrypt/read_spec.rb +0 -127
  88. data/spec/archive/zip/codec/traditional_encryption/decrypt/rewind_spec.rb +0 -36
  89. data/spec/archive/zip/codec/traditional_encryption/decrypt/seek_spec.rb +0 -80
  90. data/spec/archive/zip/codec/traditional_encryption/decrypt/tell_spec.rb +0 -27
  91. data/spec/archive/zip/codec/traditional_encryption/encrypt/close_spec.rb +0 -53
  92. data/spec/archive/zip/codec/traditional_encryption/encrypt/new_spec.rb +0 -20
  93. data/spec/archive/zip/codec/traditional_encryption/encrypt/open_spec.rb +0 -41
  94. data/spec/archive/zip/codec/traditional_encryption/encrypt/rewind_spec.rb +0 -39
  95. data/spec/archive/zip/codec/traditional_encryption/encrypt/seek_spec.rb +0 -73
  96. data/spec/archive/zip/codec/traditional_encryption/encrypt/tell_spec.rb +0 -40
  97. data/spec/archive/zip/codec/traditional_encryption/encrypt/write_spec.rb +0 -114
  98. data/spec/archive/zip/codec/traditional_encryption/fixtures/classes.rb +0 -27
  99. data/spec/archive/zip/codec/traditional_encryption/fixtures/encrypted_file.bin +0 -0
  100. data/spec/archive/zip/codec/traditional_encryption/fixtures/raw_file.txt +0 -10
  101. data/spec/binary_stringio/new_spec.rb +0 -40
  102. data/spec/binary_stringio/set_encoding_spec.rb +0 -17
  103. data/spec/ioextensions/read_exactly_spec.rb +0 -52
  104. data/spec/zlib/fixtures/classes.rb +0 -65
  105. data/spec/zlib/fixtures/compressed_file.bin +0 -1
  106. data/spec/zlib/fixtures/compressed_file_gzip.bin +0 -0
  107. data/spec/zlib/fixtures/compressed_file_huffman.bin +0 -2
  108. data/spec/zlib/fixtures/compressed_file_minmem.bin +0 -0
  109. data/spec/zlib/fixtures/compressed_file_minwin.bin +0 -1
  110. data/spec/zlib/fixtures/compressed_file_nocomp.bin +0 -0
  111. data/spec/zlib/fixtures/compressed_file_raw.bin +0 -1
  112. data/spec/zlib/fixtures/raw_file.txt +0 -10
  113. data/spec/zlib/zreader/checksum_spec.rb +0 -42
  114. data/spec/zlib/zreader/close_spec.rb +0 -16
  115. data/spec/zlib/zreader/compressed_size_spec.rb +0 -20
  116. data/spec/zlib/zreader/new_spec.rb +0 -43
  117. data/spec/zlib/zreader/open_spec.rb +0 -51
  118. data/spec/zlib/zreader/read_spec.rb +0 -58
  119. data/spec/zlib/zreader/rewind_spec.rb +0 -25
  120. data/spec/zlib/zreader/seek_spec.rb +0 -57
  121. data/spec/zlib/zreader/tell_spec.rb +0 -23
  122. data/spec/zlib/zreader/uncompressed_size_spec.rb +0 -20
  123. data/spec/zlib/zwriter/checksum_spec.rb +0 -43
  124. data/spec/zlib/zwriter/close_spec.rb +0 -16
  125. data/spec/zlib/zwriter/compressed_size_spec.rb +0 -21
  126. data/spec/zlib/zwriter/new_spec.rb +0 -66
  127. data/spec/zlib/zwriter/open_spec.rb +0 -70
  128. data/spec/zlib/zwriter/rewind_spec.rb +0 -28
  129. data/spec/zlib/zwriter/seek_spec.rb +0 -52
  130. data/spec/zlib/zwriter/tell_spec.rb +0 -31
  131. data/spec/zlib/zwriter/uncompressed_size_spec.rb +0 -21
  132. data/spec/zlib/zwriter/write_spec.rb +0 -28
@@ -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/zip/codec/deflate'
8
-
9
- describe "Archive::Zip::Deflate::Decompress#checksum" do
10
- it "computes a CRC32 checksum" do
11
- closed_decompressor = DeflateSpecs.compressed_data do |f|
12
- Archive::Zip::Codec::Deflate::Decompress.open(f) do |decompressor|
13
- decompressor.read
14
- decompressor.checksum.must_equal(Zlib.crc32(DeflateSpecs.test_data))
15
- decompressor
16
- end
17
- end
18
- closed_decompressor.checksum.must_equal(Zlib.crc32(DeflateSpecs.test_data))
19
- end
20
- end
@@ -1,34 +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/deflate'
8
- require 'archive/support/binary_stringio'
9
-
10
- describe "Archive::Zip::Codec::Deflate::Decompress#close" do
11
- it "closes the stream" do
12
- c = Archive::Zip::Codec::Deflate::Decompress.new(BinaryStringIO.new)
13
- c.close
14
- c.closed?.must_equal(true)
15
- end
16
-
17
- it "closes the delegate stream by default" do
18
- delegate = MiniTest::Mock.new
19
- delegate.expect(:close, nil)
20
- c = Archive::Zip::Codec::Deflate::Decompress.new(delegate)
21
- c.close
22
- end
23
-
24
- it "optionally leaves the delegate stream open" do
25
- delegate = MiniTest::Mock.new
26
- delegate.expect(:close, nil)
27
- c = Archive::Zip::Codec::Deflate::Decompress.new(delegate)
28
- c.close(true)
29
-
30
- delegate = MiniTest::Mock.new
31
- c = Archive::Zip::Codec::Deflate::Decompress.new(delegate)
32
- c.close(false)
33
- end
34
- 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/zip/codec/deflate'
8
-
9
- describe "Archive::Zip::Deflate::Decompress#crc32" do
10
- it "computes a CRC32 checksum" do
11
- closed_decompressor = DeflateSpecs.compressed_data do |f|
12
- Archive::Zip::Codec::Deflate::Decompress.open(f) do |decompressor|
13
- decompressor.read
14
- decompressor.crc32.must_equal(Zlib.crc32(DeflateSpecs.test_data))
15
- decompressor
16
- end
17
- end
18
- closed_decompressor.crc32.must_equal(Zlib.crc32(DeflateSpecs.test_data))
19
- end
20
- end
@@ -1,74 +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/deflate'
8
-
9
- describe "Archive::Zip::Codec::Deflate::Decompress#data_descriptor" do
10
- it "is an instance of Archive::Zip::DataDescriptor" do
11
- DeflateSpecs.compressed_data do |cd|
12
- closed_decompressor = Archive::Zip::Codec::Deflate::Decompress.open(
13
- cd
14
- ) do |decompressor|
15
- decompressor.read
16
- decompressor.data_descriptor.must_be_instance_of(
17
- Archive::Zip::DataDescriptor
18
- )
19
- decompressor
20
- end
21
- closed_decompressor.data_descriptor.must_be_instance_of(
22
- Archive::Zip::DataDescriptor
23
- )
24
- end
25
- end
26
-
27
- it "has a crc32 attribute containing the CRC32 checksum" do
28
- crc32 = Zlib.crc32(DeflateSpecs.test_data)
29
- DeflateSpecs.compressed_data do |cd|
30
- closed_decompressor = Archive::Zip::Codec::Deflate::Decompress.open(
31
- cd
32
- ) do |decompressor|
33
- decompressor.read
34
- decompressor.data_descriptor.crc32.must_equal(crc32)
35
- decompressor
36
- end
37
- closed_decompressor.data_descriptor.crc32.must_equal(crc32)
38
- end
39
- end
40
-
41
- it "has a compressed_size attribute containing the size of the compressed data" do
42
- compressed_size = DeflateSpecs.compressed_data.size
43
- DeflateSpecs.compressed_data do |cd|
44
- closed_decompressor = Archive::Zip::Codec::Deflate::Decompress.open(
45
- cd
46
- ) do |decompressor|
47
- decompressor.read
48
- decompressor.data_descriptor.compressed_size.must_equal(compressed_size)
49
- decompressor
50
- end
51
- closed_decompressor.data_descriptor.compressed_size.must_equal(
52
- compressed_size
53
- )
54
- end
55
- end
56
-
57
- it "has an uncompressed_size attribute containing the size of the input data" do
58
- uncompressed_size = DeflateSpecs.test_data.size
59
- DeflateSpecs.compressed_data do |cd|
60
- closed_decompressor = Archive::Zip::Codec::Deflate::Decompress.open(
61
- cd
62
- ) do |decompressor|
63
- decompressor.read
64
- decompressor.data_descriptor.uncompressed_size.must_equal(
65
- uncompressed_size
66
- )
67
- decompressor
68
- end
69
- closed_decompressor.data_descriptor.uncompressed_size.must_equal(
70
- uncompressed_size
71
- )
72
- end
73
- end
74
- 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/zip/codec/deflate'
8
- require 'archive/support/binary_stringio'
9
-
10
- describe "Archive::Zip::Codec::Deflate::Decompress.new" do
11
- it "returns a new instance" do
12
- d = Archive::Zip::Codec::Deflate::Decompress.new(BinaryStringIO.new)
13
- d.must_be_instance_of(Archive::Zip::Codec::Deflate::Decompress)
14
- d.close
15
- end
16
- end
@@ -1,29 +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/deflate'
8
- require 'archive/support/binary_stringio'
9
-
10
- describe "Archive::Zip::Codec::Deflate::Decompress.open" do
11
- it "returns a new instance when run without a block" do
12
- d = Archive::Zip::Codec::Deflate::Decompress.open(BinaryStringIO.new)
13
- d.must_be_instance_of(Archive::Zip::Codec::Deflate::Decompress)
14
- d.close
15
- end
16
-
17
- it "executes a block with a new instance as an argument" do
18
- Archive::Zip::Codec::Deflate::Decompress.open(BinaryStringIO.new) do |decompressor|
19
- decompressor.must_be_instance_of(Archive::Zip::Codec::Deflate::Decompress)
20
- end
21
- end
22
-
23
- it "closes the object after executing a block" do
24
- d = Archive::Zip::Codec::Deflate::Decompress.open(BinaryStringIO.new) do |decompressor|
25
- decompressor
26
- end
27
- d.closed?.must_equal(true)
28
- end
29
- end
@@ -1,25 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- class DeflateSpecs
4
- def self.compressed_data_nocomp(&b)
5
- File.open(
6
- File.join(File.dirname(__FILE__), 'compressed_file_nocomp.bin'), 'rb'
7
- ) do |f|
8
- f.read
9
- end
10
- end
11
-
12
- def self.compressed_data
13
- File.open(
14
- File.join(File.dirname(__FILE__), 'compressed_file.bin'), 'rb'
15
- ) do |f|
16
- block_given? ? yield(f) : f.read
17
- end
18
- end
19
-
20
- def self.test_data
21
- File.open(File.join(File.dirname(__FILE__), 'raw_file.txt'), 'rb') do |f|
22
- block_given? ? yield(f) : f.read
23
- end
24
- end
25
- end
@@ -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,34 +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/null_encryption'
8
- require 'archive/support/binary_stringio'
9
-
10
- describe "Archive::Zip::Codec::NullEncryption::Decrypt#close" do
11
- it "closes the stream" do
12
- d = Archive::Zip::Codec::NullEncryption::Decrypt.new(BinaryStringIO.new)
13
- d.close
14
- d.closed?.must_equal(true)
15
- end
16
-
17
- it "closes the delegate stream by default" do
18
- delegate = MiniTest::Mock.new
19
- delegate.expect(:close, nil)
20
- d = Archive::Zip::Codec::NullEncryption::Decrypt.new(delegate)
21
- d.close
22
- end
23
-
24
- it "optionally leaves the delegate stream open" do
25
- delegate = MiniTest::Mock.new
26
- delegate.expect(:close, nil)
27
- d = Archive::Zip::Codec::NullEncryption::Decrypt.new(delegate)
28
- d.close(true)
29
-
30
- delegate = MiniTest::Mock.new
31
- d = Archive::Zip::Codec::NullEncryption::Decrypt.new(delegate)
32
- d.close(false)
33
- end
34
- 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/zip/codec/null_encryption'
8
- require 'archive/support/binary_stringio'
9
-
10
- describe "Archive::Zip::Codec::NullEncryption::Decrypt.new" do
11
- it "returns a new instance" do
12
- d = Archive::Zip::Codec::NullEncryption::Decrypt.new(BinaryStringIO.new)
13
- d.must_be_instance_of(Archive::Zip::Codec::NullEncryption::Decrypt)
14
- d.close
15
- end
16
- end
@@ -1,29 +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/null_encryption'
8
- require 'archive/support/binary_stringio'
9
-
10
- describe "Archive::Zip::Codec::NullEncryption::Decrypt.open" do
11
- it "returns a new instance when run without a block" do
12
- d = Archive::Zip::Codec::NullEncryption::Decrypt.open(BinaryStringIO.new)
13
- d.must_be_instance_of(Archive::Zip::Codec::NullEncryption::Decrypt)
14
- d.close
15
- end
16
-
17
- it "executes a block with a new instance as an argument" do
18
- Archive::Zip::Codec::NullEncryption::Decrypt.open(BinaryStringIO.new) do |decryptor|
19
- decryptor.must_be_instance_of(Archive::Zip::Codec::NullEncryption::Decrypt)
20
- end
21
- end
22
-
23
- it "closes the object after executing a block" do
24
- d = Archive::Zip::Codec::NullEncryption::Decrypt.open(BinaryStringIO.new) do |decryptor|
25
- decryptor
26
- end
27
- d.closed?.must_equal(true)
28
- end
29
- end
@@ -1,26 +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/null_encryption'
8
-
9
- describe "Archive::Zip::Codec::NullEncryption::Decrypt#read" do
10
- it "calls the read method of the delegate" do
11
- delegate = MiniTest::Mock.new
12
- delegate.expect(:read, nil, [Integer])
13
- delegate.expect(:close, nil)
14
- Archive::Zip::Codec::NullEncryption::Decrypt.open(delegate) do |d|
15
- d.read
16
- end
17
- end
18
-
19
- it "passes data through unmodified" do
20
- NullEncryptionSpecs.encrypted_data do |ed|
21
- Archive::Zip::Codec::NullEncryption::Decrypt.open(ed) do |d|
22
- d.read.must_equal(NullEncryptionSpecs.test_data)
23
- end
24
- end
25
- end
26
- end
@@ -1,27 +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/null_encryption'
8
-
9
- describe "Archive::Zip::Codec::NullEncryption::Decrypt#rewind" do
10
- it "can rewind the stream when the delegate responds to rewind" do
11
- NullEncryptionSpecs.encrypted_data do |ed|
12
- Archive::Zip::Codec::NullEncryption::Decrypt.open(ed) do |d|
13
- d.read(4)
14
- d.rewind
15
- d.read.must_equal(NullEncryptionSpecs.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
- delegate = MiniTest::Mock.new
22
- delegate.expect(:close, nil)
23
- Archive::Zip::Codec::NullEncryption::Decrypt.open(delegate) do |d|
24
- lambda { d.rewind }.must_raise(Errno::EINVAL)
25
- end
26
- end
27
- end
@@ -1,59 +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/null_encryption'
8
-
9
- describe "Archive::Zip::Codec::NullEncryption::Decrypt#seek" do
10
- it "can seek to the beginning of the stream when the delegate responds to rewind" do
11
- NullEncryptionSpecs.encrypted_data do |ed|
12
- Archive::Zip::Codec::NullEncryption::Decrypt.open(ed) do |d|
13
- d.read(4)
14
- d.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
- delegate = MiniTest::Mock.new
21
- delegate.expect(:close, nil)
22
- Archive::Zip::Codec::NullEncryption::Decrypt.open(delegate) do |d|
23
- lambda { d.seek(0) }.must_raise(Errno::EINVAL)
24
- end
25
- end
26
-
27
- it "raises Errno::EINVAL when seeking forward or backward from the current position of the stream" do
28
- NullEncryptionSpecs.encrypted_data do |ed|
29
- Archive::Zip::Codec::NullEncryption::Decrypt.open(ed) do |d|
30
- # Disable read buffering to avoid some seeking optimizations implemented
31
- # by IO::Like which allow seeking forward within the buffer.
32
- d.fill_size = 0
33
-
34
- d.read(4)
35
- lambda { d.seek(1, IO::SEEK_CUR) }.must_raise(Errno::EINVAL)
36
- lambda { d.seek(-1, IO::SEEK_CUR) }.must_raise(Errno::EINVAL)
37
- end
38
- end
39
- end
40
-
41
- it "raises Errno::EINVAL when seeking a non-zero offset relative to the beginning of the stream" do
42
- NullEncryptionSpecs.encrypted_data do |ed|
43
- Archive::Zip::Codec::NullEncryption::Decrypt.open(ed) do |d|
44
- lambda { d.seek(-1, IO::SEEK_SET) }.must_raise(Errno::EINVAL)
45
- lambda { d.seek(1, IO::SEEK_SET) }.must_raise(Errno::EINVAL)
46
- end
47
- end
48
- end
49
-
50
- it "raises Errno::EINVAL when seeking relative to the end of the stream" do
51
- NullEncryptionSpecs.encrypted_data do |ed|
52
- Archive::Zip::Codec::NullEncryption::Decrypt.open(ed) do |d|
53
- lambda { d.seek(0, IO::SEEK_END) }.must_raise(Errno::EINVAL)
54
- lambda { d.seek(-1, IO::SEEK_END) }.must_raise(Errno::EINVAL)
55
- lambda { d.seek(1, IO::SEEK_END) }.must_raise(Errno::EINVAL)
56
- end
57
- end
58
- end
59
- end
@@ -1,23 +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/null_encryption'
8
-
9
- describe "Archive::Zip::Codec::NullEncryption::Decrypt#tell" do
10
- it "returns the current position of the stream" do
11
- NullEncryptionSpecs.encrypted_data do |ed|
12
- Archive::Zip::Codec::NullEncryption::Decrypt.open(ed) do |d|
13
- d.tell.must_equal(0)
14
- d.read(4)
15
- d.tell.must_equal(4)
16
- d.read
17
- d.tell.must_equal(235)
18
- d.rewind
19
- d.tell.must_equal(0)
20
- end
21
- end
22
- end
23
- end
@@ -1,34 +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/null_encryption'
8
- require 'archive/support/binary_stringio'
9
-
10
- describe "Archive::Zip::Codec::NullEncryption::Encrypt#close" do
11
- it "closes the stream" do
12
- e = Archive::Zip::Codec::NullEncryption::Encrypt.new(BinaryStringIO.new)
13
- e.close
14
- e.closed?.must_equal(true)
15
- end
16
-
17
- it "closes the delegate stream by default" do
18
- delegate = MiniTest::Mock.new
19
- delegate.expect(:close, nil)
20
- e = Archive::Zip::Codec::NullEncryption::Encrypt.new(delegate)
21
- e.close
22
- end
23
-
24
- it "optionally leaves the delegate stream open" do
25
- delegate = MiniTest::Mock.new
26
- delegate.expect(:close, nil)
27
- e = Archive::Zip::Codec::NullEncryption::Encrypt.new(delegate)
28
- e.close(true)
29
-
30
- delegate = MiniTest::Mock.new
31
- e = Archive::Zip::Codec::NullEncryption::Encrypt.new(delegate)
32
- e.close(false)
33
- end
34
- 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/zip/codec/null_encryption'
8
- require 'archive/support/binary_stringio'
9
-
10
- describe "Archive::Zip::Codec::NullEncryption::Encrypt.new" do
11
- it "returns a new instance" do
12
- e = Archive::Zip::Codec::NullEncryption::Encrypt.new(BinaryStringIO.new)
13
- e.must_be_instance_of(Archive::Zip::Codec::NullEncryption::Encrypt)
14
- e.close
15
- end
16
- end
@@ -1,31 +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/null_encryption'
8
- require 'archive/support/binary_stringio'
9
-
10
- describe "Archive::Zip::Codec::NullEncryption::Encrypt.open" do
11
- it "returns a new instance when run without a block" do
12
- e = Archive::Zip::Codec::NullEncryption::Encrypt.open(BinaryStringIO.new)
13
- e.must_be_instance_of(Archive::Zip::Codec::NullEncryption::Encrypt)
14
- e.close
15
- end
16
-
17
- it "executes a block with a new instance as an argument" do
18
- Archive::Zip::Codec::NullEncryption::Encrypt.open(BinaryStringIO.new) do |encryptor|
19
- encryptor.must_be_instance_of(
20
- Archive::Zip::Codec::NullEncryption::Encrypt
21
- )
22
- end
23
- end
24
-
25
- it "closes the object after executing a block" do
26
- e = Archive::Zip::Codec::NullEncryption::Encrypt.open(BinaryStringIO.new) do |encryptor|
27
- encryptor
28
- end
29
- e.closed?.must_equal(true)
30
- end
31
- end
@@ -1,28 +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/null_encryption'
8
- require 'archive/support/binary_stringio'
9
-
10
- describe "Archive::Zip::Codec::NullEncryption::Encrypt#rewind" do
11
- it "can rewind the stream when the delegate responds to rewind" do
12
- encrypted_data = BinaryStringIO.new
13
- Archive::Zip::Codec::NullEncryption::Encrypt.open(encrypted_data) do |e|
14
- e.write('test')
15
- e.rewind
16
- e.write(NullEncryptionSpecs.test_data)
17
- end
18
- encrypted_data.string.must_equal(NullEncryptionSpecs.encrypted_data)
19
- end
20
-
21
- it "raises Errno::EINVAL when attempting to rewind the stream when the delegate does not respond to rewind" do
22
- delegate = MiniTest::Mock.new
23
- delegate.expect(:close, nil)
24
- Archive::Zip::Codec::NullEncryption::Encrypt.open(delegate) do |e|
25
- lambda { e.rewind }.must_raise(Errno::EINVAL)
26
- end
27
- end
28
- end
@@ -1,52 +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/null_encryption'
8
- require 'archive/support/binary_stringio'
9
-
10
- describe "Archive::Zip::Codec::NullEncryption::Encrypt#seek" do
11
- it "can seek to the beginning of the stream when the delegate responds to rewind" do
12
- encrypted_data = BinaryStringIO.new
13
- Archive::Zip::Codec::NullEncryption::Encrypt.open(encrypted_data) do |e|
14
- e.write('test')
15
- e.seek(0).must_equal(0)
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
- delegate = MiniTest::Mock.new
21
- delegate.expect(:close, nil)
22
- Archive::Zip::Codec::NullEncryption::Encrypt.open(delegate) do |e|
23
- lambda { e.seek(0) }.must_raise(Errno::EINVAL)
24
- end
25
- end
26
-
27
- it "raises Errno::EINVAL when seeking forward or backward from the current position of the stream" do
28
- encrypted_data = BinaryStringIO.new
29
- Archive::Zip::Codec::NullEncryption::Encrypt.open(encrypted_data) do |e|
30
- e.write('test')
31
- lambda { e.seek(1, IO::SEEK_CUR) }.must_raise(Errno::EINVAL)
32
- lambda { e.seek(-1, IO::SEEK_CUR) }.must_raise(Errno::EINVAL)
33
- end
34
- end
35
-
36
- it "raises Errno::EINVAL when seeking a non-zero offset relative to the beginning of the stream" do
37
- encrypted_data = BinaryStringIO.new
38
- Archive::Zip::Codec::NullEncryption::Encrypt.open(encrypted_data) do |e|
39
- lambda { e.seek(-1, IO::SEEK_SET) }.must_raise(Errno::EINVAL)
40
- lambda { e.seek(1, IO::SEEK_SET) }.must_raise(Errno::EINVAL)
41
- end
42
- end
43
-
44
- it "raises Errno::EINVAL when seeking relative to the end of the stream" do
45
- encrypted_data = BinaryStringIO.new
46
- Archive::Zip::Codec::NullEncryption::Encrypt.open(encrypted_data) do |e|
47
- lambda { e.seek(0, IO::SEEK_END) }.must_raise(Errno::EINVAL)
48
- lambda { e.seek(-1, IO::SEEK_END) }.must_raise(Errno::EINVAL)
49
- lambda { e.seek(1, IO::SEEK_END) }.must_raise(Errno::EINVAL)
50
- end
51
- end
52
- end
@@ -1,31 +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/null_encryption'
8
- require 'archive/support/binary_stringio'
9
-
10
- describe "Archive::Zip::Codec::NullEncryption::Encrypt#tell" do
11
- it "returns the current position of the stream" do
12
- sio = BinaryStringIO.new
13
- Archive::Zip::Codec::NullEncryption::Encrypt.open(sio) do |e|
14
- e.tell.must_equal(0)
15
- e.write('test1')
16
- e.tell.must_equal(5)
17
- e.write('test2')
18
- e.tell.must_equal(10)
19
- e.rewind
20
- e.tell.must_equal(0)
21
- end
22
- end
23
-
24
- it "raises IOError on closed stream" do
25
- delegate = MiniTest::Mock.new
26
- delegate.expect(:close, nil)
27
- lambda do
28
- Archive::Zip::Codec::NullEncryption::Encrypt.open(delegate) { |e| e }.tell
29
- end.must_raise(IOError)
30
- end
31
- end