#[throws(ReadLimitedError)]
pub async fn read_limited_bytes<S>(limit: usize, initial: Box<[u8]>,
+ capacity: usize,
stream: &mut S) -> Box<[u8]>
where S: futures::Stream<Item=Result<hyper::body::Bytes,hyper::Error>>
+ Debug + Unpin,
// we also require that the Stream is cancellation-safe
{
let mut accum = initial.into_vec();
+ let capacity = min(limit, capacity);
+ if capacity > accum.len() { accum.reserve(capacity - accum.len()); }
while let Some(item) = stream.next().await {
let b = item?;
accum.extend(b);