Class: Zip::FileSystem::ZipFsDir

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(mappedZip) ⇒ ZipFsDir

Returns a new instance of ZipFsDir.



431
432
433
# File 'lib/zip/filesystem.rb', line 431

def initialize(mappedZip)
  @mappedZip = mappedZip
end

Instance Attribute Details

#file=(value) ⇒ Object (writeonly)

Sets the attribute file

Parameters:

  • value

    the value to set the attribute file to.



435
436
437
# File 'lib/zip/filesystem.rb', line 435

def file=(value)
  @file = value
end

Instance Method Details

#chdir(aDirectoryName) ⇒ Object



457
458
459
460
461
462
# File 'lib/zip/filesystem.rb', line 457

def chdir(aDirectoryName)
  unless @file.stat(aDirectoryName).directory?
    raise Errno::EINVAL, "Invalid argument - #{aDirectoryName}"
  end
  @mappedZip.pwd = @file.expand_path(aDirectoryName)
end

#chroot(*args) ⇒ Object

Raises:

  • (NotImplementedError)


502
503
504
# File 'lib/zip/filesystem.rb', line 502

def chroot(*args)
  raise NotImplementedError, "The chroot() function is not implemented"
end

#delete(entryName) ⇒ Object Also known as: rmdir, unlink



489
490
491
492
493
494
# File 'lib/zip/filesystem.rb', line 489

def delete(entryName)
  unless @file.stat(entryName).directory?
    raise Errno::EINVAL, "Invalid argument - #{entryName}"
  end
  @mappedZip.remove(entryName)
end

#entries(aDirectoryName) ⇒ Object



464
465
466
467
468
# File 'lib/zip/filesystem.rb', line 464

def entries(aDirectoryName)
  entries = []
  foreach(aDirectoryName) { |e| entries << e }
  entries
end

#foreach(aDirectoryName) ⇒ Object



474
475
476
477
478
479
480
481
482
483
484
485
486
487
# File 'lib/zip/filesystem.rb', line 474

def foreach(aDirectoryName)
  unless @file.stat(aDirectoryName).directory?
    raise Errno::ENOTDIR, aDirectoryName
  end
  path = @file.expand_path(aDirectoryName)
  path << '/' unless path.end_with?('/')
  path = Regexp.escape(path)
  subDirEntriesRegex = Regexp.new("^#{path}([^/]+)$")
  @mappedZip.each { 
    |fileName|
    match = subDirEntriesRegex.match(fileName)
    yield(match[1]) unless match == nil
  }
end

#glob(*args, &block) ⇒ Object



470
471
472
# File 'lib/zip/filesystem.rb', line 470

def glob(*args,&block)
  @mappedZip.glob(*args,&block)
end

#mkdir(entryName, permissionInt = 0755) ⇒ Object



498
499
500
# File 'lib/zip/filesystem.rb', line 498

def mkdir(entryName, permissionInt = 0755)
  @mappedZip.mkdir(entryName, permissionInt)
end

#new(aDirectoryName) ⇒ Object



437
438
439
# File 'lib/zip/filesystem.rb', line 437

def new(aDirectoryName)
  ZipFsDirIterator.new(entries(aDirectoryName))
end

#open(aDirectoryName) ⇒ Object



441
442
443
444
445
446
447
448
449
450
451
452
# File 'lib/zip/filesystem.rb', line 441

def open(aDirectoryName)
  dirIt = new(aDirectoryName)
  if block_given?
    begin
      yield(dirIt)
      return nil
    ensure
      dirIt.close
    end
  end
  dirIt
end

#pwdObject Also known as: getwd



454
# File 'lib/zip/filesystem.rb', line 454

def pwd; @mappedZip.pwd; end