rubyzip 0.9.9 → 1.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rubyzip might be problematic. Click here for more details.

Files changed (46) hide show
  1. checksums.yaml +7 -0
  2. data/NEWS +9 -5
  3. data/README.md +79 -21
  4. data/Rakefile +1 -1
  5. data/lib/zip.rb +52 -0
  6. data/lib/zip/central_directory.rb +135 -0
  7. data/lib/zip/constants.rb +57 -7
  8. data/lib/zip/decompressor.rb +2 -2
  9. data/lib/zip/deflater.rb +11 -12
  10. data/lib/zip/dos_time.rb +9 -9
  11. data/lib/zip/entry.rb +609 -0
  12. data/lib/zip/entry_set.rb +86 -0
  13. data/lib/zip/errors.rb +8 -0
  14. data/lib/zip/extra_field.rb +90 -0
  15. data/lib/zip/extra_field/generic.rb +43 -0
  16. data/lib/zip/extra_field/universal_time.rb +47 -0
  17. data/lib/zip/extra_field/unix.rb +39 -0
  18. data/lib/zip/{zip_file.rb → file.rb} +140 -61
  19. data/lib/zip/{zipfilesystem.rb → filesystem.rb} +12 -12
  20. data/lib/zip/inflater.rb +24 -24
  21. data/lib/zip/{zip_input_stream.rb → input_stream.rb} +11 -10
  22. data/lib/zip/ioextras.rb +145 -123
  23. data/lib/zip/null_compressor.rb +1 -1
  24. data/lib/zip/null_decompressor.rb +5 -3
  25. data/lib/zip/null_input_stream.rb +2 -2
  26. data/lib/zip/{zip_output_stream.rb → output_stream.rb} +43 -41
  27. data/lib/zip/pass_thru_compressor.rb +2 -2
  28. data/lib/zip/pass_thru_decompressor.rb +17 -16
  29. data/lib/zip/{zip_streamable_directory.rb → streamable_directory.rb} +1 -1
  30. data/lib/zip/{zip_streamable_stream.rb → streamable_stream.rb} +2 -2
  31. data/lib/zip/version.rb +3 -0
  32. data/samples/example.rb +27 -5
  33. data/samples/example_filesystem.rb +2 -2
  34. data/samples/example_recursive.rb +1 -1
  35. data/samples/gtkRubyzip.rb +1 -1
  36. data/samples/qtzip.rb +2 -2
  37. data/samples/write_simple.rb +1 -1
  38. data/samples/zipfind.rb +1 -1
  39. metadata +29 -27
  40. data/lib/zip/settings.rb +0 -10
  41. data/lib/zip/tempfile_bugfixed.rb +0 -195
  42. data/lib/zip/zip.rb +0 -56
  43. data/lib/zip/zip_central_directory.rb +0 -135
  44. data/lib/zip/zip_entry.rb +0 -638
  45. data/lib/zip/zip_entry_set.rb +0 -77
  46. data/lib/zip/zip_extra_field.rb +0 -213
