rubyzip 1.3.0 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -8
  3. data/Rakefile +3 -0
  4. data/lib/zip.rb +4 -3
  5. data/lib/zip/central_directory.rb +9 -5
  6. data/lib/zip/constants.rb +52 -0
  7. data/lib/zip/crypto/decrypted_io.rb +40 -0
  8. data/lib/zip/crypto/traditional_encryption.rb +9 -9
  9. data/lib/zip/decompressor.rb +19 -1
  10. data/lib/zip/dos_time.rb +12 -7
  11. data/lib/zip/entry.rb +57 -38
  12. data/lib/zip/entry_set.rb +2 -0
  13. data/lib/zip/errors.rb +1 -0
  14. data/lib/zip/extra_field.rb +11 -9
  15. data/lib/zip/extra_field/generic.rb +10 -9
  16. data/lib/zip/extra_field/ntfs.rb +4 -0
  17. data/lib/zip/extra_field/old_unix.rb +3 -1
  18. data/lib/zip/extra_field/universal_time.rb +42 -12
  19. data/lib/zip/extra_field/unix.rb +3 -1
  20. data/lib/zip/extra_field/zip64.rb +4 -2
  21. data/lib/zip/file.rb +79 -54
  22. data/lib/zip/filesystem.rb +193 -177
  23. data/lib/zip/inflater.rb +24 -36
  24. data/lib/zip/input_stream.rb +33 -26
  25. data/lib/zip/ioextras.rb +1 -1
  26. data/lib/zip/ioextras/abstract_input_stream.rb +19 -8
  27. data/lib/zip/ioextras/abstract_output_stream.rb +1 -1
  28. data/lib/zip/null_decompressor.rb +1 -9
  29. data/lib/zip/output_stream.rb +14 -5
  30. data/lib/zip/pass_thru_compressor.rb +2 -2
  31. data/lib/zip/pass_thru_decompressor.rb +13 -22
  32. data/lib/zip/streamable_directory.rb +3 -3
  33. data/lib/zip/streamable_stream.rb +6 -10
  34. data/lib/zip/version.rb +1 -1
  35. data/samples/example.rb +2 -2
  36. data/samples/example_filesystem.rb +1 -1
  37. data/samples/gtk_ruby_zip.rb +19 -19
  38. data/samples/qtzip.rb +6 -6
  39. data/samples/write_simple.rb +2 -4
  40. data/samples/zipfind.rb +23 -22
  41. metadata +28 -169
  42. data/test/basic_zip_file_test.rb +0 -60
  43. data/test/case_sensitivity_test.rb +0 -69
  44. data/test/central_directory_entry_test.rb +0 -69
  45. data/test/central_directory_test.rb +0 -100
  46. data/test/crypto/null_encryption_test.rb +0 -57
  47. data/test/crypto/traditional_encryption_test.rb +0 -80
  48. data/test/data/WarnInvalidDate.zip +0 -0
  49. data/test/data/file1.txt +0 -46
  50. data/test/data/file1.txt.deflatedData +0 -0
  51. data/test/data/file2.txt +0 -1504
  52. data/test/data/globTest.zip +0 -0
  53. data/test/data/globTest/foo.txt +0 -0
  54. data/test/data/globTest/foo/bar/baz/foo.txt +0 -0
  55. data/test/data/globTest/food.txt +0 -0
  56. data/test/data/gpbit3stored.zip +0 -0
  57. data/test/data/mimetype +0 -1
  58. data/test/data/notzippedruby.rb +0 -7
  59. data/test/data/ntfs.zip +0 -0
  60. data/test/data/oddExtraField.zip +0 -0
  61. data/test/data/path_traversal/Makefile +0 -10
  62. data/test/data/path_traversal/jwilk/README.md +0 -5
  63. data/test/data/path_traversal/jwilk/absolute1.zip +0 -0
  64. data/test/data/path_traversal/jwilk/absolute2.zip +0 -0
  65. data/test/data/path_traversal/jwilk/dirsymlink.zip +0 -0
  66. data/test/data/path_traversal/jwilk/dirsymlink2a.zip +0 -0
  67. data/test/data/path_traversal/jwilk/dirsymlink2b.zip +0 -0
  68. data/test/data/path_traversal/jwilk/relative0.zip +0 -0
  69. data/test/data/path_traversal/jwilk/relative2.zip +0 -0
  70. data/test/data/path_traversal/jwilk/symlink.zip +0 -0
  71. data/test/data/path_traversal/relative1.zip +0 -0
  72. data/test/data/path_traversal/tilde.zip +0 -0
  73. data/test/data/path_traversal/tuzovakaoff/README.md +0 -3
  74. data/test/data/path_traversal/tuzovakaoff/absolutepath.zip +0 -0
  75. data/test/data/path_traversal/tuzovakaoff/symlink.zip +0 -0
  76. data/test/data/rubycode.zip +0 -0
  77. data/test/data/rubycode2.zip +0 -0
  78. data/test/data/test.xls +0 -0
  79. data/test/data/testDirectory.bin +0 -0
  80. data/test/data/zip64-sample.zip +0 -0
  81. data/test/data/zipWithDirs.zip +0 -0
  82. data/test/data/zipWithEncryption.zip +0 -0
  83. data/test/deflater_test.rb +0 -65
  84. data/test/encryption_test.rb +0 -42
  85. data/test/entry_set_test.rb +0 -163
  86. data/test/entry_test.rb +0 -154
  87. data/test/errors_test.rb +0 -35
  88. data/test/extra_field_test.rb +0 -76
  89. data/test/file_extract_directory_test.rb +0 -54
  90. data/test/file_extract_test.rb +0 -145
  91. data/test/file_permissions_test.rb +0 -65
  92. data/test/file_split_test.rb +0 -57
  93. data/test/file_test.rb +0 -666
  94. data/test/filesystem/dir_iterator_test.rb +0 -58
  95. data/test/filesystem/directory_test.rb +0 -139
  96. data/test/filesystem/file_mutating_test.rb +0 -87
  97. data/test/filesystem/file_nonmutating_test.rb +0 -508
  98. data/test/filesystem/file_stat_test.rb +0 -64
  99. data/test/gentestfiles.rb +0 -126
  100. data/test/inflater_test.rb +0 -14
  101. data/test/input_stream_test.rb +0 -182
  102. data/test/ioextras/abstract_input_stream_test.rb +0 -102
  103. data/test/ioextras/abstract_output_stream_test.rb +0 -106
  104. data/test/ioextras/fake_io_test.rb +0 -18
  105. data/test/local_entry_test.rb +0 -154
  106. data/test/output_stream_test.rb +0 -128
  107. data/test/pass_thru_compressor_test.rb +0 -30
  108. data/test/pass_thru_decompressor_test.rb +0 -14
  109. data/test/path_traversal_test.rb +0 -141
  110. data/test/samples/example_recursive_test.rb +0 -37
  111. data/test/settings_test.rb +0 -95
  112. data/test/test_helper.rb +0 -234
  113. data/test/unicode_file_names_and_comments_test.rb +0 -62
  114. data/test/zip64_full_test.rb +0 -51
  115. data/test/zip64_support_test.rb +0 -14
