diff --git a/bundle.json b/bundle.json index 78b145b37c41506c2958d7904c596617eca78693..ded14f6a75e1871877a533a53154379aa192f90d 100644 --- a/bundle.json +++ b/bundle.json @@ -19,7 +19,9 @@ "SystemCapability.FileManagement.File.DistributedFile", "SystemCapability.FileManagement.File.Environment.FolderObtain" ], - "features": [], + "features": [ + "file_api_read_optimize" + ], "adapted_system_type": [ "mini","small","standard" ], "rom": "4096KB", "ram": "4096KB", diff --git a/file_api.gni b/file_api.gni index 7fc94ace62004264471a75000deb0900070d3727..16a2906232aa9e6c0be06d10d274a6f673b32e2e 100644 --- a/file_api.gni +++ b/file_api.gni @@ -23,3 +23,7 @@ utils_path = "${file_api_path}/utils" use_mac = "${current_os}_${current_cpu}" == "mac_x64" || "${current_os}_${current_cpu}" == "mac_arm64" use_mingw_win = "${current_os}_${current_cpu}" == "mingw_x86_64" + +declare_args() { + file_api_read_optimize = false +} diff --git a/interfaces/kits/js/BUILD.gn b/interfaces/kits/js/BUILD.gn index e06a5ceced045c0612723daad369a7875dd74312..9fc445f9ab59139dfe499b9fb3c1c33d8d637021 100644 --- a/interfaces/kits/js/BUILD.gn +++ b/interfaces/kits/js/BUILD.gn @@ -377,6 +377,10 @@ ohos_shared_library("file") { "hilog:libhilog", "napi:ace_napi", ] + + if (file_api_read_optimize) { + defines = [ "WEARABLE_PRODUCT" ] + } } ohos_shared_library("statfs") { diff --git a/interfaces/kits/js/src/mod_file/class_file/file_n_exporter.cpp b/interfaces/kits/js/src/mod_file/class_file/file_n_exporter.cpp index 972c56b50e24e06c9da0c230609323ca6dfcc464..01f591e74928233f30d421f2474786e3aa46a53b 100644 --- a/interfaces/kits/js/src/mod_file/class_file/file_n_exporter.cpp +++ b/interfaces/kits/js/src/mod_file/class_file/file_n_exporter.cpp @@ -905,7 +905,11 @@ void ReadArrayBufferExec(napi_env env, void *data) if (read(fdg.GetFD(), buffer.get(), len) != FAILED) { asyncCallbackInfo->result = SUCCESS; asyncCallbackInfo->len = len; +#ifdef WEARABLE_PRODUCT + asyncCallbackInfo->contents = std::move(buffer); +#else asyncCallbackInfo->contents = std::string(buffer.get()); +#endif } } } else if (statPath == ENOENT) { diff --git a/interfaces/kits/js/src/mod_file/class_file/file_n_exporter.h b/interfaces/kits/js/src/mod_file/class_file/file_n_exporter.h index b9760b8a5c75ee115c0bc81e3f16e46339401a74..f39a8069ea84c2e58d15649705fd7fe6fd626a51 100644 --- a/interfaces/kits/js/src/mod_file/class_file/file_n_exporter.h +++ b/interfaces/kits/js/src/mod_file/class_file/file_n_exporter.h @@ -172,7 +172,11 @@ struct AsyncReadBufferCallbackInfo { int result = DEFAULT_RESULT; int errorType = -1; int32_t len = 0; +#ifdef WEARABLE_PRODUCT + std::unique_ptr contents = nullptr; +#else std::string contents = ""; +#endif }; class FileNExporter final : public NExporter {