@@ -141,6 +141,7 @@ def __init__(
141141 extensions : Optional [Dict [str , str ]] = {},
142142 stream_id : str | None = None ,
143143 total_size : int | None = None ,
144+ mime_type : str = "" ,
144145 ):
145146 self ._local_participant = local_participant
146147 if stream_id is None :
@@ -149,7 +150,7 @@ def __init__(
149150 self ._header = proto_DataStream .Header (
150151 stream_id = stream_id ,
151152 timestamp = timestamp ,
152- mime_type = "text/plain" ,
153+ mime_type = mime_type ,
153154 topic = topic ,
154155 extensions = extensions ,
155156 total_length = total_size ,
@@ -234,7 +235,14 @@ def __init__(
234235 total_size : int | None = None ,
235236 reply_to_id : str | None = None ,
236237 ) -> None :
237- super ().__init__ (local_participant , topic , extensions , stream_id , total_size )
238+ super ().__init__ (
239+ local_participant ,
240+ topic ,
241+ extensions ,
242+ stream_id ,
243+ total_size ,
244+ mime_type = "text/plain" ,
245+ )
238246 if reply_to_id :
239247 self ._header .text_header .reply_to_stream_id = reply_to_id
240248 self ._info = TextStreamInfo (
@@ -248,13 +256,16 @@ def __init__(
248256 )
249257
250258 async def write (self , text : str , chunk_index : int | None = None ):
259+ content = text .encode ()
260+ if len (content ) > STREAM_CHUNK_SIZE :
261+ raise ValueError ("maximum chunk size exceeded" )
251262 if chunk_index is None :
252263 chunk_index = self ._next_chunk_index
253264 self ._next_chunk_index += 1
254265 chunk_msg = proto_DataStream .Chunk (
255266 stream_id = self ._header .stream_id ,
256267 chunk_index = chunk_index ,
257- content = text . encode () ,
268+ content = content ,
258269 )
259270 await self ._send_chunk (chunk_msg )
260271
@@ -272,8 +283,16 @@ def __init__(
272283 extensions : Optional [Dict [str , str ]] = {},
273284 stream_id : str | None = None ,
274285 total_size : int | None = None ,
286+ mime_type : str = "" ,
275287 ) -> None :
276- super ().__init__ (local_participant , topic , extensions , stream_id , total_size )
288+ super ().__init__ (
289+ local_participant ,
290+ topic ,
291+ extensions ,
292+ stream_id ,
293+ total_size ,
294+ mime_type = mime_type ,
295+ )
277296 self ._header .file_header .file_name = file_name
278297 self ._info = FileStreamInfo (
279298 id = self ._header .stream_id ,
@@ -286,6 +305,9 @@ def __init__(
286305 )
287306
288307 async def write (self , data : bytes , chunk_index : int | None = None ):
308+ if len (data ) > STREAM_CHUNK_SIZE :
309+ raise ValueError ("maximum chunk size exceeded" )
310+
289311 if chunk_index is None :
290312 chunk_index = self ._next_chunk_index
291313 self ._next_chunk_index += 1
0 commit comments