@@ -35,25 +35,25 @@ module Zip
35
35
 
36
36
  module FileSystem
37
37
  def initialize # :nodoc:
38
- mappedZip = ZipFileNameMapper.new(self)
39
- @zipFsDir = ZipFsDir.new(mappedZip)
40
- @zipFsFile = ZipFsFile.new(mappedZip)
41
- @zipFsDir.file = @zipFsFile
42
- @zipFsFile.dir = @zipFsDir
38
+ mapped_zip = ZipFileNameMapper.new(self)
39
+ @zip_fs_dir = ZipFsDir.new(mapped_zip)
40
+ @zip_fs_file = ZipFsFile.new(mapped_zip)
41
+ @zip_fs_dir.file = @zip_fs_file
42
+ @zip_fs_file.dir = @zip_fs_dir
43
43
  end
44
44
 
45
45
  # Returns a ZipFsDir which is much like ruby's builtin Dir (class)
46
46
  # object, except it works on the Zip::File on which this method is
47
47
  # invoked
48
48
  def dir
49
- @zipFsDir
49
+ @zip_fs_dir
50
50
  end
51
51
 
52
52
  # Returns a ZipFsFile which is much like ruby's builtin File (class)
53
53
  # object, except it works on the Zip::File on which this method is
54
54
  # invoked
