Function readFile [src]
Read all of file contents using a preallocated buffer.
The returned slice has the same pointer as buffer. If the length matches buffer.len
the situation is ambiguous. It could either mean that the entire file was read, and
it exactly fits the buffer, or it could mean the buffer was not big enough for the
entire file.
On Windows, file_path should be encoded as WTF-8.
On WASI, file_path should be encoded as valid UTF-8.
On other platforms, file_path is an opaque sequence of bytes with no particular encoding.
Prototype
pub fn readFile(self: Dir, file_path: []const u8, buffer: []u8) ![]u8
Parameters
self: Dir
file_path: []const u8
buffer: []u8
Source
pub fn readFile(self: Dir, file_path: []const u8, buffer: []u8) ![]u8 {
var file = try self.openFile(file_path, .{});
defer file.close();
const end_index = try file.readAll(buffer);
return buffer[0..end_index];
}