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,119 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- class Time
4
- # Returns a DOSTime representing this time object as a DOS date-time
5
- # structure. Times are bracketed by the limits of the ability of the DOS
6
- # date-time structure to represent them. Accuracy is 2 seconds and years
7
- # range from 1980 to 2099. The returned structure represents as closely as
8
- # possible the time of this object.
9
- #
10
- # See DOSTime#new for a description of this structure.
11
- def to_dos_time
12
- dos_sec = sec/2
13
- dos_year = year - 1980
14
- dos_year = 0 if dos_year < 0
15
- dos_year = 119 if dos_year > 119
16
-
17
- Archive::DOSTime.new(
18
- (dos_sec ) |
19
- (min << 5) |
20
- (hour << 11) |
21
- (day << 16) |
22
- (month << 21) |
23
- (dos_year << 25)
24
- )
25
- end
26
- end
27
-
28
- module Archive
29
- # A representation of the DOS time structure which can be converted into
30
- # instances of Time.
31
- class DOSTime
32
- include Comparable
33
-
34
- # Creates a new instance of DOSTime. _dos_time_ is a 4 byte String or
35
- # unsigned number (Integer) representing an MS-DOS time structure where:
36
- # Bits 0-4:: 2 second increments (0-29)
37
- # Bits 5-10:: minutes (0-59)
38
- # Bits 11-15:: hours (0-24)
39
- # Bits 16-20:: day (1-31)
40
- # Bits 21-24:: month (1-12)
41
- # Bits 25-31:: four digit year minus 1980 (0-119)
42
- #
43
- # If _dos_time_ is ommitted or +nil+, a new instance is created based on the
44
- # current time.
45
- def initialize(dos_time = nil)
46
- case dos_time
47
- when nil
48
- @dos_time = Time.now.to_dos_time.to_i
49
- when Integer
50
- @dos_time = dos_time
51
- else
52
- unless dos_time.length == 4 then
53
- raise ArgumentError, 'length of DOS time structure is not 4'
54
- end
55
- @dos_time = dos_time.unpack('V')[0]
56
- end
57
-
58
- validate
59
- end
60
-
61
- # Returns -1 if _other_ is a time earlier than this one, 0 if _other_ is the
62
- # same time, and 1 if _other_ is a later time.
63
- def cmp(other)
64
- to_i <=> other.to_i
65
- end
66
- alias :<=> :cmp
67
-
68
- # Returns the time value of this object as an integer representing the DOS
69
- # time structure.
70
- def to_i
71
- @dos_time
72
- end
73
-
74
- # Returns the 32 bit integer that backs this object packed into a String in
75
- # little endian format. This is suitable for use with #new.
76
- def pack
77
- [to_i].pack('V')
78
- end
79
-
80
- # Returns a Time instance which is equivalent to the time represented by
81
- # this object.
82
- def to_time
83
- second = ((0b11111 & @dos_time) ) * 2
84
- minute = ((0b111111 << 5 & @dos_time) >> 5)
85
- hour = ((0b11111 << 11 & @dos_time) >> 11)
86
- day = ((0b11111 << 16 & @dos_time) >> 16)
87
- month = ((0b1111 << 21 & @dos_time) >> 21)
88
- year = ((0b1111111 << 25 & @dos_time) >> 25) + 1980
89
- return Time.local(year, month, day, hour, minute, second)
90
- end
91
-
92
- private
93
-
94
- def validate
95
- second = (0b11111 & @dos_time)
96
- minute = (0b111111 << 5 & @dos_time) >> 5
97
- hour = (0b11111 << 11 & @dos_time) >> 11
98
- day = (0b11111 << 16 & @dos_time) >> 16
99
- month = (0b1111 << 21 & @dos_time) >> 21
100
- year = (0b1111111 << 25 & @dos_time) >> 25
101
-
102
- if second > 29
103
- raise ArgumentError, 'second must not be greater than 29'
104
- elsif minute > 59
105
- raise ArgumentError, 'minute must not be greater than 59'
106
- elsif hour > 24
107
- raise ArgumentError, 'hour must not be greater than 24'
108
- elsif day < 1
109
- raise ArgumentError, 'day must not be less than 1'
110
- elsif month < 1
111
- raise ArgumentError, 'month must not be less than 1'
112
- elsif month > 12
113
- raise ArgumentError, 'month must not be greater than 12'
114
- elsif year > 119
115
- raise ArgumentError, 'year must not be greater than 119'
116
- end
117
- end
118
- end
119
- end
@@ -1,6 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- module Archive; class Zip
4
- # The current version of this gem.
5
- VERSION = '0.12.0'
6
- end; end
@@ -1,113 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- require 'minitest/autorun'
4
-
5
- require 'archive/support/time'
6
-
7
- describe 'Archive::DOSTime.new' do
8
- let(:epoc) { 0b0000000_0001_00001_00000_000000_00000 }
9
- let(:end_times) { 0b1110111_1100_11111_11000_111011_11101 }
10
-
11
- it 'uses the current time when no structure is given' do
12
- now = Time.now.localtime
13
- dos_time = Archive::DOSTime.new.to_time
14
-
15
- now.year.must_be_close_to(dos_time.year, 1)
16
- now.month.must_be_close_to(dos_time.month, 1)
17
- now.day.must_be_close_to(dos_time.day, 1)
18
- now.hour.must_be_close_to(dos_time.hour, 1)
19
- now.min.must_be_close_to(dos_time.min, 1)
20
- now.sec.must_be_close_to(dos_time.sec, 3)
21
- end
22
-
23
- it 'accepts valid Integer structures' do
24
- Archive::DOSTime.new(epoc)
25
- Archive::DOSTime.new(end_times)
26
- end
27
-
28
- it 'accepts valid String structures' do
29
- Archive::DOSTime.new([epoc].pack('V'))
30
- Archive::DOSTime.new([end_times].pack('V'))
31
- end
32
-
33
- it 'rejects invalid Integer structures' do
34
- # Second must not be greater than 29.
35
- proc {
36
- Archive::DOSTime.new(epoc | 0b0000000_0000_00000_00000_000000_11110)
37
- }.must_raise(ArgumentError)
38
-
39
- # Minute must not be greater than 59.
40
- proc {
41
- Archive::DOSTime.new(epoc | 0b0000000_0000_00000_00000_111100_00000)
42
- }.must_raise(ArgumentError)
43
-
44
- # Hour must not be greater than 24.
45
- proc {
46
- Archive::DOSTime.new(epoc | 0b0000000_0000_00000_11001_000000_00000)
47
- }.must_raise(ArgumentError)
48
-
49
- # Day must not be zero.
50
- proc {
51
- Archive::DOSTime.new(epoc & 0b1111111_1111_00000_11111_111111_11111)
52
- }.must_raise(ArgumentError)
53
-
54
- # Month must not be zero.
55
- proc {
56
- Archive::DOSTime.new(epoc & 0b1111111_0000_11111_11111_111111_11111)
57
- }.must_raise(ArgumentError)
58
-
59
- # Month must not be greater than 12.
60
- proc {
61
- Archive::DOSTime.new(epoc | 0b0000000_1101_00000_00000_000000_00000)
62
- }.must_raise(ArgumentError)
63
-
64
- # Year must not be greater than 119.
65
- proc {
66
- Archive::DOSTime.new(epoc | 0b1111000_0000_00000_00000_000000_00000)
67
- }.must_raise(ArgumentError)
68
- end
69
-
70
- it 'rejects invalid String structures' do
71
- # Second must not be greater than 29.
72
- proc {
73
- packed = [epoc | 0b0000000_0000_00000_00000_000000_11110].pack('V')
74
- Archive::DOSTime.new(packed)
75
- }.must_raise(ArgumentError)
76
-
77
- # Minute must not be greater than 59.
78
- proc {
79
- packed = [epoc | 0b0000000_0000_00000_00000_111100_00000].pack('V')
80
- Archive::DOSTime.new(packed)
81
- }.must_raise(ArgumentError)
82
-
83
- # Hour must not be greater than 24.
84
- proc {
85
- packed = [epoc | 0b0000000_0000_00000_11001_000000_00000].pack('V')
86
- Archive::DOSTime.new(packed)
87
- }.must_raise(ArgumentError)
88
-
89
- # Day must not be zero.
90
- proc {
91
- packed = [epoc & 0b1111111_1111_00000_11111_111111_11111].pack('V')
92
- Archive::DOSTime.new(packed)
93
- }.must_raise(ArgumentError)
94
-
95
- # Month must not be zero.
96
- proc {
97
- packed = [epoc & 0b1111111_0000_11111_11111_111111_11111].pack('V')
98
- Archive::DOSTime.new(packed)
99
- }.must_raise(ArgumentError)
100
-
101
- # Month must not be greater than 12.
102
- proc {
103
- packed = [epoc | 0b0000000_1101_00000_00000_000000_00000].pack('V')
104
- Archive::DOSTime.new(packed)
105
- }.must_raise(ArgumentError)
106
-
107
- # Year must not be greater than 119.
108
- proc {
109
- packed = [epoc | 0b1111000_0000_00000_00000_000000_00000].pack('V')
110
- Archive::DOSTime.new(packed)
111
- }.must_raise(ArgumentError)
112
- end
113
- end
@@ -1,54 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- require 'minitest/autorun'
4
- require 'tmpdir'
5
-
6
- require 'archive/zip'
7
-
8
- describe 'Archive::Zip#archive' do
9
- it 'adds file entries' do
10
- file_name = 'file'
11
- Dir.mktmpdir('archive_zip#archive') do |dir|
12
- file_path = File.join(dir, file_name)
13
- File.open(file_path, 'wb') { |f| f.write('data') }
14
- archive_file_path = File.join(dir, 'archive.zip')
15
-
16
- Archive::Zip.open(archive_file_path, 'w') do |a|
17
- a.archive(file_path)
18
- end
19
-
20
- Archive::Zip.open(archive_file_path, 'r') do |a|
21
- entry = a.first
22
- entry.wont_be_nil
23
- entry.zip_path.must_equal(file_name)
24
- entry.file?.must_equal(true)
25
- entry.file_data.read.must_equal('data')
26
- end
27
- end
28
- end
29
-
30
- it 'adds entries with multibyte names' do
31
- unless Object.const_defined?(:Encoding)
32
- skip("String encodings are not supported on current Ruby (#{RUBY_DESCRIPTION})")
33
- end
34
-
35
- mb_file_name = '☂file☄'
36
- Dir.mktmpdir('archive_zip#archive') do |dir|
37
- mb_file_path = File.join(dir, mb_file_name)
38
- File.open(mb_file_path, 'wb') { |f| f.write('data') }
39
- archive_file_path = File.join(dir, 'archive.zip')
40
-
41
- Archive::Zip.open(archive_file_path, 'w') do |a|
42
- a.archive(mb_file_path)
43
- end
44
-
45
- Archive::Zip.open(archive_file_path, 'r') do |a|
46
- entry = a.first
47
- entry.wont_be_nil
48
- entry.zip_path.must_equal(mb_file_name.dup.force_encoding('binary'))
49
- entry.file?.must_equal(true)
50
- entry.file_data.read.must_equal('data')
51
- end
52
- end
53
- end
54
- end
@@ -1,44 +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::Compress#checksum" do
11
- it "computes the CRC32 checksum" do
12
- compressed_data = BinaryStringIO.new
13
- closed_compressor = Archive::Zip::Codec::Deflate::Compress.open(
14
- compressed_data, Zlib::DEFAULT_COMPRESSION
15
- ) do |compressor|
16
- compressor.write(DeflateSpecs.test_data)
17
- compressor.flush
18
- compressor.checksum.must_equal Zlib.crc32(DeflateSpecs.test_data)
19
- compressor
20
- end
21
- closed_compressor.checksum.must_equal Zlib.crc32(DeflateSpecs.test_data)
22
- end
23
-
24
- it "computes the CRC32 checksum even when the delegate performs partial writes" do
25
- compressed_data = BinaryStringIO.new
26
- # Override compressed_data.write to perform writes 1 byte at a time.
27
- class << compressed_data
28
- alias :write_orig :write
29
- def write(buffer)
30
- write_orig(buffer.slice(0, 1))
31
- end
32
- end
33
-
34
- closed_compressor = Archive::Zip::Codec::Deflate::Compress.open(
35
- compressed_data, Zlib::DEFAULT_COMPRESSION
36
- ) do |compressor|
37
- compressor.write(DeflateSpecs.test_data)
38
- compressor.flush
39
- compressor.checksum.must_equal Zlib.crc32(DeflateSpecs.test_data)
40
- compressor
41
- end
42
- closed_compressor.checksum.must_equal Zlib.crc32(DeflateSpecs.test_data)
43
- end
44
- end
@@ -1,45 +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::Compress#close" do
11
- it "closes the stream" do
12
- c = Archive::Zip::Codec::Deflate::Compress.new(
13
- BinaryStringIO.new, Zlib::DEFAULT_COMPRESSION
14
- )
15
- c.close
16
- c.closed?.must_equal true
17
- end
18
-
19
- it "closes the delegate stream by default" do
20
- delegate = MiniTest::Mock.new
21
- delegate.expect(:write, 8, [String])
22
- delegate.expect(:close, nil)
23
- c = Archive::Zip::Codec::Deflate::Compress.new(
24
- delegate, Zlib::DEFAULT_COMPRESSION
25
- )
26
- c.close
27
- end
28
-
29
- it "optionally leaves the delegate stream open" do
30
- delegate = MiniTest::Mock.new
31
- delegate.expect(:write, 8, [String])
32
- delegate.expect(:close, nil)
33
- c = Archive::Zip::Codec::Deflate::Compress.new(
34
- delegate, Zlib::DEFAULT_COMPRESSION
35
- )
36
- c.close(true)
37
-
38
- delegate = MiniTest::Mock.new
39
- delegate.expect(:write, 8, [String])
40
- c = Archive::Zip::Codec::Deflate::Compress.new(
41
- delegate, Zlib::DEFAULT_COMPRESSION
42
- )
43
- c.close(false)
44
- end
45
- 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/deflate'
8
- require 'archive/support/binary_stringio'
9
-
10
- describe "Archive::Zip::Codec::Deflate::Compress#crc32" do
11
- it "computes the CRC32 checksum" do
12
- compressed_data = BinaryStringIO.new
13
- closed_compressor = Archive::Zip::Codec::Deflate::Compress.open(
14
- compressed_data, Zlib::DEFAULT_COMPRESSION
15
- ) do |compressor|
16
- compressor.write(DeflateSpecs.test_data)
17
- compressor.flush
18
- compressor.crc32.must_equal Zlib.crc32(DeflateSpecs.test_data)
19
- compressor
20
- end
21
- closed_compressor.crc32.must_equal Zlib.crc32(DeflateSpecs.test_data)
22
- end
23
- 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
- require 'archive/support/binary_stringio'
9
-
10
- describe "Archive::Zip::Codec::Deflate::Compress#data_descriptor" do
11
- it "is an instance of Archive::Zip::DataDescriptor" do
12
- test_data = DeflateSpecs.test_data
13
- compressed_data = BinaryStringIO.new
14
- closed_compressor = Archive::Zip::Codec::Deflate::Compress.open(
15
- compressed_data, Zlib::DEFAULT_COMPRESSION
16
- ) do |compressor|
17
- compressor.write(test_data)
18
- compressor.flush
19
- compressor.data_descriptor.class.must_equal(Archive::Zip::DataDescriptor)
20
- compressor
21
- end
22
- closed_compressor.data_descriptor.class.must_equal(
23
- Archive::Zip::DataDescriptor
24
- )
25
- end
26
-
27
- it "has a crc32 attribute containing the CRC32 checksum" do
28
- test_data = DeflateSpecs.test_data
29
- compressed_data = BinaryStringIO.new
30
- closed_compressor = Archive::Zip::Codec::Deflate::Compress.open(
31
- compressed_data, Zlib::DEFAULT_COMPRESSION
32
- ) do |compressor|
33
- compressor.write(test_data)
34
- compressor.flush
35
- compressor.data_descriptor.crc32.must_equal(Zlib.crc32(test_data))
36
- compressor
37
- end
38
- closed_compressor.data_descriptor.crc32.must_equal(Zlib.crc32(test_data))
39
- end
40
-
41
- it "has a compressed_size attribute containing the size of the compressed data" do
42
- test_data = DeflateSpecs.test_data
43
- compressed_data = BinaryStringIO.new
44
- closed_compressor = Archive::Zip::Codec::Deflate::Compress.open(
45
- compressed_data, Zlib::DEFAULT_COMPRESSION
46
- ) do |compressor|
47
- compressor.write(test_data)
48
- compressor.flush
49
- compressor.data_descriptor.compressed_size.must_equal(
50
- compressed_data.size
51
- )
52
- compressor
53
- end
54
- closed_compressor.data_descriptor.compressed_size.must_equal(
55
- compressed_data.size
56
- )
57
- end
58
-
59
- it "has an uncompressed_size attribute containing the size of the input data" do
60
- test_data = DeflateSpecs.test_data
61
- compressed_data = BinaryStringIO.new
62
- closed_compressor = Archive::Zip::Codec::Deflate::Compress.open(
63
- compressed_data, Zlib::DEFAULT_COMPRESSION
64
- ) do |compressor|
65
- compressor.write(test_data)
66
- compressor.flush
67
- compressor.data_descriptor.uncompressed_size.must_equal(test_data.size)
68
- compressor
69
- end
70
- closed_compressor.data_descriptor.uncompressed_size.must_equal(
71
- test_data.size
72
- )
73
- end
74
- end
@@ -1,39 +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::Compress.new" do
11
- it "returns a new instance" do
12
- c = Archive::Zip::Codec::Deflate::Compress.new(
13
- BinaryStringIO.new, Zlib::DEFAULT_COMPRESSION
14
- )
15
- c.must_be_instance_of(Archive::Zip::Codec::Deflate::Compress)
16
- c.close
17
- end
18
-
19
- it "allows level to be set" do
20
- data = DeflateSpecs.test_data
21
- compressed_data = BinaryStringIO.new
22
- c = Archive::Zip::Codec::Deflate::Compress.new(
23
- compressed_data, Zlib::DEFAULT_COMPRESSION
24
- )
25
- c.write(data)
26
- c.close
27
-
28
- compressed_data.string.must_equal(DeflateSpecs.compressed_data)
29
-
30
- compressed_data = BinaryStringIO.new
31
- c = Archive::Zip::Codec::Deflate::Compress.new(
32
- compressed_data, Zlib::NO_COMPRESSION
33
- )
34
- c.write(data)
35
- c.close
36
-
37
- compressed_data.string.must_equal(DeflateSpecs.compressed_data_nocomp)
38
- end
39
- end
@@ -1,48 +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::Compress.open" do
11
- it "returns a new instance when run without a block" do
12
- c = Archive::Zip::Codec::Deflate::Compress.open(
13
- BinaryStringIO.new, Zlib::DEFAULT_COMPRESSION
14
- )
15
- c.must_be_instance_of(Archive::Zip::Codec::Deflate::Compress)
16
- c.close
17
- end
18
-
19
- it "executes a block with a new instance as an argument" do
20
- Archive::Zip::Codec::Deflate::Compress.open(
21
- BinaryStringIO.new, Zlib::DEFAULT_COMPRESSION
22
- ) { |c| c.must_be_instance_of(Archive::Zip::Codec::Deflate::Compress) }
23
- end
24
-
25
- it "closes the object after executing a block" do
26
- Archive::Zip::Codec::Deflate::Compress.open(
27
- BinaryStringIO.new, Zlib::DEFAULT_COMPRESSION
28
- ) { |c| c }.closed?.must_equal(true)
29
- end
30
-
31
- it "allows level to be set" do
32
- data = DeflateSpecs.test_data
33
- compressed_data = BinaryStringIO.new
34
- Archive::Zip::Codec::Deflate::Compress.open(
35
- compressed_data, Zlib::DEFAULT_COMPRESSION
36
- ) { |c| c.write(data) }
37
-
38
- compressed_data.string.must_equal(DeflateSpecs.compressed_data)
39
-
40
- data = DeflateSpecs.test_data
41
- compressed_data = BinaryStringIO.new
42
- Archive::Zip::Codec::Deflate::Compress.open(
43
- compressed_data, Zlib::NO_COMPRESSION
44
- ) { |c| c.write(data) }
45
-
46
- compressed_data.string.must_equal(DeflateSpecs.compressed_data_nocomp)
47
- end
48
- end
@@ -1,111 +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::Compress#write" do
11
- it "calls the write method of the delegate" do
12
- delegate = MiniTest::Mock.new
13
- delegate.expect(
14
- :write, DeflateSpecs.compressed_data.size, [DeflateSpecs.compressed_data]
15
- )
16
- delegate.expect(:close, 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.must_equal(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.must_equal(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
55
- # it's called.
56
- class << compressed_data
57
- alias :write_orig :write
58
- def write(buffer)
59
- @error_raised ||= false
60
- if @error_raised then
61
- @error_raised = false
62
- write_orig(buffer)
63
- else
64
- @error_raised = true
65
- raise Errno::EAGAIN
66
- end
67
- end
68
- end
69
-
70
- Archive::Zip::Codec::Deflate::Compress.open(
71
- compressed_data, Zlib::DEFAULT_COMPRESSION
72
- ) do |compressor|
73
- begin
74
- compressor.write(DeflateSpecs.test_data)
75
- rescue Errno::EAGAIN
76
- retry
77
- end
78
- end
79
- compressed_data.string.must_equal(DeflateSpecs.compressed_data)
80
- end
81
-
82
- it "writes compressed data to a delegate that raises Errno::EINTR" do
83
- compressed_data = BinaryStringIO.new
84
- # Override compressed_data.write to raise Errno::EINTR every other time it's
85
- # called.
86
- class << compressed_data
87
- alias :write_orig :write
88
- def write(buffer)
89
- @error_raised ||= false
90
- if @error_raised then
91
- @error_raised = false
92
- write_orig(buffer)
93
- else
94
- @error_raised = true
95
- raise Errno::EINTR
96
- end
97
- end
98
- end
99
-
100
- Archive::Zip::Codec::Deflate::Compress.open(
101
- compressed_data, Zlib::DEFAULT_COMPRESSION
102
- ) do |compressor|
103
- begin
104
- compressor.write(DeflateSpecs.test_data)
105
- rescue Errno::EINTR
106
- retry
107
- end
108
- end
109
- compressed_data.string.must_equal(DeflateSpecs.compressed_data)
110
- end
111
- end