Class: Excavate::Archive

Inherits:
Object
  • Object
show all
Defined in:
lib/excavate/archive.rb

Constant Summary collapse

INVALID_MEMORY_MESSAGE =
"invalid memory read at address=0x0000000000000000".freeze
TYPES =
{ "cab" => Extractors::CabExtractor,
"cpio" => Extractors::CpioExtractor,
"exe" => Extractors::SevenZipExtractor,
"gz" => Extractors::GzipExtractor,
"msi" => Extractors::OleExtractor,
"rpm" => Extractors::RpmExtractor,
"tar" => Extractors::TarExtractor,
"pkg" => Extractors::XarExtractor,
"zip" => Extractors::ZipExtractor }.freeze

Instance Method Summary collapse

Constructor Details

#initialize(archive) ⇒ Archive

Returns a new instance of Archive.



16
17
18
# File 'lib/excavate/archive.rb', line 16

def initialize(archive)
  @archive = archive
end

Instance Method Details

#extract(target = nil, recursive_packages: false, files: [], filter: nil) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/excavate/archive.rb', line 30

def extract(target = nil,
            recursive_packages: false,
            files: [],
            filter: nil)
  if files.size.positive?
    extract_particular_files(target, files,
                             recursive_packages: recursive_packages)
  elsif filter
    extract_by_filter(target, filter,
                      recursive_packages: recursive_packages)
  else
    extract_all(target, recursive_packages: recursive_packages)
  end
end

#files(recursive_packages: false, files: [], filter: nil, &block) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/excavate/archive.rb', line 20

def files(recursive_packages: false, files: [], filter: nil, &block)
  target = Dir.mktmpdir
  extract(target, recursive_packages: recursive_packages,
                  files: files, filter: filter)

  all_files_in(target).map(&block)
ensure
  FileUtils.rm_rf(target)
end