Class: Zip::ZipFileSystem::ZipFileNameMapper

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/zip/zipfilesystem.rb

Overview

All access to ZipFile from ZipFsFile and ZipFsDir goes through a ZipFileNameMapper, which has one responsibility: ensure

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Methods included from Enumerable

#inject, #select_map

Constructor Details

- (ZipFileNameMapper) initialize(zipFile)



538
539
540
541
# File 'lib/zip/zipfilesystem.rb', line 538

def initialize(zipFile)
  @zipFile = zipFile
  @pwd = "/"
end

Instance Attribute Details

- (Object) pwd

Returns the value of attribute pwd



543
544
545
# File 'lib/zip/zipfilesystem.rb', line 543

def pwd
  @pwd
end

Instance Method Details

- (Object) each

Turns entries into strings and adds leading / and removes trailing slash on directories



580
581
582
583
584
585
# File 'lib/zip/zipfilesystem.rb', line 580

def each
  @zipFile.each {
    |e|
    yield("/"+e.to_s.chomp("/"))
  }
end

- (Object) expand_path(aPath)



587
588
589
590
591
592
# File 'lib/zip/zipfilesystem.rb', line 587

def expand_path(aPath)
  expanded = aPath.starts_with("/") ? aPath : @pwd.ensure_end("/") + aPath
  expanded.gsub!(/\/\.(\/|$)/, "")
  expanded.gsub!(/[^\/]+\/\.\.(\/|$)/, "")
  expanded.empty? ? "/" : expanded
end

- (Object) find_entry(fileName)



545
546
547
# File 'lib/zip/zipfilesystem.rb', line 545

def find_entry(fileName)
  @zipFile.find_entry(expand_to_entry(fileName))
end

- (Object) get_entry(fileName)



549
550
551
# File 'lib/zip/zipfilesystem.rb', line 549

def get_entry(fileName)
  @zipFile.get_entry(expand_to_entry(fileName))
end

- (Object) get_input_stream(fileName, &aProc)



553
554
555
# File 'lib/zip/zipfilesystem.rb', line 553

def get_input_stream(fileName, &aProc)
  @zipFile.get_input_stream(expand_to_entry(fileName), &aProc)
end

- (Object) get_output_stream(fileName, &aProc)



557
558
559
# File 'lib/zip/zipfilesystem.rb', line 557

def get_output_stream(fileName, &aProc)
  @zipFile.get_output_stream(expand_to_entry(fileName), &aProc)
end

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



574
575
576
# File 'lib/zip/zipfilesystem.rb', line 574

def mkdir(fileName, permissionInt = 0755)
  @zipFile.mkdir(expand_to_entry(fileName), permissionInt)
end

- (Object) read(fileName)



561
562
563
# File 'lib/zip/zipfilesystem.rb', line 561

def read(fileName)
  @zipFile.read(expand_to_entry(fileName))
end

- (Object) remove(fileName)



565
566
567
# File 'lib/zip/zipfilesystem.rb', line 565

def remove(fileName)
  @zipFile.remove(expand_to_entry(fileName))
end

- (Object) rename(fileName, newName, &continueOnExistsProc)



569
570
571
572
# File 'lib/zip/zipfilesystem.rb', line 569

def rename(fileName, newName, &continueOnExistsProc)
  @zipFile.rename(expand_to_entry(fileName), expand_to_entry(newName), 
                  &continueOnExistsProc)
end