Skip to content

file

import {
createFile,
deleteFile,
readFile,
writeFile,
touchFile,
createDir,
deleteDir,
createLink,
deleteLink,
getPathInfo,
getFileStat,
sha256,
waitFilePath,
waitFileContent,
} from 'sysopkit/op/file';

IDEMPOTENT

Creates or updates a file. Compares content via SHA256, updates metadata only when changed.

await createFile({
path: '/etc/nginx/nginx.conf',
content: 'server { listen 80; }',
mode: 0o644,
user: 'nginx',
group: 'nginx',
});

IDEMPOTENT

Deletes a file. No-op if the file does not exist.

Reads a file as string. tryReadFile() returns undefined if not found.

const content = await readFile('/etc/hostname');
const maybe = await tryReadFile('/etc/missing'); // undefined

Writes content to a file using cat >. Not idempotent.

IDEMPOTENT

Updates timestamps via touch, creates file if missing.

IDEMPOTENT

Creates or removes directories:

await createDir({ path: '/var/www', mode: 0o755, recursive: true });
await deleteDir({ path: '/tmp/old', recursive: true });

IDEMPOTENT

Creates or removes symbolic links. createLink compares target via readlink.

Returns file metadata: type, user, group, mode, timestamps, size.

Computes SHA256 hash of a file.

Waits for a path to exist (with optional permission check).

Waits for a file to contain or not-contain a regex pattern.