Sha256: 2235480650001c6c7063ea2e49e8f6c38d4b7d2482d108992cc5857ad949b168

Contents?: true

Size: 1.32 KB

Versions: 19

Compression:

Stored size: 1.32 KB

Contents

require "rubygems/package"

module Linner
  class Archive

    class << self
      def tar(glob, dest)
        archived = StringIO.new
        Gem::Package::TarWriter.new(archived) do |tar|
          Dir[glob].each do |file|
            paths = Linner.env.paths
            mode = File.stat(file).mode
            relative_file = file.gsub /^#{paths.join("|")}\/?/, ""
            if File.directory?(file)
              tar.mkdir relative_file, mode
            else
              tar.add_file relative_file, mode do |tf|
                File.open(file, "rb") { |f| tf.write f.read }
              end
            end
          end
        end

        archived.rewind

        Zlib::GzipWriter.open(dest) do |gz|
          gz.write archived.string
        end
      end

      def untar(path, dest)
        extracted = Gem::Package::TarReader.new Zlib::GzipReader.open(path)

        extracted.rewind

        extracted.each do |entry|
          file = File.join dest, entry.full_name
          if entry.directory?
            FileUtils.mkdir_p file
          else
            directory = File.dirname(file)
            FileUtils.mkdir_p directory unless File.directory?(directory)
            File.open file, "wb" do |f|
              f.print entry.read
            end
          end
        end

        extracted.close
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 2 rubygems

Version Path
linner-hc-1.0.0 lib/linner/archive.rb
linner-0.12.0 lib/linner/archive.rb
linner-0.11.6 lib/linner/archive.rb
linner-0.11.5 lib/linner/archive.rb
linner-0.11.4 lib/linner/archive.rb
linner-0.11.3 lib/linner/archive.rb
linner-0.11.2 lib/linner/archive.rb
linner-0.11.1 lib/linner/archive.rb
linner-0.11.0 lib/linner/archive.rb
linner-0.10.0 lib/linner/archive.rb
linner-0.9.1 lib/linner/archive.rb
linner-0.9.0 lib/linner/archive.rb
linner-0.8.7 lib/linner/archive.rb
linner-0.8.6 lib/linner/archive.rb
linner-0.8.5 lib/linner/archive.rb
linner-0.8.4 lib/linner/archive.rb
linner-0.8.3 lib/linner/archive.rb
linner-0.8.2 lib/linner/archive.rb
linner-0.8.1 lib/linner/archive.rb