@classmethod<EOL><INDENT>def frombuf(cls, buf, encoding, errors):<DEDENT>
if len(buf) == <NUM_LIT:0>:<EOL><INDENT>raise EmptyHeaderError("<STR_LIT>")<EOL><DEDENT>if len(buf) != BLOCKSIZE:<EOL><INDENT>raise TruncatedHeaderError("<STR_LIT>")<EOL><DEDENT>if buf.count(NUL) == BLOCKSIZE:<EOL><INDENT>raise EOFHeaderError("<STR_LIT>")<EOL><DEDENT>chksum = nti(buf[<NUM_LIT>:<NUM_LIT>])<EOL>if chksum not in calc_chksums(buf):<EOL><INDENT>raise InvalidHeaderError("<STR_LIT>")<EOL><DEDENT>obj = cls()<EOL>obj.name = nts(buf[<NUM_LIT:0>:<NUM_LIT:100>], encoding, errors)<EOL>obj.mode = nti(buf[<NUM_LIT:100>:<NUM_LIT>])<EOL>obj.uid = nti(buf[<NUM_LIT>:<NUM_LIT>])<EOL>obj.gid = nti(buf[<NUM_LIT>:<NUM_LIT>])<EOL>obj.size = nti(buf[<NUM_LIT>:<NUM_LIT>])<EOL>obj.mtime = nti(buf[<NUM_LIT>:<NUM_LIT>])<EOL>obj.chksum = chksum<EOL>obj.type = buf[<NUM_LIT>:<NUM_LIT>]<EOL>obj.linkname = nts(buf[<NUM_LIT>:<NUM_LIT>], encoding, errors)<EOL>obj.uname = nts(buf[<NUM_LIT>:<NUM_LIT>], encoding, errors)<EOL>obj.gname = nts(buf[<NUM_LIT>:<NUM_LIT>], encoding, errors)<EOL>obj.devmajor = nti(buf[<NUM_LIT>:<NUM_LIT>])<EOL>obj.devminor = nti(buf[<NUM_LIT>:<NUM_LIT>])<EOL>prefix = nts(buf[<NUM_LIT>:<NUM_LIT>], encoding, errors)<EOL>if obj.type == AREGTYPE and obj.name.endswith("<STR_LIT:/>"):<EOL><INDENT>obj.type = DIRTYPE<EOL><DEDENT>if obj.type == GNUTYPE_SPARSE:<EOL><INDENT>pos = <NUM_LIT><EOL>structs = []<EOL>for i in range(<NUM_LIT:4>):<EOL><INDENT>try:<EOL><INDENT>offset = nti(buf[pos:pos + <NUM_LIT:12>])<EOL>numbytes = nti(buf[pos + <NUM_LIT:12>:pos + <NUM_LIT>])<EOL><DEDENT>except ValueError:<EOL><INDENT>break<EOL><DEDENT>structs.append((offset, numbytes))<EOL>pos += <NUM_LIT><EOL><DEDENT>isextended = bool(buf[<NUM_LIT>])<EOL>origsize = nti(buf[<NUM_LIT>:<NUM_LIT>])<EOL>obj._sparse_structs = (structs, isextended, origsize)<EOL><DEDENT>if obj.isdir():<EOL><INDENT>obj.name = obj.name.rstrip("<STR_LIT:/>")<EOL><DEDENT>if prefix and obj.type not in GNU_TYPES:<EOL><INDENT>obj.name = prefix + "<STR_LIT:/>" + obj.name<EOL><DEDENT>return obj<EOL>
Construct a TarInfo object from a 512 byte bytes object.