Class: Falkor::Extract::TarGz

Inherits:
Object
  • Object
show all
Includes:
TrackableProgress
Defined in:
lib/falkor/extract/tar_gz.rb

Constant Summary collapse

"././@LongLink"

Instance Method Summary collapse

Methods included from TrackableProgress

#report_progress

Constructor Details

#initialize(file_name, has_root_dir: false) ⇒ TarGz

Returns a new instance of TarGz.



13
14
15
16
17
18
19
20
21
# File 'lib/falkor/extract/tar_gz.rb', line 13

def initialize(file_name, has_root_dir: false)
  @file_name = file_name
  @extraction_destination =
    if has_root_dir
      File.dirname(file_name)
    else
      source_destination
    end
end

Instance Method Details

#extractObject



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/falkor/extract/tar_gz.rb', line 23

def extract
  return source_destination if Dir.exist? source_destination

  FileUtils.mkdir_p extraction_destination

  block = block_given? ? Proc.new : proc {}

  report_progress(:write_each_tarfile, open_file(&:count), &block)
  FileUtils.rm file_name
  source_destination
end