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
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.
pubfnreadFile(dir: Dir, io: Io, file_path: []constu8, buffer: []u8) ReadFileError![]u8 {
varfile = trydir.openFile(io, file_path, .{
// We can take advantage of this on Windows since it doesn't involve any extra syscalls,// so we can get error.IsDir during open rather than during the read.
.allow_directory = if (native_os == .windows) falseelsetrue,
});
deferfile.close(io);
varreader = file.reader(io, &.{});
constn = reader.interface.readSliceShort(buffer) catch |err| switch (err) {
error.ReadFailed => returnreader.err.?,
};
returnbuffer[0..n];
}
Read all of file contents using a preallocated buffer.
The returned slice has the same pointer as
buffer. If the length matchesbuffer.lenthe 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.file_pathshould be encoded as WTF-8.file_pathshould be encoded as valid UTF-8.file_pathis an opaque sequence of bytes with no particular encoding.