Files
hfut-bishe/client/core/persistence/JsonFileAtomic.h
T
2026-05-14 13:30:06 +08:00

21 lines
636 B
C++

#pragma once
#include <QByteArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <QString>
namespace core::persistence {
/// 原子写 JSON:写入 .tmp 后 rename 覆盖,避免截断导致下次打开“损坏”。
bool writeJsonAtomic(const QString& absolutePath, const QJsonObject& obj, bool pretty = true);
/// 读取 JSON 文件(必须为 object)。失败返回 false。
bool readJsonObject(const QString& absolutePath, QJsonObject& out);
/// 原子写 bytes:写入 .tmp 后 rename 覆盖。
bool writeBytesAtomic(const QString& absolutePath, const QByteArray& bytes);
} // namespace core::persistence