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
@@ -0,0 +1,86 @@
1
+ module Zip
2
+ class EntrySet #:nodoc:all
3
+ include Enumerable
4
+ attr_accessor :entry_set, :entry_order
5
+
6
+ def initialize(an_enumerable = [])
7
+ super()
8
+ @entry_set = {}
9
+ @entry_order = []
10
+ an_enumerable.each { |o| push(o) }
11
+ end
12
+
13
+ def include?(entry)
14
+ @entry_set.include?(to_key(entry))
15
+ end
16
+
17
+ def find_entry(entry)
18
+ @entry_set[to_key(entry)]
19
+ end
20
+
21
+ def <<(entry)
22
+ @entry_order.delete(to_key(entry))
23
+ @entry_order << to_key(entry)
24
+ @entry_set[to_key(entry)] = entry
25
+ end
26
+
27
+ alias :push :<<
28
+
29
+ def size
30
+ @entry_set.size
31
+ end
32
+
33
+ alias :length :size
34
+
35
+ def delete(entry)
36
+ if @entry_order.delete(to_key(entry)) && @entry_set.delete(to_key(entry))
37
+ entry
38
+ else
39
+ nil
40
+ end
41
+ end
42
+
43
+ def each(&block)
44
+ @entry_order.each do |key|
45
+ block.call @entry_set[key]
46
+ end
47
+ end
48
+
49
+ def entries
50
+ @entry_order.map { |key| @entry_set[key] }
51
+ end
52
+
53
+ # deep clone
54
+ def dup
55
+ EntrySet.new(@entry_order.map { |key| @entry_set[key].dup })
56
+ end
57
+
58
+ def ==(other)
59
+ return false unless other.kind_of?(EntrySet)
60
+ @entry_set == other.entry_set && @entry_order == other.entry_order
61
+ end
62
+
63
+ def parent(entry)
64
+ @entry_set[to_key(entry.parent_as_string)]
65
+ end
66
+
67
+ def glob(pattern, flags = ::File::FNM_PATHNAME|::File::FNM_DOTMATCH)
68
+ entries.map do |entry|
69
+ next nil unless ::File.fnmatch(pattern, entry.name.chomp('/'), flags)
70
+ yield(entry) if block_given?
71
+ entry
72
+ end.compact
73
+ end
74
+
75
+ protected
76
+
77
+ private
78
+ def to_key(entry)
79
+ entry.to_s.sub(/\/$/, '')
80
+ end
81
+ end
82
+ end
83
+
84
+ # Copyright (C) 2002, 2003 Thomas Sondergaard
85
+ # rubyzip is free software; you can redistribute it and/or
86
+ # modify it under the terms of the ruby license.
@@ -0,0 +1,8 @@
1
+ module Zip
2
+ class ZipError < StandardError; end
3
+ class ZipEntryExistsError < ZipError; end
4
+ class ZipDestinationFileExistsError < ZipError; end
5
+ class ZipCompressionMethodError < ZipError; end
6
+ class ZipEntryNameError < ZipError; end
7
+ class ZipInternalError < ZipError; end
8
+ end
@@ -0,0 +1,90 @@
1
+ module Zip
2
+ class ExtraField < Hash
3
+ ID_MAP = {}
4
+
5
+ def initialize(binstr = nil)
6
+ binstr and merge(binstr)
7
+ end
8
+
9
+ def extra_field_type_exist(binstr, id, len, i)
10
+ field_name = ID_MAP[id].name
11
+ if self.member?(field_name)
12
+ self[field_name].merge(binstr[i, len + 4])
13
+ else
14
+ field_obj = ID_MAP[id].new(binstr[i, len + 4])
15
+ self[field_name] = field_obj
16
+ end
17
+ end
18
+
19
+ def extra_field_type_unknown(binstr, len, i)
20
+ create_unknown_item unless self['Unknown']
21
+ if !len || len + 4 > binstr[i..-1].bytesize
22
+ self['Unknown'] << binstr[i..-1]
23
+ return
24
+ end
25
+ self['Unknown'] << binstr[i, len + 4]
26
+ end
27
+
28
+ def create_unknown_item
29
+ s = ''
30
+ class << s
31
+ alias_method :to_c_dir_bin, :to_s
32
+ alias_method :to_local_bin, :to_s
33
+ end
34
+ self['Unknown'] = s
35
+ end
36
+
37
+ def merge(binstr)
38
+ return if binstr.empty?
39
+ i = 0
40
+ while i < binstr.bytesize
41
+ id = binstr[i, 2]
42
+ len = binstr[i + 2, 2].to_s.unpack('v').first
43
+ if id && ID_MAP.member?(id)
44
+ extra_field_type_exist(binstr, id, len, i)
45
+ elsif id
46
+ create_unknown_item unless self['Unknown']
47
+ break unless extra_field_type_unknown(binstr, len, i)
48
+ end
49
+ i += len + 4
50
+ end
51
+ end
52
+
53
+ def create(name)
54
+ unless field_class = ID_MAP.values.find { |k| k.name == name }
55
+ raise ZipError, "Unknown extra field '#{name}'"
56
+ end
57
+ self[name] = field_class.new
58
+ end
59
+
60
+ def to_local_bin
61
+ self.map { |_, v| v.to_local_bin }.join
62
+ end
63
+
64
+ alias :to_s :to_local_bin
65
+
66
+ def to_c_dir_bin
67
+ self.map { |_, v| v.to_c_dir_bin }.join
68
+ end
69
+
70
+ def c_dir_length
71
+ to_c_dir_bin.bytesize
72
+ end
73
+
74
+ def local_length
75
+ to_local_bin.bytesize
76
+ end
77
+
78
+ alias :c_dir_size :c_dir_length
79
+ alias :local_size :local_length
80
+ alias :length :local_length
81
+ alias :size :local_length
82
+ end
83
+ end
84
+
85
+ require 'zip/extra_field/generic'
86
+ require 'zip/extra_field/universal_time'
87
+ require 'zip/extra_field/unix'
88
+ # Copyright (C) 2002, 2003 Thomas Sondergaard
89
+ # rubyzip is free software; you can redistribute it and/or
90
+ # modify it under the terms of the ruby license.
@@ -0,0 +1,43 @@
1
+ module Zip
2
+ class ExtraField::Generic
3
+ def self.register_map
4
+ if self.const_defined?(:HEADER_ID)
5
+ ::Zip::ExtraField::ID_MAP[self.const_get(:HEADER_ID)] = self
6
+ end
7
+ end
8
+
9
+ def self.name
10
+ self.to_s.split("::")[-1]
11
+ end
12
+
13
+ # return field [size, content] or false
14
+ def initial_parse(binstr)
15
+ if !binstr
16
+ # If nil, start with empty.
17
+ return false
18
+ elsif binstr[0, 2] != self.class.const_get(:HEADER_ID)
19
+ $stderr.puts "Warning: weired extra feild header ID. skip parsing"
20
+ return false
21
+ end
22
+ [binstr[2, 2].unpack("v")[0], binstr[4..-1]]
23
+ end
24
+
25
+ def ==(other)
26
+ return false if self.class != other.class
27
+ each do |k, v|
28
+ v != other[k] and return false
29
+ end
30
+ true
31
+ end
32
+
33
+ def to_local_bin
34
+ s = pack_for_local
35
+ self.class.const_get(:HEADER_ID) + [s.bytesize].pack("v") + s
36
+ end
37
+
38
+ def to_c_dir_bin
39
+ s = pack_for_c_dir
40
+ self.class.const_get(:HEADER_ID) + [s.bytesize].pack("v") + s
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,47 @@
1
+ module Zip
2
+ # Info-ZIP Additional timestamp field
3
+ class ExtraField::UniversalTime < ExtraField::Generic
4
+ HEADER_ID = "UT"
5
+ register_map
6
+
7
+ def initialize(binstr = nil)
8
+ @ctime = nil
9
+ @mtime = nil
10
+ @atime = nil
11
+ @flag = nil
12
+ binstr and merge(binstr)
13
+ end
14
+
15
+ attr_accessor :atime, :ctime, :mtime, :flag
16
+
17
+ def merge(binstr)
18
+ return if binstr.empty?
19
+ size, content = initial_parse(binstr)
20
+ size or return
21
+ @flag, mtime, atime, ctime = content.unpack("CVVV")
22
+ mtime and @mtime ||= ::Zip::DOSTime.at(mtime)
23
+ atime and @atime ||= ::Zip::DOSTime.at(atime)
24
+ ctime and @ctime ||= ::Zip::DOSTime.at(ctime)
25
+ end
26
+
27
+ def ==(other)
28
+ @mtime == other.mtime &&
29
+ @atime == other.atime &&
30
+ @ctime == other.ctime
31
+ end
32
+
33
+ def pack_for_local
34
+ s = [@flag].pack("C")
35
+ @flag & 1 != 0 and s << [@mtime.to_i].pack("V")
36
+ @flag & 2 != 0 and s << [@atime.to_i].pack("V")
37
+ @flag & 4 != 0 and s << [@ctime.to_i].pack("V")
38
+ s
39
+ end
40
+
41
+ def pack_for_c_dir
42
+ s = [@flag].pack("C")
43
+ @flag & 1 == 1 and s << [@mtime.to_i].pack("V")
44
+ s
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,39 @@
1
+ module Zip
2
+ # Info-ZIP Extra for UNIX uid/gid
3
+ class ExtraField::IUnix < ExtraField::Generic
4
+ HEADER_ID = "Ux"
5
+ register_map
6
+
7
+ def initialize(binstr = nil)
8
+ @uid = 0
9
+ @gid = 0
10
+ binstr and merge(binstr)
11
+ end
12
+
13
+ attr_accessor :uid, :gid
14
+
15
+ def merge(binstr)
16
+ return if binstr.empty?
17
+ size, content = initial_parse(binstr)
18
+ # size: 0 for central directory. 4 for local header
19
+ return if (!size || size == 0)
20
+ uid, gid = content.unpack("vv")
21
+ @uid ||= uid
22
+ @gid ||= gid
23
+ end
24
+
25
+ def ==(other)
26
+ @uid == other.uid &&
27
+ @gid == other.gid
28
+ end
29
+
30
+ def pack_for_local
31
+ [@uid, @gid].pack("vv")
32
+ end
33
+
34
+ def pack_for_c_dir
35
+ ""
36
+ end
37
+ end
38
+
39
+ end
@@ -42,9 +42,13 @@ module Zip
42
42
  # ZipFileSystem offers an alternative API that emulates ruby's
