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:
readSliceAllpub fn readSliceShort(r: *Reader, buffer: []u8) ShortError!usize
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;
}
}