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.
pub fn readVec(r: *Reader, data: [][]u8) Error!usize
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;
}