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

readVec

Public Function
std.Io.Reader.readVec
pub fn readVec(r: *Reader, data: [][]u8) Error!usize

Writes bytes from the internally tracked stream position to data.

Returns the number of bytes written, which will be at minimum 0 and at most the sum of each data slice length. The number of bytes read, including zero, does not indicate end of stream.

The reader's internal logical seek position moves forward in accordance with the number of bytes returned from this function.

Params

Errors

ReadFailed

See the Reader implementation for detailed diagnostics.

EndOfStream

File

Io/Reader.zig:420
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
pub fn readVec(r: *Reader, data: [][]u8) Error!usize {
    var seek = r.seek;
    for (data, 0..) |buf, i| {
        const contents = r.buffer[seek..r.end];
        const copy_len = @min(contents.len, buf.len);
        @memcpy(buf[0..copy_len], contents[0..copy_len]);
        seek += copy_len;
        if (buf.len - copy_len == 0) continue;

        // All of `buffer` has been copied to `data`.
        const n = seek - r.seek;
        r.seek = seek;
        data[i] = buf[copy_len..];
        defer data[i] = buf;
        return n + (r.vtable.readVec(r, data[i..]) catch |err| switch (err) {
            error.EndOfStream => if (n == 0) return error.EndOfStream else 0,
            error.ReadFailed => |e| return e,
        });
    }
    const n = seek - r.seek;
    r.seek = seek;
    return n;
}