Zig 0.17.0-dev (Split by item)

Shortcut keys
?
Show these tips
S
Focus search field
Esc
Clear focus & close tips
U
Jump to source code
↑
Move up in search results
↓
Move down in search results
↵
Go to active search result
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 standard library. Public Function

discardShort

Public Function
std.Io.Reader.discardShort
pub fn discardShort(r: *Reader, n: usize) ShortError!usize

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:

Params

Errors

ReadFailed

See the Reader implementation for detailed diagnostics.

File

Io/Reader.zig:635
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
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;
    }
}