class AndFeathers::Tarball

The base tarball representation

Attributes

path[R]

@!attribute [r] path

@return [String] the base tarball path

Public Class Methods

new(path = '.') click to toggle source

Creates a new Tarball

@param path [String] the base tarball path

# File lib/and_feathers/tarball.rb, line 27
def initialize(path = '.')
  @path = path
  @children = []
end

Public Instance Methods

each(&block) click to toggle source

Iterates through each entity in the tarball, depth-first

@yieldparam child [File, Directory]

# File lib/and_feathers/tarball.rb, line 37
def each(&block)
  @children.each do |child|
    block.call(child)
    child.each(&block)
  end
end
to_io() click to toggle source

Returns this Tarball as a GZipped and tarred StringIO

@return [StringIO]

# File lib/and_feathers/tarball.rb, line 49
def to_io
  tarball_io = StringIO.new("")

  Gem::Package::TarWriter.new(tarball_io) do |tar|
    each do |child|
      case child
      when File
        tar.add_file(child.path, child.mode) do |file|
          file.write child.read
        end
      when Directory
        tar.mkdir(child.path, child.mode)
      end
    end
  end

  gzip_io = StringIO.new("")

  Zlib::GzipWriter.new(gzip_io).tap do |writer|
    writer.write(tarball_io.tap(&:rewind).string)
    writer.close
  end

  StringIO.new(gzip_io.string)
end