55
55
  def file
56
- @zipFsFile
56
+ @zip_fs_file
57
57
  end
58
58
 
59
59
  # Instances of this class are normally accessed via the accessor
@@ -70,22 +70,22 @@ module Zip
70
70
  class << self
71
71
  def delegate_to_fs_file(*methods)
72
72
  methods.each do |method|
73
- class_eval <<-end_eval, __FILE__, __LINE__ + 1
73
+ class_eval <<-END_EVAL, __FILE__, __LINE__ + 1
74
74
  def #{method} # def file?
75
- @zipFsFile.#{method}(@entryName) # @zipFsFile.file?(@entryName)
75
+ @zip_fs_file.#{method}(@entry_name) # @zip_fs_file.file?(@entry_name)
76
76
  end # end
77
- end_eval
77
+ END_EVAL
78
78
  end
79
79
  end
80
80
  end
81
81
 
82
- def initialize(zipFsFile, entryName)
83
- @zipFsFile = zipFsFile
84
- @entryName = entryName
82
+ def initialize(zip_fs_file, entry_name)
83
+ @zip_fs_file = zip_fs_file
84
+ @entry_name = entry_name
85
85
  end
86
86
 
87
- def kind_of?(t)
88
- super || t == ::File::Stat
87
+ def kind_of?(type)
88
+ super || type == ::File::Stat
89
89
  end
90
90
 
91
91
  delegate_to_fs_file :file?, :directory?, :pipe?, :chardev?, :symlink?,
@@ -98,7 +98,7 @@ module Zip
98
98
  end
99
99
 
100
100
  def get_entry
101
- @zipFsFile.__send__(:get_entry, @entryName)
101
+ @zip_fs_file.__send__(:get_entry, @entry_name)
102
102
  end
103
103
  private :get_entry
104
104
 
@@ -168,28 +168,29 @@ module Zip
168
168
  end
169
169
  end
170
170
 
171
- def initialize(mappedZip)
172
- @mappedZip = mappedZip
171
+ def initialize(mapped_zip)
172
+ @mapped_zip = mapped_zip
173
173
  end
174
174
 
175
- def get_entry(fileName)
176
- unless exists?(fileName)
177
- raise Errno::ENOENT, "No such file or directory - #{fileName}"
175
+ def get_entry(filename)
176
+ unless exists?(filename)
177
+ raise Errno::ENOENT, "No such file or directory - #{filename}"
178
178
  end
179
- @mappedZip.find_entry(fileName)
179
+
180
+ @mapped_zip.find_entry(filename)
180
181
  end
181
182
  private :get_entry
182
183
 
183
- def unix_mode_cmp(fileName, mode)
184
- e = get_entry(fileName)
184
+ def unix_mode_cmp(filename, mode)
185
+ e = get_entry(filename)
185
186
  e.fstype == 3 && ((e.external_file_attributes >> 16) & mode) != 0
186
187
  rescue Errno::ENOENT
187
188
  false
188
189
  end
189
190
  private :unix_mode_cmp
190
191
 
191
- def exists?(fileName)
192
- expand_path(fileName) == '/' || !@mappedZip.find_entry(fileName).nil?
192
+ def exists?(filename)
193
+ expand_path(filename) == '/' || !@mapped_zip.find_entry(filename).nil?
193
194
  end
194
195
  alias exist? exists?
195
196
 
@@ -197,133 +198,133 @@ module Zip
197
198
  alias owned? exists?
198
199
  alias grpowned? exists?
199
200
 
200
- def readable?(fileName)
201
- unix_mode_cmp(fileName, 0o444)
201
+ def readable?(filename)
202
+ unix_mode_cmp(filename, 0o444)
202
203
  end
203
204
  alias readable_real? readable?
204
205
 
205
- def writable?(fileName)
206
- unix_mode_cmp(fileName, 0o222)
206
+ def writable?(filename)
207
+ unix_mode_cmp(filename, 0o222)
207
208
  end
208
209
  alias writable_real? writable?
209
210
 
