Skip to content

appendFile ​

appendFile appends string data to a file. If the file does not exist, it is created.

SignatureappendFile(path: string, data: string): Promise<Result<void, FsError>>
tyrus
import { appendFile, FsError } from "tyrus:fs";

match (await appendFile("log.txt", "new entry\n")) {
    Ok(_) => { print("append complete"); } // append complete
    Err(error) => { printError(error.code); } // ERR_FS_APPEND_FAILED
}

Error Handling ​

If the file cannot be appended to, the fulfilled promise contains Err(FsError). Match the returned result:

error

tyrus
import { appendFile, FsError } from "tyrus:fs";

match (await appendFile("log.txt", "new entry\n")) {
    Ok(_) => { print("append complete"); } // append complete
    Err(error) => { printError(error.code); } // ERR_FS_APPEND_FAILED
}