def merge_fdata(fdata: Callable, index: int, bdata: bytes):
    """Merge a data provider and bytes into a new composite data provider."""
    def composite_fdata(start_pos: int, length: int) -> tuple:
        if start_pos == None and length == -1:
            #_, _, _, sz = fdata(None, -1)
            sz = index
            return (None, None, None, sz + len(bdata))
        if start_pos > index:
            start_pos = start_pos - index
            #if start_pos == -1 and length == 0:
            #    return (None, None, None, len(bdata))
            if length == -1:
                length = len(bdata) - start_pos
            if start_pos == -1:
                i = len(bdata) - length
            else:
                i = start_pos
            return (bdata, i, 0, min(len(bdata) - start_pos, length))
            #return (bdata, i, index, min(len(bdata) - start_pos, length)) #TODO
        else:
            return fdata(start_pos, length)
    return composite_fdata
Merge a data provider and bytes into a new composite data provider.
pdfsyntax/docstruct.py