Class: Zip::FileSystem::ZipFileNameMapper

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/hotplate/gems/rubyzip-1.1.7/lib/zip/filesystem.rb

Overview

All access to Zip::File 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

#compare_enumerables

Constructor Details

#initialize(zipFile) ⇒ ZipFileNameMapper

Returns a new instance of ZipFileNameMapper.



555
556
557
558
# File 'lib/hotplate/gems/rubyzip-1.1.7/lib/zip/filesystem.rb', line 555

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

Instance Attribute Details

#pwdObject

Returns the value of attribute pwd.



560
561
562
# File 'lib/hotplate/gems/rubyzip-1.1.7/lib/zip/filesystem.rb', line 560

def pwd
  @pwd
end

Instance Method Details

#eachObject

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



597
598
599
600
601
602
# File 'lib/hotplate/gems/rubyzip-1.1.7/lib/zip/filesystem.rb', line 597

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

#expand_path(aPath) ⇒ Object



604
605
606
607
608
609
# File 'lib/hotplate/gems/rubyzip-1.1.7/lib/zip/filesystem.rb', line 604

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

#find_entry(fileName) ⇒ Object



562
563
564
# File 'lib/hotplate/gems/rubyzip-1.1.7/lib/zip/filesystem.rb', line 562

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

#get_entry(fileName) ⇒ Object



566
567
568
# File 'lib/hotplate/gems/rubyzip-1.1.7/lib/zip/filesystem.rb', line 566

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

#get_input_stream(fileName, &aProc) ⇒ Object



570
571
572
# File 'lib/hotplate/gems/rubyzip-1.1.7/lib/zip/filesystem.rb', line 570

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

#get_output_stream(fileName, permissionInt = nil, &aProc) ⇒ Object



574
575
576
# File 'lib/hotplate/gems/rubyzip-1.1.7/lib/zip/filesystem.rb', line 574

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

#mkdir(fileName, permissionInt = 0755) ⇒ Object



591
592
593
# File 'lib/hotplate/gems/rubyzip-1.1.7/lib/zip/filesystem.rb', line 591

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

#read(fileName) ⇒ Object



578
579
580
# File 'lib/hotplate/gems/rubyzip-1.1.7/lib/zip/filesystem.rb', line 578

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

#remove(fileName) ⇒ Object



582
583
584
# File 'lib/hotplate/gems/rubyzip-1.1.7/lib/zip/filesystem.rb', line 582

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

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



586
587
588
589
# File 'lib/hotplate/gems/rubyzip-1.1.7/lib/zip/filesystem.rb', line 586

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