make bytes_total_limit optional

This commit is contained in:
yggverse 2024-12-09 14:14:01 +02:00
parent 8c298977f3
commit eb32db3d3b

View file

@ -16,9 +16,9 @@ pub fn move_all_from_stream_async(
cancellable: Cancellable, cancellable: Cancellable,
priority: Priority, priority: Priority,
bytes: ( bytes: (
usize, // bytes_in_chunk usize, // bytes_in_chunk
usize, // bytes_total_limit Option<usize>, // bytes_total_limit, `None` to unlimited
usize, // bytes_total usize, // bytes_total
), ),
callback: ( callback: (
impl Fn((Bytes, usize)) + 'static, // on_chunk impl Fn((Bytes, usize)) + 'static, // on_chunk
@ -41,8 +41,10 @@ pub fn move_all_from_stream_async(
on_chunk((bytes.clone(), bytes_total)); on_chunk((bytes.clone(), bytes_total));
// Validate max size // Validate max size
if bytes_total > bytes_total_limit { if let Some(bytes_total_limit) = bytes_total_limit {
return on_complete(Err(Error::BytesTotal(bytes_total, bytes_total_limit))); if bytes_total > bytes_total_limit {
return on_complete(Err(Error::BytesTotal(bytes_total, bytes_total_limit)));
}
} }
// No bytes were read, end of stream // No bytes were read, end of stream