43
43
  # interface for accessing the filesystem, ie. the File and Dir classes.
44
44
 
45
- class ZipFile < ZipCentralDirectory
45
+ class File < CentralDirectory
46
46
 
47
- CREATE = 1
47
+ CREATE = 1
48
+ SPLIT_SIGNATURE = 0x08074b50
49
+ MAX_SEGMENT_SIZE = 3221225472
50
+ MIN_SEGMENT_SIZE = 65536
51
+ DATA_BUFFER_SIZE = 8192
48
52
 
49
53
  attr_reader :name
50
54
 
@@ -59,24 +63,25 @@ module Zip
59
63
  # a new archive if it doesn't exist already.
60
64
  def initialize(fileName, create = nil, buffer = false)
61
65
  super()
62
- @name = fileName
66
+ @name = fileName
63
67
  @comment = ""
68
+ @create = create
64
69
  case
65
- when ::File.exists?(fileName) && !buffer
66
- ::File.open(name, "rb") do |f|
67
- read_from_stream(f)
68
- end
69
- when create
70
- @entrySet = ZipEntrySet.new
71
- else
72
- raise ZipError, "File #{fileName} not found"
70
+ when ::File.exists?(fileName) && !buffer
71
+ @create = nil
72
+ ::File.open(name, "rb") do |f|
73
+ read_from_stream(f)
74
+ end
75
+ when create
76
+ @entry_set = EntrySet.new
77
+ else
78
+ raise ZipError, "File #{fileName} not found"
73
79
  end
