UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

38 lines (37 loc) • 795 B
import { closeSync, constants as fsConstants, fsyncSync, openSync } from "node:fs"; export function fsyncFile(path) { const fd = openSync(path, fsConstants.O_RDWR | (fsConstants.O_NOFOLLOW ?? 0)); try { fsyncSync(fd); } finally { closeSync(fd); } } export function fsyncDir(dir, mode = "best-effort") { if (mode === "required" && process.platform === "win32") return; let dfd; try { dfd = openSync(dir, "r"); } catch (err) { if (mode === "required") throw err; return; } try { fsyncSync(dfd); } catch (err) { if (mode === "required") throw err; } finally { try { closeSync(dfd); } catch { } } }