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