210
- def executable?(fileName)
211
- unix_mode_cmp(fileName, 0o111)
211
+ def executable?(filename)
212
+ unix_mode_cmp(filename, 0o111)
212
213
  end
213
214
  alias executable_real? executable?
214
215
 
215
- def setuid?(fileName)
216
- unix_mode_cmp(fileName, 0o4000)
216
+ def setuid?(filename)
217
+ unix_mode_cmp(filename, 0o4000)
217
218
  end
218
219
 
219
- def setgid?(fileName)
220
- unix_mode_cmp(fileName, 0o2000)
220
+ def setgid?(filename)
221
+ unix_mode_cmp(filename, 0o2000)
221
222
  end
222
223
 
223
- def sticky?(fileName)
224
- unix_mode_cmp(fileName, 0o1000)
224
+ def sticky?(filename)
225
+ unix_mode_cmp(filename, 0o1000)
225
226
  end
226
227
 
227
228
  def umask(*args)
228
229
  ::File.umask(*args)
229
230
  end
230
231
 
231
- def truncate(_fileName, _len)
232
+ def truncate(_filename, _len)
232
233
  raise StandardError, 'truncate not supported'
233
234
  end
234
235
 
235
- def directory?(fileName)
236
- entry = @mappedZip.find_entry(fileName)
237
- expand_path(fileName) == '/' || (!entry.nil? && entry.directory?)
236
+ def directory?(filename)
237
+ entry = @mapped_zip.find_entry(filename)
238
+ expand_path(filename) == '/' || (!entry.nil? && entry.directory?)
238
239
  end
239
240
 
240
- def open(fileName, openMode = 'r', permissionInt = 0o644, &block)
241
- openMode.delete!('b') # ignore b option
242
- case openMode
241
+ def open(filename, mode = 'r', permissions = 0o644, &block)
242
+ mode.delete!('b') # ignore b option
243
+ case mode
243
244
  when 'r'
244
- @mappedZip.get_input_stream(fileName, &block)
245
+ @mapped_zip.get_input_stream(filename, &block)
245
246
  when 'w'
246
- @mappedZip.get_output_stream(fileName, permissionInt, &block)
247
+ @mapped_zip.get_output_stream(filename, permissions, &block)
247
248
  else
248
- raise StandardError, "openmode '#{openMode} not supported" unless openMode == 'r'
249
+ raise StandardError, "openmode '#{mode} not supported" unless mode == 'r'
249
250
  end
250
251
  end
251
252
 
252
- def new(fileName, openMode = 'r')
253
- open(fileName, openMode)
253
+ def new(filename, mode = 'r')
254
+ self.open(filename, mode)
254
255
  end
255
256
 
256
- def size(fileName)
257
- @mappedZip.get_entry(fileName).size
257
+ def size(filename)
258
+ @mapped_zip.get_entry(filename).size
258
259
  end
259
260
 
260
261
  # Returns nil for not found and nil for directories
261
- def size?(fileName)
262
- entry = @mappedZip.find_entry(fileName)
262
+ def size?(filename)
263
+ entry = @mapped_zip.find_entry(filename)
263
264
  entry.nil? || entry.directory? ? nil : entry.size
264
265
  end
265
266
 
266
- def chown(ownerInt, groupInt, *filenames)
267
- filenames.each do |fileName|
268
- e = get_entry(fileName)
267
+ def chown(owner, group, *filenames)
268
+ filenames.each do |filename|
269
+ e = get_entry(filename)
269
270
  e.extra.create('IUnix') unless e.extra.member?('IUnix')
270
- e.extra['IUnix'].uid = ownerInt
271
- e.extra['IUnix'].gid = groupInt
271
+ e.extra['IUnix'].uid = owner
272
+ e.extra['IUnix'].gid = group
272
273
  end
273
274
  filenames.size
274
275
  end
275
276
 
276
- def chmod(modeInt, *filenames)
277
- filenames.each do |fileName|
278
- e = get_entry(fileName)
277
+ def chmod(mode, *filenames)
278
+ filenames.each do |filename|
279
+ e = get_entry(filename)
279
280
  e.fstype = 3 # force convertion filesystem type to unix
