rubyzip 0.9.1 → 2.3.2

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 (103) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +354 -0
  3. data/Rakefile +15 -104
  4. data/TODO +0 -1
  5. data/lib/zip/central_directory.rb +212 -0
  6. data/lib/zip/compressor.rb +9 -0
  7. data/lib/zip/constants.rb +115 -0
  8. data/lib/zip/crypto/decrypted_io.rb +40 -0
  9. data/lib/zip/crypto/encryption.rb +11 -0
  10. data/lib/zip/crypto/null_encryption.rb +43 -0
  11. data/lib/zip/crypto/traditional_encryption.rb +99 -0
  12. data/lib/zip/decompressor.rb +31 -0
  13. data/lib/zip/deflater.rb +34 -0
  14. data/lib/zip/dos_time.rb +53 -0
  15. data/lib/zip/entry.rb +719 -0
  16. data/lib/zip/entry_set.rb +88 -0
  17. data/lib/zip/errors.rb +19 -0
  18. data/lib/zip/extra_field/generic.rb +44 -0
  19. data/lib/zip/extra_field/ntfs.rb +94 -0
  20. data/lib/zip/extra_field/old_unix.rb +46 -0
  21. data/lib/zip/extra_field/universal_time.rb +77 -0
  22. data/lib/zip/extra_field/unix.rb +39 -0
  23. data/lib/zip/extra_field/zip64.rb +70 -0
  24. data/lib/zip/extra_field/zip64_placeholder.rb +15 -0
  25. data/lib/zip/extra_field.rb +103 -0
  26. data/lib/zip/file.rb +468 -0
  27. data/lib/zip/filesystem.rb +643 -0
  28. data/lib/zip/inflater.rb +54 -0
  29. data/lib/zip/input_stream.rb +180 -0
  30. data/lib/zip/ioextras/abstract_input_stream.rb +122 -0
  31. data/lib/zip/ioextras/abstract_output_stream.rb +43 -0
  32. data/lib/zip/ioextras.rb +21 -140
  33. data/lib/zip/null_compressor.rb +15 -0
  34. data/lib/zip/null_decompressor.rb +19 -0
  35. data/lib/zip/null_input_stream.rb +10 -0
  36. data/lib/zip/output_stream.rb +198 -0
  37. data/lib/zip/pass_thru_compressor.rb +23 -0
  38. data/lib/zip/pass_thru_decompressor.rb +31 -0
  39. data/lib/zip/streamable_directory.rb +15 -0
  40. data/lib/zip/streamable_stream.rb +52 -0
  41. data/lib/zip/version.rb +3 -0
  42. data/lib/zip.rb +72 -0
  43. data/samples/example.rb +44 -32
  44. data/samples/example_filesystem.rb +16 -19
  45. data/samples/example_recursive.rb +54 -0
  46. data/samples/gtk_ruby_zip.rb +84 -0
  47. data/samples/qtzip.rb +25 -34
  48. data/samples/write_simple.rb +10 -13
  49. data/samples/zipfind.rb +38 -45
  50. metadata +182 -91
  51. data/ChangeLog +0 -1504
  52. data/NEWS +0 -144
  53. data/README +0 -72
  54. data/install.rb +0 -22
  55. data/lib/download_quizzes.rb +0 -119
  56. data/lib/quiz1/t/solutions/Bill Guindon/solitaire.rb +0 -205
  57. data/lib/quiz1/t/solutions/Carlos/solitaire.rb +0 -111
  58. data/lib/quiz1/t/solutions/Dennis Ranke/solitaire.rb +0 -111
  59. data/lib/quiz1/t/solutions/Florian Gross/solitaire.rb +0 -301
  60. data/lib/quiz1/t/solutions/Glen M. Lewis/solitaire.rb +0 -268
  61. data/lib/quiz1/t/solutions/James Edward Gray II/solitaire.rb +0 -132
  62. data/lib/quiz1/t/solutions/Jamis Buck/bin/main.rb +0 -13
  63. data/lib/quiz1/t/solutions/Jamis Buck/lib/cipher.rb +0 -230
  64. data/lib/quiz1/t/solutions/Jamis Buck/lib/cli.rb +0 -24
  65. data/lib/quiz1/t/solutions/Jamis Buck/test/tc_deck.rb +0 -30
  66. data/lib/quiz1/t/solutions/Jamis Buck/test/tc_key-stream.rb +0 -19
  67. data/lib/quiz1/t/solutions/Jamis Buck/test/tc_keying-algorithms.rb +0 -31
  68. data/lib/quiz1/t/solutions/Jamis Buck/test/tc_solitaire-cipher.rb +0 -66
  69. data/lib/quiz1/t/solutions/Jamis Buck/test/tc_unkeyed-algorithm.rb +0 -17
  70. data/lib/quiz1/t/solutions/Jamis Buck/test/tests.rb +0 -2
  71. data/lib/quiz1/t/solutions/Jim Menard/solitaire_cypher.rb +0 -204
  72. data/lib/quiz1/t/solutions/Jim Menard/test.rb +0 -47
  73. data/lib/quiz1/t/solutions/Moses Hohman/cipher.rb +0 -97
  74. data/lib/quiz1/t/solutions/Moses Hohman/deck.rb +0 -140
  75. data/lib/quiz1/t/solutions/Moses Hohman/solitaire.rb +0 -14
  76. data/lib/quiz1/t/solutions/Moses Hohman/test_cipher.rb +0 -68
  77. data/lib/quiz1/t/solutions/Moses Hohman/test_deck.rb +0 -146
  78. data/lib/quiz1/t/solutions/Moses Hohman/test_util.rb +0 -38
  79. data/lib/quiz1/t/solutions/Moses Hohman/testsuite.rb +0 -5
  80. data/lib/quiz1/t/solutions/Moses Hohman/util.rb +0 -27
  81. data/lib/quiz1/t/solutions/Niklas Frykholm/solitaire.rb +0 -151
  82. data/lib/quiz1/t/solutions/Thomas Leitner/solitaire.rb +0 -198
  83. data/lib/zip/stdrubyext.rb +0 -111
  84. data/lib/zip/tempfile_bugfixed.rb +0 -195
  85. data/lib/zip/zip.rb +0 -1847
  86. data/lib/zip/zipfilesystem.rb +0 -609
  87. data/lib/zip/ziprequire.rb +0 -90
  88. data/samples/gtkRubyzip.rb +0 -86
  89. data/test/alltests.rb +0 -9
  90. data/test/data/file1.txt +0 -46
  91. data/test/data/file1.txt.deflatedData +0 -0
  92. data/test/data/file2.txt +0 -1504
  93. data/test/data/notzippedruby.rb +0 -7
  94. data/test/data/rubycode.zip +0 -0
  95. data/test/data/rubycode2.zip +0 -0
  96. data/test/data/testDirectory.bin +0 -0
  97. data/test/data/zipWithDirs.zip +0 -0
  98. data/test/gentestfiles.rb +0 -157
  99. data/test/ioextrastest.rb +0 -208
  100. data/test/stdrubyexttest.rb +0 -52
  101. data/test/zipfilesystemtest.rb +0 -831
  102. data/test/ziprequiretest.rb +0 -43
  103. data/test/ziptest.rb +0 -1599
