Class: Zip::ZipFileSystem::ZipFsDir

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_archive/handlers/rubyzip/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.



424
425
426
# File 'lib/ruby_archive/handlers/rubyzip/zip/zipfilesystem.rb', line 424

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.



428
429
430
# File 'lib/ruby_archive/handlers/rubyzip/zip/zipfilesystem.rb', line 428

def file=(value)
  @file = value
end

Instance Method Details

#chdir(aDirectoryName) ⇒ Object



450
451
452
453
454
455
# File 'lib/ruby_archive/handlers/rubyzip/zip/zipfilesystem.rb', line 450

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)


490
491
492
# File 'lib/ruby_archive/handlers/rubyzip/zip/zipfilesystem.rb', line 490

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

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



477
478
479
480
481
482
# File 'lib/ruby_archive/handlers/rubyzip/zip/zipfilesystem.rb', line 477

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

#entries(aDirectoryName) ⇒ Object



457
458
459
460
461
# File 'lib/ruby_archive/handlers/rubyzip/zip/zipfilesystem.rb', line 457

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

#foreach(aDirectoryName) ⇒ Object



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

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

#glob(pattern, flags = 0) ⇒ Object



503
504
505
506
507
508
509
510
511
512
513
# File 'lib/ruby_archive/handlers/rubyzip/zip/zipfilesystem.rb', line 503

def glob(pattern,flags=0)
  case pattern
  when String then return glob_single(pattern,flags) if pattern.is_a?(String)
  when Array
    results = []
    pattern.each { |p| results += glob_single(p,flags) }
    return results
  else
    raise TypeError, "Unexpected type #{pattern.class}, expected String or Array"
  end
end

#mkdir(entryName, permissionInt = 0755) ⇒ Object



486
487
488
# File 'lib/ruby_archive/handlers/rubyzip/zip/zipfilesystem.rb', line 486

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

#new(aDirectoryName) ⇒ Object



430
431
432
# File 'lib/ruby_archive/handlers/rubyzip/zip/zipfilesystem.rb', line 430

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

#open(aDirectoryName) ⇒ Object



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

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



447
# File 'lib/ruby_archive/handlers/rubyzip/zip/zipfilesystem.rb', line 447

def pwd; @mappedZip.pwd; end