Function discardShort [src]
Skips the next n bytes from the stream, advancing the seek position.
Unlike toss which is infallible, in this function n can be any amount.
Returns the number of bytes discarded, which is less than n if and only
if the stream reached the end.
See also:
discardAll
discardRemaining
discard
Prototype
pub fn discardShort(r: *Reader, n: usize) ShortError!usize
Parameters
r: *Reader
n: usize
Possible Errors
See the Reader
implementation for detailed diagnostics.
Source
pub 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 => return error.ReadFailed,
};
remaining -= discard_len;
if (remaining == 0) return n;
}
}