Class: Zip::ZipFileSystem::ZipFsDir

Inherits:
Object
  • Object
show all
Defined in:
lib/zip/zipfilesystem.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

- (ZipFsDir) initialize(mappedZip)



423
424
425
# File 'lib/zip/zipfilesystem.rb', line 423

def initialize(mappedZip)
  @mappedZip = mappedZip
end

Instance Attribute Details

- (Object) file=(value) (writeonly)

Sets the attribute file



427
428
429
# File 'lib/zip/zipfilesystem.rb', line 427

def file=(value)
  @file = value
end

Instance Method Details

- (Object) chdir(aDirectoryName)



449
450
451
452
453
454
# File 'lib/zip/zipfilesystem.rb', line 449

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

- (Object) chroot(*args)

Raises:

  • (NotImplementedError)


489
490
491
# File 'lib/zip/zipfilesystem.rb', line 489

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

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



476
477
478
479
480
481
# File 'lib/zip/zipfilesystem.rb', line 476

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

- (Object) entries(aDirectoryName)



456
457
458
459
460
# File 'lib/zip/zipfilesystem.rb', line 456

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

- (Object) foreach(aDirectoryName)



462
463
464
465
466
467
468
469
470
471
472
473
474
# File 'lib/zip/zipfilesystem.rb', line 462

def foreach(aDirectoryName)
  unless @file.stat(aDirectoryName).directory?
    raise Errno::ENOTDIR, aDirectoryName
  end
  path = @file.expand_path(aDirectoryName).ensure_end("/")

  subDirEntriesRegex = Regexp.new("^#{path}([^/]+)$")
  @mappedZip.each { 
    |fileName|
    match = subDirEntriesRegex.match(fileName)
    yield(match[1]) unless match == nil
  }
end

- (Object) mkdir(entryName, permissionInt = 0755)



485
486
487
# File 'lib/zip/zipfilesystem.rb', line 485

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

- (Object) new(aDirectoryName)



429
430
431
# File 'lib/zip/zipfilesystem.rb', line 429

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

- (Object) open(aDirectoryName)



433
434
435
436
437
438
439
440
441
442
443
444
# File 'lib/zip/zipfilesystem.rb', line 433

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

- (Object) pwd Also known as: getwd



446
# File 'lib/zip/zipfilesystem.rb', line 446

def pwd; @mappedZip.pwd; end