Capy-Bearer Documentation

file_append

lib call

Capy

function file_append(path : string, content : string, opt : any = {}) any
function file_append(path : string, first : string, second : string) any
function file_append(path : string, first : string, second : string, third : string) any

Description

file_append adds text to the end of a file. Use file_put_contents to replace a file.

It holds an exclusive lock while it writes, so lines from concurrent requests do not mix. When another reader or writer holds the lock longer than the lock timeout (BEARER_FILE_LOCK_TIMEOUT_MS, 2000 milliseconds by default), the call returns a failure.

Parameters

path : path of the file to update

content : text to append

first : first text value to append

second : second text value to append

third : third text value to append

opt : optional map with the file mode for a new file, for example { "mode": "0600" }. mode is an octal string. The default is "0644".

Return Values

A map with ok and error. ok is true when Capy appends the text. error holds the failure reason when the call fails.

Example

Capy

file_unlink("/tmp/doc-append.txt")
file_append("/tmp/doc-append.txt", "a", "b", "c")
print(file_get_contents("/tmp/doc-append.txt").value ?? "", "\n")

Output

abc