74
- @create = create
75
- @storedEntries = @entrySet.dup
76
- @storedComment = @comment
77
- @restore_ownership = false
80
+ @storedEntries = @entry_set.dup
81
+ @storedComment = @comment
82
+ @restore_ownership = false
78
83
  @restore_permissions = false
79
- @restore_times = true
84
+ @restore_times = true
80
85
  end
81
86
 
82
87
  class << self
@@ -84,7 +89,7 @@ module Zip
84
89
  # to the block and is automatically closed afterwards just as with
85
90
  # ruby's builtin File.open method.
86
91
  def open(fileName, create = nil)
87
- zf = ZipFile.new(fileName, create)
92
+ zf = ::Zip::File.new(fileName, create)
88
93
  if block_given?
89
94
  begin
90
95
  yield zf
@@ -98,7 +103,7 @@ module Zip
98
103
 
99
104
  # Same as #open. But outputs data to a buffer instead of a file
100
105
  def add_buffer
101
- zf = ZipFile.new('', true, true)
106
+ zf = ::Zip::File.new('', true, true)
102
107
  yield zf
103
108
  zf.write_buffer
104
109
  end
@@ -108,7 +113,7 @@ module Zip
108
113
  # (This can be used to extract data from a
109
114
  # downloaded zip archive without first saving it to disk.)
