"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.atomicWriteFileSync = atomicWriteFileSync;
exports.atomicWriteFile = atomicWriteFile;
const fs_1 = __importDefault(require("fs"));
function atomicWriteFileSync(filePath, data) {
    const tmp = filePath + '.tmp';
    try {
        fs_1.default.writeFileSync(tmp, data);
        fs_1.default.renameSync(tmp, filePath);
    }
    catch (err) {
        try {
            fs_1.default.unlinkSync(tmp);
        }
        catch { }
        throw err;
    }
}
async function atomicWriteFile(filePath, data) {
    const tmp = filePath + '.tmp';
    try {
        await fs_1.default.promises.writeFile(tmp, data);
        await fs_1.default.promises.rename(tmp, filePath);
    }
    catch (err) {
        try {
            await fs_1.default.promises.unlink(tmp);
        }
        catch { }
        throw err;
    }
}
//# sourceMappingURL=atomicWrite.js.map