pub fn streamExactPreserve(r: *Reader, w: *Writer, preserve_len: usize, n: usize) StreamError!void ReadFailedSee the Reader implementation for detailed diagnostics.
WriteFailedSee the Writer implementation for detailed diagnostics.
EndOfStreamEnd of stream indicated from the Reader. This error cannot originate from the Writer.
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256pub fn streamExactPreserve(r: *Reader, w: *Writer, preserve_len: usize, n: usize) StreamError!void {
if (w.end + n <= w.buffer.len) {
@branchHint(.likely);
return streamExact(r, w, n);
}
// If `n` is large, we can ignore `preserve_len` up to a point.
var remaining = n;
while (remaining > preserve_len) {
assert(remaining != 0);
remaining -= try r.stream(w, .limited(remaining - preserve_len));
if (w.end + remaining <= w.buffer.len) return streamExact(r, w, remaining);
}
// Offset the amount preserved by the amount we have left to stream
// since the remaining bytes are always going to be part of that
// preservation.
try w.rebase(preserve_len -| remaining, remaining);
return streamExact(r, w, remaining);
}
"Pump" exactly
nbytes from the reader to the writer.On success, at least
preserve_lenbytes will remain buffered if there are enough buffered bytes to do so. The amount buffered by the writer after the call will only be less thanpreserve_lenifw.end + nis less thanpreserve_lenbefore the call. The intentionally preserved bytes will include up topreserve_len -| nbytes from the previously buffered bytes, plus@min(n, preserve_len)of the newly "pumped" bytes.Asserts
Writer.buffercapacity is at leastpreserve_len.ncan be greater than theWriter.buffercapacity.