@@ -1,77 +0,0 @@
1
- module Zip
2
- class ZipEntrySet #:nodoc:all
3
- include Enumerable
4
-
5
- def initialize(anEnumerable = [])
6
- super()
7
- @entrySet = {}
8
- anEnumerable.each { |o| push(o) }
9
- end
10
-
11
- def include?(entry)
12
- @entrySet.include?(to_key(entry))
13
- end
14
-
15
- def find_entry(entry)
16
- @entrySet[to_key(entry)]
17
- end
18
-
19
- def <<(entry)
20
- @entrySet[to_key(entry)] = entry
21
- end
22
- alias :push :<<
23
-
24
- def size
25
- @entrySet.size
26
- end
27
-
28
- alias :length :size
29
-
30
- def delete(entry)
31
- @entrySet.delete(to_key(entry)) ? entry : nil
32
- end
33
-
34
- def each(&aProc)
35
- @entrySet.values.each(&aProc)
36
- end
37
-
38
- def entries
39
- @entrySet.values
40
- end
41
-
42
- # deep clone
43
- def dup
44
- ZipEntrySet.new(@entrySet.values.map { |e| e.dup })
45
- end
46
-
47
- def ==(other)
48
- return false unless other.kind_of?(ZipEntrySet)
49
- @entrySet == other.entrySet
50
- end
51
-
52
- def parent(entry)
53
- @entrySet[to_key(entry.parent_as_string)]
54
- end
55
-
56
- def glob(pattern, flags = ::File::FNM_PATHNAME|::File::FNM_DOTMATCH)
57
- entries.map do |entry|
58
- next nil unless ::File.fnmatch(pattern, entry.name.chomp('/'), flags)
59
- yield(entry) if block_given?
60
- entry
61
- end.compact
62
- end
63
-
64
- #TODO attr_accessor :auto_create_directories
65
- protected
66
- attr_accessor :entrySet
67
-
68
- private
69
- def to_key(entry)
70
- entry.to_s.sub(/\/$/, "")
71
- end
72
- end
73
- end
74
-
75
- # Copyright (C) 2002, 2003 Thomas Sondergaard
76
- # rubyzip is free software; you can redistribute it and/or
77
- # modify it under the terms of the ruby license.
@@ -1,213 +0,0 @@
1
- module Zip
2
- class ZipExtraField < Hash
3
- ID_MAP = {}
4
-
5
- # Meta class for extra fields
6
- class Generic
7
- def self.register_map
8
- if self.const_defined?(:HEADER_ID)
9
- ID_MAP[self.const_get(:HEADER_ID)] = self
10
- end
11
- end
12
-
13
- def self.name
14
- self.to_s.split("::")[-1]
15
- end
16
-
17
- # return field [size, content] or false
18
- def initial_parse(binstr)
19
- if ! binstr
20
- # If nil, start with empty.
21
- return false
22
- elsif binstr[0,2] != self.class.const_get(:HEADER_ID)
23
- $stderr.puts "Warning: weired extra feild header ID. skip parsing"
24
- return false
25
- end
26
- [binstr[2,2].unpack("v")[0], binstr[4..-1]]
27
- end
28
-
29
- def ==(other)
30
- return false if self.class != other.class
31
- each do |k, v|
32
- v != other[k] and return false
33
- end
34
- true
35
- end
36
-
37
- def to_local_bin
38
- s = pack_for_local
39
- self.class.const_get(:HEADER_ID) + [s.bytesize].pack("v") + s
40
- end
41
-
42
- def to_c_dir_bin
43
- s = pack_for_c_dir
44
- self.class.const_get(:HEADER_ID) + [s.bytesize].pack("v") + s
45
- end
46
- end
47
-
48
- # Info-ZIP Additional timestamp field
49
- class UniversalTime < Generic
50
- HEADER_ID = "UT"
51
- register_map
52
-
53
- def initialize(binstr = nil)
54
- @ctime = nil
55
- @mtime = nil
56
- @atime = nil
57
- @flag = nil
58
- binstr and merge(binstr)
59
- end
60
- attr_accessor :atime, :ctime, :mtime, :flag
61
-
62
- def merge(binstr)
63
- return if binstr.empty?
64
- size, content = initial_parse(binstr)
65
- size or return
66
- @flag, mtime, atime, ctime = content.unpack("CVVV")
67
- mtime and @mtime ||= DOSTime.at(mtime)
68
- atime and @atime ||= DOSTime.at(atime)
69
- ctime and @ctime ||= DOSTime.at(ctime)
70
- end
71
-
72
- def ==(other)
73
- @mtime == other.mtime &&
74
- @atime == other.atime &&
75
- @ctime == other.ctime
76
- end
77
-
78
- def pack_for_local
79
- s = [@flag].pack("C")
80
- @flag & 1 != 0 and s << [@mtime.to_i].pack("V")
81
- @flag & 2 != 0 and s << [@atime.to_i].pack("V")
82
- @flag & 4 != 0 and s << [@ctime.to_i].pack("V")
83
- s
84
- end
85
-
86
- def pack_for_c_dir
87
- s = [@flag].pack("C")
88
- @flag & 1 == 1 and s << [@mtime.to_i].pack("V")
89
- s
90
- end
91
- end
92
-
93
- # Info-ZIP Extra for UNIX uid/gid
94
- class IUnix < Generic
95
- HEADER_ID = "Ux"
96
- register_map
97
-
98
- def initialize(binstr = nil)
99
- @uid = 0
100
- @gid = 0
101
- binstr and merge(binstr)
102
- end
103
- attr_accessor :uid, :gid
104
-
105
- def merge(binstr)
106
- return if binstr.empty?
107
- size, content = initial_parse(binstr)
108
- # size: 0 for central directory. 4 for local header
109
- return if(!size || size == 0)
110
- uid, gid = content.unpack("vv")
111
- @uid ||= uid
112
- @gid ||= gid
113
- end
114
-
115
- def ==(other)
116
- @uid == other.uid &&
117
- @gid == other.gid
118
- end
119
-
120
- def pack_for_local
121
- [@uid, @gid].pack("vv")
122
- end
123
-
124
- def pack_for_c_dir
125
- ""
126
- end
127
- end
128
-
129
- ## start main of ZipExtraField < Hash
130
- def initialize(binstr = nil)
131
- binstr and merge(binstr)
132
- end
133
-
134
- def merge(binstr)
135
- return if binstr.empty?
136
- i = 0
137
- while i < binstr.bytesize
138
- id = binstr[i,2]
139
- len = binstr[i + 2,2].to_s.unpack("v")[0]
140
- if id && ID_MAP.member?(id)
141
- field_name = ID_MAP[id].name
142
- if self.member?(field_name)
143
- self[field_name].mergea(binstr[i, len + 4])
144
- else
145
- field_obj = ID_MAP[id].new(binstr[i, len + 4])
146
- self[field_name] = field_obj
147
- end
148
- elsif id
149
- unless self["Unknown"]
150
- s = ""
151
- class << s
152
- alias_method :to_c_dir_bin, :to_s
153
- alias_method :to_local_bin, :to_s
154
- end
155
- self["Unknown"] = s
156
- end
157
- if !len || len + 4 > binstr[i..-1].bytesize
158
- self["Unknown"] << binstr[i..-1]
159
- break
160
- end
161
- self["Unknown"] << binstr[i, len + 4]
162
- end
163
- i += len + 4
164
- end
165
- end
166
-
167
- def create(name)
168
- field_class = nil
169
- ID_MAP.each { |id, klass|
170
- if klass.name == name
171
- field_class = klass
172
- break
173
- end
174
- }
175
- if ! field_class
176
- raise ZipError, "Unknown extra field '#{name}'"
177
- end
178
- self[name] = field_class.new()
179
- end
180
-
181
- def to_local_bin
182
- s = ""
183
- each do |k, v|
184
- s << v.to_local_bin
185
- end
186
- s
187
- end
188
- alias :to_s :to_local_bin
189
-
190
- def to_c_dir_bin
191
- s = ""
192
- each do |k, v|
193
- s << v.to_c_dir_bin
194
- end
195
- s
196
- end
197
-
198
- def c_dir_length
199
- to_c_dir_bin.bytesize
200
- end
201
- def local_length
202
- to_local_bin.bytesize
203
- end
204
- alias :c_dir_size :c_dir_length
205
- alias :local_size :local_length
206
- alias :length :local_length
207
- alias :size :local_length
208
- end
209
- end
210
-
211
- # Copyright (C) 2002, 2003 Thomas Sondergaard
212
- # rubyzip is free software; you can redistribute it and/or
213
- # modify it under the terms of the ruby license.