@@ -1,132 +0,0 @@
1
- #!/usr/bin/ruby -w
2
-
3
- $deck = (1..52).to_a + ["A", "B"] # Unkeyed deck - Keystream Step 1
4
-
5
- def encrypt(message)
6
- # Step 1
7
- message = message.upcase.tr("^A-Z", "")
8
- i = 5
9
- while i < message.size
10
- message[i, 0] = " "
11
- i += 6
12
- end
13
- message += "X" while message.rindex(" ") != message.size - 6
14
-
15
- # Step 2
16
- key_stream = generate(message.count("^ "))
17
-
18
- # Step 3
19
- values = message.split("").map { |letter| letter[0] - ?A + 1 }
20
-
21
- # Step 4
22
- key_values = key_stream.split("").map { |letter| letter[0] - ?A + 1 }
23
-
24
- # Step 5
25
- values.each_with_index do |value, index|
26
- next if value < 0
27
- values[index] = value + key_values[index]
28
- values[index] -= 26 if values[index] > 26
29
- end
30
-
31
- # Step 6
32
- message = (values.map { |number| (number - 1 + ?A).chr }).join("")
33
-
34
- return message
35
- end
36
-
37
- def decrypt(message)
38
- # Step 1
39
- key_stream = generate(message.size)
40
-
41
- # Step 2
42
- values = message.split("").map { |letter| letter[0] - ?A + 1 }
43
-
44
- # Step 3
45
- key_values = key_stream.split("").map { |letter| letter[0] - ?A + 1 }
46
-
47
- # Step 4
48
- values.each_with_index do |value, index|
49
- next if value < 0
50
- if value <= key_values[index]
51
- values[index] = value + 26 - key_values[index]
52
- else
53
- values[index] = value - key_values[index]
54
- end
55
- end
56
-
57
- # Step 5
58
- message = (values.map { |number| (number - 1 + ?A).chr }).join("")
59
-
60
- return message
61
- end
62
-
63
- def generate(count) # Keystream Steps
64
- key_stream = [ ]
65
-
66
- until key_stream.size == count
67
- # Step 2
68
- a = $deck.index("A")
69
- if a == 53
70
- $deck.insert(1, $deck.pop)
71
- else
72
- $deck.insert(a + 1, $deck.delete_at(a))
73
- end
74
-
75
- # Step 3
76
- b = $deck.index("B")
77
- if b == 53
78
- $deck.insert(2, $deck.pop)
79
- elsif b == 52
80
- $deck.insert(1, $deck.delete_at(b))
81
- else
82
- $deck.insert(b + 2, $deck.delete_at(b))
83
- end
84
-
85
- # Step 4
86
- a = $deck.index("A")
87
- b = $deck.index("B")
88
- top = [a, b].min
89
- bottom = [a, b].max
90
- $deck = $deck.values_at((bottom + 1)..53, top..bottom, 0...top)
91
-
92
- # Step 5
93
- if $deck[53].kind_of? Integer
94
- $deck = $deck.values_at($deck[53]..52, 0...$deck[53], 53)
95
- end
96
-
97
- # Step 5
98
- if $deck[0].kind_of? Integer
99
- if $deck[$deck[0]].kind_of? Integer
100
- key_stream.push($deck[$deck[0]])
101
- end
102
- else
103
- if $deck[53].kind_of? Integer
104
- key_stream.push($deck[53])
105
- end
106
- end
107
- end # Step 7
108
-
109
- key_stream.map! do |number|
110
- if number > 26
111
- (number - 26 - 1 + ?A).chr
112
- else
113
- (number - 1 + ?A).chr
114
- end
115
- end
116
- key_stream = key_stream.join("")
117
- i = 5
118
- while i < key_stream.size
119
- key_stream[i, 0] = " "
120
- i += 6
121
- end
122
- return key_stream
123
- end
124
-
125
- # Mind reading interface
126
- if ARGV.size == 1 and ARGV[0] =~ /^(?:[A-Z]{5} )*[A-Z]{5}$/
127
- puts decrypt(ARGV[0])
128
- elsif ARGV.size == 1
129
- puts encrypt(ARGV[0])
130
- else
131
- puts "Usage: solitaire.rb MESSAGE"
132
- end
@@ -1,13 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'copland'
4
-
5
- libdir = File.join( File.dirname( __FILE__ ), "..", "lib" )
6
- $: << libdir
7
-
8
- registry = Copland::Registry.build libdir, :log_device => STDOUT
9
-
10
- cli = registry.service( "solitaire.cipher.CLI" )
11
- cli.run
12
-
13
- registry.shutdown
@@ -1,230 +0,0 @@
1
- require 'optparse'
2
-
3
- class Deck
4
-
5
- def initialize
6
- @deck = (1..52).to_a + [ "A", "B" ]
7
- @length = @deck.length
8
- end
9
-
10
- def cipher_shuffle!
11
- # move joker A down one card, circularly
12
- reposition_card( "A", 1 )
13
-
14
- # move joker B down two cards, circularly
15
- reposition_card( "B", 2 )
16
-
17
- joker_A = @deck.index( "A" )
18
- joker_B = @deck.index( "B" )
19
-
20
- # move all cards above the top-most joker, below the bottom-most joker, and
21
- # all cards below the bottom-most joker, above the top-most joker.
22
- top = ( joker_A < joker_B ? joker_A : joker_B )
23
- bottom = ( joker_A > joker_B ? joker_A : joker_B )
24
- @deck = @deck[bottom+1..-1] + @deck[top..bottom] + @deck[0,top]
25
-
26
- # take value of the bottom-most card, and cut that many cards off the
27
- # top, inserting them just before the bottom-most card.
28
- cut = @deck.last
29
- @deck = @deck[cut..-2] + @deck[0,cut] + [ @deck.last ]
30
- end
31
-
32
- def cipher_letter
33
- count = @deck.first
34
- count = 53 if count.is_a?( String )
35
- result = @deck[ count ]
36
- return nil unless result.is_a? Fixnum
37
- result -= 26 while result > 26
38
- return (result+64).chr
39
- end
40
-
41
- def to_a
42
- @deck.dup
43
- end
44
-
45
- def cards=( deck )
46
- @deck = deck
47
- @length = @deck.length
48
- raise "the deck must contain an 'A' joker" unless @deck.include?("A")
49
- raise "the deck must contain a 'B' joker" unless @deck.include?("B")
50
- end
51
-
52
- def reposition_card( card, delta )
53
- pos = @deck.index card
54
- @deck.delete_at pos
55
- new_pos = pos + delta
56
- new_pos = 1 + new_pos % @length if new_pos >= @length
57
- @deck.insert new_pos, card
58
- new_pos
59
- end
60
- private :reposition_card
61
-
62
- end
63
-
64
- class KeyingAlgorithms
65
-
66
- attr_writer :algorithms
67
- attr_writer :registry
68
-
69
- def get( name )
70
- svc_name = @algorithms[ name ]
71
- raise "No such algorithm #{name.inspect}" if svc_name.nil?
72
-
73
- return @registry.service( svc_name )
74
- end
75
-
76
- end
77
-
78
- class UnkeyedAlgorithm
79
-
80
- def new_deck
81
- Deck.new
82
- end
83
-
84
- end
85
-
86
- class KeyStream
87
-
88
- attr_writer :deck
89
-
90
- def next
91
- loop do
92
- @deck.cipher_shuffle!
93
- letter = @deck.cipher_letter
94
- return letter if letter
95
- end
96
- end
97
-
98
- end
99
-
100
- class SolitaireCipher
101
-
102
- attr_writer :algorithms
103
- attr_writer :stream
104
-
105
- def initialize( default_algorithm )
106
- @algorithm = default_algorithm
107
- end
108
-
109
- def use_algorithm( keying_algorithm )
110
- @algorithm = @algorithms.get( keying_algorithm )
111
- end
112
-
113
- def encrypt( message )
114
- reset
115
-
116
- chars = message.split(//).map { |c| c.upcase }. reject { |c| c !~ /[A-Z]/ }
117
- chars.concat ["X"] * ( 5 - chars.length % 5 ) if chars.length % 5 > 0
118
- chars.map! { |c| c[0] - 64 }
119
- key = generate_key( chars.length )
120
- code = chars.zip( key ).map { |c,k| ( c + k > 26 ? c + k - 26 : c + k ) }.map { |c| (c+64).chr }
121
-
122
- msg = ""
123
- (code.length/5).times do
124
- msg << " " if msg.length > 0
125
- 5.times { msg << code.shift }
126
- end
127
-
128
- return msg
129
- end
130
-
131
- def decrypt( message )
132
- raise "bad decrypt message: #{message.inspect}" if message =~ /[^A-Z ]/
133
-
134
- reset
135
- chars = message.split(//).reject { |c| c == " " }.map { |c| c[0] - 64 }
136
- key = generate_key( chars.length )
137
- chars.zip( key ).map { |c,k| ( k >= c ? c + 26 - k : c - k ) }.map { |c| (c+64).chr }.join
138
- end
139
-
140
- def generate_key( length )
141
- key = []
142
- length.times { key << @stream.next }
143
- key.map { |c| c[0] - 64 }
144
- end
145
- private :generate_key
146
-
147
- def reset
148
- @stream.deck = @algorithm.new_deck
149
- end
150
- private :reset
151
-
152
- end
153
-
154
- class Options
155
-
156
- attr_reader :strings
157
- attr_reader :keying_algorithm
158
-
159
- def initialize( argv = ARGV )
160
- @named_options = Hash.new
161
- @run_app = true
162
- @keying_algorithm = "unkeyed"
163
-
164
- OptionParser.new do |opts|
165
- opts.banner = "Usage: #{$0} [options] [strings]"
166
- opts.separator ""
167
-
168
- opts.on( "-o", "--option NAME=VALUE",
169
- "Specify a named value, for use by a component of the cipher."
170
- ) do |pair|
171
- name, value = pair.split( / *= */, 2 )
172
- @named_options[ name ] = value
173
- end
174
-
175
- opts.on( "-k", "--key NAME", "Specify the keying algorithm to use" ) do |value|
176
- @keying_algorithm = value
177
- end
178
-
179
- opts.separator ""
180
-
181
- opts.on_tail( "-h", "--help", "This help text" ) do
182
- puts opts
183
- @run_app = false
184
- end
185
-
186
- opts.parse!( argv )
187
- end
188
-
189
- @strings = argv
190
- end
191
-
192
- def []( value )
193
- @named_options[ value ]
194
- end
195
-
196
- def run_app?
197
- @run_app
198
- end
199
-
200
- end
201
-
202
-
203
- class BackwardsAlgorithm
204
-
205
- def new_deck
206
- deck = Deck.new
207
- deck.cards = deck.to_a.reverse
208
- deck
209
- end
210
-
211
- end
212
-
213
- class ShuffleAlgorithm
214
-
215
- attr_writer :options
216
-
217
- def new_deck
218
- deck = Deck.new
219
- cards = deck.to_a
220
-
221
- seed = ( @options[ "seed" ] || 0 ).to_i
222
- srand seed
223
-
224
- 7.times { cards.sort! { rand(3)-1 } }
225
- deck.cards = cards
226
-
227
- return deck
228
- end
229
-
230
- end
@@ -1,24 +0,0 @@
1
- class CLI
2
-
3
- ENCRYPTED = /^([A-Z]{5} )*[A-Z]{5}$/
4
-
5
- attr_writer :cipher
6
- attr_writer :options
7
-
8
- def run
9
- return unless @options.run_app?
10
-
11
- @cipher.use_algorithm @options.keying_algorithm
12
-
13
- @options.strings.each do |arg|
14
- if arg =~ ENCRYPTED
15
- puts arg.inspect
16
- puts " (decrypt)--> #{@cipher.decrypt(arg).inspect}"
17
- else
18
- puts arg.inspect
19
- puts " (encrypt)--> #{@cipher.encrypt(arg).inspect}"
20
- end
21
- end
22
- end
23
-
24
- end
@@ -1,30 +0,0 @@
1
- $: << File.join( File.dirname( __FILE__ ), "..", "lib" )
2
- require 'test/unit'
3
- require 'cipher'
4
-
5
- class TC_Deck < Test::Unit::TestCase
6
-
7
- def setup
8
- @deck = Deck.new
9
- end
10
-
11
- def test_content
12
- expected = (1..52).to_a + [ "A", "B" ]
13
- assert_equal expected, @deck.to_a
14
- end
15
-
16
- def test_shuffle
17
- @deck.cipher_shuffle!
18
- expected = (2..52).to_a + [ "A", "B", 1 ]
19
- assert_equal expected, @deck.to_a
20
- end
21
-
22
- def test_letter
23
- expected = %w{ D W J nil X H Y R F D G }
24
- expected.each do |expected_letter|
25
- @deck.cipher_shuffle!
26
- assert_equal expected_letter, @deck.cipher_letter || "nil"
27
- end
28
- end
29
-
30
- end
@@ -1,19 +0,0 @@
1
- $: << File.join( File.dirname( __FILE__ ), "..", "lib" )
2
- require 'test/unit'
3
- require 'cipher'
4
-
5
- class TC_KeyStream < Test::Unit::TestCase
6
-
7
- def setup
8
- @stream = KeyStream.new
9
- @stream.deck = Deck.new
10
- end
11
-
12
- def test_next
13
- expected = %w{ D W J X H Y R F D G }
14
- expected.each do |expected_letter|
15
- assert_equal expected_letter, @stream.next
16
- end
17
- end
18
-
19
- end
@@ -1,31 +0,0 @@
1
- $: << File.join( File.dirname( __FILE__ ), "..", "lib" )
2
- require 'test/unit'
3
- require 'cipher'
4
-
5
- class TC_KeyingAlgorithms < Test::Unit::TestCase
6
-
7
- class MockRegistry
8
- def service( name )
9
- return "found" if name == "something.mock"
10
- return nil
11
- end
12
- end
13
-
14
- def setup
15
- @algorithms = KeyingAlgorithms.new
16
- @algorithms.algorithms = { "mock" => "something.mock" }
17
- @algorithms.registry = MockRegistry.new
18
- end
19
-
20
- def test_get_not_found
21
- assert_raise( RuntimeError ) do
22
- @algorithms.get( "bogus" )
23
- end
24
- end
25
-
26
- def test_get_found
27
- svc = @algorithms.get( "mock" )
28
- assert_equal svc, "found"
29
- end
30
-
31
- end
@@ -1,66 +0,0 @@
1
- $: << File.join( File.dirname( __FILE__ ), "..", "lib" )
2
- require 'test/unit'
3
- require 'cipher'
4
-
5
- class TC_SolitaireCipher < Test::Unit::TestCase
6
-
7
- class MockAlgorithms
8
- def get( name )
9
- MockAlgorithm.new
10
- end
11
- end
12
-
13
- class MockDeck
14
- def cipher_shuffle!
15
- end
16
-
17
- def cipher_letter
18
- "X"
19
- end
20
- end
21
-
22
- class MockAlgorithm
23
- def new_deck
24
- MockDeck.new
25
- end
26
- end
27
-
28
- def setup
29
- @cipher = SolitaireCipher.new( UnkeyedAlgorithm.new )
30
- @cipher.algorithms = MockAlgorithms.new
31
- @cipher.stream = KeyStream.new
32
- end
33
-
34
- def test_use_algorithm
35
- @cipher.use_algorithm "mock"
36
- assert_equal "FCJJM", @cipher.encrypt( "HELLO" )
37
- assert_equal "JGNNQ", @cipher.decrypt( "HELLO" )
38
- end
39
-
40
- def test_encrypt
41
- msg = "Code in Ruby! Live longer."
42
- expected = "GLNCQ MJAFF FVOMB JIYCB"
43
- assert_equal expected, @cipher.encrypt( msg )
44
- end
45
-
46
- def test_decrypt_bad
47
- assert_raise( RuntimeError ) do
48
- @cipher.decrypt( "not good" )
49
- end
50
-
51
- assert_raise( RuntimeError ) do
52
- @cipher.decrypt( "BOGUS 12345" )
53
- end
54
- end
55
-
56
- def test_decrypt_good
57
- msg = "CLEPK HHNIY CFPWH FDFEH"
58
- expected = "YOURCIPHERISWORKINGX"
59
- assert_equal expected, @cipher.decrypt( msg )
60
-
61
- msg = "ABVAW LWZSY OORYK DUPVH"
62
- expected = "WELCOMETORUBYQUIZXXX"
63
- assert_equal expected, @cipher.decrypt( msg )
64
- end
65
-
66
- end
@@ -1,17 +0,0 @@
1
- $: << File.join( File.dirname( __FILE__ ), "..", "lib" )
2
- require 'test/unit'
3
- require 'cipher'
4
-
5
- class TC_UnkeyedAlgorithm < Test::Unit::TestCase
6
-
7
- def setup
8
- @algo = UnkeyedAlgorithm.new
9
- end
10
-
11
- def test_new_deck
12
- expected = (1..52).to_a + [ "A", "B" ]
13
- deck = @algo.new_deck
14
- assert_equal expected, deck.to_a
15
- end
16
-
17
- end
@@ -1,2 +0,0 @@
1
- Dir.chdir File.dirname( __FILE__ )
2
- Dir["tc_*.rb"].each { |test| load test }