OTA: Passing incoming serial stream to Update.writeStream()

I want to program an ESP32 from another MCU (MT3620) using the arduino OTA functionality in Update.h
I am already able to communicate between the MCUs using UART.

The idea is, to set the esp32 in a specified "firmware receiving state" in which I would do (after checking size with Update.begin()):

Update.writeStream(Serial2);

The problem is, that I don't know when and how to stop passing the stream to Update.writeStream() and continue with further processing (e.g. checking the md5 of the received image).

In theory, when the MT3620 has sent the full firmware image, I would send any defined end marker which signals, that the image has fully been transferred. Then I would send another message with the md5 of the firmware to confirm it on the esp32.

How can I detect the right point to stop forwarding the stream to Update.WriteStream() and continue processing the Serial2 input stream to my normal message handling routine?

Ah, ok, thank you! I am not that native C++ guy, but of course I should have looked into the sources by myself.

So if I understand correctly, Update.begin() also sets the total size of the update and so Update.writeStream() will automatically return when the total bytes received reaches the total size, right?