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

#initialize(mappedZip) ⇒ ZipFsDir

Returns a new instance of ZipFsDir



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

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.



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

def file=(value)
  @file = value
end

Instance Method Details

#chdir(aDirectoryName) ⇒ Object



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

#chroot(*args) ⇒ Object

Raises:

  • (NotImplementedError)


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

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

#delete(entryName) ⇒ Object 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

#entries(aDirectoryName) ⇒ Object



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

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

#foreach(aDirectoryName) ⇒ Object



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

#mkdir(entryName, permissionInt = 0755) ⇒ Object



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

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

#new(aDirectoryName) ⇒ Object



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

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

#open(aDirectoryName) ⇒ Object



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

#pwdObject Also known as: getwd



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

def pwd; @mappedZip.pwd; end