def read_until_size_or_end()

in azure-kusto-ingest/azure/kusto/ingest/_stream_extensions.py [0:0]


def read_until_size_or_end(stream: IO[AnyStr], size: int) -> io.BytesIO:
    pos = 0
    result = io.BytesIO()
    while True:
        try:
            returned = stream.read(size - pos)
            pos += len(returned)
            result.write(returned)

            if len(returned) == 0 or pos == size:
                result.seek(0, io.SEEK_SET)
                return result

        except BlockingIOError:
            continue