'Process a GNU sparse header plus extra headers.'

def _proc_sparse(self, tarfile):

    buf = self.buf
    sp = _ringbuffer()
    pos = 386
    lastpos = 0L
    realpos = 0L
    for i in xrange(4):
        try:
            offset = nti(buf[pos:(pos + 12)])
            numbytes = nti(buf[(pos + 12):(pos + 24)])
        except ValueError:
            break
        if (offset > lastpos):
            sp.append(_hole(lastpos, (offset - lastpos)))
        sp.append(_data(offset, numbytes, realpos))
        realpos += numbytes
        lastpos = (offset + numbytes)
        pos += 24
    isextended = ord(buf[482])
    origsize = nti(buf[483:495])
    while (isextended == 1):
        buf = tarfile.fileobj.read(BLOCKSIZE)
        pos = 0
        for i in xrange(21):
            try:
                offset = nti(buf[pos:(pos + 12)])
                numbytes = nti(buf[(pos + 12):(pos + 24)])
            except ValueError:
                break
            if (offset > lastpos):
                sp.append(_hole(lastpos, (offset - lastpos)))
            sp.append(_data(offset, numbytes, realpos))
            realpos += numbytes
            lastpos = (offset + numbytes)
            pos += 24
        isextended = ord(buf[504])
    if (lastpos < origsize):
        sp.append(_hole(lastpos, (origsize - lastpos)))
    self.sparse = sp
    self.offset_data = tarfile.fileobj.tell()
    tarfile.offset = (self.offset_data + self._block(self.size))
    self.size = origsize
    return self
