diff --git a/interfaces/kits/js/BUILD.gn b/interfaces/kits/js/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..9325a4b00b0ab8dbb0f63fecd32700f0976555cb --- /dev/null +++ b/interfaces/kits/js/BUILD.gn @@ -0,0 +1,242 @@ +# Copyright (c) 2021 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/ohos.gni") +import("//foundation/filemanagement/file_api/file_api.gni") + +file_common_src = [ + "src/common/file_helper/fd_guard.cpp", + "src/common/napi/n_async/n_async_work_callback.cpp", + "src/common/napi/n_async/n_async_work_promise.cpp", + "src/common/napi/n_async/n_ref.cpp", + "src/common/napi/n_class.cpp", + "src/common/napi/n_func_arg.cpp", + "src/common/napi/n_val.cpp", + "src/common/uni_error.cpp", +] + +ohos_shared_library("fileio") { + subsystem_name = "filemanagement" + part_name = "file_api" + + relative_install_dir = "module" + + include_dirs = [ + "//foundation/arkui/napi/interfaces/kits", + "//foundation/filemanagement/file_api/interfaces/kits/js/src/common/file_helper", + "//foundation/filemanagement/file_api/interfaces/kits/js/src/common/napi", + "//foundation/filemanagement/file_api/interfaces/kits/js/src/common/napi/n_async", + "//third_party/node/src", + "//third_party/bounds_checking_function/include", + "//third_party/libuv/include", + "//third_party/openssl/include", + ] + + sources = file_common_src + sources += [ + "src/common/file_helper/hash_file.cpp", + "src/mod_fileio/class_constants/constants.cpp", + "src/mod_fileio/class_dir/dir_n_exporter.cpp", + "src/mod_fileio/class_dirent/dirent_n_exporter.cpp", + "src/mod_fileio/class_stat/stat_n_exporter.cpp", + "src/mod_fileio/class_stream/flush.cpp", + "src/mod_fileio/class_stream/stream_n_exporter.cpp", + "src/mod_fileio/class_watcher/watcher_n_exporter.cpp", + "src/mod_fileio/common_func.cpp", + "src/mod_fileio/module.cpp", + "src/mod_fileio/properties/chmod.cpp", + "src/mod_fileio/properties/chown.cpp", + "src/mod_fileio/properties/close.cpp", + "src/mod_fileio/properties/copy_file.cpp", + "src/mod_fileio/properties/create_stream.cpp", + "src/mod_fileio/properties/fchmod.cpp", + "src/mod_fileio/properties/fchown.cpp", + "src/mod_fileio/properties/fdatasync.cpp", + "src/mod_fileio/properties/fdopen_stream.cpp", + "src/mod_fileio/properties/fstat.cpp", + "src/mod_fileio/properties/fsync.cpp", + "src/mod_fileio/properties/ftruncate.cpp", + "src/mod_fileio/properties/hash.cpp", + "src/mod_fileio/properties/lchown.cpp", + "src/mod_fileio/properties/link.cpp", + "src/mod_fileio/properties/lseek.cpp", + "src/mod_fileio/properties/lstat.cpp", + "src/mod_fileio/properties/mkdtemp.cpp", + "src/mod_fileio/properties/open.cpp", + "src/mod_fileio/properties/open_dir.cpp", + "src/mod_fileio/properties/posix_fallocate.cpp", + "src/mod_fileio/properties/prop_n_exporter.cpp", + "src/mod_fileio/properties/read_text.cpp", + "src/mod_fileio/properties/rename.cpp", + "src/mod_fileio/properties/rmdir.cpp", + "src/mod_fileio/properties/stat.cpp", + "src/mod_fileio/properties/symlink.cpp", + "src/mod_fileio/properties/truncate.cpp", + "src/mod_fileio/properties/watcher.cpp", + ] + + deps = [ + "//foundation/arkui/napi:ace_napi", + "//third_party/bounds_checking_function:libsec_static", + "//third_party/openssl:libcrypto_static", + ] + + external_deps = [ "hiviewdfx_hilog_native:libhilog" ] +} + +ohos_shared_library("file") { + subsystem_name = "filemanagement" + part_name = "file_api" + + relative_install_dir = "module" + + include_dirs = [ + "//foundation/arkui/napi/interfaces/kits", + "//foundation/filemanagement/file_api/interfaces/kits/js/src/common/napi", + "//foundation/filemanagement/file_api/interfaces/kits/js/src/common/napi/n_async", + "//foundation/filemanagement/file_api/interfaces/kits/js/src/common/file_helper", + "//third_party/node/src", + "//third_party/bounds_checking_function/include", + ] + + sources = file_common_src + sources += [ + "src/common/ability_helper.cpp", + "src/mod_file/class_file/file_n_exporter.cpp", + "src/mod_file/common_func.cpp", + "src/mod_file/module.cpp", + ] + + deps = [ + "${aafwk_kits_path}/ability/native:abilitykit_native", + "//foundation/arkui/napi:ace_napi", + "//third_party/bounds_checking_function:libsec_static", + ] + + external_deps = [ + "eventhandler:libeventhandler", + "hiviewdfx_hilog_native:libhilog", + ] +} + +ohos_shared_library("statfs") { + subsystem_name = "filemanagement" + part_name = "file_api" + + relative_install_dir = "module" + + sources = [ + "src/mod_statfs/statfs_n_exporter.cpp", + "src/mod_statfs/statfs_napi.cpp", + ] + + deps = [ + "//foundation/filemanagement/file_api/utils/filemgmt_libhilog", + "//foundation/filemanagement/file_api/utils/filemgmt_libn", + ] + + external_deps = [ "hiviewdfx_hilog_native:libhilog" ] +} + +ohos_shared_library("environment") { + subsystem_name = "filemanagement" + part_name = "file_api" + + relative_install_dir = "module" + + include_dirs = [ + "//foundation/arkui/napi/interfaces/kits", + "//foundation/filemanagement/file_api/interfaces/kits/js/src/common/napi/n_async", + "//third_party/node/src", + ] + + sources = [ + "src/common/napi/n_async/n_async_work_callback.cpp", + "src/common/napi/n_async/n_async_work_promise.cpp", + "src/common/napi/n_async/n_ref.cpp", + "src/common/napi/n_func_arg.cpp", + "src/common/napi/n_val.cpp", + "src/common/uni_error.cpp", + "src/mod_environment/environment_n_exporter.cpp", + "src/mod_environment/environment_napi.cpp", + ] + + deps = [ "//foundation/arkui/napi:ace_napi" ] + + external_deps = [ "hiviewdfx_hilog_native:libhilog" ] +} + +ohos_shared_library("securitylabel") { + subsystem_name = "filemanagement" + part_name = "file_api" + + relative_install_dir = "module" + + cflags = [ "-Wno-format" ] + + include_dirs = [ + "//foundation/arkui/napi/interfaces/kits", + "//foundation/arkui/ace_engine/frameworks/base/utils", + "//foundation/arkui/ace_engine/frameworks", + "//foundation/filemanagement/file_api/interfaces/kits/js/src/common/napi/n_async", + ] + + sources = file_common_src + sources += [ + "src/mod_securitylabel/securitylabel_n_exporter.cpp", + "src/mod_securitylabel/securitylabel_napi.cpp", + ] + + deps = [ "//foundation/arkui/napi:ace_napi" ] + + external_deps = [ "hiviewdfx_hilog_native:libhilog" ] +} + +ohos_shared_library("document") { + subsystem_name = "filemanagement" + part_name = "file_api" + + relative_install_dir = "module" + + include_dirs = [ + "//foundation/arkui/napi/interfaces/kits", + "//foundation/filemanagement/file_api/interfaces/kits/js/src/common/napi/n_async", + "//third_party/node/src", + ] + + sources = [ + "src/common/napi/n_async/n_async_work_callback.cpp", + "src/common/napi/n_async/n_async_work_promise.cpp", + "src/common/napi/n_async/n_ref.cpp", + "src/common/napi/n_func_arg.cpp", + "src/common/napi/n_val.cpp", + "src/common/uni_error.cpp", + "src/mod_document/document_n_exporter.cpp", + "src/mod_document/document_napi.cpp", + ] + + deps = [ "//foundation/arkui/napi:ace_napi" ] + + external_deps = [ "hiviewdfx_hilog_native:libhilog" ] +} + +group("build_kits_js") { + deps = [ + ":document", + ":environment", + ":file", + ":fileio", + ":securitylabel", + ":statfs", + ] +} diff --git a/interfaces/kits/js/napi/@system.file.d.ts b/interfaces/kits/js/napi/@system.file.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..9bd26a69d357ab1ce62b1b475c878890c04ca67b --- /dev/null +++ b/interfaces/kits/js/napi/@system.file.d.ts @@ -0,0 +1,752 @@ +/* + * Copyright (c) 2020 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export interface FileResponse { + /** + * File URI. + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + */ + uri: string; + + /** + * File size, in bytes. + * If type is dir, the length value is fixed to 0. + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + */ + length: number; + + /** + * Timestamp when the file is stored, which is the number of milliseconds elapsed since 1970/01/01 00:00:00. + * For lite wearables, the value is fixed to 0, because this parameter is restricted by the underlying file system. + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + */ + lastModifiedTime: number; + + /** + * File type. The values are as follows: + * dir: directory + * file: file + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + */ + type: "dir" | "file"; + + /** + * File list. When the recursive value is true and the type is dir, the file information under the subdirectory will be returned. + * Otherwise, no value will be returned. + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + */ + subFiles?: Array; +} + +/** + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + */ +export interface FileMoveOption { + /** + * URI of the file to move. + * Restricted by the underlying file system of lite wearables, the value must meet the following requirements: + * 1. The URI cannot contain special characters such as \/"*+,:;<=>?[]|\x7F. + * 2. The maximum number of characters allowed is 128. + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + */ + srcUri: string; + + /** + * URI of the file moved to the target location. + * Restricted by the underlying file system of lite wearables, the value must meet the following requirements: + * 1. The URI cannot contain special characters such as \/"*+,:;<=>?[]|\x7F. + * 2. The maximum number of characters allowed is 128. + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + */ + dstUri: string; + + /** + * Called when the source file is moved to the specified location successfully. + * This function returns the URI of the file moved to the target location. + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + */ + success?: (uri: string) => void; + + /** + * Called when moving fails. + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + */ + fail?: (data: string, code: number) => void; + + /** + * Called when the execution is completed. + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + */ + complete?: () => void; +} + +/** + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + */ +export interface FileListResponse { + /** + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + */ + fileList: Array; +} + +/** + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + */ +export interface FileListOption { + /** + * URI of the directory. + * Restricted by the underlying file system of lite wearables, the value must meet the following requirements: + * 1. The URI cannot contain special characters such as \/"*+,:;<=>?[]|\x7F. + * 2. The maximum number of characters allowed is 128. + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + */ + uri: string; + + /** + * Called when the list is obtained successfully. + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + */ + success?: (data: FileListResponse) => void; + + /** + * Called when the list fails to be obtained. + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + */ + fail?: (data: string, code: number) => void; + + /** + * Called when the execution is completed. + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + */ + complete?: () => void; +} + +export interface FileCopyOption { + /** + * URI of the file to copy. + * Restricted by the underlying file system of lite wearables, the value must meet the following requirements: + * 1. The URI cannot contain special characters such as \/"*+,:;<=>?[]|\x7F. + * 2. The maximum number of characters allowed is 128. + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + */ + srcUri: string; + + /** + * URI of the file moved to the target location. + * Restricted by the underlying file system of lite wearables, the value must meet the following requirements: + * 1. The URI cannot contain special characters such as \/"*+,:;<=>?[]|\x7F. + * 2. The maximum number of characters allowed is 128. + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + */ + dstUri: string; + + /** + * Called when the copy file is saved successful. + * This function returns the URI of the file saved to the target location. + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + */ + success?: (uri: string) => void; + + /** + * Called when the copy or save operation fails. + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + */ + fail?: (data: string, code: number) => void; + + /** + * Called when the execution is completed. + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + */ + complete?: () => void; +} + +export interface FileGetOption { + /** + * File URI, which cannot be an application resource path. + * Restricted by the underlying file system of lite wearables, the value must meet the following requirements: + * 1. The URI cannot contain special characters such as \/"*+,:;<=>?[]|\x7F. + * 2. The maximum number of characters allowed is 128. + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + */ + uri: string; + + /** + * Whether to recursively obtain the file list under a subdirectory. + * The default value is false. + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + */ + recursive?: boolean; + + /** + * Called when file information is obtained successfully. + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + */ + success?: (file: FileResponse) => void; + + /** + * Called when file information fails to be obtained. + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + */ + fail?: (data: string, code: number) => void; + + /** + * Called when the execution is completed. + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + */ + complete?: () => void; +} + +export interface FileDeleteOption { + /** + * URI of the file to be deleted, which cannot be an application resource path. + * Restricted by the underlying file system of lite wearables, the value must meet the following requirements: + * 1. The URI cannot contain special characters such as \/"*+,:;<=>?[]|\x7F. + * 2. The maximum number of characters allowed is 128. + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + */ + uri: string; + + /** + * Called when local files are deleted successfully. + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + */ + success?: () => void; + + /** + * Called when the deletion fails. + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + */ + fail?: (data: string, code: number) => void; + + /** + * Called when the execution is completed. + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + */ + complete?: () => void; +} + +/** + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + */ +export interface FileWriteTextOption { + /** + * URI of a local file. If it does not exist, a file will be created. + * Restricted by the underlying file system of lite wearables, the value must meet the following requirements: + * 1. The URI cannot contain special characters such as \/"*+,:;<=>?[]|\x7F. + * 2. The maximum number of characters allowed is 128. + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + */ + uri: string; + + /** + * Character string to write into the local file. + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + */ + text: string; + + /** + * Encoding format. The default format is UTF-8. + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + */ + encoding?: string; + + /** + * Whether to enable the append mode. The default value is false. + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + */ + append?: boolean; + + /** + * Called when texts are written into a file successfully. + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + */ + success?: () => void; + + /** + * Called when texts fail to be written into a file. + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + */ + fail?: (data: string, code: number) => void; + + /** + * Called when the execution is completed. + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + */ + complete?: () => void; +} + +/** + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + */ +export interface FileReadTextResponse { + /** + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + */ + text: string; +} + +export interface FileReadTextOption { + /** + * URI of a local file. + * Restricted by the underlying file system of lite wearables, the value must meet the following requirements: + * 1. The URI cannot contain special characters such as \/"*+,:;<=>?[]|\x7F. + * 2. The maximum number of characters allowed is 128. + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + */ + uri: string; + + /** + * Encoding format. The default format is UTF-8. + * Currently, only UTF-8 is supported. + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + */ + encoding?: string; + + /** + * Position where the reading starts. + * The default value is the start position of the file. + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + */ + position?: number; + + /** + * Position where the reading starts. + * The default value is the start position of the file. + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + */ + length?: number; + + /** + * Called when texts are read successfully. + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + */ + success?: (data: FileReadTextResponse) => void; + + /** + * Called when texts fail to be read. + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + */ + fail?: (data: string, code: number) => void; + + /** + * Called when the execution is completed. + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + */ + complete?: () => void; +} + +/** + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + */ +export interface FileWriteArrayBufferOption { + /** + * URI of a local file. If it does not exist, a file will be created. + * Restricted by the underlying file system of lite wearables, the value must meet the following requirements: + * 1. The URI cannot contain special characters such as \/"*+,:;<=>?[]|\x7F. + * 2. The maximum number of characters allowed is 128. + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + */ + uri: string; + + /** + * Buffer from which the data is derived. + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + */ + buffer: Uint8Array; + + /** + * Offset to the position where the writing starts. The default value is 0. + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + */ + position?: number; + + /** + * Whether to enable the append mode. + * The default value is false. If the value is true, the position parameter will become invalid. + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + */ + append?: boolean; + + /** + * Called when data from a buffer is written into a file successfully. + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + */ + success?: () => void; + + /** + * Called when data from a buffer fails to be written into a file. + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + */ + fail?: (data: string, code: number) => void; + + /** + * Called when the execution is completed. + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + */ + complete?: () => void; +} + +/** + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + */ +export interface FileReadArrayBufferResponse { + /** + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + */ + buffer: Uint8Array; +} + +/** + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + */ +export interface FileReadArrayBufferOption { + /** + * URI of a local file. + * Restricted by the underlying file system of lite wearables, the value must meet the following requirements: + * 1. The URI cannot contain special characters such as \/"*+,:;<=>?[]|\x7F. + * 2. The maximum number of characters allowed is 128. + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + */ + uri: string; + + /** + * Position where the reading starts. + * The default value is the start position of the file. + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + */ + position?: number; + + /** + * Length of the content to read. + * If this parameter is not set, all content of the file will be read. + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + */ + length?: number; + + /** + * Called when the buffer data is read successfully. + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + */ + success?: (data: FileReadArrayBufferResponse) => void; + + /** + * Called when the buffer data fails to be read. + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + */ + fail?: (data: string, code: number) => void; + + /** + * Called when the execution is completed. + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + */ + complete?: () => void; +} + +/** + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + */ +export interface FileAccessOption { + /** + * URI of the directory or file. + * Restricted by the underlying file system of lite wearables, the value must meet the following requirements: + * 1. The URI cannot contain special characters such as \/"*+,:;<=>?[]|\x7F. + * 2. The maximum number of characters allowed is 128. + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + */ + uri: string; + + /** + * Called when the check result is obtained successfully. + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + */ + success?: () => void; + + /** + * Called when the check fails. + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + */ + fail?: (data: string, code: number) => void; + + /** + * Called when the execution is completed. + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + */ + complete?: () => void; +} + +/** + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + */ +export interface FileMkdirOption { + /** + * URI of the directory. + * Restricted by the underlying file system of lite wearables, the value must meet the following requirements: + * 1. The URI cannot contain special characters such as \/"*+,:;<=>?[]|\x7F. + * 2. The maximum number of characters allowed is 128. + * 3. A maximum of five recursions are allowed for creating the directory. + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + */ + uri: string; + + /** + * Whether to create the directory after creating its upper-level directory recursively. + * The default value is false. + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + */ + recursive?: boolean; + + /** + * Called when the directory is created successfully. + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + */ + success?: () => void; + + /** + * Called when the creation fails. + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + */ + fail?: (data: string, code: number) => void; + + /** + * Called when the execution is completed. + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + */ + complete?: () => void; +} + +/** + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + */ +export interface FileRmdirOption { + /** + * URI of the directory. + * Restricted by the underlying file system of lite wearables, the value must meet the following requirements: + * 1. The URI cannot contain special characters such as \/"*+,:;<=>?[]|\x7F. + * 2. The maximum number of characters allowed is 128. + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + */ + uri: string; + + /** + * Whether to delete files and subdirectories recursively. + * The default value is false. + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + */ + recursive?: boolean; + + /** + * Called when the directory is deleted successfully. + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + */ + success?: () => void; + + /** + * Called when the deletion fails. + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + */ + fail?: (data: string, code: number) => void; + + /** + * Called when the execution is completed. + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + */ + complete?: () => void; +} + +/** + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + */ +export default class File { + /** + * Moves the source file to a specified location. + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + * @param options Options. + */ + static move(options: FileMoveOption): void; + + /** + * Copies a source file and save the copy to a specified location. + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + * @param options Options. + */ + static copy(options: FileCopyOption): void; + + /** + * Obtains the list of files in a specified directory. + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + * @param options Options. + */ + static list(options: FileListOption): void; + + /** + * Obtains information about a local file. + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + * @param options Options. + */ + static get(options: FileGetOption): void; + + /** + * Deletes local files. + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + * @param options Options. + */ + static delete(options: FileDeleteOption): void; + + /** + * Writes texts into a file. + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + * @param options Options. + */ + static writeText(options: FileWriteTextOption): void; + + /** + * Reads texts from a file. + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + * @param options Options. + */ + static readText(options: FileReadTextOption): void; + + /** + * Writes data from a buffer into a file. + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + * @param options Options. + */ + static writeArrayBuffer(options: FileWriteArrayBufferOption): void; + + /** + * Reads buffer data from a file. + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + * @param options Options. + */ + static readArrayBuffer(options: FileReadArrayBufferOption): void; + + /** + * Checks whether a file or directory exists. + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + * @param options Options. + */ + static access(options: FileAccessOption): void; + + /** + * Creates a directory. + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + * @param options Options. + */ + static mkdir(options: FileMkdirOption): void; + + /** + * Deletes a directory. + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 3 + * @param options Options. + */ + static rmdir(options: FileRmdirOption): void; +}