280
- e.unix_perms = modeInt
281
- e.external_file_attributes = modeInt << 16
281
+ e.unix_perms = mode
282
+ e.external_file_attributes = mode << 16
282
283
  e.dirty = true
283
284
  end
284
285
  filenames.size
285
286
  end
286
287
 
287
- def zero?(fileName)
288
- sz = size(fileName)
288
+ def zero?(filename)
289
+ sz = size(filename)
289
290
  sz.nil? || sz == 0
290
291
  rescue Errno::ENOENT
291
292
  false
292
293
  end
293
294
 
294
- def file?(fileName)
295
- entry = @mappedZip.find_entry(fileName)
295
+ def file?(filename)
296
+ entry = @mapped_zip.find_entry(filename)
296
297
  !entry.nil? && entry.file?
297
298
  end
298
299
 
299
- def dirname(fileName)
300
- ::File.dirname(fileName)
300
+ def dirname(filename)
301
+ ::File.dirname(filename)
301
302
  end
302
303
 
303
- def basename(fileName)
304
- ::File.basename(fileName)
304
+ def basename(filename)
305
+ ::File.basename(filename)
305
306
  end
306
307
 
307
- def split(fileName)
308
- ::File.split(fileName)
308
+ def split(filename)
309
+ ::File.split(filename)
309
310
  end
310
311
 
311
312
  def join(*fragments)
312
313
  ::File.join(*fragments)
313
314
  end
314
315
 
315
- def utime(modifiedTime, *fileNames)
316
- fileNames.each do |fileName|
317
- get_entry(fileName).time = modifiedTime
316
+ def utime(modified_time, *filenames)
317
+ filenames.each do |filename|
318
+ get_entry(filename).time = modified_time
318
319
  end
319
320
  end
320
321
 
321
- def mtime(fileName)
322
- @mappedZip.get_entry(fileName).mtime
322
+ def mtime(filename)
323
+ @mapped_zip.get_entry(filename).mtime
323
324
  end
324
325
 
325
- def atime(fileName)
326
- e = get_entry(fileName)
326
+ def atime(filename)
327
+ e = get_entry(filename)
327
328
  if e.extra.member? 'UniversalTime'
328
329
  e.extra['UniversalTime'].atime
329
330
  elsif e.extra.member? 'NTFS'
@@ -331,8 +332,8 @@ module Zip
331
332
  end
332
333
  end
333
334
 
334
- def ctime(fileName)
335
- e = get_entry(fileName)
335
+ def ctime(filename)
336
+ e = get_entry(filename)
336
337
  if e.extra.member? 'UniversalTime'
337
338
  e.extra['UniversalTime'].ctime
338
339
  elsif e.extra.member? 'NTFS'
@@ -352,27 +353,27 @@ module Zip
352
353
  false
353
354
  end
354
355
 
355
- def symlink?(_fileName)
356
+ def symlink?(_filename)
356
357
  false
357
358
  end
358
359
 
359
- def socket?(_fileName)
360
+ def socket?(_filename)
360
361
  false
361
362
  end
362
363
 
363
- def ftype(fileName)
364
- @mappedZip.get_entry(fileName).directory? ? 'directory' : 'file'
364
+ def ftype(filename)
365
+ @mapped_zip.get_entry(filename).directory? ? 'directory' : 'file'
365
366
  end
366
367
 
367
- def readlink(_fileName)
368
+ def readlink(_filename)
368
369
  raise NotImplementedError, 'The readlink() function is not implemented'
369
370
  end
370
371
 
371
- def symlink(_fileName, _symlinkName)
372
+ def symlink(_filename, _symlink_name)
372
373
  raise NotImplementedError, 'The symlink() function is not implemented'
373
374
  end
374
375
 
375
- def link(_fileName, _symlinkName)
376
+ def link(_filename, _symlink_name)
376
377
  raise NotImplementedError, 'The link() function is not implemented'
377
378
  end
378
379
 
@@ -380,46 +381,48 @@ module Zip
380
381
  raise NotImplementedError, 'The pipe() function is not implemented'
381
382
  end
382
383
 
383
- def stat(fileName)
384
- raise Errno::ENOENT, fileName unless exists?(fileName)
385
- ZipFsStat.new(self, fileName)
384
+ def stat(filename)
385
+ raise Errno::ENOENT, filename unless exists?(filename)
386
+
387
+ ZipFsStat.new(self, filename)
386
388
  end
