nvflare.app_common.streamers.file_streamer module¶
- class FileStreamer[source]¶
Bases:
StreamerBase
- static get_file_location(stream_ctx: dict)[source]¶
Get the file location property from stream context. This method is intended to be used by the stream_done_cb() function of the receiving side.
- Parameters:
stream_ctx – the stream context
Returns: location (full file path) of the received file
- static get_file_name(stream_ctx: dict)[source]¶
Get the file base name property from stream context. This method is intended to be used by the stream_done_cb() function of the receiving side.
- Parameters:
stream_ctx – the stream context
Returns: file base name
- static get_file_size(stream_ctx: dict)[source]¶
Get the file size property from stream context. This method is intended to be used by the stream_done_cb() function of the receiving side.
- Parameters:
stream_ctx – the stream context
Returns: size (in bytes) of the received file
- static register_stream_processing(fl_ctx: FLContext, channel: str, topic: str, dest_dir: str | None = None, stream_done_cb=None, **cb_kwargs)[source]¶
Register for stream processing on the receiving side.
- Parameters:
fl_ctx – the FLContext object
channel – the app channel
topic – the app topic
dest_dir – the destination dir for received file. If not specified, system temp dir is used
stream_done_cb – if specified, the callback to be called when the file is completely received
**cb_kwargs – the kwargs for the stream_done_cb
Returns: None
Notes: the stream_done_cb must follow stream_done_cb_signature as defined in apis.streaming.
- static stream_file(channel: str, topic: str, stream_ctx: dict, targets: List[str], file_name: str, fl_ctx: FLContext, chunk_size=None, chunk_timeout=None, optional=False, secure=False) bool [source]¶
Stream a file to one or more targets.
- Parameters:
channel – the app channel
topic – the app topic
stream_ctx – context data of the stream
targets – targets that the file will be sent to
file_name – full path to the file to be streamed
fl_ctx – a FLContext object
chunk_size – size of each chunk to be streamed. If not specified, default to 1M bytes.
chunk_timeout – timeout for each chunk of data sent to targets.
optional – whether the file is optional
secure – whether P2P security is required
Returns: whether the streaming completed successfully
Notes: this is a blocking call - only returns after the streaming is done.