Method: Inspec::Targets::ZipHelper#content

Defined in:
lib/inspec/targets/zip.rb

#content(input, files, rootdir = nil, opts = {}) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/inspec/targets/zip.rb', line 15

def content(input, files, rootdir = nil, opts = {})
  content = []
  ::Zip::InputStream.open(input) do |io|
    while (entry = io.get_next_entry)
      next if !files.include?(entry.name.gsub(rootdir, ''))
      h = {
        # NB if some file is empty, return empty-string, not nil
        content: io.read || '',
        type: opts[:as] || :test,
        ref: entry.name,
      }
      content.push(h)
    end
  end
  content
end