add checkExist() for Python

This commit is contained in:
guoling
2025-04-22 20:16:06 +08:00
parent 185f867888
commit da52da97ca
2 changed files with 14 additions and 1 deletions
+9
View File
@@ -125,6 +125,7 @@ PYBIND11_MODULE(mmkv, m) {
clsNameSpace.def("removeStorage", &NameSpace::removeStorage);
clsNameSpace.def("isFileValid", &NameSpace::isFileValid);
clsNameSpace.def("checkExist", &NameSpace::checkExist);
py::class_<MMKV, unique_ptr<MMKV, py::nodelete>> clsMMKV(m, "MMKV");
@@ -435,4 +436,12 @@ PYBIND11_MODULE(mmkv, m) {
},
"detect if the MMKV file is valid or not", py::arg("mmapID"),
py::arg("rootDir") = MMKVPath_t());
clsMMKV.def_static("checkExist",
[](const string &mmapID, const MMKVPath_t &rootDir) {
MMKVPath_t *rootDirPtr = (!rootDir.empty()) ? (MMKVPath_t *) &rootDir : nullptr;
return MMKV::checkExist(mmapID, rootDirPtr);
},
"check if the MMKV file is exist or not", py::arg("mmapID"),
py::arg("rootDir") = MMKVPath_t());
}