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

#deep_clone, #deep_dup, #inject, #select_map

Constructor Details

#initialize(zipFile) ⇒ ZipFileNameMapper

Returns a new instance of ZipFileNameMapper.



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

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

Instance Attribute Details

#pwdObject

Returns the value of attribute pwd.



492
493
494
# File 'lib/zip/zipfilesystem.rb', line 492

def pwd
  @pwd
end

Instance Method Details

#eachObject

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



529
530
531
532
533
534
# File 'lib/zip/zipfilesystem.rb', line 529

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

#expand_path(aPath) ⇒ Object



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

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

#find_entry(fileName) ⇒ Object



494
495
496
# File 'lib/zip/zipfilesystem.rb', line 494

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

#get_entry(fileName) ⇒ Object



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

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

#get_input_stream(fileName, &aProc) ⇒ Object



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

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

#get_output_stream(fileName, &aProc) ⇒ Object



506
507
508
# File 'lib/zip/zipfilesystem.rb', line 506

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

#mkdir(fileName, permissionInt = 0) ⇒ Object



523
524
525
# File 'lib/zip/zipfilesystem.rb', line 523

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

#read(fileName) ⇒ Object



510
511
512
# File 'lib/zip/zipfilesystem.rb', line 510

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

#remove(fileName) ⇒ Object



514
515
516
# File 'lib/zip/zipfilesystem.rb', line 514

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

#rename(fileName, newName, &continueOnExistsProc) ⇒ Object



518
519
520
521
# File 'lib/zip/zipfilesystem.rb', line 518

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