2015-08-13 04:14:48 +00:00
|
|
|
# encoding: utf-8
|
|
|
|
require 'rubygems/package'
|
|
|
|
require 'zlib'
|
|
|
|
|
|
|
|
module Vulcano::Targets
|
|
|
|
class TarHelper
|
2015-09-03 18:43:58 +00:00
|
|
|
def structure(input)
|
2015-09-04 07:59:30 +00:00
|
|
|
files = []
|
2015-09-05 14:07:54 +00:00
|
|
|
Gem::Package::TarReader.new(Zlib::GzipReader.open input) do |tar|
|
2015-09-09 10:18:42 +00:00
|
|
|
files = tar.map(&:full_name)
|
2015-08-13 04:14:48 +00:00
|
|
|
end
|
2015-09-03 18:45:37 +00:00
|
|
|
files
|
2015-08-13 04:14:48 +00:00
|
|
|
end
|
|
|
|
|
2015-09-03 18:43:58 +00:00
|
|
|
def content(input)
|
2015-08-13 04:14:48 +00:00
|
|
|
content = {}
|
2015-09-05 14:07:54 +00:00
|
|
|
Gem::Package::TarReader.new(Zlib::GzipReader.open input) do |tar|
|
2015-08-13 04:14:48 +00:00
|
|
|
tar.each do |entry|
|
|
|
|
if entry.directory?
|
2015-09-04 07:59:30 +00:00
|
|
|
# nothing to do
|
2015-08-13 04:14:48 +00:00
|
|
|
elsif entry.file?
|
|
|
|
content[entry.full_name] = entry.read
|
|
|
|
elsif entry.header.typeflag == '2'
|
|
|
|
# ignore symlinks for now
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2015-09-03 18:45:37 +00:00
|
|
|
content
|
2015-08-13 04:14:48 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|