Class
A header for a tar file
Constants
Fields in the tar header
Pack format for a tar header
Unpack format for a tar header
Class Methods
::
lib/rubygems/package/tar_header.rb
View on GitHub
# File tmp/rubies/ruby-2.4.10/lib/rubygems/package/tar_header.rb, line 99
def self.from(stream)
header = stream.read 512
empty = (header == "\0" * 512)
fields = header.unpack UNPACK_FORMAT
new :name => fields.shift,
:mode => strict_oct(fields.shift),
:uid => strict_oct(fields.shift),
:gid => strict_oct(fields.shift),
:size => strict_oct(fields.shift),
:mtime => strict_oct(fields.shift),
:checksum => strict_oct(fields.shift),
:typeflag => fields.shift,
:linkname => fields.shift,
:magic => fields.shift,
:version => strict_oct(fields.shift),
:uname => fields.shift,
:gname => fields.shift,
:devmajor => strict_oct(fields.shift),
:devminor => strict_oct(fields.shift),
:prefix => fields.shift,
:empty => empty
end
Creates a tar header from IO
stream
::
lib/rubygems/package/tar_header.rb
View on GitHub
# File tmp/rubies/ruby-2.4.10/lib/rubygems/package/tar_header.rb, line 133
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" if vals[:typeflag].nil? || vals[:typeflag].empty?
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
Creates a new TarHeader
using vals
lib/rubygems/package/tar_header.rb
View on GitHub
# File tmp/rubies/ruby-2.4.10/lib/rubygems/package/tar_header.rb, line 125
def self.strict_oct(str)
return str.oct if str =~ /\A[0-7]*\z/
raise ArgumentError, "#{str.inspect} is not an octal string"
end
No documentation available
Instance Methods
lib/rubygems/package/tar_header.rb
View on GitHub
# File tmp/rubies/ruby-2.4.10/lib/rubygems/package/tar_header.rb, line 199
def calculate_checksum(header)
header.unpack("C*").inject { |a, b| a + b }
end
No documentation available
#
lib/rubygems/package/tar_header.rb
View on GitHub
# File tmp/rubies/ruby-2.4.10/lib/rubygems/package/tar_header.rb, line 160
def empty?
@empty
end
Is the tar entry empty?
lib/rubygems/package/tar_header.rb
View on GitHub
# File tmp/rubies/ruby-2.4.10/lib/rubygems/package/tar_header.rb, line 203
def header(checksum = @checksum)
header = [
name,
oct(mode, 7),
oct(uid, 7),
oct(gid, 7),
oct(size, 11),
oct(mtime, 11),
checksum,
" ",
typeflag,
linkname,
magic,
oct(version, 2),
uname,
gname,
oct(devmajor, 7),
oct(devminor, 7),
prefix
]
header = header.pack PACK_FORMAT
header << ("\0" * ((512 - header.size) % 512))
end
No documentation available
lib/rubygems/package/tar_header.rb
View on GitHub
# File tmp/rubies/ruby-2.4.10/lib/rubygems/package/tar_header.rb, line 229
def oct(num, len)
"%0#{len}o" % num
end
No documentation available
lib/rubygems/package/tar_header.rb
View on GitHub
# File tmp/rubies/ruby-2.4.10/lib/rubygems/package/tar_header.rb, line 192
def update_checksum
header = header " " * 8
@checksum = oct calculate_checksum(header), 6
end
Updates the TarHeader’s checksum