def build_xref_sequence(fdata: Callable) -> tuple:
    """Build a list of all xref sequentially found in file.

    Return:
    - the list of xref
    - a dict that gives the following abs_pos
    - the max obj number
    """
    EOF = b'%%EOF'
    STARTXREF = b'startxref'
    XREF = b'xref'
    start = True
    prev = False
    xrefstm = False
    prev_eof = None
    chrono = []
    seq = []
    while start or prev or xrefstm:
        a0 = 0
        o0 = 0
        if start:
            start = False
            bdata, a0, o0, _ = fdata(-100, -1)
            eof_pos = o0 + bdata.rfind(EOF, a0)
            startxref_pos = o0 + bdata.rfind(STARTXREF, a0)
            i, j, _ = next_token(bdata, startxref_pos + len(STARTXREF) - o0)
            xref_pos = int(bdata[i:j])
            last = startxref_pos
        elif xrefstm:
            xref_pos = xrefstm
            startxref_pos = o0 + bdata.find(STARTXREF, xref_pos)
            eof_pos = o0 + bdata.find(EOF, xref_pos)
            last = eof_pos
            xrefstm = False
        elif prev:
            xref_pos = prev
            startxref_pos = o0 + bdata.find(STARTXREF, xref_pos)
            eof_pos = o0 + bdata.find(EOF, xref_pos)
            last = eof_pos
            prev = False
        bdata, a0, o0, _ = fdata(xref_pos, last - xref_pos)
        if bdata[a0:a0+4] == XREF:
            xref_index = parse_xref_table(bdata, a0, o0)
            i, j, _ = next_token(bdata, xref_index[0]['abs_pos'] - o0) #b'trailer'
            i, j, _ = next_token(bdata, j)                            #dict
            trailer = parse_obj(bdata[i:j])
        else: # must be a /XRef stream
            bdata, a0, o0, _ = fdata(xref_pos, startxref_pos - xref_pos)
            i, j, _ = next_token(bdata, a0 - o0) #o_num
            o_num = parse_obj(bdata, i)
            i, j, _ = next_token(bdata, j)       #o_ver
            i, j, _ = next_token(bdata, j)       #b'obj'
            i, j, _ = next_token(bdata, j)       #dict
            xref = parse_obj(bdata, i)
            xref_index = parse_xref_stream(xref, xref_pos, o_num)
            trailer = xref['entries']
        xref_index[0]['startxref_pos'] = startxref_pos
        xref_index.append({'o_num': -1, 'o_gen': -1, 'abs_pos': eof_pos})
        chrono.append(xref_index)
        seq += [(i.get('abs_pos'), i.get('o_num')) for i in xref_index if 'abs_pos' in i and 'env_num' not in i]
        if xrefstm == False and prev == False:
            if '/XRefStm' in trailer:
                xref_index[0]['xref_stm'] = True
                xrefstm = int(trailer['/XRefStm'])
            if '/Prev' in trailer:
                prev = int(trailer['/Prev'])
    idx = sorted([i[0] for i in seq])
    _, _, _, file_sz = fdata(None, -1)
    idx.append(file_sz)
    #idx.append(None)
    nxt = {idx[i]: idx[i+1] for i in range(len(idx)-1) if idx[i] < idx[i+1]}
    #nxt = {idx[i]: idx[i+1] for i in range(len(idx)-1)}
    nb = max(seq, key = lambda i: i[1])[1]
    return chrono, nxt, nb
Build a list of all xref sequentially found in file.

    Return:
    - the list of xref
    - a dict that gives the following abs_pos
    - the max obj number
    
pdfsyntax/filestruct.py