class CFBundle::Storage::Zip
A bundle storage that reads from a ZIP archive.
Public Class Methods
new(zip, path, skip_close: false)
click to toggle source
@param zip [Zip::File] The Zip
file containing the bundle. @param path [String] The path of the bundle within the Zip
file. @param skip_close [Boolean] Whether the storage should skip closing
the Zip file when receiving {#close}.
# File lib/cfbundle/storage/zip.rb, line 12 def initialize(zip, path, skip_close: false) @zip = zip @root = path @skip_close = skip_close end
Public Instance Methods
close()
click to toggle source
Invoked when the storage is no longer needed.
This method closes the underlying Zip
file unless the storage was initialized with +skip_close: true+. @return [void]
# File lib/cfbundle/storage/zip.rb, line 58 def close @zip.close unless @skip_close end
directory?(path)
click to toggle source
(see Base#directory?
)
# File lib/cfbundle/storage/zip.rb, line 30 def directory?(path) entry = find(path) !entry.nil? && entry.directory? end
exist?(path)
click to toggle source
(see Base#exist?
)
# File lib/cfbundle/storage/zip.rb, line 19 def exist?(path) find(path) != nil end
file?(path)
click to toggle source
(see Base#file?
)
# File lib/cfbundle/storage/zip.rb, line 24 def file?(path) entry = find(path) !entry.nil? && entry.file? end
foreach(path)
click to toggle source
(see Base#foreach
)
# File lib/cfbundle/storage/zip.rb, line 41 def foreach(path) Enumerator.new do |y| directory = find! path base = @zip.entries.sort.each loop do entry = base.next next unless entry.parent_as_string == directory.name y << PathUtils.join(path, File.basename(entry.name)) end end end
open(path, &block)
click to toggle source
(see Base#open
)
# File lib/cfbundle/storage/zip.rb, line 36 def open(path, &block) find!(path).get_input_stream(&block) end
Private Instance Methods
find(path, symlinks = Set.new)
click to toggle source
# File lib/cfbundle/storage/zip.rb, line 64 def find(path, symlinks = Set.new) name = PathUtils.join(@root, path) entry = @zip.find_entry name if entry.nil? find_in_parent(path, symlinks) elsif entry.symlink? find_symlink(entry.get_input_stream(&:read), path, symlinks) else entry end end
find!(path)
click to toggle source
# File lib/cfbundle/storage/zip.rb, line 76 def find!(path) find(path) || raise(Errno::ENOENT, path) end
find_in_parent(path, symlinks)
click to toggle source
# File lib/cfbundle/storage/zip.rb, line 80 def find_in_parent(path, symlinks) directory, filename = File.split(path) return if ['.', '/'].include? filename entry = find(directory, symlinks) return unless entry && entry.directory? @zip.find_entry File.join(entry.name, filename) end
find_symlink(path, symlink, symlinks)
click to toggle source
# File lib/cfbundle/storage/zip.rb, line 88 def find_symlink(path, symlink, symlinks) return if path.start_with?('/') || symlinks.include?(symlink) symlinks << symlink resolved_path = PathUtils.join(File.dirname(symlink), path) find(resolved_path, symlinks) end