def bdata_provider(data_source, mode: str = "SINGLE"):
    """Build - with a higher order function - an interface to binary data.
    
    The generated function arguments are:
    - start_pos: index in the data source, can be a negative integer to count from the end
    - length: number of bytes needed
    Return a tuple containing:
    - the buffer to read,
    - the index into the buffer,
    - the offset from the beginning of the file to the buffer,
    - the number of readable bytes.
    """
    if mode == "SINGLE":
        if type(data_source) == bytes:
            bdata = data_source
        else:
            bdata = data_source.read()
        def single_load(start_pos: int, length: int) -> tuple:
            if start_pos ==  None and length == -1: #Special escape for length only
                return (None, None, None, len(bdata))
            i = (start_pos + len(bdata)) % len(bdata)
            if length == -1:
                nb_read = len(bdata) - i
            else:
                nb_read = min(len(bdata) - i, length)
            return (bdata, i, 0, nb_read)
        return single_load
    else:
        file_obj = data_source
        def continuous_load(start_pos: int, length: int) -> tuple:
            file_obj.seek(0, os.SEEK_END)
            file_size = file_obj.tell()
            if start_pos == None and length == -1:
                return (None, None, None, file_size)
            i = (start_pos + file_size) % file_size
            if length == -1:
                nb_read = file_size - i
            else:
                nb_read = min(file_size - i, length)
            file_obj.seek(i)
            bdata = file_obj.read(nb_read)
            return (bdata, i, 0, nb_read)
        return continuous_load
Build - with a higher order function - an interface to binary data.
    
    The generated function arguments are:
    - start_pos: index in the data source, can be a negative integer to count from the end
    - length: number of bytes needed
    Return a tuple containing:
    - the buffer to read,
    - the index into the buffer,
    - the offset from the beginning of the file to the buffer,
    - the number of readable bytes.
    
pdfsyntax/filestruct.py