pub fn copy_until(
reader: &mut dyn Read,
sink: &mut dyn Write,
cancel: &dyn Fn() -> bool,
cap_remaining: u64,
buf: &mut [u8],
) -> (CopyEnd, u64)Expand description
Copy from reader to sink until EOF, cancellation, the byte cap, or an
error. cancel is checked between reads — a read already in flight finishes
first, so this is cooperative (paired with a short read timeout on the real
stream). Always returns the bytes written (even on error), so the caller’s cap
and totals stay correct across reconnects. Never writes past cap_remaining.