110
115
  def open_buffer(io)
111
- zf = ZipFile.new('',true,true)
116
+ zf = ::Zip::File.new('', true, true)
112
117
  if io.is_a? IO
113
118
  zf.read_from_stream(io)
114
119
  elsif io.is_a? String
@@ -132,9 +137,83 @@ module Zip
132
137
  zipFile.each(&block)
133
138
  end
134
139
  end
140
+
141
+ def get_segment_size_for_split(segment_size)
142
+ case
143
+ when MIN_SEGMENT_SIZE > segment_size
144
+ MIN_SEGMENT_SIZE
145
+ when MAX_SEGMENT_SIZE < segment_size
146
+ MAX_SEGMENT_SIZE
147
+ else
148
+ segment_size
149
+ end
150
+ end
151
+
152
+ def get_partial_zip_file_name(zip_file_name, partial_zip_file_name)
153
+ partial_zip_file_name = zip_file_name.sub(/#{::File.basename(zip_file_name)}\z/,
154
+ partial_zip_file_name + ::File.extname(zip_file_name)) unless partial_zip_file_name.nil?
155
+ partial_zip_file_name ||= zip_file_name
156
+ partial_zip_file_name
157
+ end
158
+
159
+ def get_segment_count_for_split(zip_file_size, segment_size)
160
+ (zip_file_size / segment_size).to_i + (zip_file_size % segment_size == 0 ? 0 : 1)
161
+ end
162
+
163
+ def put_split_signature(szip_file, segment_size)
164
+ signature_packed = [SPLIT_SIGNATURE].pack('V')
165
+ szip_file << signature_packed
166
+ segment_size - signature_packed.size
167
+ end
168
+
169
+ #
170
+ # TODO: Make the code more understandable
171
+ #
172
+ def save_splited_part(zip_file, partial_zip_file_name, zip_file_size, szip_file_index, segment_size, segment_count)
173
+ ssegment_size = zip_file_size - zip_file.pos
174
+ ssegment_size = segment_size if ssegment_size > segment_size
175
+ szip_file_name = "#{partial_zip_file_name}.#{'%03d'%(szip_file_index)}"
176
+ ::File.open(szip_file_name, 'wb') do |szip_file|
177
+ if szip_file_index == 1
178
+ ssegment_size = put_split_signature(szip_file, segment_size)
179
+ end
180
+ chunk_bytes = 0
181
+ until ssegment_size == chunk_bytes || zip_file.eof?
182
+ segment_bytes_left = ssegment_size - chunk_bytes
183
+ buffer_size = segment_bytes_left < DATA_BUFFER_SIZE ? segment_bytes_left : DATA_BUFFER_SIZE
184
+ chunk = zip_file.read(buffer_size)
185
+ chunk_bytes += buffer_size
186
+ szip_file << chunk
187
+ # Info for track splitting
188
+ yield segment_count, szip_file_index, chunk_bytes, ssegment_size if block_given?
189
+ end
190
+ end
191
+ end
192
+
193
+ # Splits an archive into parts with segment size
194
+ def split(zip_file_name, segment_size = MAX_SEGMENT_SIZE, delete_zip_file = true, partial_zip_file_name = nil)
195
+ raise ZipError, "File #{zip_file_name} not found" unless ::File.exists?(zip_file_name)
196
+ raise Errno::ENOENT, zip_file_name unless ::File.readable?(zip_file_name)
197
+ zip_file_size = ::File.size(zip_file_name)
198
+ segment_size = get_segment_size_for_split(segment_size)
199
+ return if zip_file_size <= segment_size
200
+ segment_count = get_segment_count_for_split(zip_file_size, segment_size)
201
+ # Checking for correct zip structure
202
+ self.open(zip_file_name) {}
203
+ partial_zip_file_name = get_partial_zip_file_name(zip_file_name, partial_zip_file_name)
204
+ szip_file_index = 0
205
+ ::File.open(zip_file_name, 'rb') do |zip_file|
206
+ until zip_file.eof?
207
+ szip_file_index += 1
208
+ save_splited_part(zip_file, partial_zip_file_name, zip_file_size, szip_file_index, segment_size, segment_count)
209
+ end
210
+ end
211
+ ::File.delete(zip_file_name) if delete_zip_file
212
+ szip_file_index
213
+ end
135
214
  end
136
215
 
137
- # Returns the zip files comment, if it has one
216
+ # Returns the zip files comment, if it has one
138
217
  attr_accessor :comment
139
218
 
