[ClientModel] Validate pattern for returning dual BinaryData/Stream content for large files from protocol methods #43034
Labels
Azure.Core
Client
This issue points to a problem in the data-plane of the library.
System.ClientModel
Base Core library
Milestone
In some APIs like DownloadFile in OpenAI client, users sometimes want BinaryData for simplicity, but if the file size is too large to fit in memory, they may need to call the protocol method to use response.ContentStream instead. There are some challenges that come up here, both in general, and for unbranded clients:
ClientResult
instead ofPipelineResponse
from protocol methods.ClientResult
is not disposable, so the caller can't just put the return value in ausing
block, they must instead retrieve the response viaGetRawResponse
and dispose that directly.response.Content
andresponse.ContentStream
to be useful is challenging for large data downloads over a network stream. We did a lot of work to mitigate this in ClientModel: Change approach to buffering response.Content #41080, and did not fully complete ClientModel: Investigate the feasibility of providing a tester to know whether PipelineResponse.ContentStream has been read #42049, which may or may not be relevant here. The consideration here is that the caller may need to specify ahead of time which property -- the BinaryData response.Content or the Stream response.ContentStream -- they intend to use so that the client pipeline will know whether to a) buffer it or b) wrap it in aRetriableStream
internally instead of buffering it, so that the streamed content will be tolerant to network issues.A final solution to this would need to make sure it doesn't break the intent of https://gist.github.com/KrzysztofCwalina/da4f27f4513d9c6cc81299b67054416e -- whose goal it was to avoid breaking changes to clients when the return type of a method changes from
Response
toRepsonse<T>
in Azure clients. Or, if it does, that we are ok with that trade-off.The text was updated successfully, but these errors were encountered: