diff --git a/interfaces/kits/js/src/mod_fileio/common_func.cpp b/interfaces/kits/js/src/mod_fileio/common_func.cpp index b03d1e07cd933a328c3de2aa1408b737a02c28fa..e03d5c9de20be8f1aee6957b440b41f9528f815f 100644 --- a/interfaces/kits/js/src/mod_fileio/common_func.cpp +++ b/interfaces/kits/js/src/mod_fileio/common_func.cpp @@ -32,6 +32,27 @@ namespace DistributedFS { namespace ModuleFileIO { using namespace std; +void InitOpenMode(napi_env env, napi_value exports) +{ + char propertyName[] = "OpenMode"; + napi_property_descriptor desc[] = { + DECLARE_NAPI_STATIC_PROPERTY("READ_ONLY", NVal::CreateInt32(env, RDONLY).val_), + DECLARE_NAPI_STATIC_PROPERTY("WRITE_ONLY", NVal::CreateInt32(env, WRONLY).val_), + DECLARE_NAPI_STATIC_PROPERTY("READ_WRITE", NVal::CreateInt32(env, RDWR).val_), + DECLARE_NAPI_STATIC_PROPERTY("CREATE", NVal::CreateInt32(env, CREATE).val_), + DECLARE_NAPI_STATIC_PROPERTY("TRUNC", NVal::CreateInt32(env, TRUNC).val_), + DECLARE_NAPI_STATIC_PROPERTY("APPEND", NVal::CreateInt32(env, APPEND).val_), + DECLARE_NAPI_STATIC_PROPERTY("NONBLOCK", NVal::CreateInt32(env, NONBLOCK).val_), + DECLARE_NAPI_STATIC_PROPERTY("DIR", NVal::CreateInt32(env, DIRECTORY).val_), + DECLARE_NAPI_STATIC_PROPERTY("NOFOLLOW", NVal::CreateInt32(env, NOFOLLOW).val_), + DECLARE_NAPI_STATIC_PROPERTY("SYNC", NVal::CreateInt32(env, SYNC).val_), + }; + napi_value obj = nullptr; + napi_create_object(env, &obj); + napi_define_properties(env, obj, sizeof(desc) / sizeof(desc[0]), desc); + napi_set_named_property(env, exports, propertyName, obj); +} + static tuple GetActualBuf(napi_env env, void *rawBuf, int64_t bufLen, NVal op) { bool succ = false; diff --git a/interfaces/kits/js/src/mod_fileio/common_func.h b/interfaces/kits/js/src/mod_fileio/common_func.h index 5c0adb2e152434e9ae4ea3b1a673ecca09c9a33d..2ef467d28fadee3a4f40bd48e4010528801d7a9d 100644 --- a/interfaces/kits/js/src/mod_fileio/common_func.h +++ b/interfaces/kits/js/src/mod_fileio/common_func.h @@ -22,6 +22,18 @@ namespace OHOS { namespace DistributedFS { namespace ModuleFileIO { constexpr int64_t INVALID_POSITION = std::numeric_limits::max(); +constexpr int RDONLY = 00; +constexpr int WRONLY = 01; +constexpr int RDWR = 02; +constexpr int CREATE = 0100; +constexpr int TRUNC = 01000; +constexpr int APPEND = 02000; +constexpr int NONBLOCK = 04000; +constexpr int DIRECTORY = 0200000; +constexpr int NOFOLLOW = 0400000; +constexpr int SYNC = 04010000; + +void InitOpenMode(napi_env env, napi_value exports); struct CommonFunc { static int ConvertJsFlags(int &flags); diff --git a/interfaces/kits/js/src/mod_fileio/module_v9.cpp b/interfaces/kits/js/src/mod_fileio/module_v9.cpp index 7f2bb4bce468ec1817b2ba05ec2711e856698752..2e1cc8635b02c5aa692eea0a149f49ce1fd45398 100644 --- a/interfaces/kits/js/src/mod_fileio/module_v9.cpp +++ b/interfaces/kits/js/src/mod_fileio/module_v9.cpp @@ -19,6 +19,7 @@ #include "../common/log.h" #include "class_file/file_n_exporter.h" #include "class_stat_v9/stat_n_exporter_v9.h" +#include "common_func.h" #include "properties/prop_n_exporter_v9.h" using namespace std; @@ -28,6 +29,7 @@ namespace DistributedFS { namespace ModuleFileIO { static napi_value Export(napi_env env, napi_value exports) { + InitOpenMode(env, exports); std::vector> products; products.emplace_back(make_unique(env, exports)); products.emplace_back(make_unique(env, exports));