Class: Zip::FileSystem::ZipFileNameMapper

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
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

Constructor Details

#initialize(zipFile) ⇒ ZipFileNameMapper

Returns a new instance of ZipFileNameMapper


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

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

Instance Attribute Details

#pwdObject

Returns the value of attribute pwd


558
559
560
# File 'lib/zip/filesystem.rb', line 558

def pwd
  @pwd
end

Instance Method Details

#eachObject

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


599
600
601
602
603
# File 'lib/zip/filesystem.rb', line 599

def each
  @zipFile.each do |e|
    yield('/' + e.to_s.chomp('/'))
  end
end

#expand_path(aPath) ⇒ Object


605
606
607
608
609
610
# File 'lib/zip/filesystem.rb', line 605

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


560
561
562
# File 'lib/zip/filesystem.rb', line 560

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

#get_entry(fileName) ⇒ Object


564
565
566
# File 'lib/zip/filesystem.rb', line 564

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

#get_input_stream(fileName, &aProc) ⇒ Object


568
569
570
# File 'lib/zip/filesystem.rb', line 568

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

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


572
573
574
# File 'lib/zip/filesystem.rb', line 572

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

#glob(pattern, *flags, &block) ⇒ Object


576
577
578
# File 'lib/zip/filesystem.rb', line 576

def glob(pattern, *flags, &block)
  @zipFile.glob(expand_to_entry(pattern), *flags, &block)
end

#mkdir(fileName, permissionInt = 0o755) ⇒ Object


593
594
595
# File 'lib/zip/filesystem.rb', line 593

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

#read(fileName) ⇒ Object


580
581
582
# File 'lib/zip/filesystem.rb', line 580

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

#remove(fileName) ⇒ Object


584
585
586
# File 'lib/zip/filesystem.rb', line 584

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

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


588
589
590
591
# File 'lib/zip/filesystem.rb', line 588

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