Skip to Content
APIappendFile

appendFile

Append data to a file, creating the file if it does not exist.

Basic usage

import { appendFile } from '@rush-fs/core' await appendFile('./log.txt', 'new line\n') await appendFile('./log.txt', buffer, { encoding: 'utf8', mode: 0o644 })

Methods

appendFile(path, data, options?)

Async. Returns Promise<void>.

ArgumentTypeDescription
pathstringFile path.
datastring | BufferData to append.
optionsobjectOptional: encoding, mode, flag.

appendFileSync(path, data, options?)

Sync. Same arguments; throws on error.

Performance

From repo benchmarks (pnpm build && pnpm bench):

ScenarioNode.jsRush-FSRatio
appendFile30 µs27 µs0.9x

On par with Node.js; single-file append is an atomic syscall.

Notes

  • Encodings: utf8, ascii, latin1, base64, base64url, hex. Same semantics as Node.js.
Last updated on