Skip to content

Commit

Permalink
Add Response::bytes_stream()
Browse files Browse the repository at this point in the history
This converts the `Response` into a `Stream` of `Bytes`.

Closes #734
  • Loading branch information
seanmonstar committed Dec 23, 2019
1 parent 24abf2f commit faf1c09
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/async_impl/response.rs
Expand Up @@ -292,6 +292,28 @@ impl Response {
}
}

/// Convert the response into a `Stream` of `Bytes` from the body.
///
/// # Example
///
/// ```
/// use futures_util::StreamExt;
///
/// # async fn run() -> Result<(), Box<dyn std::error::Error>> {
/// let mut stream = reqwest::get("http://httpbin.org/ip")
/// .await?
/// .bytes_stream();
///
/// while let Some(item) = stream.next() {
/// println!("Chunk: {:?}", item?);
/// }
/// # Ok(())
/// # }
/// ```
pub fn bytes_stream(self) -> impl futures_core::Stream<Item = crate::Result<Bytes>> {
self.body
}

// util methods

/// Turn a response into an error if the server returned an error.
Expand Down

0 comments on commit faf1c09

Please sign in to comment.