archive-zip 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (132) hide show
  1. data/HACKING +25 -42
  2. data/NEWS +25 -0
  3. data/README +2 -2
  4. data/Rakefile +202 -0
  5. data/TODO +5 -0
  6. data/default.mspec +8 -0
  7. data/lib/archive/support/binary_stringio.rb +23 -0
  8. data/lib/archive/support/integer.rb +13 -0
  9. data/lib/archive/support/io-like.rb +3 -1
  10. data/lib/archive/support/ioextensions.rb +16 -0
  11. data/lib/archive/support/iowindow.rb +10 -18
  12. data/lib/archive/support/time.rb +2 -0
  13. data/lib/archive/support/zlib.rb +298 -71
  14. data/lib/archive/zip.rb +161 -139
  15. data/lib/archive/zip/codec.rb +2 -0
  16. data/lib/archive/zip/codec/deflate.rb +59 -11
  17. data/lib/archive/zip/codec/null_encryption.rb +75 -14
  18. data/lib/archive/zip/codec/store.rb +75 -26
  19. data/lib/archive/zip/codec/traditional_encryption.rb +146 -35
  20. data/lib/archive/zip/data_descriptor.rb +6 -4
  21. data/lib/archive/zip/entry.rb +184 -132
  22. data/lib/archive/zip/error.rb +2 -0
  23. data/lib/archive/zip/extra_field.rb +20 -6
  24. data/lib/archive/zip/extra_field/extended_timestamp.rb +141 -60
  25. data/lib/archive/zip/extra_field/raw.rb +70 -12
  26. data/lib/archive/zip/extra_field/unix.rb +58 -16
  27. data/lib/archive/zip/version.rb +6 -0
  28. data/spec/archive/zip/codec/deflate/compress/checksum_spec.rb +42 -0
  29. data/spec/archive/zip/codec/deflate/compress/close_spec.rb +44 -0
  30. data/spec/archive/zip/codec/deflate/compress/crc32_spec.rb +21 -0
  31. data/spec/archive/zip/codec/deflate/compress/data_descriptor_spec.rb +67 -0
  32. data/spec/archive/zip/codec/deflate/compress/new_spec.rb +37 -0
  33. data/spec/archive/zip/codec/deflate/compress/open_spec.rb +46 -0
  34. data/spec/archive/zip/codec/deflate/compress/write_spec.rb +109 -0
  35. data/spec/archive/zip/codec/deflate/decompress/checksum_spec.rb +18 -0
  36. data/spec/archive/zip/codec/deflate/decompress/close_spec.rb +33 -0
  37. data/spec/archive/zip/codec/deflate/decompress/crc32_spec.rb +18 -0
  38. data/spec/archive/zip/codec/deflate/decompress/data_descriptor_spec.rb +67 -0
  39. data/spec/archive/zip/codec/deflate/decompress/new_spec.rb +14 -0
  40. data/spec/archive/zip/codec/deflate/decompress/open_spec.rb +27 -0
  41. data/spec/archive/zip/codec/deflate/fixtures/classes.rb +25 -0
  42. data/spec/archive/zip/codec/deflate/fixtures/compressed_file.bin +1 -0
  43. data/spec/archive/zip/codec/deflate/fixtures/compressed_file_nocomp.bin +0 -0
  44. data/spec/archive/zip/codec/deflate/fixtures/raw_file.txt +10 -0
  45. data/spec/archive/zip/codec/null_encryption/decrypt/close_spec.rb +33 -0
  46. data/spec/archive/zip/codec/null_encryption/decrypt/new_spec.rb +14 -0
  47. data/spec/archive/zip/codec/null_encryption/decrypt/open_spec.rb +27 -0
  48. data/spec/archive/zip/codec/null_encryption/decrypt/read_spec.rb +24 -0
  49. data/spec/archive/zip/codec/null_encryption/decrypt/rewind_spec.rb +25 -0
  50. data/spec/archive/zip/codec/null_encryption/decrypt/seek_spec.rb +57 -0
  51. data/spec/archive/zip/codec/null_encryption/decrypt/tell_spec.rb +21 -0
  52. data/spec/archive/zip/codec/null_encryption/encrypt/close_spec.rb +33 -0
  53. data/spec/archive/zip/codec/null_encryption/encrypt/new_spec.rb +14 -0
  54. data/spec/archive/zip/codec/null_encryption/encrypt/open_spec.rb +27 -0
  55. data/spec/archive/zip/codec/null_encryption/encrypt/rewind_spec.rb +26 -0
  56. data/spec/archive/zip/codec/null_encryption/encrypt/seek_spec.rb +50 -0
  57. data/spec/archive/zip/codec/null_encryption/encrypt/tell_spec.rb +29 -0
  58. data/spec/archive/zip/codec/null_encryption/encrypt/write_spec.rb +29 -0
  59. data/spec/archive/zip/codec/null_encryption/fixtures/classes.rb +12 -0
  60. data/spec/archive/zip/codec/null_encryption/fixtures/raw_file.txt +10 -0
  61. data/spec/archive/zip/codec/store/compress/close_spec.rb +33 -0
  62. data/spec/archive/zip/codec/store/compress/data_descriptor_spec.rb +68 -0
  63. data/spec/archive/zip/codec/store/compress/new_spec.rb +14 -0
  64. data/spec/archive/zip/codec/store/compress/open_spec.rb +27 -0
  65. data/spec/archive/zip/codec/store/compress/rewind_spec.rb +26 -0
  66. data/spec/archive/zip/codec/store/compress/seek_spec.rb +50 -0
  67. data/spec/archive/zip/codec/store/compress/tell_spec.rb +29 -0
  68. data/spec/archive/zip/codec/store/compress/write_spec.rb +29 -0
  69. data/spec/archive/zip/codec/store/decompress/close_spec.rb +33 -0
  70. data/spec/archive/zip/codec/store/decompress/data_descriptor_spec.rb +68 -0
  71. data/spec/archive/zip/codec/store/decompress/new_spec.rb +14 -0
  72. data/spec/archive/zip/codec/store/decompress/open_spec.rb +27 -0
  73. data/spec/archive/zip/codec/store/decompress/read_spec.rb +24 -0
  74. data/spec/archive/zip/codec/store/decompress/rewind_spec.rb +25 -0
  75. data/spec/archive/zip/codec/store/decompress/seek_spec.rb +57 -0
  76. data/spec/archive/zip/codec/store/decompress/tell_spec.rb +21 -0
  77. data/spec/archive/zip/codec/store/fixtures/classes.rb +12 -0
  78. data/spec/archive/zip/codec/store/fixtures/raw_file.txt +10 -0
  79. data/spec/archive/zip/codec/traditional_encryption/decrypt/close_spec.rb +64 -0
  80. data/spec/archive/zip/codec/traditional_encryption/decrypt/new_spec.rb +18 -0
  81. data/spec/archive/zip/codec/traditional_encryption/decrypt/open_spec.rb +39 -0
  82. data/spec/archive/zip/codec/traditional_encryption/decrypt/read_spec.rb +126 -0
  83. data/spec/archive/zip/codec/traditional_encryption/decrypt/rewind_spec.rb +38 -0
  84. data/spec/archive/zip/codec/traditional_encryption/decrypt/seek_spec.rb +82 -0
  85. data/spec/archive/zip/codec/traditional_encryption/decrypt/tell_spec.rb +25 -0
  86. data/spec/archive/zip/codec/traditional_encryption/encrypt/close_spec.rb +64 -0
  87. data/spec/archive/zip/codec/traditional_encryption/encrypt/new_spec.rb +18 -0
  88. data/spec/archive/zip/codec/traditional_encryption/encrypt/open_spec.rb +39 -0
  89. data/spec/archive/zip/codec/traditional_encryption/encrypt/rewind_spec.rb +41 -0
  90. data/spec/archive/zip/codec/traditional_encryption/encrypt/seek_spec.rb +75 -0
  91. data/spec/archive/zip/codec/traditional_encryption/encrypt/tell_spec.rb +42 -0
  92. data/spec/archive/zip/codec/traditional_encryption/encrypt/write_spec.rb +127 -0
  93. data/spec/archive/zip/codec/traditional_encryption/fixtures/classes.rb +27 -0
  94. data/spec/archive/zip/codec/traditional_encryption/fixtures/encrypted_file.bin +0 -0
  95. data/spec/archive/zip/codec/traditional_encryption/fixtures/raw_file.txt +10 -0
  96. data/spec/binary_stringio/new_spec.rb +34 -0
  97. data/spec/binary_stringio/set_encoding_spec.rb +14 -0
  98. data/spec/ioextensions/read_exactly_spec.rb +50 -0
  99. data/spec/zlib/fixtures/classes.rb +65 -0
  100. data/spec/zlib/fixtures/compressed_file.bin +1 -0
  101. data/spec/zlib/fixtures/compressed_file_gzip.bin +0 -0
  102. data/spec/zlib/fixtures/compressed_file_huffman.bin +2 -0
  103. data/spec/zlib/fixtures/compressed_file_minmem.bin +0 -0
  104. data/spec/zlib/fixtures/compressed_file_minwin.bin +1 -0
  105. data/spec/zlib/fixtures/compressed_file_nocomp.bin +0 -0
  106. data/spec/zlib/fixtures/compressed_file_raw.bin +1 -0
  107. data/spec/zlib/fixtures/raw_file.txt +10 -0
  108. data/spec/zlib/zreader/checksum_spec.rb +40 -0
  109. data/spec/zlib/zreader/close_spec.rb +14 -0
  110. data/spec/zlib/zreader/compressed_size_spec.rb +18 -0
  111. data/spec/zlib/zreader/new_spec.rb +41 -0
  112. data/spec/zlib/zreader/open_spec.rb +49 -0
  113. data/spec/zlib/zreader/read_spec.rb +47 -0
  114. data/spec/zlib/zreader/rewind_spec.rb +23 -0
  115. data/spec/zlib/zreader/seek_spec.rb +55 -0
  116. data/spec/zlib/zreader/tell_spec.rb +21 -0
  117. data/spec/zlib/zreader/uncompressed_size_spec.rb +18 -0
  118. data/spec/zlib/zwriter/checksum_spec.rb +41 -0
  119. data/spec/zlib/zwriter/close_spec.rb +14 -0
  120. data/spec/zlib/zwriter/compressed_size_spec.rb +19 -0
  121. data/spec/zlib/zwriter/new_spec.rb +64 -0
  122. data/spec/zlib/zwriter/open_spec.rb +68 -0
  123. data/spec/zlib/zwriter/rewind_spec.rb +26 -0
  124. data/spec/zlib/zwriter/seek_spec.rb +54 -0
  125. data/spec/zlib/zwriter/tell_spec.rb +29 -0
  126. data/spec/zlib/zwriter/uncompressed_size_spec.rb +19 -0
  127. data/spec/zlib/zwriter/write_spec.rb +28 -0
  128. data/spec_helper.rb +49 -0
  129. metadata +296 -74
  130. data/MANIFEST +0 -27
  131. data/lib/archive/support/io.rb +0 -14
  132. data/lib/archive/support/stringio.rb +0 -22
