@@ -974,6 +974,56 @@ async def send_file(
974974
975975 return _byte_stream_info_from_proto (cb .send_file .info )
976976
977+ async def send_bytes (
978+ self ,
979+ data : bytes ,
980+ * ,
981+ topic : str = "" ,
982+ name : str | None = None ,
983+ mime_type : str | None = None ,
984+ destination_identities : Optional [List [str ]] = None ,
985+ attributes : Optional [Dict [str , str ]] = None ,
986+ stream_id : str | None = None ,
987+ compress : bool = True ,
988+ ) -> ByteStreamInfo :
989+ """
990+ Sends an in-memory buffer as a complete byte stream in one call.
991+ Unlike stream_bytes(), the whole payload is known up front, so short payloads can be
992+ sent as a single packet and larger ones compressed, when every recipient supports it.
993+ `name` defaults to "unknown" and `mime_type` to "application/octet-stream".
994+ """
995+ req = proto_ffi .FfiRequest ()
996+ req .send_bytes .local_participant_handle = self ._ffi_handle .handle
997+ req .send_bytes .bytes = data
998+ options = req .send_bytes .options
999+ options .topic = topic
1000+ if name is not None :
1001+ options .name = name
1002+ if mime_type is not None :
1003+ options .mime_type = mime_type
1004+ if attributes :
1005+ options .attributes .update (attributes )
1006+ if destination_identities :
1007+ options .destination_identities .extend (destination_identities )
1008+ if stream_id is not None :
1009+ options .id = stream_id
1010+ options .compress = compress
1011+ options .sender_identity = self .identity
1012+
1013+ queue = FfiClient .instance .queue .subscribe ()
1014+ try :
1015+ resp = FfiClient .instance .request (req )
1016+ cb : proto_ffi .FfiEvent = await queue .wait_for (
1017+ lambda e : e .send_bytes .async_id == resp .send_bytes .async_id
1018+ )
1019+ finally :
1020+ FfiClient .instance .queue .unsubscribe (queue )
1021+
1022+ if cb .send_bytes .HasField ("error" ):
1023+ raise StreamError (cb .send_bytes .error .description )
1024+
1025+ return _byte_stream_info_from_proto (cb .send_bytes .info )
1026+
9771027 async def publish_data_track (
9781028 self ,
9791029 * ,
0 commit comments