Extended maintenance of Ruby 1.9.3 ended on February 23, 2015. Read more

In Files

  • rubygems/package/tar_header.rb

Class/Module Index [+]

Quicksearch

Gem::Package::TarHeader

A header for a tar file

Constants

FIELDS

Fields in the tar header

PACK_FORMAT

Pack format for a tar header

UNPACK_FORMAT

Unpack format for a tar header

Public Class Methods

from(stream) click to toggle source

Creates a tar header from IO stream

 
               # File rubygems/package/tar_header.rb, line 98
def self.from(stream)
  header = stream.read 512
  empty = (header == "\0" * 512)

  fields = header.unpack UNPACK_FORMAT

  name     = fields.shift
  mode     = fields.shift.oct
  uid      = fields.shift.oct
  gid      = fields.shift.oct
  size     = fields.shift.oct
  mtime    = fields.shift.oct
  checksum = fields.shift.oct
  typeflag = fields.shift
  linkname = fields.shift
  magic    = fields.shift
  version  = fields.shift.oct
  uname    = fields.shift
  gname    = fields.shift
  devmajor = fields.shift.oct
  devminor = fields.shift.oct
  prefix   = fields.shift

  new :name     => name,
      :mode     => mode,
      :uid      => uid,
      :gid      => gid,
      :size     => size,
      :mtime    => mtime,
      :checksum => checksum,
      :typeflag => typeflag,
      :linkname => linkname,
      :magic    => magic,
      :version  => version,
      :uname    => uname,
      :gname    => gname,
      :devmajor => devmajor,
      :devminor => devminor,
      :prefix   => prefix,

      :empty    => empty

  # HACK unfactor for Rubinius
  #new :name     => fields.shift,
  #    :mode     => fields.shift.oct,
  #    :uid      => fields.shift.oct,
  #    :gid      => fields.shift.oct,
  #    :size     => fields.shift.oct,
  #    :mtime    => fields.shift.oct,
  #    :checksum => fields.shift.oct,
  #    :typeflag => fields.shift,
  #    :linkname => fields.shift,
  #    :magic    => fields.shift,
  #    :version  => fields.shift.oct,
  #    :uname    => fields.shift,
  #    :gname    => fields.shift,
  #    :devmajor => fields.shift.oct,
  #    :devminor => fields.shift.oct,
  #    :prefix   => fields.shift,

  #    :empty => empty
end
            
new(vals) click to toggle source

Creates a new TarHeader using vals

 
               # File rubygems/package/tar_header.rb, line 164
def initialize(vals)
  unless vals[:name] && vals[:size] && vals[:prefix] && vals[:mode] then
    raise ArgumentError, ":name, :size, :prefix and :mode required"
  end

  vals[:uid] ||= 0
  vals[:gid] ||= 0
  vals[:mtime] ||= 0
  vals[:checksum] ||= ""
  vals[:typeflag] ||= "0"
  vals[:magic] ||= "ustar"
  vals[:version] ||= "00"
  vals[:uname] ||= "wheel"
  vals[:gname] ||= "wheel"
  vals[:devmajor] ||= 0
  vals[:devminor] ||= 0

  FIELDS.each do |name|
    instance_variable_set "@#{name}", vals[name]
  end

  @empty = vals[:empty]
end
            

Public Instance Methods

empty?() click to toggle source

Is the tar entry empty?

 
               # File rubygems/package/tar_header.rb, line 191
def empty?
  @empty
end
            
update_checksum() click to toggle source

Updates the TarHeader’s checksum

 
               # File rubygems/package/tar_header.rb, line 223
def update_checksum
  header = header " " * 8
  @checksum = oct calculate_checksum(header), 6
end
            

Commenting is here to help enhance the documentation. For example, code samples, or clarification of the documentation.

If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.

If you wish to post a correction of the docs, please do so, but also file bug report so that it can be corrected for the next release. Thank you.

If you want to help improve the Ruby documentation, please visit Documenting-ruby.org.