pub fn discardShort(r: *Reader, n: usize) ShortError!usize r: *Readern: usizeReadFailedSee the Reader implementation for detailed diagnostics.
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652pub fn discardShort(r: *Reader, n: usize) ShortError!usize {
const proposed_seek = r.seek + n;
if (proposed_seek <= r.end) {
@branchHint(.likely);
r.seek = proposed_seek;
return n;
}
var remaining = n - (r.end - r.seek);
r.seek = r.end;
while (true) {
const discard_len = r.vtable.discard(r, .limited(remaining)) catch |err| switch (err) {
error.EndOfStream => return n - remaining,
error.ReadFailed => |e| return e,
};
remaining -= discard_len;
if (remaining == 0) return n;
}
}
Skips the next
nbytes from the stream, advancing the seek position.Unlike
tosswhich is infallible, in this functionncan be any amount.Returns the number of bytes discarded, which is less than
nif and only if the stream reached the end.See also:
discardAlldiscardRemainingdiscard