/
Alex_Ural
/
opencode
Обзор
Документация
Войти
/
Alex_Ural
/
opencode
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
dev
packages/tui/src/util/persistence.ts
33 строки
1 KB
Dax
refactor(server): canonicalize service API (#31049)
07 июн 2026, 06:27
Не верифицирован
07 июн 2026, 06:27
fe0c4f8
Код
Авторство
О чём код?
import path from "path" import { appendFile, mkdir, rename, rm } from "fs/promises" export function readText(filePath: string) { return Bun.file(filePath).text() } export function readJson<T>(filePath: string) { return Bun.file(filePath).json() as Promise<T> } export async function writeText(filePath: string, content: string) { await mkdir(path.dirname(filePath), { recursive: true }) await Bun.write(filePath, content) } export async function appendText(filePath: string, content: string) { await mkdir(path.dirname(filePath), { recursive: true }) await appendFile(filePath, content) } export async function writeJsonAtomic(filePath: string, value: unknown) { await mkdir(path.dirname(filePath), { recursive: true }) const temporary = `${filePath}.${process.pid}.${crypto.randomUUID()}.tmp` await Bun.write(temporary, JSON.stringify(value)).catch(async (error) => { await rm(temporary, { force: true }).catch(() => undefined) throw error }) await rename(temporary, filePath).catch(async (error) => { await rm(temporary, { force: true }).catch(() => undefined) throw error }) }