inspec/lib/vulcano/targets/zip.rb

45 lines
1,003 B
Ruby
Raw Normal View History

# encoding: utf-8
require 'zip'
require 'vulcano/targets/dir'
module Vulcano::Targets
class ZipHelper
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
2015-09-03 18:45:37 +00:00
content
end
2015-09-03 18:43:58 +00:00
def structure(input)
2015-09-04 07:59:30 +00:00
files = []
::Zip::InputStream.open(input) do |io|
while (entry = io.get_next_entry)
2015-09-04 07:59:30 +00:00
files.push(entry.name)
end
end
2015-09-03 18:45:37 +00:00
files
end
def resolve(path)
files = structure(path)
helper = DirsHelper.get_handler(files)
if helper.nil?
2015-09-03 21:24:42 +00:00
fail "Don't know how to handle folder #{path}"
end
# get all file contents
# @TODO
_file_handler = Vulcano::Targets.modules['file']
test_files = helper.get_filenames(files)
content(path, test_files)
end
end
end