140
219
  # Returns an input stream to the specified entry. If a block is passed
@@ -148,14 +227,14 @@ module Zip
148
227
  # the stream object is passed to the block and the stream is automatically
149
228
  # closed afterwards just as with ruby's builtin File.open method.
150
229
  def get_output_stream(entry, permissionInt = nil, &aProc)
151
- newEntry = entry.kind_of?(ZipEntry) ? entry : ZipEntry.new(@name, entry.to_s)
230
+ newEntry = entry.kind_of?(Entry) ? entry : Entry.new(@name, entry.to_s)
152
231
  if newEntry.directory?
153
232
  raise ArgumentError,
154
- "cannot open stream to directory entry - '#{newEntry}'"
233
+ "cannot open stream to directory entry - '#{newEntry}'"
155
234
  end
156
235
  newEntry.unix_perms = permissionInt
157
- zipStreamableEntry = ZipStreamableStream.new(newEntry)
158
- @entrySet << zipStreamableEntry
236
+ zipStreamableEntry = StreamableStream.new(newEntry)
237
+ @entry_set << zipStreamableEntry
159
238
  zipStreamableEntry.get_output_stream(&aProc)
160
239
  end
161
240
 
@@ -170,26 +249,26 @@ module Zip
170
249
  end
171
250
 
172
251
  # Convenience method for adding the contents of a file to the archive
173
- def add(entry, srcPath, &continueOnExistsProc)
174
- continueOnExistsProc ||= proc { Zip.options[:continue_on_exists_proc] }
175
- check_entry_exists(entry, continueOnExistsProc, "add")
176
- newEntry = entry.kind_of?(ZipEntry) ? entry : ZipEntry.new(@name, entry.to_s)
252
+ def add(entry, srcPath, &continue_on_exists_proc)
253
+ continue_on_exists_proc ||= proc { Zip.continue_on_exists_proc }
254
+ check_entry_exists(entry, continue_on_exists_proc, "add")
255
+ newEntry = entry.kind_of?(Entry) ? entry : Entry.new(@name, entry.to_s)
177
256
  newEntry.gather_fileinfo_from_srcpath(srcPath)
178
- @entrySet << newEntry
257
+ @entry_set << newEntry
179
258
  end
180
259
 
181
260
  # Removes the specified entry.
182
261
  def remove(entry)
183
- @entrySet.delete(get_entry(entry))
262
+ @entry_set.delete(get_entry(entry))
184
263
  end
185
264
 
186
265
  # Renames the specified entry.
187
- def rename(entry, newName, &continueOnExistsProc)
266
+ def rename(entry, new_name, &continue_on_exists_proc)
188
267
  foundEntry = get_entry(entry)
189
- check_entry_exists(newName, continueOnExistsProc, "rename")
190
- @entrySet.delete(foundEntry)
191
- foundEntry.name = newName
192
- @entrySet << foundEntry
268
+ check_entry_exists(new_name, continue_on_exists_proc, 'rename')
269
+ @entry_set.delete(foundEntry)
270
+ foundEntry.name = new_name
271
+ @entry_set << foundEntry
193
272
  end
194
273
 
195
274
  # Replaces the specified entry with the contents of srcPath (from
@@ -200,11 +279,11 @@ module Zip
200
279
  add(entry, srcPath)
201
280
  end
202
281
 
203
- # Extracts entry to file destPath.
204
- def extract(entry, destPath, &onExistsProc)
205
- onExistsProc ||= proc { Zip.options[:on_exists_proc] }
206
- foundEntry = get_entry(entry)
207
- foundEntry.extract(destPath, &onExistsProc)
282
+ # Extracts entry to file dest_path.
283
+ def extract(entry, dest_path, &block)
284
+ block ||= proc { ::Zip.on_exists_proc }
285
+ found_entry = get_entry(entry)
286
+ found_entry.extract(dest_path, &block)
208
287
  end
209
288
 
210
289
  # Commits changes that has been made since the previous commit to
@@ -213,10 +292,10 @@ module Zip
213
292
  return if !commit_required?
