inspec/lib/vulcano/targets/tar.rb

34 lines
753 B
Ruby
Raw Normal View History

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-08-13 04:14:48 +00:00
files = Array.new
Gem::Package::TarReader.new( Zlib::GzipReader.open input ) do |tar|
files = tar.map{|entry| entry.full_name }
end
return files
end
2015-09-03 18:43:58 +00:00
def content(input)
2015-08-13 04:14:48 +00:00
content = {}
Gem::Package::TarReader.new( Zlib::GzipReader.open input ) do |tar|
tar.each do |entry|
if entry.directory?
#nothing to do
elsif entry.file?
content[entry.full_name] = entry.read
elsif entry.header.typeflag == '2'
# ignore symlinks for now
end
end
end
return content
end
end
end