file_read
host callCapy
function file_read(handle : u64, count : u64) string
Description
file_read reads from the current handle position. It clamps count to 16 MiB per call. It advances the position by the bytes read. A short read does not necessarily complete the requested range.
Parameters
handle : readable handle returned by file_open
count : maximum number of bytes to read
Return Values
A string with up to count bytes from the current position.
Errors
End of file, a zero count, an invalid or closed handle, and a read failure all return "". There is no separate error result.
Example
Capy
var writer := file_open("/tmp/doc-read.txt", "w")
file_write(writer, "hello world")
file_close(writer)
var reader := file_open("/tmp/doc-read.txt", "r")
print(file_read(reader, 5), "\n")
file_close(reader)
Output
hello