387
389
 
388
390
  alias lstat stat
389
391
 
390
- def readlines(fileName)
391
- open(fileName) { |is| is.readlines }
392
+ def readlines(filename)
393
+ self.open(filename, &:readlines)
392
394
  end
393
395
 
394
- def read(fileName)
395
- @mappedZip.read(fileName)
396
+ def read(filename)
397
+ @mapped_zip.read(filename)
396
398
  end
397
399
 
398
- def popen(*args, &aProc)
399
- ::File.popen(*args, &aProc)
400
+ def popen(*args, &a_proc)
401
+ ::File.popen(*args, &a_proc)
400
402
  end
401
403
 
402
- def foreach(fileName, aSep = $/, &aProc)
403
- open(fileName) { |is| is.each_line(aSep, &aProc) }
404
+ def foreach(filename, sep = $INPUT_RECORD_SEPARATOR, &a_proc)
405
+ self.open(filename) { |is| is.each_line(sep, &a_proc) }
404
406
  end
405
407
 
406
408
  def delete(*args)
407
- args.each do |fileName|
408
- if directory?(fileName)
409
- raise Errno::EISDIR, "Is a directory - \"#{fileName}\""
409
+ args.each do |filename|
410
+ if directory?(filename)
411
+ raise Errno::EISDIR, "Is a directory - \"#{filename}\""
410
412
  end
411
- @mappedZip.remove(fileName)
413
+
414
+ @mapped_zip.remove(filename)
412
415
  end
413
416
  end
414
417
 
415
- def rename(fileToRename, newName)
416
- @mappedZip.rename(fileToRename, newName) { true }
418
+ def rename(file_to_rename, new_name)
419
+ @mapped_zip.rename(file_to_rename, new_name) { true }
417
420
  end
418
421
 
419
422
  alias unlink delete
420
423
 
421
- def expand_path(aPath)
422
- @mappedZip.expand_path(aPath)
424
+ def expand_path(path)
425
+ @mapped_zip.expand_path(path)
423
426
  end
424
427
  end
425
428
 
@@ -430,76 +433,79 @@ module Zip
430
433
  # The individual methods are not documented due to their
431
434
  # similarity with the methods in Dir
432
435
  class ZipFsDir
433
- def initialize(mappedZip)
434
- @mappedZip = mappedZip
436
+ def initialize(mapped_zip)
437
+ @mapped_zip = mapped_zip
435
438
  end
436
439
 
437
440
  attr_writer :file
438
441
 
439
- def new(aDirectoryName)
440
- ZipFsDirIterator.new(entries(aDirectoryName))
442
+ def new(directory_name)
443
+ ZipFsDirIterator.new(entries(directory_name))
441
444
  end
442
445
 
443
- def open(aDirectoryName)
444
- dirIt = new(aDirectoryName)
446
+ def open(directory_name)
447
+ dir_iter = new(directory_name)
445
448
  if block_given?
446
449
  begin
447
- yield(dirIt)
450
+ yield(dir_iter)
448
451
  return nil
449
452
  ensure
450
- dirIt.close
453
+ dir_iter.close
451
454
  end
452
455
  end
453
- dirIt
456
+ dir_iter
454
457
  end
455
458
 
456
459
  def pwd
457
- @mappedZip.pwd
460
+ @mapped_zip.pwd
458
461
  end
459
462
  alias getwd pwd
460
463
 
461
- def chdir(aDirectoryName)
462
- unless @file.stat(aDirectoryName).directory?
463
- raise Errno::EINVAL, "Invalid argument - #{aDirectoryName}"
464
+ def chdir(directory_name)
465
+ unless @file.stat(directory_name).directory?
466
+ raise Errno::EINVAL, "Invalid argument - #{directory_name}"
464
467
  end
465
- @mappedZip.pwd = @file.expand_path(aDirectoryName)
468
+
469
+ @mapped_zip.pwd = @file.expand_path(directory_name)
466
470
  end
467
471
 
468
- def entries(aDirectoryName)
472
+ def entries(directory_name)
469
473
  entries = []
