Class: Groundwork::TarWrapper

Inherits:
Object
  • Object
show all
Includes:
Archive::Tar
Defined in:
lib/tar_wrapper.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(encoded) ⇒ TarWrapper

Takes a base64-encoded, tarred string



9
10
11
12
13
14
15
16
# File 'lib/tar_wrapper.rb', line 9

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

Class Method Details

.compress(files) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/tar_wrapper.rb', line 22

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

Instance Method Details

#[](name) ⇒ Object



18
19
20
# File 'lib/tar_wrapper.rb', line 18

def [] name
  @files[name]
end