class Inspec::ZipProvider
def initialize(path)
def initialize(path) @path = path @contents = {} @files = [] walk_zip(@path) do |io| while (entry = io.get_next_entry) name = entry.name.sub(%r{/+$}, '') @files.push(name) unless name.empty? end end end
def read(file)
def read(file) @contents[file] ||= read_from_zip(file) end
def read_from_zip(file)
def read_from_zip(file) return nil unless @files.include?(file) res = nil walk_zip(@path) do |io| while (entry = io.get_next_entry) next unless file == entry.name res = io.read break end end res end
def walk_zip(path, &callback)
def walk_zip(path, &callback) ::Zip::InputStream.open(path, &callback) end