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

readSliceShort

Public Function
std.Io.Reader.readSliceShort
pub fn readSliceShort(r: *Reader, buffer: []u8) ShortError!usize

Fill buffer with the next buffer.len bytes from the stream, advancing the seek position.

Invalidates previously returned values from peek.

Returns the number of bytes read, which is less than buffer.len 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:680
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
pub fn readSliceShort(r: *Reader, buffer: []u8) ShortError!usize {
    const contents = r.buffer[r.seek..r.end];
    const copy_len = @min(buffer.len, contents.len);
    @memcpy(buffer[0..copy_len], contents[0..copy_len]);
    r.seek += copy_len;
    if (buffer.len - copy_len == 0) {
        @branchHint(.likely);
        return buffer.len;
    }
    var i: usize = copy_len;
    var data: [1][]u8 = undefined;
    while (true) {
        data[0] = buffer[i..];
        i += readVec(r, &data) catch |err| switch (err) {
            error.EndOfStream => return i,
            error.ReadFailed => |e| return e,
        };
        if (buffer.len - i == 0) return buffer.len;
    }
}