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.

readVec

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.

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

File

lib/std/Io/Reader.zig:419

Code

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;
}