Skip to content

Conversation

@rylev
Copy link
Contributor

@rylev rylev commented Aug 8, 2022

Fixes #981

This allows operations to expose a streaming response body so that they don't have to collect response bodies into a Bytes collection. For example, get_blob now returns back a ResponseBody as part of its response type. This type implements Stream for users who want to stream the data as well as collect methods for users that just want the data as Bytes or even as a String.

This also makes PinnedStream and collect_pinned_stream private which were always a bit of an awkward API.

This is what fetching a blob now looks like:

let mut result: Vec<u8> = vec![];
let mut stream = blob_client
     .get()
     .chunk_size(0xFFFF_FFFF_FFFFu64)
     .into_stream();
while let Some(response) = stream.next().await {
     let mut body = response?.data;
     while let Some(value) = body.next().await {
         // Instead of this while loop the user can also call `body.collect()` to get back `Bytes`
         // or `body.collect_string()` to get a `String`
         let value = value?;
         result.extend(&value);
     }
}

@cataggar
Copy link
Member

cataggar commented Aug 8, 2022

Sorry, #984 caused some conflicts. Probably best to revert 96c66c1, merge main, and rerun codegen.

@rylev rylev force-pushed the streaming-response branch from 96c66c1 to 4d384ae Compare August 8, 2022 13:50
Copy link
Member

@cataggar cataggar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great!

Copy link
Contributor

@yoshuawuyts yoshuawuyts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks really good!

@rajasekarv
Copy link

Didn't expect it to be done this quick. Thanks a lot @rylev

@rylev rylev merged commit 8d64f1f into Azure:main Aug 8, 2022
@rylev rylev deleted the streaming-response branch August 8, 2022 19:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Expose streaming for operations with potentially large data

4 participants