Class: Gem::Package::TarHeader
- Inherits:
-
Object
- Object
- Gem::Package::TarHeader
- Defined in:
- lib/rubygems/package/tar_header.rb
Overview
– struct tarfile_entry_posix
char name[100]; # ASCII + (Z unless filled)
char mode[8]; # 0 padded, octal, null
char uid[8]; # ditto
char gid[8]; # ditto
char size[12]; # 0 padded, octal, null
char mtime[12]; # 0 padded, octal, null
char checksum[8]; # 0 padded, octal, null, space
char typeflag[1]; # file: "0" dir: "5"
char linkname[100]; # ASCII + (Z unless filled)
char magic[6]; # "ustar\0"
char version[2]; # "00"
char uname[32]; # ASCIIZ
char gname[32]; # ASCIIZ
char devmajor[8]; # 0 padded, octal, null
char devminor[8]; # o padded, octal, null
char prefix[155]; # ASCII + (Z unless filled)
; ++ A header for a tar file
Constant Summary collapse
- FIELDS =
Fields in the tar header
[ :checksum, :devmajor, :devminor, :gid, :gname, :linkname, :magic, :mode, :mtime, :name, :prefix, :size, :typeflag, :uid, :uname, :version, ]
- PACK_FORMAT =
Pack format for a tar header
'a100' + # name 'a8' + # mode 'a8' + # uid 'a8' + # gid 'a12' + # size 'a12' + # mtime 'a7a' + # chksum 'a' + # typeflag 'a100' + # linkname 'a6' + # magic 'a2' + # version 'a32' + # uname 'a32' + # gname 'a8' + # devmajor 'a8' + # devminor 'a155'
- UNPACK_FORMAT =
Unpack format for a tar header
'A100' + # name 'A8' + # mode 'A8' + # uid 'A8' + # gid 'A12' + # size 'A12' + # mtime 'A8' + # checksum 'A' + # typeflag 'A100' + # linkname 'A6' + # magic 'A2' + # version 'A32' + # uname 'A32' + # gname 'A8' + # devmajor 'A8' + # devminor 'A155'
Class Method Summary collapse
-
.from(stream) ⇒ Object
Creates a tar header from IO
stream
.
Instance Method Summary collapse
-
#==(other) ⇒ Object
:nodoc:.
-
#empty? ⇒ Boolean
Is the tar entry empty?.
-
#initialize(vals) ⇒ TarHeader
constructor
Creates a new TarHeader using
vals
. -
#to_s ⇒ Object
:nodoc:.
-
#update_checksum ⇒ Object
Updates the TarHeader’s checksum.
Constructor Details
#initialize(vals) ⇒ TarHeader
Creates a new TarHeader using vals
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/rubygems/package/tar_header.rb', line 165 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 |
Class Method Details
.from(stream) ⇒ Object
Creates a tar header from IO stream
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File '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 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 |
Instance Method Details
#==(other) ⇒ Object
:nodoc:
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
# File 'lib/rubygems/package/tar_header.rb', line 196 def ==(other) # :nodoc: self.class === other and @checksum == other.checksum and @devmajor == other.devmajor and @devminor == other.devminor and @gid == other.gid and @gname == other.gname and @linkname == other.linkname and @magic == other.magic and @mode == other.mode and @mtime == other.mtime and @name == other.name and @prefix == other.prefix and @size == other.size and @typeflag == other.typeflag and @uid == other.uid and @uname == other.uname and @version == other.version end |
#empty? ⇒ Boolean
Is the tar entry empty?
192 193 194 |
# File 'lib/rubygems/package/tar_header.rb', line 192 def empty? @empty end |
#to_s ⇒ Object
:nodoc:
216 217 218 219 |
# File 'lib/rubygems/package/tar_header.rb', line 216 def to_s # :nodoc: update_checksum header end |
#update_checksum ⇒ Object
Updates the TarHeader’s checksum
224 225 226 227 |
# File 'lib/rubygems/package/tar_header.rb', line 224 def update_checksum header = header " " * 8 @checksum = oct calculate_checksum(header), 6 end |