lib/inspec/file_provider.rb in inspec-1.31.1 vs lib/inspec/file_provider.rb in inspec-1.32.1
- old
+ new
@@ -95,27 +95,32 @@
def initialize(path)
@path = path
@contents = {}
@files = []
- ::Zip::InputStream.open(@path) do |io|
+ walk_zip(@path) do |io|
while (entry = io.get_next_entry)
- @files.push(entry.name.sub(%r{/+$}, ''))
+ name = entry.name.sub(%r{/+$}, '')
+ @files.push(name) unless name.empty?
end
end
end
def read(file)
@contents[file] ||= read_from_zip(file)
end
private
+ def walk_zip(path, &callback)
+ ::Zip::InputStream.open(path, &callback)
+ end
+
def read_from_zip(file)
return nil unless @files.include?(file)
res = nil
- ::Zip::InputStream.open(@path) do |io|
+ walk_zip(@path) do |io|
while (entry = io.get_next_entry)
next unless file == entry.name
res = io.read
break
end
@@ -129,25 +134,29 @@
def initialize(path)
@path = path
@contents = {}
@files = []
- Gem::Package::TarReader.new(Zlib::GzipReader.open(@path)) do |tar|
- @files = tar.map(&:full_name)
+ walk_tar(@path) do |tar|
+ @files = tar.map(&:full_name).find_all { |x| !x.empty? }
end
end
def read(file)
@contents[file] ||= read_from_tar(file)
end
private
+ def walk_tar(path, &callback)
+ Gem::Package::TarReader.new(Zlib::GzipReader.open(path), &callback)
+ end
+
def read_from_tar(file)
return nil unless @files.include?(file)
res = nil
# NB `TarReader` includes `Enumerable` beginning with Ruby 2.x
- Gem::Package::TarReader.new(Zlib::GzipReader.open(@path)) do |tar|
+ walk_tar(@path) do |tar|
tar.each do |entry|
next unless entry.file? && file == entry.full_name
res = entry.read
break
end