file_write
host callCapy
function file_write(handle : u64, value : string) u64
Description
file_write writes bytes at the current handle position. It advances the position by the bytes written. Compare the returned count with length(value) before you assume the complete value was written.
Parameters
handle : writable handle from file_open
value : bytes to write
Return Values
The number of bytes written.
Errors
An invalid, closed, or read-only handle returns zero. A write failure can return a partial byte count. Zero also represents a successful empty write. This call provides no error message.
Example
Capy
var handle := file_open("/tmp/doc-write.txt", "w")
var count := file_write(handle, "hello")
file_close(handle)
print(count, " ", file_get_contents("/tmp/doc-write.txt").value ?? "", "\n")
Output
5 hello