Sha256: b51ec4466dadcbc153eea2b72ea7557049c376677373851d690e856972b7aee6

Contents?: true

Size: 650 Bytes

Versions: 9

Compression:

Stored size: 650 Bytes

Contents

require "rubygems"
require "archive/tar/minitar"
require "base64"

class Groundwork::TarWrapper
  include Archive::Tar

  # Takes a base64-encoded, tarred string
  def initialize encoded
    tar = Base64.decode64(encoded)
    @files = {}
    Minitar::Reader.new(StringIO.new(tar)).each do |entry|
      next unless entry.file?
      @files[entry.full_name] = entry.read
    end
  end

  def [] name
    @files[name]
  end

  def self.compress files
    string = StringIO.new
    output = Minitar::Output.new(string)

    files.each do |file|
      Minitar.pack_file(file, output)
    end

    output.close
    Base64.encode64 string.string
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
groundwork-1.0.2 lib/tar_wrapper.rb
groundwork-1.0.1 lib/tar_wrapper.rb
groundwork-1.0.0 lib/tar_wrapper.rb
groundwork-0.0.6 lib/tar_wrapper.rb
groundwork-0.0.5 lib/tar_wrapper.rb
groundwork-0.0.4 lib/tar_wrapper.rb
groundwork-0.0.3 lib/tar_wrapper.rb
groundwork-0.0.2 lib/tar_wrapper.rb
groundwork-0.0.1 lib/tar_wrapper.rb