def squash(doc: Doc) -> Doc:
    """Group all revisions into a single one."""
    obj_stms = envelope_objects(doc)
    if type(doc.index[0][0]) == dict:
        xref_stream_num = doc.index[0][0].get('xref_stream_num')
    else: #TODO
        xref_stream_num = doc.index[0][0][0].get('xref_stream_num')
    old_index = doc.index[-1]
    new_index, mapping = defragment_map(old_index, set())
    if xref_stream_num:
        new_index[0]['xref_stream_num'] = xref_stream_num
    new_cache = len(new_index) * [None]
    new_data = [{}]
    new_cache[0] = {'/Root': trailer(doc)['/Root']}
    new_cache[0] = deep_ref_retarget(new_cache[0], mapping)
    for i in range(1, len(new_index)):
        old_ref = new_index[i]['OLD_REF']
        obj = get_object(doc, old_ref)
        obj = deep_ref_retarget(obj, mapping)
        new_cache[i] = obj
    new_doc = Doc([new_index], new_cache, new_data)
    chg = changes(new_doc)
    if not chg:
        return b''
    header = f"%PDF-{version(doc)}".encode('ascii')
    new_data[-1]['fdata'] = bdata_dummy(header)
    #new_doc = commit(new_doc) #TODO: keep?
    return new_doc
Group all revisions into a single one.
pdfsyntax/docstruct.py