class RakeDependencies::Extractors::TarGzExtractor

Public Class Methods

new(file_path, extract_path, options = {}) click to toggle source
# File lib/rake_dependencies/extractors.rb, line 32
def initialize(file_path, extract_path, options = {})
  @file_path = file_path
  @extract_path = extract_path
  @options = options
end

Public Instance Methods

extract() click to toggle source
# File lib/rake_dependencies/extractors.rb, line 38
def extract
  FileUtils.mkdir_p(@extract_path)
  Zlib::GzipReader.open(@file_path) do |tar_file|
    Archive::Tar::Minitar.open(tar_file) do |tar_file_entries|
      tar_file_entries.each do |entry|
        entry_pathname = Pathname.new(entry.name)
        strip_pathname = Pathname.new(@options[:strip_path] || '')
        target_pathname = entry_pathname.relative_path_from(strip_pathname)

        file_path = File.join(@extract_path, target_pathname)
        FileUtils.mkdir_p(File.dirname(file_path))
        if entry.file? && !File.exist?(file_path)
          File.open(file_path, 'w', entry.mode) { |f| f.write(entry.read) }
        end
      end
    end
  end
end