signalk-server
Version:
An implementation of a [Signal K](http://signalk.org) server for boats.
37 lines • 1.07 kB
JavaScript
;
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