|
24 | 24 | from ._proto import ffi_pb2 as proto_ffi |
25 | 25 | from ._proto import room_pb2 as proto_room |
26 | 26 | from ._ffi_client import FfiClient |
27 | | - |
| 27 | +from ._utils import split_utf8 |
28 | 28 | from typing import TYPE_CHECKING |
29 | 29 |
|
30 | 30 | if TYPE_CHECKING: |
@@ -287,19 +287,17 @@ def __init__( |
287 | 287 | attachments=list(self._header.text_header.attached_stream_ids), |
288 | 288 | ) |
289 | 289 |
|
290 | | - async def write(self, text: str, chunk_index: int | None = None): |
291 | | - content = text.encode() |
292 | | - if len(content) > STREAM_CHUNK_SIZE: |
293 | | - raise ValueError("maximum chunk size exceeded") |
294 | | - if chunk_index is None: |
| 290 | + async def write(self, text: str): |
| 291 | + for chunk in split_utf8(text, STREAM_CHUNK_SIZE): |
| 292 | + content = chunk.encode() |
295 | 293 | chunk_index = self._next_chunk_index |
296 | 294 | self._next_chunk_index += 1 |
297 | | - chunk_msg = proto_DataStream.Chunk( |
298 | | - stream_id=self._header.stream_id, |
299 | | - chunk_index=chunk_index, |
300 | | - content=content, |
301 | | - ) |
302 | | - await self._send_chunk(chunk_msg) |
| 295 | + chunk_msg = proto_DataStream.Chunk( |
| 296 | + stream_id=self._header.stream_id, |
| 297 | + chunk_index=chunk_index, |
| 298 | + content=content, |
| 299 | + ) |
| 300 | + await self._send_chunk(chunk_msg) |
303 | 301 |
|
304 | 302 | @property |
305 | 303 | def info(self) -> TextStreamInfo: |
|
0 commit comments