move zip and tar helpers

Signed-off-by: Dominik Richter <dominik.richter@gmail.com>
This commit is contained in:
Dominik Richter 2015-08-12 22:45:42 -07:00
parent 7a59d9ce76
commit 5875864f45
4 changed files with 45 additions and 29 deletions

View file

@ -1,28 +0,0 @@
# encoding: utf-8
require 'zip'
module Vulcano::Targets
class ZipHelper
def content input
content = {}
::Zip::InputStream.open(input) do |io|
while (entry = io.get_next_entry)
content[entry.name] = io.read
end
end
return content
end
def structure input
files = Array.new
::Zip::InputStream.open(input) do |io|
while (entry = io.get_next_entry)
files.push(entry.name)
end
end
return files
end
end
end

View file

@ -25,7 +25,7 @@ module Vulcano::Targets
zipfile.binmode
zipfile.write(open(url).read)
zipfile.rewind
content = ZipHelper.resolve(zipfile.path)
content = ZipHelper.new.resolve(zipfile.path)
zipfile.close
zipfile.unlink
return content

View file

@ -0,0 +1,44 @@
# 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)
content.push({
content: io.read,
ref: File::join(input, entry.name),
})
end
end
return content
end
def structure input
files = Array.new
::Zip::InputStream.open(input) do |io|
while (entry = io.get_next_entry)
files.push(entry.name)
end
end
return files
end
def resolve(path)
files = structure(path)
helper = DirsHelper.getHandler(files)
if helper.nil?
raise "Don't know how to handle folder #{path}"
end
# get all file contents
file_handler = Vulcano::Targets.modules['file']
test_files = helper.get_filenames(files)
content(path, test_files)
end
end
end