214
293
  on_success_replace(name) {
215
294
  |tmpFile|
216
- ZipOutputStream.open(tmpFile) {
295
+ OutputStream.open(tmpFile) {
217
296
  |zos|
218
297
 
219
- @entrySet.each {
298
+ @entry_set.each {
220
299
  |e|
221
300
  e.write_to_zip_output_stream(zos)
222
301
  e.dirty = false
@@ -230,8 +309,8 @@ module Zip
230
309
 
231
310
  # Write buffer write changes to buffer and return
232
311
  def write_buffer
233
- buffer = ZipOutputStream.write_buffer do |zos|
234
- @entrySet.each { |e| e.write_to_zip_output_stream(zos) }
312
+ buffer = OutputStream.write_buffer do |zos|
313
+ @entry_set.each { |e| e.write_to_zip_output_stream(zos) }
235
314
  zos.comment = comment
236
315
  end
237
316
  return buffer
@@ -245,21 +324,21 @@ module Zip
245
324
  # Returns true if any changes has been made to this archive since
246
325
  # the previous commit
247
326
  def commit_required?
248
- @entrySet.each do |e|
327
+ @entry_set.each do |e|
249
328
  return true if e.dirty
250
329
  end
251
- @comment != @storedComment || @entrySet != @storedEntries || @create == ZipFile::CREATE
330
+ @comment != @storedComment || @entry_set != @storedEntries || @create == File::CREATE
252
331
  end
253
332
 
254
333
  # Searches for entry with the specified name. Returns nil if
255
334
  # no entry is found. See also get_entry
256
335
  def find_entry(entry_name)
257
- @entrySet.find_entry(entry_name)
336
+ @entry_set.find_entry(entry_name)
258
337
  end
259
338
 
260
339
  # Searches for entries given a glob
261
- def glob(*args,&block)
262
- @entrySet.glob(*args,&block)
340
+ def glob(*args, &block)
341
+ @entry_set.glob(*args, &block)
263
342
  end
264
343
 
265
344
  # Searches for an entry just as find_entry, but throws Errno::ENOENT
@@ -269,9 +348,9 @@ module Zip
269
348
  unless selectedEntry
270
349
  raise Errno::ENOENT, entry
271
350
  end
272
- selectedEntry.restore_ownership = @restore_ownership
351
+ selectedEntry.restore_ownership = @restore_ownership
273
352
  selectedEntry.restore_permissions = @restore_permissions
274
- selectedEntry.restore_times = @restore_times
353
+ selectedEntry.restore_times = @restore_times
275
354
  selectedEntry
276
355
  end
277
356
 
@@ -282,31 +361,31 @@ module Zip
282
361
  end
283
362
  entryName = entryName.dup.to_s
284
363
  entryName << '/' unless entryName.end_with?('/')
285
- @entrySet << ZipStreamableDirectory.new(@name, entryName, nil, permissionInt)
364
+ @entry_set << StreamableDirectory.new(@name, entryName, nil, permissionInt)
286
365
  end
287
366
 
288
367
  private
289
368
 
290
369
  def is_directory(newEntry, srcPath)
291
370
  srcPathIsDirectory = ::File.directory?(srcPath)
292
- if newEntry.is_directory && ! srcPathIsDirectory
371
+ if newEntry.is_directory && !srcPathIsDirectory
293
372
  raise ArgumentError,
294
- "entry name '#{newEntry}' indicates directory entry, but "+
295
- "'#{srcPath}' is not a directory"
373
+ "entry name '#{newEntry}' indicates directory entry, but "+
374
+ "'#{srcPath}' is not a directory"
296
375
  elsif !newEntry.is_directory && srcPathIsDirectory
297
376
  newEntry.name += "/"
298
377
  end
299
378
  newEntry.is_directory && srcPathIsDirectory
300
379
  end
301
380
 
302
- def check_entry_exists(entryName, continueOnExistsProc, procedureName)
303
- continueOnExistsProc ||= proc { Zip.options[:continue_on_exists_proc] }
304
- if @entrySet.include?(entryName)
305
- if continueOnExistsProc.call
381
+ def check_entry_exists(entryName, continue_on_exists_proc, procedureName)
382
+ continue_on_exists_proc ||= proc { Zip.continue_on_exists_proc }
383
+ if @entry_set.include?(entryName)
384
+ if continue_on_exists_proc.call
306
385
  remove get_entry(entryName)
307
386
  else
308
387
  raise ZipEntryExistsError,
309
- procedureName + " failed. Entry #{entryName} already exists"
388
+ procedureName + " failed. Entry #{entryName} already exists"
310
389
  end
311
390
  end
312
391
  end
@@ -318,7 +397,7 @@ module Zip
318
397
  end
319
398
 
320
399
  def on_success_replace(aFilename)
321
- tmpfile = get_tempfile
400
+ tmpfile = get_tempfile
322
401
  tmpFilename = tmpfile.path
323
402
  tmpfile.close
324
403
  if yield tmpFilename