def seek_delimiter(file, delimiter, blocksize):

    if file.tell() == 0:
        return

    last = b''
    while True:
        current = file.read(blocksize)
        if not current:
            return
        full = last + current
        try:
            i = full.index(delimiter)
            file.seek(file.tell() - (len(full) - i) + len(delimiter))
            return
        except ValueError:
            pass
        last = full[-len(delimiter):]
Seek current file to next byte after a delimiter bytestring
dataset/ETHPy150Open dask/dask/dask/bytes/utils.py/seek_delimiter