Class: Inspec::Targets::ZipHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/inspec/targets/zip.rb

Instance Method Summary collapse

Instance Method Details

#content(input, _filter) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/inspec/targets/zip.rb', line 10

def content(input, _filter)
  content = []
  ::Zip::InputStream.open(input) do |io|
    while (entry = io.get_next_entry)
      h = {
        content: io.read,
        ref: File.join(input, entry.name),
      }
      content.push(h)
    end
  end
  content
end

#resolve(path) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/inspec/targets/zip.rb', line 34

def resolve(path)
  files = structure(path)
  helper = DirsHelper.get_handler(files)
  if helper.nil?
    fail "Don't know how to handle folder #{path}"
  end
  # get all file contents
  # @TODO
  _file_handler = Inspec::Targets.modules['file']
  test_files = helper.get_filenames(files)
  content(path, test_files)
end

#structure(input) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/inspec/targets/zip.rb', line 24

def structure(input)
  files = []
  ::Zip::InputStream.open(input) do |io|
    while (entry = io.get_next_entry)
      files.push(entry.name)
    end
  end
  files
end