From 1123c589d22f465a484f1cf04e10f399711166f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=AD=8F=E5=AD=90=E6=81=92?= Date: Mon, 14 Apr 2025 11:08:34 +0800 Subject: [PATCH] bugfix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 魏子恒 --- bundle.json | 4 +++- file_api.gni | 4 ++++ interfaces/kits/js/BUILD.gn | 4 ++++ .../kits/js/src/mod_file/class_file/file_n_exporter.cpp | 4 ++++ interfaces/kits/js/src/mod_file/class_file/file_n_exporter.h | 4 ++++ 5 files changed, 19 insertions(+), 1 deletion(-) diff --git a/bundle.json b/bundle.json index 78b145b37..ded14f6a7 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 7fc94ace6..16a290623 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 e06a5cece..9fc445f9a 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 972c56b50..01f591e74 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 b9760b8a5..f39a8069e 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 { -- Gitee