@@ -0,0 +1,6 @@
1
+ # encoding: UTF-8
2
+
3
+ module Archive; class Zip
4
+ # The current version of this gem.
5
+ VERSION = "0.4.0"
6
+ end; end
@@ -0,0 +1,42 @@
1
+ # encoding: UTF-8
2
+
3
+ require File.dirname(__FILE__) + '/../../../../../../spec_helper'
4
+ require File.dirname(__FILE__) + '/../fixtures/classes'
5
+ require 'archive/zip/codec/deflate'
6
+ require 'archive/support/binary_stringio'
7
+
8
+ describe "Archive::Zip::Codec::Deflate::Compress#checksum" do
9
+ it "computes the CRC32 checksum" do
10
+ compressed_data = BinaryStringIO.new
11
+ closed_compressor = Archive::Zip::Codec::Deflate::Compress.open(
12
+ compressed_data, Zlib::DEFAULT_COMPRESSION
13
+ ) do |compressor|
14
+ compressor.write(DeflateSpecs.test_data)
15
+ compressor.flush
16
+ compressor.checksum.should == Zlib.crc32(DeflateSpecs.test_data)
17
+ compressor
18
+ end
19
+ closed_compressor.checksum.should == Zlib.crc32(DeflateSpecs.test_data)
20
+ end
21
+
22
+ it "computes the CRC32 checksum even when the delegate performs partial writes" do
23
+ compressed_data = BinaryStringIO.new
24
+ # Override compressed_data.write to perform writes 1 byte at a time.
25
+ class << compressed_data
26
+ alias :write_orig :write
27
+ def write(buffer)
28
+ write_orig(buffer.slice(0, 1))
29
+ end
30
+ end
31
+
32
+ closed_compressor = Archive::Zip::Codec::Deflate::Compress.open(
33
+ compressed_data, Zlib::DEFAULT_COMPRESSION
34
+ ) do |compressor|
35
+ compressor.write(DeflateSpecs.test_data)
36
+ compressor.flush
37
+ compressor.checksum.should == Zlib.crc32(DeflateSpecs.test_data)
38
+ compressor
39
+ end
40
+ closed_compressor.checksum.should == Zlib.crc32(DeflateSpecs.test_data)
41
+ end
42
+ end
@@ -0,0 +1,44 @@
1
+ # encoding: UTF-8
2
+
3
+ require File.dirname(__FILE__) + '/../../../../../../spec_helper'
4
+ require File.dirname(__FILE__) + '/../fixtures/classes'
5
+ require 'archive/zip/codec/deflate'
6
+ require 'archive/support/binary_stringio'
7
+
8
+ describe "Archive::Zip::Codec::Deflate::Compress#close" do
9
+ it "closes the stream" do
10
+ c = Archive::Zip::Codec::Deflate::Compress.new(
11
+ BinaryStringIO.new, Zlib::DEFAULT_COMPRESSION
12
+ )
13
+ c.close
14
+ c.closed?.should be_true
15
+ end
16
+
17
+ it "closes the delegate stream by default" do
18
+ delegate = mock('delegate')
19
+ delegate.should_receive(:close).and_return(nil)
20
+ delegate.should_receive(:write).at_least(:once).and_return(1)
21
+ c = Archive::Zip::Codec::Deflate::Compress.new(
22
+ delegate, Zlib::DEFAULT_COMPRESSION
23
+ )
24
+ c.close
25
+ end
26
+
27
+ it "optionally leaves the delegate stream open" do
28
+ delegate = mock('delegate')
29
+ delegate.should_receive(:close).and_return(nil)
30
+ delegate.should_receive(:write).at_least(:once).and_return(1)
31
+ c = Archive::Zip::Codec::Deflate::Compress.new(
32
+ delegate, Zlib::DEFAULT_COMPRESSION
33
+ )
34
+ c.close(true)
35
+
36
+ delegate = mock('delegate')
37
+ delegate.should_not_receive(:close)
38
+ delegate.should_receive(:write).at_least(:once).and_return(1)
39
+ c = Archive::Zip::Codec::Deflate::Compress.new(
40
+ delegate, Zlib::DEFAULT_COMPRESSION
41
+ )
42
+ c.close(false)
43
+ end
44
+ end
@@ -0,0 +1,21 @@
1
+ # encoding: UTF-8
2
+
3
+ require File.dirname(__FILE__) + '/../../../../../../spec_helper'
4
+ require File.dirname(__FILE__) + '/../fixtures/classes'
5
+ require 'archive/zip/codec/deflate'
6
+ require 'archive/support/binary_stringio'
7
+
8
+ describe "Archive::Zip::Codec::Deflate::Compress#crc32" do
9
+ it "computes the CRC32 checksum" do
10
+ compressed_data = BinaryStringIO.new
11
+ closed_compressor = Archive::Zip::Codec::Deflate::Compress.open(
12
+ compressed_data, Zlib::DEFAULT_COMPRESSION
13
+ ) do |compressor|
14
+ compressor.write(DeflateSpecs.test_data)
15
+ compressor.flush
16
+ compressor.crc32.should == Zlib.crc32(DeflateSpecs.test_data)
17
+ compressor
18
+ end
19
+ closed_compressor.crc32.should == Zlib.crc32(DeflateSpecs.test_data)
20
+ end
21
+ end
@@ -0,0 +1,67 @@
1
+ # encoding: UTF-8
2
+
3
+ require File.dirname(__FILE__) + '/../../../../../../spec_helper'
4
+ require File.dirname(__FILE__) + '/../fixtures/classes'
5
+ require 'archive/zip/codec/deflate'
6
+ require 'archive/support/binary_stringio'
7
+
8
+ describe "Archive::Zip::Codec::Deflate::Compress#data_descriptor" do
9
+ it "is an instance of Archive::Zip::DataDescriptor" do
10
+ test_data = DeflateSpecs.test_data
11
+ compressed_data = BinaryStringIO.new
12
+ closed_compressor = Archive::Zip::Codec::Deflate::Compress.open(
13
+ compressed_data, Zlib::DEFAULT_COMPRESSION
14
+ ) do |compressor|
15
+ compressor.write(test_data)
16
+ compressor.flush
17
+ compressor.data_descriptor.class.should == Archive::Zip::DataDescriptor
18
+ compressor
19
+ end
20
+ closed_compressor.data_descriptor.class.should ==
21
+ Archive::Zip::DataDescriptor
22
+ end
23
+
24
+ it "has a crc32 attribute containing the CRC32 checksum" do
25
+ test_data = DeflateSpecs.test_data
26
+ compressed_data = BinaryStringIO.new
27
+ closed_compressor = Archive::Zip::Codec::Deflate::Compress.open(
28
+ compressed_data, Zlib::DEFAULT_COMPRESSION
29
+ ) do |compressor|
30
+ compressor.write(test_data)
31
+ compressor.flush
32
+ compressor.data_descriptor.crc32.should == Zlib.crc32(test_data)
33
+ compressor
34
+ end
35
+ closed_compressor.data_descriptor.crc32.should == Zlib.crc32(test_data)
36
+ end
37
+
38
+ it "has a compressed_size attribute containing the size of the compressed data" do
39
+ test_data = DeflateSpecs.test_data
40
+ compressed_data = BinaryStringIO.new
41
+ closed_compressor = Archive::Zip::Codec::Deflate::Compress.open(
42
+ compressed_data, Zlib::DEFAULT_COMPRESSION
43
+ ) do |compressor|
44
+ compressor.write(test_data)
45
+ compressor.flush
46
+ compressor.data_descriptor.compressed_size.should ==
47
+ compressed_data.size
48
+ compressor
49
+ end
50
+ closed_compressor.data_descriptor.compressed_size.should ==
51
+ compressed_data.size
52
+ end
53
+
54
+ it "has an uncompressed_size attribute containing the size of the input data" do
55
+ test_data = DeflateSpecs.test_data
56
+ compressed_data = BinaryStringIO.new
57
+ closed_compressor = Archive::Zip::Codec::Deflate::Compress.open(
58
+ compressed_data, Zlib::DEFAULT_COMPRESSION
59
+ ) do |compressor|
60
+ compressor.write(test_data)
61
+ compressor.flush
62
+ compressor.data_descriptor.uncompressed_size.should == test_data.size
63
+ compressor
64
+ end
65
+ closed_compressor.data_descriptor.uncompressed_size.should == test_data.size
66
+ end
67
+ end
@@ -0,0 +1,37 @@
1
+ # encoding: UTF-8
2
+
3
+ require File.dirname(__FILE__) + '/../../../../../../spec_helper'
4
+ require File.dirname(__FILE__) + '/../fixtures/classes'
5
+ require 'archive/zip/codec/deflate'
6
+ require 'archive/support/binary_stringio'
7
+
8
+ describe "Archive::Zip::Codec::Deflate::Compress.new" do
9
+ it "returns a new instance" do
10
+ c = Archive::Zip::Codec::Deflate::Compress.new(
11
+ BinaryStringIO.new, Zlib::DEFAULT_COMPRESSION
12
+ )
13
+ c.class.should == Archive::Zip::Codec::Deflate::Compress
14
+ c.close
15
+ end
16
+
17
+ it "allows level to be set" do
18
+ data = DeflateSpecs.test_data
19
+ compressed_data = BinaryStringIO.new
20
+ c = Archive::Zip::Codec::Deflate::Compress.new(
21
+ compressed_data, Zlib::DEFAULT_COMPRESSION
22
+ )
23
+ c.write(data)
24
+ c.close
25
+
26
+ compressed_data.string.should == DeflateSpecs.compressed_data
27
+
28
+ compressed_data = BinaryStringIO.new
29
+ c = Archive::Zip::Codec::Deflate::Compress.new(
30
+ compressed_data, Zlib::NO_COMPRESSION
31
+ )
32
+ c.write(data)
33
+ c.close
34
+
35
+ compressed_data.string.should == DeflateSpecs.compressed_data_nocomp
36
+ end
37
+ end
@@ -0,0 +1,46 @@
1
+ # encoding: UTF-8
2
+
3
+ require File.dirname(__FILE__) + '/../../../../../../spec_helper'
4
+ require File.dirname(__FILE__) + '/../fixtures/classes'
5
+ require 'archive/zip/codec/deflate'
6
+ require 'archive/support/binary_stringio'
7
+
8
+ describe "Archive::Zip::Codec::Deflate::Compress.open" do
9
+ it "returns a new instance when run without a block" do
10
+ c = Archive::Zip::Codec::Deflate::Compress.open(
11
+ BinaryStringIO.new, Zlib::DEFAULT_COMPRESSION
12
+ )
13
+ c.class.should == Archive::Zip::Codec::Deflate::Compress
14
+ c.close
15
+ end
16
+
17
+ it "executes a block with a new instance as an argument" do
18
+ Archive::Zip::Codec::Deflate::Compress.open(
19
+ BinaryStringIO.new, Zlib::DEFAULT_COMPRESSION
20
+ ) { |c| c.class.should == Archive::Zip::Codec::Deflate::Compress }
21
+ end
22
+
23
+ it "closes the object after executing a block" do
24
+ Archive::Zip::Codec::Deflate::Compress.open(
25
+ BinaryStringIO.new, Zlib::DEFAULT_COMPRESSION
26
+ ) { |c| c }.closed?.should.be_true
27
+ end
28
+
29
+ it "allows level to be set" do
30
+ data = DeflateSpecs.test_data
31
+ compressed_data = BinaryStringIO.new
32
+ c = Archive::Zip::Codec::Deflate::Compress.open(
33
+ compressed_data, Zlib::DEFAULT_COMPRESSION
34
+ ) { |c| c.write(data) }
35
+
36
+ compressed_data.string.should == DeflateSpecs.compressed_data
37
+
38
+ data = DeflateSpecs.test_data
39
+ compressed_data = BinaryStringIO.new
40
+ c = Archive::Zip::Codec::Deflate::Compress.open(
41
+ compressed_data, Zlib::NO_COMPRESSION
42
+ ) { |c| c.write(data) }
43
+
44
+ compressed_data.string.should == DeflateSpecs.compressed_data_nocomp
45
+ end
46
+ end
@@ -0,0 +1,109 @@
1
+ # encoding: UTF-8
2
+
3
+ require File.dirname(__FILE__) + '/../../../../../../spec_helper'
4
+ require File.dirname(__FILE__) + '/../fixtures/classes'
5
+ require 'archive/zip/codec/deflate'
6
+ require 'archive/support/binary_stringio'
7
+
8
+ describe "Archive::Zip::Codec::Deflate::Compress#write" do
9
+ it "calls the write method of the delegate" do
10
+ delegate = mock('delegate')
11
+ # RSpec's mocking facility supposedly supports this, but MSpec's does not as
12
+ # of version 1.5.10.
13
+ #delegate.should_receive(:write).with(an_instance_of(String)).at_least(:once).and_return { |s| s.length }
14
+ # Use the following instead for now.
15
+ delegate.should_receive(:write).at_least(:once).and_return(1)
16
+ delegate.should_receive(:close).once.and_return(nil)
17
+ Archive::Zip::Codec::Deflate::Compress.open(
18
+ delegate, Zlib::DEFAULT_COMPRESSION
19
+ ) do |compressor|
20
+ compressor.write(DeflateSpecs.test_data)
21
+ end
22
+ end
23
+
24
+ it "writes compressed data to the delegate" do
25
+ compressed_data = BinaryStringIO.new
26
+ Archive::Zip::Codec::Deflate::Compress.open(
27
+ compressed_data, Zlib::DEFAULT_COMPRESSION
28
+ ) do |compressor|
29
+ compressor.write(DeflateSpecs.test_data)
30
+ end
31
+ compressed_data.string.should == DeflateSpecs.compressed_data
32
+ end
33
+
34
+ it "writes compressed data to a delegate that only performs partial writes" do
35
+ compressed_data = BinaryStringIO.new
36
+ # Override compressed_data.write to perform writes 1 byte at a time.
37
+ class << compressed_data
38
+ alias :write_orig :write
39
+ def write(buffer)
40
+ write_orig(buffer.slice(0, 1))
41
+ end
42
+ end
43
+
44
+ Archive::Zip::Codec::Deflate::Compress.open(
45
+ compressed_data, Zlib::DEFAULT_COMPRESSION
46
+ ) do |compressor|
47
+ compressor.write(DeflateSpecs.test_data)
48
+ end
49
+ compressed_data.string.should == DeflateSpecs.compressed_data
50
+ end
51
+
52
+ it "writes compressed data to a delegate that raises Errno::EAGAIN" do
53
+ compressed_data = BinaryStringIO.new
54
+ # Override compressed_data.write to raise Errno::EAGAIN every other time it's
55
+ # called.
56
+ class << compressed_data
57
+ alias :write_orig :write
58
+ def write(buffer)
59
+ if @error_raised then
60
+ @error_raised = false
61
+ write_orig(buffer)
62
+ else
63
+ @error_raised = true
64
+ raise Errno::EAGAIN
65
+ end
66
+ end
67
+ end
68
+
69
+ Archive::Zip::Codec::Deflate::Compress.open(
70
+ compressed_data, Zlib::DEFAULT_COMPRESSION
71
+ ) do |compressor|
72
+ begin
73
+ compressor.write(DeflateSpecs.test_data)
74
+ rescue Errno::EAGAIN
75
+ retry
76
+ end
77
+ end
78
+ compressed_data.string.should == DeflateSpecs.compressed_data
79
+ end
80
+
81
+ it "writes compressed data to a delegate that raises Errno::EINTR" do
82
+ compressed_data = BinaryStringIO.new
83
+ # Override compressed_data.write to raise Errno::EINTR every other time it's
84
+ # called.
85
+ class << compressed_data
86
+ alias :write_orig :write
87
+ def write(buffer)
88
+ if @error_raised then
89
+ @error_raised = false
90
+ write_orig(buffer)
91
+ else
92
+ @error_raised = true
93
+ raise Errno::EINTR
94
+ end
95
+ end
96
+ end
97
+
98
+ Archive::Zip::Codec::Deflate::Compress.open(
99
+ compressed_data, Zlib::DEFAULT_COMPRESSION
100
+ ) do |compressor|
101
+ begin
102
+ compressor.write(DeflateSpecs.test_data)
103
+ rescue Errno::EINTR
104
+ retry
105
+ end
106
+ end
107
+ compressed_data.string.should == DeflateSpecs.compressed_data
108
+ end
109
+ end
@@ -0,0 +1,18 @@
1
+ # encoding: UTF-8
2
+
3
+ require File.dirname(__FILE__) + '/../../../../../../spec_helper'
4
+ require File.dirname(__FILE__) + '/../fixtures/classes'
5
+ require 'archive/zip/codec/deflate'
6
+
7
+ describe "Archive::Zip::Deflate::Decompress#checksum" do
8
+ it "computes a CRC32 checksum" do
9
+ closed_decompressor = DeflateSpecs.compressed_data do |f|
10
+ Archive::Zip::Codec::Deflate::Decompress.open(f) do |decompressor|
11
+ decompressor.read
12
+ decompressor.checksum.should == Zlib.crc32(DeflateSpecs.test_data)
13
+ decompressor
14
+ end
15
+ end
16
+ closed_decompressor.checksum.should == Zlib.crc32(DeflateSpecs.test_data)
17
+ end
18
+ end
@@ -0,0 +1,33 @@
1
+ # encoding: UTF-8
2
+
3
+ require File.dirname(__FILE__) + '/../../../../../../spec_helper'
4
+ require File.dirname(__FILE__) + '/../fixtures/classes'
5
+ require 'archive/zip/codec/deflate'
6
+ require 'archive/support/binary_stringio'
7
+
8
+ describe "Archive::Zip::Codec::Deflate::Decompress#close" do
9
+ it "closes the stream" do
10
+ c = Archive::Zip::Codec::Deflate::Decompress.new(BinaryStringIO.new)
11
+ c.close
12
+ c.closed?.should be_true
13
+ end
14
+
15
+ it "closes the delegate stream by default" do
16
+ delegate = mock('delegate')
17
+ delegate.should_receive(:close).and_return(nil)
18
+ c = Archive::Zip::Codec::Deflate::Decompress.new(delegate)
19
+ c.close
20
+ end
21
+
22
+ it "optionally leaves the delegate stream open" do
23
+ delegate = mock('delegate')
24
+ delegate.should_receive(:close).and_return(nil)
25
+ c = Archive::Zip::Codec::Deflate::Decompress.new(delegate)
26
+ c.close(true)
27
+
28
+ delegate = mock('delegate')
29
+ delegate.should_not_receive(:close)
30
+ c = Archive::Zip::Codec::Deflate::Decompress.new(delegate)
31
+ c.close(false)
32
+ end
33
+ end
@@ -0,0 +1,18 @@
1
+ # encoding: UTF-8
2
+
3
+ require File.dirname(__FILE__) + '/../../../../../../spec_helper'
4
+ require File.dirname(__FILE__) + '/../fixtures/classes'
5
+ require 'archive/zip/codec/deflate'
6
+
7
+ describe "Archive::Zip::Deflate::Decompress#crc32" do
8
+ it "computes a CRC32 checksum" do
9
+ closed_decompressor = DeflateSpecs.compressed_data do |f|
10
+ Archive::Zip::Codec::Deflate::Decompress.open(f) do |decompressor|
11
+ decompressor.read
12
+ decompressor.crc32.should == Zlib.crc32(DeflateSpecs.test_data)
13
+ decompressor
14
+ end
15
+ end
16
+ closed_decompressor.crc32.should == Zlib.crc32(DeflateSpecs.test_data)
17
+ end
18
+ end