Class: Zip::FileSystem::ZipFileNameMapper
- Inherits:
-
Object
- Object
- Zip::FileSystem::ZipFileNameMapper
- 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
-
#pwd ⇒ Object
Returns the value of attribute pwd.
Instance Method Summary collapse
-
#each ⇒ Object
Turns entries into strings and adds leading / and removes trailing slash on directories.
- #expand_path(path) ⇒ Object
- #find_entry(filename) ⇒ Object
- #get_entry(filename) ⇒ Object
- #get_input_stream(filename, &a_proc) ⇒ Object
- #get_output_stream(filename, permissions = nil, &a_proc) ⇒ Object
- #glob(pattern, *flags, &block) ⇒ Object
-
#initialize(zip_file) ⇒ ZipFileNameMapper
constructor
A new instance of ZipFileNameMapper.
- #mkdir(filename, permissions = 0o755) ⇒ Object
- #read(filename) ⇒ Object
- #remove(filename) ⇒ Object
- #rename(filename, new_name, &continue_on_exists_proc) ⇒ Object
Constructor Details
#initialize(zip_file) ⇒ ZipFileNameMapper
Returns a new instance of ZipFileNameMapper.
564 565 566 567 |
# File 'lib/zip/filesystem.rb', line 564 def initialize(zip_file) @zip_file = zip_file @pwd = '/' end |
Instance Attribute Details
#pwd ⇒ Object
Returns the value of attribute pwd.
569 570 571 |
# File 'lib/zip/filesystem.rb', line 569 def pwd @pwd end |
Instance Method Details
#each ⇒ Object
Turns entries into strings and adds leading / and removes trailing slash on directories
615 616 617 618 619 |
# File 'lib/zip/filesystem.rb', line 615 def each @zip_file.each do |e| yield('/' + e.to_s.chomp('/')) end end |
#expand_path(path) ⇒ Object
621 622 623 624 625 626 |
# File 'lib/zip/filesystem.rb', line 621 def (path) = path.start_with?('/') ? path : ::File.join(@pwd, path) .gsub!(/\/\.(\/|$)/, '') .gsub!(/[^\/]+\/\.\.(\/|$)/, '') .empty? ? '/' : end |
#find_entry(filename) ⇒ Object
571 572 573 |
# File 'lib/zip/filesystem.rb', line 571 def find_entry(filename) @zip_file.find_entry((filename)) end |
#get_entry(filename) ⇒ Object
575 576 577 |
# File 'lib/zip/filesystem.rb', line 575 def get_entry(filename) @zip_file.get_entry((filename)) end |
#get_input_stream(filename, &a_proc) ⇒ Object
579 580 581 |
# File 'lib/zip/filesystem.rb', line 579 def get_input_stream(filename, &a_proc) @zip_file.get_input_stream((filename), &a_proc) end |
#get_output_stream(filename, permissions = nil, &a_proc) ⇒ Object
583 584 585 586 587 |
# File 'lib/zip/filesystem.rb', line 583 def get_output_stream(filename, = nil, &a_proc) @zip_file.get_output_stream( (filename), , &a_proc ) end |
#glob(pattern, *flags, &block) ⇒ Object
589 590 591 |
# File 'lib/zip/filesystem.rb', line 589 def glob(pattern, *flags, &block) @zip_file.glob((pattern), *flags, &block) end |
#mkdir(filename, permissions = 0o755) ⇒ Object
609 610 611 |
# File 'lib/zip/filesystem.rb', line 609 def mkdir(filename, = 0o755) @zip_file.mkdir((filename), ) end |
#read(filename) ⇒ Object
593 594 595 |
# File 'lib/zip/filesystem.rb', line 593 def read(filename) @zip_file.read((filename)) end |
#remove(filename) ⇒ Object
597 598 599 |
# File 'lib/zip/filesystem.rb', line 597 def remove(filename) @zip_file.remove((filename)) end |
#rename(filename, new_name, &continue_on_exists_proc) ⇒ Object
601 602 603 604 605 606 607 |
# File 'lib/zip/filesystem.rb', line 601 def rename(filename, new_name, &continue_on_exists_proc) @zip_file.rename( (filename), (new_name), &continue_on_exists_proc ) end |