class GZippedTar::Tar::Writer

Constants

ROW_WIDTH

Attributes

io[R]

Public Class Methods

new(io) { |writer| ... } click to toggle source
Calls superclass method
# File lib/gzipped_tar/tar/writer.rb, line 13
def self.new(io)
  writer = super

  return writer unless block_given?

  begin
    yield writer
  ensure
    writer.close
  end

  nil
end
new(io) click to toggle source

Creates a new TarWriter that will write to io

# File lib/gzipped_tar/tar/writer.rb, line 28
def initialize(io)
  raise GZippedTar::Tar::NonSeekableIO unless io.respond_to? :pos=

  @io     = io
  @closed = false
end

Public Instance Methods

add_file(name, mode, &block) click to toggle source

Adds file name with permissions mode, and yields an IO for writing the file to.

# File lib/gzipped_tar/tar/writer.rb, line 37
def add_file(name, mode, &block)
  check_closed

  GZippedTar::Tar::WriteFile.call self, io, name, mode, &block

  self
end
add_file_signed(name, mode, signer, &block) click to toggle source

Adds name with permissions mode to the tar, yielding io for writing the file. The signer is used to add a digest file using its digest_algorithm per add_file_digest and a cryptographic signature in name.sig. If the signer has no key only the checksum file is added.

Returns the digest.

# File lib/gzipped_tar/tar/writer.rb, line 51
def add_file_signed(name, mode, signer, &block)
  GZippedTar::Tar::WriteSignedFile.call self, name, mode, signer, &block
end
add_file_simple(name, mode, size) { |stream| ... } click to toggle source

Add file name with permissions mode size bytes long. Yields an IO to write the file to.

# File lib/gzipped_tar/tar/writer.rb, line 57
def add_file_simple(name, mode, size)
  write_header name, mode, :size => size

  stream = GZippedTar::Tar::BoundedStream.new io, size

  yield stream if block_given?

  min_padding = size - stream.written
  io.write("\0" * min_padding)

  pad_rows size

  self
end
close() click to toggle source

Closes the TarWriter

# File lib/gzipped_tar/tar/writer.rb, line 78
def close
  check_closed

  io.write GZippedTar::Tar::EMPTY_ROW
  io.write GZippedTar::Tar::EMPTY_ROW
  flush

  @closed = true
end
closed?() click to toggle source

Is the TarWriter closed?

# File lib/gzipped_tar/tar/writer.rb, line 89
def closed?
  @closed
end
flush() click to toggle source

Flushes the TarWriter's IO

# File lib/gzipped_tar/tar/writer.rb, line 94
def flush
  check_closed

  io.flush if io.respond_to? :flush
end
mkdir(name, mode) click to toggle source

Creates a new directory in the tar file name with mode

# File lib/gzipped_tar/tar/writer.rb, line 101
def mkdir(name, mode)
  write_header name, mode, :typeflag => "5"
end
pad_rows(size) click to toggle source
# File lib/gzipped_tar/tar/writer.rb, line 105
def pad_rows(size)
  remainder = (ROW_WIDTH - (size % ROW_WIDTH)) % ROW_WIDTH

  io.write "\0" * remainder
end
write_header(name, mode, options = {}) click to toggle source
# File lib/gzipped_tar/tar/writer.rb, line 111
def write_header(name, mode, options = {})
  check_closed

  prefix, name = GZippedTar::Tar::SplitName.call name

  io.write GZippedTar::Tar::Header.new({
    :name   => name,
    :mode   => mode,
    :prefix => prefix,
    :size   => 0,
    :mtime  => Time.now
  }.merge(options))

  self
end

Private Instance Methods

check_closed() click to toggle source

Raises IOError if the TarWriter is closed

# File lib/gzipped_tar/tar/writer.rb, line 132
def check_closed
  raise IOError, "closed #{self.class}" if closed?
end