470
- foreach(aDirectoryName) { |e| entries << e }
474
+ foreach(directory_name) { |e| entries << e }
471
475
  entries
472
476
  end
473
477
 
474
478
  def glob(*args, &block)
475
- @mappedZip.glob(*args, &block)
479
+ @mapped_zip.glob(*args, &block)
476
480
  end
477
481
 
478
- def foreach(aDirectoryName)
479
- unless @file.stat(aDirectoryName).directory?
480
- raise Errno::ENOTDIR, aDirectoryName
482
+ def foreach(directory_name)
483
+ unless @file.stat(directory_name).directory?
484
+ raise Errno::ENOTDIR, directory_name
481
485
  end
482
- path = @file.expand_path(aDirectoryName)
486
+
487
+ path = @file.expand_path(directory_name)
483
488
  path << '/' unless path.end_with?('/')
484
489
  path = Regexp.escape(path)
485
- subDirEntriesRegex = Regexp.new("^#{path}([^/]+)$")
486
- @mappedZip.each do |fileName|
487
- match = subDirEntriesRegex.match(fileName)
490
+ subdir_entry_regex = Regexp.new("^#{path}([^/]+)$")
491
+ @mapped_zip.each do |filename|
492
+ match = subdir_entry_regex.match(filename)
488
493
  yield(match[1]) unless match.nil?
489
494
  end
490
495
  end
491
496
 
492
- def delete(entryName)
493
- unless @file.stat(entryName).directory?
494
- raise Errno::EINVAL, "Invalid argument - #{entryName}"
497
+ def delete(entry_name)
498
+ unless @file.stat(entry_name).directory?
499
+ raise Errno::EINVAL, "Invalid argument - #{entry_name}"
495
500
  end
496
- @mappedZip.remove(entryName)
501
+
502
+ @mapped_zip.remove(entry_name)
497
503
  end
498
504
  alias rmdir delete
499
505
  alias unlink delete
500
506
 
501
- def mkdir(entryName, permissionInt = 0o755)
502
- @mappedZip.mkdir(entryName, permissionInt)
507
+ def mkdir(entry_name, permissions = 0o755)
508
+ @mapped_zip.mkdir(entry_name, permissions)
503
509
  end
504
510
 
505
511
  def chroot(*_args)
@@ -510,37 +516,42 @@ module Zip
510
516
  class ZipFsDirIterator # :nodoc:all
511
517
  include Enumerable
512
518
 
513
- def initialize(arrayOfFileNames)
514
- @fileNames = arrayOfFileNames
519
+ def initialize(filenames)
520
+ @filenames = filenames
515
521
  @index = 0
516
522
  end
517
523
 
518
524
  def close
519
- @fileNames = nil
525
+ @filenames = nil
520
526
  end
521
527
 
522
- def each(&aProc)
523
- raise IOError, 'closed directory' if @fileNames.nil?
524
- @fileNames.each(&aProc)
528
+ def each(&a_proc)
529
+ raise IOError, 'closed directory' if @filenames.nil?
530
+
531
+ @filenames.each(&a_proc)
525
532
  end
526
533
 
527
534
  def read
528
- raise IOError, 'closed directory' if @fileNames.nil?
529
- @fileNames[(@index += 1) - 1]
535
+ raise IOError, 'closed directory' if @filenames.nil?
536
+
537
+ @filenames[(@index += 1) - 1]
530
538
  end
531
539
 
532
540
  def rewind
533
- raise IOError, 'closed directory' if @fileNames.nil?
541
+ raise IOError, 'closed directory' if @filenames.nil?
542
+
534
543
  @index = 0
535
544
  end
536
545
 
537
- def seek(anIntegerPosition)
538
- raise IOError, 'closed directory' if @fileNames.nil?
539
- @index = anIntegerPosition
546
+ def seek(position)
547
+ raise IOError, 'closed directory' if @filenames.nil?
548
+
549
+ @index = position
540
550
  end
541
551
 
542
552
  def tell
543
- raise IOError, 'closed directory' if @fileNames.nil?
553
+ raise IOError, 'closed directory' if @filenames.nil?
554
+
544
555
  @index
545
556
  end
546
557
  end
