Skip to content

Commit

Permalink
Merge pull request #239 from Diggsey/db-add-reader-and-size-response
Browse files Browse the repository at this point in the history
Add method for constructing a response from both a reader and a size
  • Loading branch information
bradfier authored Jun 29, 2021
2 parents 92d56c7 + c637658 commit 0546487
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,29 @@ impl ResponseBody {
}
}

/// Builds a new `ResponseBody` that will read the data from a `Read`.
///
/// The caller must provide the content length. It is unspecified
/// what will happen if the content length does not match the actual
/// length of the data returned from the reader.
///
/// # Example
///
/// ```no_run
/// use std::io;
/// use std::io::Read;
/// use rouille::ResponseBody;
///
/// let body = ResponseBody::from_reader_and_size(io::stdin().take(128), 128);
/// ```
#[inline]
pub fn from_reader_and_size<R>(data: R, size: usize) -> ResponseBody where R: Read + Send + 'static {
ResponseBody {
data: Box::new(data),
data_length: Some(size),
}
}

/// Builds a new `ResponseBody` that returns the given data.
///
/// # Example
Expand Down

0 comments on commit 0546487

Please sign in to comment.