Class: Zip::FileSystem::ZipFsDir
- Inherits:
-
Object
- Object
- Zip::FileSystem::ZipFsDir
- Defined in:
- lib/zip/filesystem.rb
Overview
Instances of this class are normally accessed via the accessor ZipFile::dir. An instance of ZipFsDir behaves like ruby’s builtin Dir (class) object, except it works on ZipFile entries.
The individual methods are not documented due to their similarity with the methods in Dir
Instance Attribute Summary collapse
-
#file ⇒ Object
writeonly
Sets the attribute file.
Instance Method Summary collapse
- #chdir(aDirectoryName) ⇒ Object
- #chroot(*_args) ⇒ Object
- #delete(entryName) ⇒ Object (also: #rmdir, #unlink)
- #entries(aDirectoryName) ⇒ Object
- #foreach(aDirectoryName) ⇒ Object
- #glob(*args, &block) ⇒ Object
-
#initialize(mappedZip) ⇒ ZipFsDir
constructor
A new instance of ZipFsDir.
- #mkdir(entryName, permissionInt = 0755) ⇒ Object
- #new(aDirectoryName) ⇒ Object
- #open(aDirectoryName) ⇒ Object
- #pwd ⇒ Object (also: #getwd)
Constructor Details
#initialize(mappedZip) ⇒ ZipFsDir
Returns a new instance of ZipFsDir.
433 434 435 |
# File 'lib/zip/filesystem.rb', line 433 def initialize(mappedZip) @mappedZip = mappedZip end |
Instance Attribute Details
#file=(value) ⇒ Object (writeonly)
Sets the attribute file
437 438 439 |
# File 'lib/zip/filesystem.rb', line 437 def file=(value) @file = value end |
Instance Method Details
#chdir(aDirectoryName) ⇒ Object
461 462 463 464 465 466 |
# File 'lib/zip/filesystem.rb', line 461 def chdir(aDirectoryName) unless @file.stat(aDirectoryName).directory? raise Errno::EINVAL, "Invalid argument - #{aDirectoryName}" end @mappedZip.pwd = @file.(aDirectoryName) end |
#chroot(*_args) ⇒ Object
505 506 507 |
# File 'lib/zip/filesystem.rb', line 505 def chroot(*_args) raise NotImplementedError, 'The chroot() function is not implemented' end |
#delete(entryName) ⇒ Object Also known as: rmdir, unlink
492 493 494 495 496 497 |
# File 'lib/zip/filesystem.rb', line 492 def delete(entryName) unless @file.stat(entryName).directory? raise Errno::EINVAL, "Invalid argument - #{entryName}" end @mappedZip.remove(entryName) end |
#entries(aDirectoryName) ⇒ Object
468 469 470 471 472 |
# File 'lib/zip/filesystem.rb', line 468 def entries(aDirectoryName) entries = [] foreach(aDirectoryName) { |e| entries << e } entries end |
#foreach(aDirectoryName) ⇒ Object
478 479 480 481 482 483 484 485 486 487 488 489 490 |
# File 'lib/zip/filesystem.rb', line 478 def foreach(aDirectoryName) unless @file.stat(aDirectoryName).directory? raise Errno::ENOTDIR, aDirectoryName end path = @file.(aDirectoryName) path << '/' unless path.end_with?('/') path = Regexp.escape(path) subDirEntriesRegex = Regexp.new("^#{path}([^/]+)$") @mappedZip.each do |fileName| match = subDirEntriesRegex.match(fileName) yield(match[1]) unless match.nil? end end |
#glob(*args, &block) ⇒ Object
474 475 476 |
# File 'lib/zip/filesystem.rb', line 474 def glob(*args, &block) @mappedZip.glob(*args, &block) end |
#mkdir(entryName, permissionInt = 0755) ⇒ Object
501 502 503 |
# File 'lib/zip/filesystem.rb', line 501 def mkdir(entryName, = 0755) @mappedZip.mkdir(entryName, ) end |
#new(aDirectoryName) ⇒ Object
439 440 441 |
# File 'lib/zip/filesystem.rb', line 439 def new(aDirectoryName) ZipFsDirIterator.new(entries(aDirectoryName)) end |
#open(aDirectoryName) ⇒ Object
443 444 445 446 447 448 449 450 451 452 453 454 |
# File 'lib/zip/filesystem.rb', line 443 def open(aDirectoryName) dirIt = new(aDirectoryName) if block_given? begin yield(dirIt) return nil ensure dirIt.close end end dirIt end |
#pwd ⇒ Object Also known as: getwd
456 457 458 |
# File 'lib/zip/filesystem.rb', line 456 def pwd @mappedZip.pwd end |