Zig 0.17.0-dev (Split by item)

This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig library itself.

discardShort

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:

Reader.discardShort
pub fn discardShort(r: *Reader, n: usize) ShortError!usize

File

lib/std/Io/Reader.zig:634

Code

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 => |e| return e,
        };
        remaining -= discard_len;
        if (remaining == 0) return n;
    }
}