method
header
v2_4_6 -
Show latest stable
- Class:
Gem::Package::TarTestCase
header(type, fname, dname, length, mode, mtime, checksum = nil, linkname = "")public
No documentation available.
# File lib/rubygems/package/tar_test_case.rb, line 75
def header(type, fname, dname, length, mode, mtime, checksum = nil, linkname = "")
checksum ||= " " * 8
arr = [ # struct tarfile_entry_posix
ASCIIZ(fname, 100), # char name[100]; ASCII + (Z unless filled)
Z(to_oct(mode, 7)), # char mode[8]; 0 padded, octal null
Z(to_oct(0, 7)), # char uid[8]; ditto
Z(to_oct(0, 7)), # char gid[8]; ditto
Z(to_oct(length, 11)), # char size[12]; 0 padded, octal, null
Z(to_oct(mtime, 11)), # char mtime[12]; 0 padded, octal, null
checksum, # char checksum[8]; 0 padded, octal, null, space
type, # char typeflag[1]; file: "0" dir: "5"
ASCIIZ(linkname, 100), # char linkname[100]; ASCII + (Z unless filled)
"ustar\00"", # char magic[6]; "ustar\0"
"00", # char version[2]; "00"
ASCIIZ("wheel", 32), # char uname[32]; ASCIIZ
ASCIIZ("wheel", 32), # char gname[32]; ASCIIZ
Z(to_oct(0, 7)), # char devmajor[8]; 0 padded, octal, null
Z(to_oct(0, 7)), # char devminor[8]; 0 padded, octal, null
ASCIIZ(dname, 155) # char prefix[155]; ASCII + (Z unless filled)
]
format = "C100C8C8C8C12C12C8CC100C6C2C32C32C8C8C155"
h = if RUBY_VERSION >= "1.9" then
arr.join
else
arr = arr.join("").split(//).map{|x| x[0]}
arr.pack format
end
ret = h + "\00"" * (512 - h.size)
assert_equal(512, ret.size)
ret
end