@@ -550,60 +561,65 @@ module Zip
550
561
  class ZipFileNameMapper # :nodoc:all
551
562
  include Enumerable
552
563
 
553
- def initialize(zipFile)
554
- @zipFile = zipFile
564
+ def initialize(zip_file)
565
+ @zip_file = zip_file
555
566
  @pwd = '/'
556
567
  end
557
568
 
558
569
  attr_accessor :pwd
559
570
 
560
- def find_entry(fileName)
561
- @zipFile.find_entry(expand_to_entry(fileName))
571
+ def find_entry(filename)
572
+ @zip_file.find_entry(expand_to_entry(filename))
562
573
  end
563
574
 
564
- def get_entry(fileName)
565
- @zipFile.get_entry(expand_to_entry(fileName))
575
+ def get_entry(filename)
576
+ @zip_file.get_entry(expand_to_entry(filename))
566
577
  end
567
578
 
568
- def get_input_stream(fileName, &aProc)
569
- @zipFile.get_input_stream(expand_to_entry(fileName), &aProc)
579
+ def get_input_stream(filename, &a_proc)
580
+ @zip_file.get_input_stream(expand_to_entry(filename), &a_proc)
570
581
  end
571
582
 
572
- def get_output_stream(fileName, permissionInt = nil, &aProc)
573
- @zipFile.get_output_stream(expand_to_entry(fileName), permissionInt, &aProc)
583
+ def get_output_stream(filename, permissions = nil, &a_proc)
584
+ @zip_file.get_output_stream(
585
+ expand_to_entry(filename), permissions, &a_proc
586
+ )
574
587
  end
575
588
 
576
589
  def glob(pattern, *flags, &block)
577
- @zipFile.glob(expand_to_entry(pattern), *flags, &block)
590
+ @zip_file.glob(expand_to_entry(pattern), *flags, &block)
578
591
  end
579
592
 
580
- def read(fileName)
581
- @zipFile.read(expand_to_entry(fileName))
593
+ def read(filename)
594
+ @zip_file.read(expand_to_entry(filename))
582
595
  end
583
596
 
584
- def remove(fileName)
585
- @zipFile.remove(expand_to_entry(fileName))
597
+ def remove(filename)
598
+ @zip_file.remove(expand_to_entry(filename))
586
599
  end
587
600
 
588
- def rename(fileName, newName, &continueOnExistsProc)
589
- @zipFile.rename(expand_to_entry(fileName), expand_to_entry(newName),
590
- &continueOnExistsProc)
601
+ def rename(filename, new_name, &continue_on_exists_proc)
602
+ @zip_file.rename(
603
+ expand_to_entry(filename),
604
+ expand_to_entry(new_name),
605
+ &continue_on_exists_proc
606
+ )
591
607
  end
592
608
 
593
- def mkdir(fileName, permissionInt = 0o755)
594
- @zipFile.mkdir(expand_to_entry(fileName), permissionInt)
609
+ def mkdir(filename, permissions = 0o755)
610
+ @zip_file.mkdir(expand_to_entry(filename), permissions)
595
611
  end
596
612
 
597
613
  # Turns entries into strings and adds leading /
598
614
  # and removes trailing slash on directories
599
615
  def each
600
- @zipFile.each do |e|
616
+ @zip_file.each do |e|
601
617
  yield('/' + e.to_s.chomp('/'))
602
618
  end
603
619
  end
604
620
 
605
- def expand_path(aPath)
606
- expanded = aPath.start_with?('/') ? aPath : ::File.join(@pwd, aPath)
621
+ def expand_path(path)
622
+ expanded = path.start_with?('/') ? path : ::File.join(@pwd, path)
607
623
  expanded.gsub!(/\/\.(\/|$)/, '')
608
624
  expanded.gsub!(/[^\/]+\/\.\.(\/|$)/, '')
609
625
  expanded.empty? ? '/' : expanded
@@ -611,8 +627,8 @@ module Zip
611
627
 
612
628
  private
613
629
 
614
- def expand_to_entry(aPath)
615
- expand_path(aPath)[1..-1]
630
+ def expand_to_entry(path)
631
+ expand_path(path)[1..-1]
616
632
  end
617
633
  end
618
634
  end