Sha256: 3d889bb08772e04f380cb810e4d977decfc5f32c07f1035b783a5fe3be4c182c

Contents?: true

Size: 631 Bytes

Versions: 16

Compression:

Stored size: 631 Bytes

Contents

require "rubygems/package"

module Excavate
  module Extractors
    class TarExtractor < Extractor
      def extract(target)
        File.open(@archive, "rb") do |archive_file|
          Gem::Package::TarReader.new(archive_file) do |tar|
            tar.each do |tarfile|
              save_tar_file(tarfile, target)
            end
          end
        end
      end

      private

      def save_tar_file(file, dir)
        path = File.join(dir, file.full_name)

        if file.directory?
          FileUtils.mkdir_p(path)
        else
          File.write(path, file.read, mode: "wb")
        end
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
excavate-0.3.7 lib/excavate/extractors/tar_extractor.rb
excavate-0.3.6 lib/excavate/extractors/tar_extractor.rb
excavate-0.3.5 lib/excavate/extractors/tar_extractor.rb
excavate-0.3.4 lib/excavate/extractors/tar_extractor.rb
excavate-0.3.3 lib/excavate/extractors/tar_extractor.rb
excavate-0.3.2 lib/excavate/extractors/tar_extractor.rb
excavate-0.3.1 lib/excavate/extractors/tar_extractor.rb
excavate-0.3.0 lib/excavate/extractors/tar_extractor.rb
excavate-0.2.5 lib/excavate/extractors/tar_extractor.rb
excavate-0.2.4 lib/excavate/extractors/tar_extractor.rb
excavate-0.2.3 lib/excavate/extractors/tar_extractor.rb
excavate-0.2.2 lib/excavate/extractors/tar_extractor.rb
excavate-0.2.1 lib/excavate/extractors/tar_extractor.rb
excavate-0.2.0 lib/excavate/extractors/tar_extractor.rb
excavate-0.1.1 lib/excavate/extractors/tar_extractor.rb
excavate-0.1.0 lib/excavate/extractors/tar_extractor.rb