diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000000000000000000000000000000000000..c403f9c093105cef3d31eecf3c13a752f256884c
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,15 @@
+*.tgz filter=lfs diff=lfs merge=lfs -text
+*.trp filter=lfs diff=lfs merge=lfs -text
+*.apk filter=lfs diff=lfs merge=lfs -text
+*.jar filter=lfs diff=lfs merge=lfs -text
+*.mp4 filter=lfs diff=lfs merge=lfs -text
+*.zip filter=lfs diff=lfs merge=lfs -text
+*.asm filter=lfs diff=lfs merge=lfs -text
+*.8svn filter=lfs diff=lfs merge=lfs -text
+*.9svn filter=lfs diff=lfs merge=lfs -text
+*.dylib filter=lfs diff=lfs merge=lfs -text
+*.exe filter=lfs diff=lfs merge=lfs -text
+*.a filter=lfs diff=lfs merge=lfs -text
+*.so filter=lfs diff=lfs merge=lfs -text
+*.bin filter=lfs diff=lfs merge=lfs -text
+*.dll filter=lfs diff=lfs merge=lfs -text
diff --git a/LICENSE b/LICENSE
index 4947287f7b5ccb5d1e8b7b2d3aa5d89f322c160d..21254fc75dcad77bffde10dcab0ad5464a1f0963 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,177 +1,176 @@
-
- Apache License
- Version 2.0, January 2004
- http://www.apache.org/licenses/
-
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
-
- 1. Definitions.
-
- "License" shall mean the terms and conditions for use, reproduction,
- and distribution as defined by Sections 1 through 9 of this document.
-
- "Licensor" shall mean the copyright owner or entity authorized by
- the copyright owner that is granting the License.
-
- "Legal Entity" shall mean the union of the acting entity and all
- other entities that control, are controlled by, or are under common
- control with that entity. For the purposes of this definition,
- "control" means (i) the power, direct or indirect, to cause the
- direction or management of such entity, whether by contract or
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
- outstanding shares, or (iii) beneficial ownership of such entity.
-
- "You" (or "Your") shall mean an individual or Legal Entity
- exercising permissions granted by this License.
-
- "Source" form shall mean the preferred form for making modifications,
- including but not limited to software source code, documentation
- source, and configuration files.
-
- "Object" form shall mean any form resulting from mechanical
- transformation or translation of a Source form, including but
- not limited to compiled object code, generated documentation,
- and conversions to other media types.
-
- "Work" shall mean the work of authorship, whether in Source or
- Object form, made available under the License, as indicated by a
- copyright notice that is included in or attached to the work
- (an example is provided in the Appendix below).
-
- "Derivative Works" shall mean any work, whether in Source or Object
- form, that is based on (or derived from) the Work and for which the
- editorial revisions, annotations, elaborations, or other modifications
- represent, as a whole, an original work of authorship. For the purposes
- of this License, Derivative Works shall not include works that remain
- separable from, or merely link (or bind by name) to the interfaces of,
- the Work and Derivative Works thereof.
-
- "Contribution" shall mean any work of authorship, including
- the original version of the Work and any modifications or additions
- to that Work or Derivative Works thereof, that is intentionally
- submitted to Licensor for inclusion in the Work by the copyright owner
- or by an individual or Legal Entity authorized to submit on behalf of
- the copyright owner. For the purposes of this definition, "submitted"
- means any form of electronic, verbal, or written communication sent
- to the Licensor or its representatives, including but not limited to
- communication on electronic mailing lists, source code control systems,
- and issue tracking systems that are managed by, or on behalf of, the
- Licensor for the purpose of discussing and improving the Work, but
- excluding communication that is conspicuously marked or otherwise
- designated in writing by the copyright owner as "Not a Contribution."
-
- "Contributor" shall mean Licensor and any individual or Legal Entity
- on behalf of whom a Contribution has been received by Licensor and
- subsequently incorporated within the Work.
-
- 2. Grant of Copyright License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- copyright license to reproduce, prepare Derivative Works of,
- publicly display, publicly perform, sublicense, and distribute the
- Work and such Derivative Works in Source or Object form.
-
- 3. Grant of Patent License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- (except as stated in this section) patent license to make, have made,
- use, offer to sell, sell, import, and otherwise transfer the Work,
- where such license applies only to those patent claims licensable
- by such Contributor that are necessarily infringed by their
- Contribution(s) alone or by combination of their Contribution(s)
- with the Work to which such Contribution(s) was submitted. If You
- institute patent litigation against any entity (including a
- cross-claim or counterclaim in a lawsuit) alleging that the Work
- or a Contribution incorporated within the Work constitutes direct
- or contributory patent infringement, then any patent licenses
- granted to You under this License for that Work shall terminate
- as of the date such litigation is filed.
-
- 4. Redistribution. You may reproduce and distribute copies of the
- Work or Derivative Works thereof in any medium, with or without
- modifications, and in Source or Object form, provided that You
- meet the following conditions:
-
- (a) You must give any other recipients of the Work or
- Derivative Works a copy of this License; and
-
- (b) You must cause any modified files to carry prominent notices
- stating that You changed the files; and
-
- (c) You must retain, in the Source form of any Derivative Works
- that You distribute, all copyright, patent, trademark, and
- attribution notices from the Source form of the Work,
- excluding those notices that do not pertain to any part of
- the Derivative Works; and
-
- (d) If the Work includes a "NOTICE" text file as part of its
- distribution, then any Derivative Works that You distribute must
- include a readable copy of the attribution notices contained
- within such NOTICE file, excluding those notices that do not
- pertain to any part of the Derivative Works, in at least one
- of the following places: within a NOTICE text file distributed
- as part of the Derivative Works; within the Source form or
- documentation, if provided along with the Derivative Works; or,
- within a display generated by the Derivative Works, if and
- wherever such third-party notices normally appear. The contents
- of the NOTICE file are for informational purposes only and
- do not modify the License. You may add Your own attribution
- notices within Derivative Works that You distribute, alongside
- or as an addendum to the NOTICE text from the Work, provided
- that such additional attribution notices cannot be construed
- as modifying the License.
-
- You may add Your own copyright statement to Your modifications and
- may provide additional or different license terms and conditions
- for use, reproduction, or distribution of Your modifications, or
- for any such Derivative Works as a whole, provided Your use,
- reproduction, and distribution of the Work otherwise complies with
- the conditions stated in this License.
-
- 5. Submission of Contributions. Unless You explicitly state otherwise,
- any Contribution intentionally submitted for inclusion in the Work
- by You to the Licensor shall be under the terms and conditions of
- this License, without any additional terms or conditions.
- Notwithstanding the above, nothing herein shall supersede or modify
- the terms of any separate license agreement you may have executed
- with Licensor regarding such Contributions.
-
- 6. Trademarks. This License does not grant permission to use the trade
- names, trademarks, service marks, or product names of the Licensor,
- except as required for reasonable and customary use in describing the
- origin of the Work and reproducing the content of the NOTICE file.
-
- 7. Disclaimer of Warranty. Unless required by applicable law or
- agreed to in writing, Licensor provides the Work (and each
- Contributor provides its Contributions) on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
- implied, including, without limitation, any warranties or conditions
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
- PARTICULAR PURPOSE. You are solely responsible for determining the
- appropriateness of using or redistributing the Work and assume any
- risks associated with Your exercise of permissions under this License.
-
- 8. Limitation of Liability. In no event and under no legal theory,
- whether in tort (including negligence), contract, or otherwise,
- unless required by applicable law (such as deliberate and grossly
- negligent acts) or agreed to in writing, shall any Contributor be
- liable to You for damages, including any direct, indirect, special,
- incidental, or consequential damages of any character arising as a
- result of this License or out of the use or inability to use the
- Work (including but not limited to damages for loss of goodwill,
- work stoppage, computer failure or malfunction, or any and all
- other commercial damages or losses), even if such Contributor
- has been advised of the possibility of such damages.
-
- 9. Accepting Warranty or Additional Liability. While redistributing
- the Work or Derivative Works thereof, You may choose to offer,
- and charge a fee for, acceptance of support, warranty, indemnity,
- or other liability obligations and/or rights consistent with this
- License. However, in accepting such obligations, You may act only
- on Your own behalf and on Your sole responsibility, not on behalf
- of any other Contributor, and only if You agree to indemnify,
- defend, and hold each Contributor harmless for any liability
- incurred by, or claims asserted against, such Contributor by reason
- of your accepting any such warranty or additional liability.
-
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
END OF TERMS AND CONDITIONS
\ No newline at end of file
diff --git a/README.md b/README.md
index 76562969b350c0a8a0d32232860b134f43e815c8..78daa51a44959d8570e1b51a9c55ef21a73f1769 100644
--- a/README.md
+++ b/README.md
@@ -1,36 +1,280 @@
-# storage_app_file_manager
-
-#### Description
-{**When you're done, you can delete the content in this README and update the file with details for others getting started with your repository**}
-
-#### Software Architecture
-Software architecture description
-
-#### Installation
-
-1. xxxx
-2. xxxx
-3. xxxx
-
-#### Instructions
-
-1. xxxx
-2. xxxx
-3. xxxx
-
-#### Contribution
-
-1. Fork the repository
-2. Create Feat_xxx branch
-3. Commit your code
-4. Create Pull Request
-
-
-#### Gitee Feature
-
-1. You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md
-2. Gitee blog [blog.gitee.com](https://blog.gitee.com)
-3. Explore open source project [https://gitee.com/explore](https://gitee.com/explore)
-4. The most valuable open source project [GVP](https://gitee.com/gvp)
-5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help)
-6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
+# Distributed File
+
+- [Introduction](#section104mcpsimp)
+ - [Architecture](#section110mcpsimp)
+
+- [Directory Structure](#section113mcpsimp)
+- [Constraints](#section117mcpsimp)
+- [Usage](#section125mcpsimp)
+ - [Available APIs](#section127mcpsimp)
+ - [Usage Guidelines](#section149mcpsimp)
+
+- [Repositories Involved](#section178mcpsimp)
+
+## Introduction
+
+Currently, the Distributed File subsystem provides apps with JavaScript APIs for I/O capabilities, including APIs for managing files and directories, obtaining file information, reading and writing data streams of files, and receiving URIs rather than absolute paths.
+
+### Architecture
+
+Currently, the Distributed File subsystem provides only local JavaScript file APIs for apps through the FileIO and File modules. The Distributed File subsystem uses LibN to abstract APIs at the NAPI layer, providing basic capabilities such as the basic type system, memory management, and general programming models for the subsystem. This subsystem depends on the engine layer of the JS application development framework to provide the capability of converting JavaScript APIs into C++ code, depends on the application framework to provide app-related directories, and depends on the GLIBC runtimes to provide I/O capabilities.
+
+**Figure 1** Distributed File subsystem architecture
+
+
+## Directory Structure
+
+```
+foundation/distributeddatamgr/distributedfile
+└── interfaces # APIs
+ └── kits # APIs exposed externally
+```
+
+## Constraints
+
+Constraints on local I/O APIs:
+
+- Only UTF-8/16 encoding is supported.
+- The URIs cannot include external storage directories.
+
+## Usage
+
+### Available APIs
+
+Currently, the Distributed File subsystem provides APIs for accessing local files and directories. The following table describes the API types classified by function.
+
+**Table 1** API types
+
+
+
API Type
+ |
+Function
+ |
+Related Module
+ |
+Example API (Class Name.Method Name)
+ |
+
+
+Basic file API
+ |
+Creates, modifies, and accesses files, and changes file permissions based on the specified absolute paths or file descriptors.
+ |
+@OHOS.distributedfile.fileio
+ |
+accessSync
+chownSync
+chmodSync
+ |
+
+Basic directory API
+ |
+Reads directories and determines file types based on the specified absolute paths.
+ |
+@OHOS.distributedfile.fileio
+ |
+Dir.openDirSync
+ |
+
+Basic statistical API
+ |
+Collects basic statistics including the file size, access permission, and modification time based on the specified absolute paths.
+ |
+@OHOS.distributedfile.fileio
+ |
+Stat.statSync
+ |
+
+Streaming file API
+ |
+Reads and writes data streams of files based on the specified absolute paths or file descriptors.
+ |
+@OHOS.distributedfile.fileio
+ |
+Stream.createStreamSync
+Stream.fdopenStreamSync
+ |
+
+Sandbox file API
+ |
+Provides a subset or a combination of the capabilities provided by the basic file, directory, and statistical APIs based on the specified URIs.
+ |
+@system.file
+ |
+move
+copy
+list
+ |
+
+
+
+
+The URIs used in sandbox file APIs are classified into three types, as described in the following table.
+
+**Table 2** URI types
+
+
+Directory Type
+ |
+Prefix
+ |
+Access Visibility
+ |
+Description
+ |
+
+
+Temporary directory
+ |
+internal://cache/
+ |
+Current app only
+ |
+Readable and writable, and can be cleared at any time. This directory is usually used for temporary downloads or caches.
+ |
+
+Private directory of an app
+ |
+internal://app/
+ |
+Current app only
+ |
+Deleted when the app is uninstalled.
+ |
+
+External storage
+ |
+internal://share/
+ |
+All apps
+ |
+Deleted when the app is uninstalled. Other apps with granted permissions can read and write files in this directory.
+ |
+
+
+
+
+### Usage Guidelines
+
+The I/O APIs provided by the Distributed File subsystem can be classified into the following types based on the programming model:
+
+- Synchronous programming model
+
+ APIs whose names contain **Sync** are implemented as a synchronous model. When a synchronous API is called, the calling process waits until a value is returned.
+
+ The following example opens a file stream in read-only mode, attempts to read the first 4096 bytes, converts them into a UTF-8-encoded string, and then closes the file stream:
+
+ ```
+ import fileio from '@OHOS.distributedfile.fileio';
+
+ try {
+ var ss = fileio.Stream.createStreamSync("tmp", "r")
+ buf = new ArrayBuffer(4096)
+ ss.readSync(buf)
+ console.log(String.fromCharCode.apply(null, new Uint8Array(buf)))
+ ss.closeSync()
+ }
+ catch (e) {
+ console.log(e);
+ }
+ ```
+
+
+- Asynchronous programming model: Promise
+
+ In the **@OHOS.distributedfile.fileio** module, the APIs whose names do not contain **Sync** and to which a callback is not passed as their input parameter are implemented as the Promise asynchronous model. The Promise asynchronous model is one of the OHOS standard asynchronous models. When an asynchronous API using the Promise model is called, the API returns a Promise object while executing the concerned task asynchronously. The Promise object represents the asynchronous operation result. When there is more than one result, the results are returned as properties of the Promise object.
+
+ In the following example, a Promise chain is used to open a file stream in read-only mode, attempt to read the first 4096 bytes of the file, display the length of the content read, and then close the file:
+
+ ```
+ import fileio from '@OHOS.distributedfile.fileio';
+
+ try {
+ let openedStream
+ fileio.Stream.createStream("test.txt", "r")
+ .then(function (ss) {
+ openedStream = ss;
+ return ss.read(new ArrayBuffer(4096))
+ })
+ .then(function (res) {
+ console.log(res.bytesRead);
+ console.log(String.fromCharCode.apply(null, new Uint8Array(res.buffer)))
+ return openedStream.close()
+ })
+ .then(function (undefined) {
+ console.log("Stream is closed")
+ })
+ .catch(function (e) {
+ console.log(e)
+ })
+ } catch (e) {
+ console.log(e)
+ }
+ ```
+
+
+- Asynchronous programming model: Callback
+
+ In the **@OHOS.distributedfile.fileio** module, the APIs whose names do not contain **Sync** and to which a callback is directly passed as their input parameter are implemented as the callback asynchronous model. The callback asynchronous model is also one of the OHOS standard asynchronous models. When an asynchronous API with a callback passed is called, the API executes the concerned task asynchronously and returns the execution result as the input parameters of the registered callback. The first parameter is of the **undefined** or **Error** type, indicating that the execution succeeds or fails, respectively.
+
+ The following example creates a file stream asynchronously, reads the first 4096 bytes of the file asynchronously in the callback invoked when the file stream is created, and then closes the file asynchronously in the callback invoked when the file is read:
+
+ ```
+ import fileio from '@OHOS.distributedfile.fileio';
+
+ try {
+ fileio.Stream.createStream("./testdir/test_stream.txt", "r", function (err, ss) {
+ if (!err) {
+ ss.read(new ArrayBuffer(4096), {}, function (err, buf, readLen) {
+ if (!err) {
+ console.log('readLen: ' + readLen)
+ console.log('data: ' + String.fromCharCode.apply(null, new Uint8Array(buf)))
+ } else {
+ console.log('Cannot read from the stream ' + err)
+ }
+ ss.close(function (err) {
+ console.log(`Stream is ${err ? 'not' : ''}closed`)
+ });
+ })
+ } else {
+ console.log('Cannot open the stream ' + err)
+ }
+ })
+ } catch (e) {
+ console.log(e)
+ }
+ ```
+
+
+- Asynchronous programming model: Legacy
+
+ All APIs in the **@system.file** module are implemented as the legacy asynchronous model. When calling such an API, you need to implement three callbacks \(including **success**, **fail**, and **complete**\) to be invoked when the execution is successful, fails, or is complete, respectively. If the input parameters are correct, the API calls the **success** or **fail** callback based on whether the asynchronous task is successful after the task execution is complete, and finally calls the **complete** callback.
+
+ The following example asynchronously checks whether the file pointed to by the specified URI exists and provides three callbacks to print the check result:
+
+ ```
+ import file from '@system.file'
+
+ file.access({
+ uri: 'internal://app/test.txt',
+ success: function() {
+ console.log('call access success.');
+ },
+ fail: function(data, code) {
+ console.error('call fail callback fail, code: ' + code + ', data: ' + data);
+ },
+ complete: function () {
+ console.log('call access finally.');
+ }
+ });
+
+ console.log("file access tested done")
+ ```
+
+
+## Repositories Involved
+
+**Distributed File subsystem**
+
+distributeddatamgr_distributedfile
+
diff --git a/README_zh.md b/README_zh.md
index 25fb3eb92931621d20f68452b45c55351b43c2ac..362301a666a4ca36cd4bd481264a598996157ca5 100644
--- a/README_zh.md
+++ b/README_zh.md
@@ -1,28 +1,281 @@
-# 文件访问接口
+# 分布式文件子系统
-## 简介
+- [简介](#section104mcpsimp)
+ - [系统架构](#section110mcpsimp)
+- [目录结构](#section113mcpsimp)
+- [约束](#section117mcpsimp)
+- [说明](#section125mcpsimp)
+ - [接口说明](#section127mcpsimp)
+ - [使用说明](#section149mcpsimp)
+- [相关仓](#section178mcpsimp)
-提供目录与文件管理能力,即目录和文件的访问操作接口,包括以下内容:
+## 简介
-1. 提供基础文件操作的同步和异步接口
-2. 提供目录操作的异步接口
-3. 提供流式相关操作的文件接口
-4. 提供statfs接口能力
-5. 提供目录环境相关配置接口
-6. 提供本地系统扩展接口能力
+分布式文件子系统当前向应用程序提供用于的 IO 的 JS 接口。其具体包括用于管理文件的基本文件接口,用于管理目录的基本目录接口,用于获取文件信息的统计接口,用于流式读写文件的流式接口,以及接收 URI 而非绝对路径的沙盒接口。
-## 目录
+### 系统架构
+
+当前分布式文件子系统仅面向应用提供本地 JS 文件接口,这些接口分别通过 FileIO 模块以及 File 模块提供。架构上,分布式文件子系统实现了自研的 LibN,其抽象了 NAPI 层接口,向分布式文件子系统提供包括基本类型系统、内存管理、通用编程模型在内的基本能力。本系统对外依赖 JS 开发框架提供将 JS 接口转换为 C++ 代码的能力,依赖用户程序框架提供应用相关目录,依赖 GLIBC Runtimes 提供 IO 能力。
+
+**图 1** 分布式文件子系统架构图
+
+
+## 目录结构
```
-interfaces # 接口代码
- └── kits # 对外JS接口代码
-LICENSE # 证书文件
+foundation/distributeddatamgr/distributedfile
+├── figures # 仓库图床
+└── interfaces # 接口代码
+ └── kits # 对外接口代码
```
-## 说明
+## 约束
+
+本地 IO 接口
+
+- 目前仅支持 UTF-8/16 编码;
+- 目前 URI 暂不支持外部存储目录;
+
+## 说明
+
+### 接口说明
+
+当前分布式文件子系统开放本地文件目录访问接口,按照功能,其可划分为如下几种类型:
+
+**表 1** 接口类型表
+
+
+接口类型
+ |
+接口用途
+ |
+相关模块
+ |
+接口示例(类名.方法名)
+ |
+
+
+基本文件接口
+ |
+需要用户提供绝对路径或文件描述符(fd),提供创建、修改及访问文件,或修改文件权限的能力
+ |
+@OHOS.distributedfile.fileio
+ |
+accessSync
+chownSync
+chmodSync
+ |
+
+基本目录接口
+ |
+需要用户提供绝对路径,提供读取目录及判断文件类型的能力
+ |
+@OHOS.distributedfile.fileio
+ |
+Dir.openDirSync
+ |
+
+基本Stat接口
+ |
+需要用户提供绝对路径,提供包括文件大小、访问权限、修改时间在内的基本统计信息
+ |
+@OHOS.distributedfile.fileio
+ |
+Stat.statSync
+ |
+
+流式文件接口
+ |
+需要用户提供绝对路径或文件描述符,提供流式读写文件的能力
+ |
+@OHOS.distributedfile.fileio
+ |
+Stream.createStreamSync
+Stream.fdopenStreamSync
+ |
+
+沙盒文件接口
+ |
+需要用户提供 URI,提供基本文件接口、基本目录接口及基本统计接口能力的子集能力,或这些能力的组合能力
+ |
+@system.file
+ |
+move
+copy
+list
+ |
+
+
+
+
+其中,沙盒文件接口所使用的 URI 具体可划分为三种类型:
+
+**表 2** URI类型表
+
+
+目录类型
+ |
+路径前缀
+ |
+访问可见性
+ |
+说明
+ |
+
+
+临时目录
+ |
+internal://cache/
+ |
+仅本应用可见
+ |
+可读写,随时可能清除,不保证持久性。一般用作下载临时目录或缓存目录。
+ |
+
+应用私有目录
+ |
+internal://app/
+ |
+仅本应用可见
+ |
+随应用卸载删除。
+ |
+
+外部存储
+ |
+internal://share/
+ |
+所有应用可见
+ |
+随应用卸载删除。其他应用在有相应权限的情况下可读写此目录下的文件。
+ |
+
+
+
+
+### 使用说明
+
+当前分布式文件子系统所提供的 IO 接口,按照编程模型,可划分为如下几种类型:
+
+- 同步编程模型
+
+ 名称包含 Sync 的接口实现为同步模型。用户在调用这些接口的时候,将同步等待,直至执行完成,执行结果以函数返回值的形式返回。
+
+ 下例以只读的方式打开一个文件流,接着试图读取其中前 4096 个字节并将之转换为 UTF-8 编码的字符串,最后关闭该文件流。
+
+ ```
+ import fileio from '@OHOS.distributedfile.fileio';
+
+ try {
+ var ss = fileio.Stream.createStreamSync("tmp", "r")
+ buf = new ArrayBuffer(4096)
+ ss.readSync(buf)
+ console.log(String.fromCharCode.apply(null, new Uint8Array(buf)))
+ ss.closeSync()
+ }
+ catch (e) {
+ console.log(e);
+ }
+ ```
+
+
+- 异步编程模型:Promise
+
+ @OHOS.distributedfile.fileio 模块中,名称不含 Sync 的接口,在不提供最后一个函数型参数 callback 的时候,即实现为 Promsie 异步模型。Promise 异步模型是 OHOS 标准异步模型之一。用户在调用这些接口的时候,接口实现将异步执行任务,同时返回一个 promise 对象,其代表异步操作的结果。在返回的结果的个数超过一个时,其以对象属性的形式返回。
+
+ 下例通过 Promise 链依次完成:以只读方式打开文件流、尝试读取文件前 4096 个字节、显示读取内容的长度,最后关闭文件。
+
+ ```
+ import fileio from '@OHOS.distributedfile.fileio';
+
+ try {
+ let openedStream
+ fileio.Stream.createStream("test.txt", "r")
+ .then(function (ss) {
+ openedStream = ss;
+ return ss.read(new ArrayBuffer(4096))
+ })
+ .then(function (res) {
+ console.log(res.bytesRead);
+ console.log(String.fromCharCode.apply(null, new Uint8Array(res.buffer)))
+ return openedStream.close()
+ })
+ .then(function (undefined) {
+ console.log("Stream is closed")
+ })
+ .catch(function (e) {
+ console.log(e)
+ })
+ } catch (e) {
+ console.log(e)
+ }
+ ```
+
+
+- 异步编程模型:Callback
+
+ @OHOS.distributedfile.fileio 模块中,名字不含 Sync 的接口,在提供最后一个函数性参数 callback 的时候,即实现为 Callback 异步模型。Callback 异步模型是 OHOS 标准异步模型之一。用户在调用这些接口的时候,接口实现将异步执行任务。任务执行结果以参数的形式提供给用户注册的回调函数。这些参数的第一个是 Error 或 undefined 类型,分别表示执行出错与正常。
+
+ 下例异步创建文件流,并在文件流的回调函数中异步读取文件的前 4096 字节,接着在读取文件的回调函数中异步关闭文件。
+
+ ```
+ import fileio from '@OHOS.distributedfile.fileio';
+
+ try {
+ fileio.Stream.createStream("./testdir/test_stream.txt", "r", function (err, ss) {
+ if (!err) {
+ ss.read(new ArrayBuffer(4096), {}, function (err, buf, readLen) {
+ if (!err) {
+ console.log('readLen: ' + readLen)
+ console.log('data: ' + String.fromCharCode.apply(null, new Uint8Array(buf)))
+ } else {
+ console.log('Cannot read from the stream ' + err)
+ }
+ ss.close(function (err) {
+ console.log(`Stream is ${err ? 'not' : ''}closed`)
+ });
+ })
+ } else {
+ console.log('Cannot open the stream ' + err)
+ }
+ })
+ } catch (e) {
+ console.log(e)
+ }
+ ```
+
+
+- 异步编程模型:Legacy
+
+ @system.file 模块中的所有接口都实现为 Legacy 异步模型。用户在调用这些接口的时候,需要提供 success、fail 及 complete 三个回调。在正确提供参数的情况下,当异步任务完成后,接口会根据是否成功,分别调用 success 回调或 fail 回调,并最终调用 complete 回调。
+
+ 下例异步判断 URI 所指向的文件是否存在,并相应提供三个回调用于打印判断结果。
+
+ ```
+ import file from '@system.file'
+
+ file.access({
+ uri: 'internal://app/test.txt',
+ success: function() {
+ console.log('call access success.');
+ },
+ fail: function(data, code) {
+ console.error('call fail callback fail, code: ' + code + ', data: ' + data);
+ },
+ complete: function () {
+ console.log('call access finally.');
+ }
+ });
+
+ console.log("file access tested done")
+ ```
+
+
+## 相关仓
+
+**分布式文件**
-### 接口说明
+distributeddatamgr_distributedfile
-[statfs接口](https://gitee.com/openharmony/docs/tree/master/zh-cn/application-dev/reference/apis/js-apis-statfs.md)
diff --git a/bundle.json b/bundle.json
new file mode 100644
index 0000000000000000000000000000000000000000..b4606e68df55a562d3a59abea9ea4777de341263
--- /dev/null
+++ b/bundle.json
@@ -0,0 +1,43 @@
+{
+ "name": "file_api",
+ "description": "provides the application with JS interfaces for IO",
+ "version": "3.1",
+ "license": "Apache License 2.0",
+ "publishAs": "code-segment",
+ "segment": {
+ "destPath": "foundation/filemanagement/file_api"
+ },
+ "dirs": {},
+ "scripts": {},
+ "component": {
+ "name": "file_api",
+ "subsystem": "filemanagement",
+ "syscap": [],
+ "features": [],
+ "adapted_system_type": ["standard"],
+ "rom": "",
+ "ram": "",
+ "deps": {
+ "components": [
+ "ability_base",
+ "ability_manager",
+ "appexecfwk_base",
+ "appexecfwk_core",
+ "want",
+ "libhilog",
+ "ipc_core",
+ "ace_napi",
+ "samgr_proxy"
+ ],
+ "third_party": [
+ "e2fsprogs"
+ ]
+ },
+ "build": {
+ "sub_component": [
+ "//foundation/filemanagement/file_api/interfaces/kits/js:build_kits_js",
+ "//third_party/e2fsprogs:e2fsprogs"
+ ]
+ }
+ }
+ }
\ No newline at end of file
diff --git a/figures/distributed-file-subsystem-architecture.png b/figures/distributed-file-subsystem-architecture.png
new file mode 100644
index 0000000000000000000000000000000000000000..d36a4b1bca8f27ebe38b448dc6169de767811d27
Binary files /dev/null and b/figures/distributed-file-subsystem-architecture.png differ
diff --git "a/figures/\345\210\206\345\270\203\345\274\217\346\226\207\344\273\266\345\255\220\347\263\273\347\273\237\346\236\266\346\236\204\345\233\276.png" "b/figures/\345\210\206\345\270\203\345\274\217\346\226\207\344\273\266\345\255\220\347\263\273\347\273\237\346\236\266\346\236\204\345\233\276.png"
new file mode 100644
index 0000000000000000000000000000000000000000..e3763b766aff5cf1c80c31a0ea17c527a9f70a8f
Binary files /dev/null and "b/figures/\345\210\206\345\270\203\345\274\217\346\226\207\344\273\266\345\255\220\347\263\273\347\273\237\346\236\266\346\236\204\345\233\276.png" differ
diff --git a/file_api_aafwk.gni b/file_api_aafwk.gni
new file mode 100644
index 0000000000000000000000000000000000000000..b2fc6d3ac33ced684fbe022b717720c733fb9d35
--- /dev/null
+++ b/file_api_aafwk.gni
@@ -0,0 +1,15 @@
+# Copyright (c) 2022 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.
+
+aafwk_kits_path = "//foundation/ability/ability_runtime/frameworks/kits"
+aafwk_path = "//foundation/ability/ability_runtime"
diff --git a/interfaces/kits/js/BUILD.gn b/interfaces/kits/js/BUILD.gn
new file mode 100644
index 0000000000000000000000000000000000000000..084f8d5e5a34afd25794ce2ef00a87e6f0580437
--- /dev/null
+++ b/interfaces/kits/js/BUILD.gn
@@ -0,0 +1,248 @@
+# 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_aafwk.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 = [
+ "//third_party/node/src",
+ "//foundation/arkui/napi/interfaces/kits",
+ "//third_party/bounds_checking_function/include",
+ "//third_party/libuv/include",
+ "//third_party/openssl/include",
+ "//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",
+ ]
+
+ 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 = [
+ "//third_party/node/src",
+ "//foundation/arkui/napi/interfaces/kits",
+ "//third_party/bounds_checking_function/include",
+ "//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",
+ ]
+
+ 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 = [
+ "ability_base:want",
+ "ability_runtime:ability_manager",
+ "bundle_framework:appexecfwk_base",
+ "bundle_framework:appexecfwk_core",
+ "eventhandler:libeventhandler",
+ "hiviewdfx_hilog_native:libhilog",
+ "ipc:ipc_core",
+ ]
+}
+
+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 = [
+ "//third_party/node/src",
+ "//foundation/arkui/napi/interfaces/kits",
+ "//foundation/filemanagement/file_api/interfaces/kits/js/src/common/napi/n_async",
+ ]
+
+ 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 = [
+ "//third_party/node/src",
+ "//foundation/arkui/napi/interfaces/kits",
+ "//foundation/filemanagement/file_api/interfaces/kits/js/src/common/napi/n_async",
+ ]
+
+ 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/@ohos.document.d.ts b/interfaces/kits/js/napi/@ohos.document.d.ts
similarity index 97%
rename from interfaces/kits/js/@ohos.document.d.ts
rename to interfaces/kits/js/napi/@ohos.document.d.ts
index 1333942fe64968a00d2c1895f5815ccee37d40d1..88df1e0cfde75ca6f7ae55ea9ea1645e0ba2b3be 100644
--- a/interfaces/kits/js/@ohos.document.d.ts
+++ b/interfaces/kits/js/napi/@ohos.document.d.ts
@@ -1,63 +1,63 @@
-/*
- * 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 { AsyncCallback } from './basic'
-
-export default document;
-
-/**
- * document
- * @syscap SystemCapability.FileManagement.UserFileService
- * @since 6
- * @import import document from '@ohos.document';
- * @permission N/A
- */
-declare namespace document {
- export { choose };
- export { show };
-}
-
-/**
- * choose.
- *
- * @note N/A
- * @syscap SystemCapability.FileManagement.UserFileService
- * @since 6
- * @permission N/A
- * @function choose
- * @param {string} type - type.
- * @param {AsyncCallback} [callback] - callback.
- * @returns {void | Promise} no callback return Promise otherwise return void
- * @throws {TypedError} Parameter check failed
- */
-declare function choose(types?: string[]): Promise;
-declare function choose(callback: AsyncCallback): void;
-declare function choose(types: string[], callback: AsyncCallback): void;
-
-/**
- * show.
- *
- * @note N/A
- * @syscap SystemCapability.FileManagement.UserFileService
- * @since 6
- * @permission N/A
- * @function show
- * @param {string} uri - uri.
- * @param {string} type - type.
- * @param {AsyncCallback} [callback] - callback.
- * @returns {void | Promise} no callback return Promise otherwise return void
- * @throws {TypedError} Parameter check failed
- */
-declare function show(uri: string, type: string): Promise;
+/*
+ * 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 { AsyncCallback } from './basic'
+
+export default document;
+
+/**
+ * document
+ * @syscap SystemCapability.FileManagement.UserFileService
+ * @since 6
+ * @import import document from '@ohos.document';
+ * @permission N/A
+ */
+declare namespace document {
+ export { choose };
+ export { show };
+}
+
+/**
+ * choose.
+ *
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.UserFileService
+ * @since 6
+ * @permission N/A
+ * @function choose
+ * @param {string} type - type.
+ * @param {AsyncCallback} [callback] - callback.
+ * @returns {void | Promise} no callback return Promise otherwise return void
+ * @throws {TypedError} Parameter check failed
+ */
+declare function choose(types?: string[]): Promise;
+declare function choose(callback: AsyncCallback): void;
+declare function choose(types: string[], callback: AsyncCallback): void;
+
+/**
+ * show.
+ *
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.UserFileService
+ * @since 6
+ * @permission N/A
+ * @function show
+ * @param {string} uri - uri.
+ * @param {string} type - type.
+ * @param {AsyncCallback} [callback] - callback.
+ * @returns {void | Promise} no callback return Promise otherwise return void
+ * @throws {TypedError} Parameter check failed
+ */
+declare function show(uri: string, type: string): Promise;
declare function show(uri: string, type: string, callback: AsyncCallback): void;
\ No newline at end of file
diff --git a/interfaces/kits/js/napi/@ohos.environment.d.ts b/interfaces/kits/js/napi/@ohos.environment.d.ts
new file mode 100644
index 0000000000000000000000000000000000000000..4ecb978046047db3a38db777c70b537bc8d6b874
--- /dev/null
+++ b/interfaces/kits/js/napi/@ohos.environment.d.ts
@@ -0,0 +1,41 @@
+/*
+* 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 {AsyncCallback, Callback} from "./basic";
+
+/**
+ * Provides Environment APIs.
+ *
+ * @since 8
+ * @syscap SystemCapability.FileManagement.File.Environment
+ */
+declare namespace Environment {
+ /**
+ * Get the user data path.
+ *
+ * @since 8
+ */
+ function getStorageDataDir(callback: AsyncCallback): void;
+ function getStorageDataDir(): Promise;
+ /**
+ * Get the User storage path.
+ *
+ * @since 8
+ */
+ function getUserDataDir(callback: AsyncCallback): void;
+ function getUserDataDir(): Promise;
+}
+
+export default Environment;
diff --git a/interfaces/kits/js/napi/@ohos.fileio.d.ts b/interfaces/kits/js/napi/@ohos.fileio.d.ts
new file mode 100644
index 0000000000000000000000000000000000000000..d074897db66b2d0b83bb97b2901da646653e741e
--- /dev/null
+++ b/interfaces/kits/js/napi/@ohos.fileio.d.ts
@@ -0,0 +1,1548 @@
+/*
+ * 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 { AsyncCallback } from './basic'
+
+export default fileIO;
+
+/**
+ * fileio
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 6
+ * @import import fileio from '@ohos.fileio';
+ * @permission N/A
+ */
+declare namespace fileIO {
+ export { access };
+ export { accessSync };
+ export { chmod };
+ export { chmodSync };
+ export { chown };
+ export { chownSync };
+ export { close };
+ export { closeSync };
+ export { copyFile };
+ export { copyFileSync };
+ export { createStream };
+ export { createStreamSync };
+ export { createWatcher };
+ export { fchmod };
+ export { fchmodSync };
+ export { fchown };
+ export { fchownSync };
+ export { fdatasync };
+ export { fdatasyncSync };
+ export { fdopenStream };
+ export { fdopenStreamSync };
+ export { fstat };
+ export { fstatSync };
+ export { fsync };
+ export { fsyncSync };
+ export { ftruncate };
+ export { ftruncateSync };
+ export { hash };
+ export { lchown };
+ export { lchownSync };
+ export { lstat };
+ export { lstatSync };
+ export { mkdir };
+ export { mkdirSync };
+ export { mkdtemp };
+ export { mkdtempSync };
+ export { open };
+ export { openSync };
+ export { opendir };
+ export { opendirSync };
+ export { read };
+ export { readSync };
+ export { readText };
+ export { readTextSync };
+ export { rename };
+ export { renameSync };
+ export { rmdir };
+ export { rmdirSync };
+ export { stat };
+ export { statSync };
+ export { symlink };
+ export { symlinkSync };
+ export { truncate };
+ export { truncateSync };
+ export { unlink };
+ export { unlinkSync };
+ export { write };
+ export { writeSync };
+ export { Dir };
+ export { Dirent };
+ export { ReadOut };
+ export { Stat };
+ export { Stream };
+ export { Watcher };
+}
+
+/**
+ * access.
+ *
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 6
+ * @permission N/A
+ * @function access
+ * @param {string} path - path.
+ * @param {number} [mode = 0] - mode.
+ * @param {AsyncCallback} [callback] - callback.
+ * @returns {void | Promise} no callback return Promise otherwise return void
+ * @throws {TypedError} Parameter check failed
+ */
+declare function access(path: string, mode?: number): Promise;
+declare function access(path: string, callback: AsyncCallback): void;
+declare function access(path: string, mode: number, callback: AsyncCallback): void;
+/**
+ * accessSync.
+ *
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 6
+ * @permission N/A
+ * @function accessSync
+ * @param {string} path - path.
+ * @param {number} [mode = 0] - mode.
+ * @returns {void} access success
+ * @throws {TypedError | Error} access fail
+ */
+declare function accessSync(path: string, mode?: number): void;
+/**
+ * close.
+ *
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 7
+ * @permission N/A
+ * @function close
+ * @param {number} fd - fd.
+ * @param {AsyncCallback} [callback] - callback.
+ * @returns {void | Promise} no callback return Promise otherwise return void
+ * @throws {TypedError} Parameter check failed
+ */
+declare function close(fd: number): Promise;
+declare function close(fd: number, callback: AsyncCallback): void;
+/**
+ * closeSync.
+ *
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 6
+ * @permission N/A
+ * @function closeSync
+ * @param {number} fd - fd.
+ * @returns {void} close success
+ * @throws {TypedError | Error} close fail
+ */
+declare function closeSync(fd: number): void;
+/**
+ * copyFile.
+ *
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 6
+ * @permission N/A
+ * @function copyFile
+ * @param {string | number} src - src.
+ * @param {string | number} dest - dest.
+ * @param {number} [mode = 0] - mode.
+ * @param {AsyncCallback} [callback] - callback.
+ * @returns {void | Promise} no callback return Promise otherwise return void
+ * @throws {TypedError} Parameter check failed
+ */
+declare function copyFile(src: string | number, dest: string | number, mode?: number): Promise;
+declare function copyFile(src: string | number, dest: string | number, callback: AsyncCallback): void;
+declare function copyFile(src: string | number, dest: string | number, mode: number, callback: AsyncCallback): void;
+/**
+ * copyFileSync.
+ *
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 6
+ * @permission N/A
+ * @function copyFileSync
+ * @param {string | number} src - src.
+ * @param {string | number} dest - dest.
+ * @param {number} [mode = 0] - mode.
+ * @returns {void} copyFile success
+ * @throws {TypedError | Error} copyFile fail
+ */
+declare function copyFileSync(src: string | number, dest: string | number, mode?: number): void;
+/**
+ * createStream.
+ *
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 7
+ * @permission N/A
+ * @function createStream
+ * @param {string} path - path.
+ * @param {string} mode - mode.
+ * @param {AsyncCallback} [callback] - callback.
+ * @returns {void | Promise} no callback return Promise otherwise return Stream
+ * @throws {TypedError} Parameter check failed
+ */
+declare function createStream(path: string, mode: string): Promise;
+declare function createStream(path: string, mode: string, callback: AsyncCallback): void;
+/**
+ * createStreamSync.
+ *
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 7
+ * @permission N/A
+ * @function createStreamSync
+ * @param {string} path - path.
+ * @param {string} mode - mode.
+ * @returns {Stream} createStream
+ * @throws {TypedError} Parameter check failed
+ */
+declare function createStreamSync(path: string, mode: string): Stream;
+/**
+ * chown.
+ *
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 7
+ * @permission N/A
+ * @function appendFile
+ * @param {string} path - path.
+ * @param {number} uid - mode.
+ * @param {number} gid - mode.
+ * @param {AsyncCallback} [callback] - callback.
+ * @returns {void | Promise} no callback return Promise otherwise return void
+ * @throws {TypedError} Parameter check failed
+ */
+declare function chown(path: string, uid: number, gid: number): Promise;
+declare function chown(path: string, uid: number, gid: number, callback: AsyncCallback): void;
+/**
+ * chownSync.
+ *
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 7
+ * @permission N/A
+ * @function appendFile
+ * @param {string} path - path.
+ * @param {number} uid - mode.
+ * @param {number} gid - mode.
+ * @returns {void} chown success
+ * @throws {TypedError | Error} chown fail
+ */
+declare function chownSync(path: string, uid: number, gid: number): void;
+/**
+ * chmod.
+ *
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 7
+ * @permission N/A
+ * @function chmod
+ * @param {string} path - path.
+ * @param {number} mode - mode.
+ * @param {AsyncCallback} [callback] - callback.
+ * @returns {void | Promise} no callback return Promise otherwise return void
+ * @throws {TypedError} Parameter check failed
+ */
+declare function chmod(path: string, mode: number): Promise;
+declare function chmod(path: string, mode: number, callback: AsyncCallback): void;
+/**
+ * chmodSync.
+ *
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 7
+ * @permission N/A
+ * @function chmodSync
+ * @param {string} path - path.
+ * @param {number} mode - mode.
+ * @returns {void} chmod success
+ * @throws {TypedError | Error} chmod fail
+ */
+declare function chmodSync(path: string, mode: number): void;
+/**
+ * ftruncate.
+ *
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 7
+ * @permission N/A
+ * @function ftruncate
+ * @param {number} fd - fd.
+ * @param {number} [len = 0] - len.
+ * @param {AsyncCallback} [callback] - callback.
+ * @returns {void | Promise} no callback return Promise otherwise return void
+ * @throws {TypedError} Parameter check failed
+ */
+declare function ftruncate(fd: number, len?: number): Promise;
+declare function ftruncate(fd: number, callback: AsyncCallback): void;
+declare function ftruncate(fd: number, len: number, callback: AsyncCallback): void;
+/**
+ * ftruncateSync.
+ *
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 7
+ * @permission N/A
+ * @function ftruncateSync
+ * @param {number} fd - fd.
+ * @param {number} [len = 0] - len.
+ * @returns {void} ftruncate success
+ * @throws {TypedError | Error} ftruncate fail
+ */
+declare function ftruncateSync(fd: number, len?: number): void;
+/**
+ * fsync.
+ *
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 7
+ * @permission N/A
+ * @function fsync
+ * @param {number} fd - fd.
+ * @param {AsyncCallback} [callback] - callback.
+ * @returns {void | Promise} no callback return Promise otherwise return void
+ * @throws {TypedError} Parameter check failed
+ */
+declare function fsync(fd: number): Promise;
+declare function fsync(fd: number, callback: AsyncCallback): void;
+/**
+ * fsyncSync.
+ *
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 7
+ * @permission N/A
+ * @function fsyncSync
+ * @param {number} fd - fd.
+ * @returns {void} fsync success
+ * @throws {TypedError | Error} fsync fail
+ */
+declare function fsyncSync(fd: number): void;
+/**
+ * fstat.
+ *
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 7
+ * @permission N/A
+ * @function fstat
+ * @param {number} fd - fd.
+ * @returns {Stat}
+ * @throws {TypedError | Error} fstat fail
+ */
+declare function fstat(fd: number): Promise;
+declare function fstat(fd: number, callback: AsyncCallback): void;
+/**
+ * fstatSync.
+ *
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 7
+ * @permission N/A
+ * @function fstatSync
+ * @param {number} fd - fd.
+ * @returns {Stat}
+ * @throws {TypedError | Error} fstat fail
+ */
+declare function fstatSync(fd: number): Stat;
+/**
+ * fdatasync.
+ *
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 7
+ * @permission N/A
+ * @function fdatasync
+ * @param {number} fd - fd.
+ * @param {AsyncCallback} [callback] - callback.
+ * @returns {void | Promise} no callback return Promise otherwise return void
+ * @throws {TypedError} Parameter check failed
+ */
+declare function fdatasync(fd: number): Promise;
+declare function fdatasync(fd: number, callback: AsyncCallback): void;
+/**
+ * fdatasyncSync.
+ *
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 7
+ * @permission N/A
+ * @function fdatasyncSync
+ * @param {number} fd - fd.
+ * @returns {void} fdatasync success
+ * @throws {TypedError | Error} fdatasync fail
+ */
+declare function fdatasyncSync(fd: number): void;
+/**
+ * fchown.
+ *
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 7
+ * @permission N/A
+ * @function fchown
+ * @param {number} fd - fd.
+ * @param {number} uid - uid.
+ * @param {number} gid - gid.
+ * @param {AsyncCallback} [callback] - callback.
+ * @returns {void | Promise} no callback return Promise otherwise return void
+ * @throws {TypedError} Parameter check failed
+ */
+declare function fchown(fd: number, uid: number, gid: number): Promise;
+declare function fchown(fd: number, uid: number, gid: number, callback: AsyncCallback): void;
+/**
+ * fchownSync.
+ *
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 7
+ * @permission N/A
+ * @function fchownSync
+ * @param {number} fd - fd.
+ * @param {number} uid - uid.
+ * @param {number} gid - gid.
+ * @returns {void} fchown success
+ * @throws {TypedError | Error} fchown fail
+ */
+declare function fchownSync(fd: number, uid: number, gid: number): void;
+/**
+ * fchmod.
+ *
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 7
+ * @permission N/A
+ * @function fchmod
+ * @param {number} fd - fd.
+ * @param {number} mode - mode.
+ * @param {AsyncCallback} [callback] - callback.
+ * @returns {void | Promise} no callback return Promise otherwise return void
+ * @throws {TypedError} Parameter check failed
+ */
+declare function fchmod(fd: number, mode: number): Promise;
+declare function fchmod(fd: number, mode: number, callback: AsyncCallback): void;
+/**
+ * fchmodSync.
+ *
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 7
+ * @permission N/A
+ * @function fchmodSync
+ * @param {number} fd - fd.
+ * @param {number} mode - mode.
+ * @returns {void} fchmod success
+ * @throws {TypedError | Error} fchmod fail
+ */
+declare function fchmodSync(fd: number, mode: number): void;
+/**
+ * fdopenStream.
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 7
+ * @permission N/A
+ * @function fdopenStream
+ * @param {number} fd - fd.
+ * @param {string} mode - mode.
+ * @param {AsyncCallback} [callback] - callback.
+ * @returns {void | Promise} no callback return Promise otherwise return void
+ * @throws {TypedError} Parameter check failed
+ */
+declare function fdopenStream(fd: number, mode: string): Promise;
+declare function fdopenStream(fd: number, mode: string, callback: AsyncCallback): void;
+/**
+ * fdopenStreamSync.
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 7
+ * @permission N/A
+ * @function fdopenStreamSync
+ * @param {number} fd - fd.
+ * @param {string} mode - mode.
+ * @returns {Stream} open stream from fd
+ * @throws {TypedError | Error} open fail
+ */
+declare function fdopenStreamSync(fd: number, mode: string): Stream;
+ /**
+ * hash.
+ * @static
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 6
+ * @permission N/A
+ * @function hash
+ * @param {string} path - path.
+ * @param {string} algorithm - algorithm md5 sha1 sha256.
+ * @param {AsyncCallback} [callback] - callback.
+ * @returns {void | Promise} no callback return Promise otherwise return void
+ * @throws {TypedError} Parameter check failed
+ */
+declare function hash(path: string, algorithm: string): Promise;
+declare function hash(path: string, algorithm: string, callback: AsyncCallback): void;
+/**
+ * lchown.
+ *
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 7
+ * @permission N/A
+ * @function lchown
+ * @param {string} path - path.
+ * @param {number} uid - uid.
+ * @param {number} gid - gid.
+ * @param {AsyncCallback} [callback] - callback.
+ * @returns {void | Promise} no callback return Promise otherwise return void
+ * @throws {TypedError} Parameter check failed
+ */
+declare function lchown(path: string, uid: number, gid: number): Promise;
+declare function lchown(path: string, uid: number, gid: number, callback: AsyncCallback): void;
+/**
+ * lchownSync.
+ *
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 7
+ * @permission N/A
+ * @function lchownSync
+ * @param {string} path - path.
+ * @param {number} uid - uid.
+ * @param {number} gid - gid.
+ * @returns {void} lchown success
+ * @throws {TypedError | Error} lchown fail
+ */
+declare function lchownSync(path: string, uid: number, gid: number): void;
+/**
+ * lstat.
+ *
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 7
+ * @permission N/A
+ * @function lstat
+ * @param {string} path - path.
+ * @param {AsyncCallback} [callback] - callback.
+ * @returns {void | Promise} no callback return Promise otherwise return void
+ * @throws {TypedError} Parameter check failed
+ */
+declare function lstat(path: string): Promise;
+declare function lstat(path: string, callback: AsyncCallback): void;
+/**
+ * lstatSync.
+ *
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 7
+ * @permission N/A
+ * @function lstatSync
+ * @param {string} path - path.
+ * @returns {Stat} lstat success
+ * @throws {TypedError | Error} lstat fail
+ */
+declare function lstatSync(path: string): Stat;
+/**
+ * mkdir.
+ *
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 6
+ * @permission N/A
+ * @function mkdir
+ * @param {string} path - path.
+ * @param {number} [mode = 0o775] - path.
+ * @param {AsyncCallback} [callback] - callback.
+ * @returns {void | Promise} no callback return Promise otherwise return void
+ * @throws {TypedError} Parameter check failed
+ */
+declare function mkdir(path: string, mode?: number): Promise;
+declare function mkdir(path: string, callback: AsyncCallback): void;
+declare function mkdir(path: string, mode: number, callback: AsyncCallback): void;
+/**
+ * mkdirSync.
+ *
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 6
+ * @permission N/A
+ * @function mkdirSync
+ * @param {string} path - path.
+ * @param {number} [mode = 0o775] - path.
+ * @returns {void} mkdir success
+ * @throws {TypedError | Error} mkdir fail
+ */
+declare function mkdirSync(path: string, mode?: number): void;
+/**
+ * mkdtemp.
+ *
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 7
+ * @permission N/A
+ * @function mkdtemp
+ * @param {string} prefix - dir prefix.
+ * @param {AsyncCallback} [callback] - callback.
+ * @returns {void | Promise} no callback return Promise otherwise return void
+ * @throws {TypedError} Parameter check failed
+ */
+declare function mkdtemp(prefix: string): Promise;
+declare function mkdtemp(prefix: string, callback: AsyncCallback): void;
+/**
+ * mkdtempSync.
+ *
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 7
+ * @permission N/A
+ * @function mkdtempSync
+ * @param {string} prefix - dir prefix.
+ * @returns {string} directory name
+ * @throws {TypedError | Error} mkdtemp fail
+ */
+declare function mkdtempSync(prefix: string): string;
+/**
+ * open.
+ *
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 7
+ * @permission N/A
+ * @function open
+ * @param {string} path - path.
+ * @param {number} [flags = 0] - flags.
+ * @param {number} [mode = 0o666] - mode.
+ * @param {AsyncCallback} [callback] - callback.
+ * @returns {void | Promise} no callback return Promise otherwise return void
+ * @throws {TypedError} Parameter check failed
+ */
+declare function open(path: string, flags?: number, mode?: number): Promise;
+declare function open(path: string, callback: AsyncCallback): void;
+declare function open(path: string, flags: number, callback: AsyncCallback): void;
+declare function open(path: string, flags: number, mode: number, callback: AsyncCallback): void;
+/**
+ * openSync.
+ *
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 6
+ * @permission N/A
+ * @function openSync
+ * @param {string} path - path.
+ * @param {number} [flags = 0] - flags.
+ * @param {number} [mode = 0o666] - mode.
+ * @returns {number} open fd
+ * @throws {TypedError | Error} open fail
+ */
+declare function openSync(path: string, flags?: number, mode?: number): number;
+/**
+ * opendir.
+ *
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 6
+ * @permission N/A
+ * @function opendir
+ * @param {string} path - directory name.
+ * @param {AsyncCallback} [callback] - callback.
+ * @returns {void | Promise} no callback return Promise otherwise return void
+ * @throws {TypedError} Parameter check failed
+ */
+declare function opendir(path: string): Promise;
+declare function opendir(path: string, callback: AsyncCallback): void;
+/**
+ * opendirSync.
+ *
+ * @param {string} path - directory name.
+ * @returns {Dir} opendir Dir Object
+ * @throws {TypedError | Error} opendir fail
+ */
+declare function opendirSync(path: string): Dir;
+/**
+ * readText.
+ *
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 7
+ * @permission N/A
+ * @function readText
+ * @param {string} filePath - file path.
+ * @param {Object} [options] - options.
+ * @param {number} [options.offset = 0] - offset in bytes.
+ * @param {number} [options.length = -1] - length in bytes.
+ * @param {number} [options.encoding = 'utf-8'] - encoding.
+ * @param {AsyncCallback} [callback] - callback.
+ * @returns {void | Promise} no callback return Promise otherwise return void
+ * @throws {TypedError} Parameter check failed
+ */
+declare function readText(filePath: string, options?: {
+ position?: number;
+ length?: number;
+ encoding?: string;
+}): Promise;
+declare function readText(filePath: string, options: {
+ position?: number;
+ length?: number;
+ encoding?: string;
+}, callback: AsyncCallback): void;
+
+/**
+ * readTextSync.
+ *
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 7
+ * @permission N/A
+ * @function readTextSync
+ * @param {string} filePath - file path.
+ * @param {Object} [options] - options.
+ * @param {number} [options.offset = 0] - offset in bytes.
+ * @param {number} [options.length = -1] - length in bytes.
+ * @param {number} [options.encoding = 'utf-8'] - encoding.
+ * @returns {string} readout result
+ * @throws {TypedError} Parameter check failed
+ */
+declare function readTextSync(filePath: string, options?: {
+ position?: number;
+ length?: number;
+ encoding?: string;
+}): string;
+
+/**
+ * read.
+ *
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 6
+ * @permission N/A
+ * @function read
+ * @param {number} fd - file descriptor.
+ * @param {ArrayBuffer} buffer - file descriptor.
+ * @param {Object} [options] - options.
+ * @param {number} [options.offset = 0] - offset.
+ * @param {number} [options.length = -1] - length.
+ * @param {number} [options.position = -1] - position.
+ * @param {AsyncCallback} [callback] - callback.
+ * @returns {void | Promise} no callback return Promise otherwise return void
+ * @throws {TypedError} Parameter check failed
+ */
+declare function read(fd: number, buffer: ArrayBuffer, options?: {
+ offset?: number;
+ length?: number;
+ position?: number;
+}): Promise
+declare function read(fd: number, buffer: ArrayBuffer, callback: AsyncCallback): void;
+declare function read(fd: number, buffer: ArrayBuffer, options: {
+ offset?: number;
+ length?: number;
+ position?: number;
+}, callback: AsyncCallback): void;
+/**
+ * readSync.
+ *
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 6
+ * @permission N/A
+ * @function readSync
+ * @param {number} fd - file descriptor.
+ * @param {ArrayBuffer} buffer - file descriptor.
+ * @param {Object} [options] - options.
+ * @param {number} [options.offset = 0] - offset.
+ * @param {number} [options.length = -1] - length.
+ * @param {number} [options.position = -1] - position.
+ * @returns {number} number of bytesRead
+ * @throws {TypedError | Error} read fail
+ */
+declare function readSync(fd: number, buffer: ArrayBuffer, options?: {
+ offset?: number;
+ length?: number;
+ position?: number;
+}): number;
+/**
+ * rename.
+ *
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 7
+ * @permission N/A
+ * @function rename
+ * @param {string} oldPath - oldPath.
+ * @param {string} newPath - newPath.
+ * @param {AsyncCallback} [callback] - callback.
+ * @returns {void | Promise} no callback return Promise otherwise return void
+ * @throws {TypedError} Parameter check failed
+ */
+declare function rename(oldPath: string, newPath: string): Promise;
+declare function rename(oldPath: string, newPath: string, callback: AsyncCallback): void;
+/**
+ * renameSync.
+ *
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 7
+ * @permission N/A
+ * @function renameSync
+ * @param {string} oldPath - oldPath.
+ * @param {string} newPath - newPath.
+ * @returns {void} rename success
+ * @throws {TypedError | Error} rename fail
+ */
+declare function renameSync(oldPath: string, newPath: string): void;
+/**
+ * rmdir.
+ *
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 7
+ * @permission N/A
+ * @function rmdir
+ * @param {string} path - path.
+ * @param {AsyncCallback} [callback] - callback.
+ * @returns {void | Promise} no callback return Promise otherwise return void
+ * @throws {TypedError} Parameter check failed
+ */
+declare function rmdir(path: string): Promise;
+declare function rmdir(path: string, callback: AsyncCallback): void;
+/**
+ * rmdirSync.
+ *
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 7
+ * @permission N/A
+ * @function rmdirSync
+ * @param {string} path - path.
+ * @returns {void} rmdir success
+ * @throws {TypedError | Error} rmdir fail
+ */
+declare function rmdirSync(path: string): void;
+/**
+ * stat.
+ * @static
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 6
+ * @permission N/A
+ * @param {string} path - path.
+ * @param {AsyncCallback} [callback] - callback.
+ * @returns {void | Promise} no callback return Promise otherwise return void
+ * @throws {TypedError} Parameter check failed
+ */
+declare function stat(path: string): Promise;
+declare function stat(path: string, callback: AsyncCallback): void;
+/**
+ * statSync.
+ * @static
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 6
+ * @permission N/A
+ * @param {string} path - path.
+ * @returns {Stat} stat success
+ * @throws {TypedError | Error} stat fail
+ */
+declare function statSync(path: string): Stat;
+/**
+ * symlink.
+ *
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 7
+ * @permission N/A
+ * @function symlink
+ * @param {string} target - target.
+ * @param {string} srcPath - srcPath.
+ * @param {AsyncCallback} [callback] - callback.
+ * @returns {void | Promise} no callback return Promise otherwise return void
+ * @throws {TypedError} Parameter check failed
+ */
+declare function symlink(target: string, srcPath: string): Promise;
+declare function symlink(target: string, srcPath: string, callback: AsyncCallback): void;
+/**
+ * symlinkSync.
+ *
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 7
+ * @permission N/A
+ * @function symlinkSync
+ * @param {string} target - target.
+ * @param {string} srcPath - srcPath.
+ * @returns {void} symlink success
+ * @throws {TypedError | Error} symlink fail
+ */
+ declare function symlinkSync(target: string, srcPath: string): void;
+ /**
+ * truncate.
+ *
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 7
+ * @permission N/A
+ * @function truncate
+ * @param {string} path - path.
+ * @param {number} [len = 0] - len.
+ * @param {AsyncCallback} [callback] - callback.
+ * @returns {void | Promise} no callback return Promise otherwise return void
+ * @throws {TypedError} Parameter check failed
+ */
+declare function truncate(path: string, len?: number): Promise;
+declare function truncate(path: string, callback: AsyncCallback): void;
+declare function truncate(path: string, len: number, callback: AsyncCallback): void;
+/**
+ * truncateSync.
+ *
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 7
+ * @permission N/A
+ * @function truncateSync
+ * @param {string} path - path.
+ * @param {number} [len = 0] - len.
+ * @returns {void} truncate success
+ * @throws {TypedError | Error} truncate fail
+ */
+declare function truncateSync(path: string, len?: number): void;
+/**
+ * unlink.
+ *
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 6
+ * @permission N/A
+ * @function unlink
+ * @param {string} path - path.
+ * @param {AsyncCallback} [callback] - callback.
+ * @returns {void | Promise} no callback return Promise otherwise return void
+ * @throws {TypedError} Parameter check failed
+ */
+declare function unlink(path: string): Promise;
+declare function unlink(path: string, callback: AsyncCallback): void;
+/**
+ * unlinkSync.
+ *
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 6
+ * @permission N/A
+ * @function unlinkSync
+ * @param {string} path - path.
+ * @returns {void} unlink success
+ * @throws {TypedError | Error} unlink fail
+ */
+declare function unlinkSync(path: string): void;
+/**
+ * write.
+ *
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 6
+ * @permission N/A
+ * @function write
+ * @param {number} fd - file descriptor.
+ * @param {ArrayBuffer | string} buffer - file descriptor.
+ * @param {Object} [options] - options.
+ * @param {number} [options.offset = 0] - offset(bytes) ignored when buffer is string.
+ * @param {number} [options.length = -1] - length(bytes) ignored when buffer is string.
+ * @param {number} [options.position = -1] - position(bytes) where start to write < 0 use read, else use pread.
+ * @param {string} [options.encoding = 'utf-8'] - encoding.
+ * @param {AsyncCallback} [callback] - callback.
+ * @returns {void | Promise} no callback return Promise otherwise return void
+ * @throws {TypedError | RangeError} Parameter check failed
+ */
+declare function write(fd: number, buffer: ArrayBuffer | string, options?: {
+ offset?: number;
+ length?: number;
+ position?: number;
+ encoding?: string;
+}): Promise;
+declare function write(fd: number, buffer: ArrayBuffer | string, callback: AsyncCallback): void;
+declare function write(fd: number, buffer: ArrayBuffer | string, options: {
+ offset?: number;
+ length?: number;
+ position?: number;
+ encoding?: string;
+}, callback: AsyncCallback): void;
+/**
+ * writeSync.
+ *
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 6
+ * @permission N/A
+ * @function writeSync
+ * @param {number} fd - file descriptor.
+ * @param {ArrayBuffer | string} buffer - file descriptor.
+ * @param {Object} [options] - options.
+ * @param {number} [options.offset = 0] - offset(bytes) ignored when buffer is string.
+ * @param {number} [options.length = -1] - length(bytes) ignored when buffer is string.
+ * @param {number} [options.position = -1] - position(bytes) where start to write < 0 use read, else use pread.
+ * @param {string} [options.encoding = 'utf-8'] - encoding.
+ * @returns {number} on success number of bytesRead
+ * @throws {TypedError | RangeError | Error} write fail
+ */
+declare function writeSync(fd: number, buffer: ArrayBuffer | string, options?: {
+ offset?: number;
+ length?: number;
+ position?: number;
+ encoding?: string;
+}): number;
+
+/**
+ * createWatcher.
+ *
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 7
+ * @permission N/A
+ * @function createWatcher
+ * @param {string} filename - filename.
+ * @param {number} events - events(depends on OS & filesystem) events = 1 rename events =2 change.
+ * @param {AsyncCallback} [callback] - callback.
+ * @returns {Watcher} watch success
+ * @throws {TypedError | Error} watch fail
+ */
+declare function createWatcher(filename: string, events: number, callback: AsyncCallback): Watcher;
+/**
+ * Dir
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 6
+ * @permission N/A
+ */
+declare interface Dir {
+ /**
+ * read.
+ *
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 6
+ * @permission N/A
+ * @function read
+ * @param {AsyncCallback} [callback] - callback.
+ * @returns {void | Promise} no callback return Promise otherwise return void
+ * @throws {TypedError} Parameter check failed if read to end, Error.msg = "NoMore"
+ */
+ read(): Promise;
+ read(callback: AsyncCallback): void;
+ /**
+ * readSync.
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 6
+ * @permission N/A
+ * @function readSync
+ * @returns {Dirent} Dirent Object
+ * @throws {TypedError | Error} read fail if read to end, Error.msg = "NoMore"
+ */
+ readSync(): Dirent;
+ /**
+ * close.
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 7
+ * @permission N/A
+ * @function close
+ * @param {AsyncCallback} [callback] - callback.
+ * @returns {void | Promise} close success
+ * @throws {TypedError | Error} close fail
+ */
+ close(): Promise;
+ close(callback: AsyncCallback): void;
+ /**
+ * closeSync.
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 6
+ * @permission N/A
+ * @function closeSync
+ * @returns {void} close success
+ * @throws {TypedError | Error} close fail
+ */
+ closeSync(): void;
+}
+
+/**
+ * Dirent
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 6
+ * @permission N/A
+ */
+declare interface Dirent {
+ /**
+ * @type {string}
+ * @readonly
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 6
+ * @permission N/A
+ */
+ readonly name: string;
+ /**
+ * isBlockDevice.
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 6
+ * @permission N/A
+ * @returns {boolean} is or not
+ */
+ isBlockDevice(): boolean;
+ /**
+ * isCharacterDevice.
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 6
+ * @permission N/A
+ * @returns {boolean} is or not
+ */
+ isCharacterDevice(): boolean;
+ /**
+ * isDirectory.
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 6
+ * @permission N/A
+ * @returns {boolean} is or not
+ */
+ isDirectory(): boolean;
+ /**
+ * isFIFO.
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 6
+ * @permission N/A
+ * @returns {boolean} is or not
+ */
+ isFIFO(): boolean;
+ /**
+ * isFile.
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 6
+ * @permission N/A
+ * @returns {boolean} is or not
+ */
+ isFile(): boolean;
+ /**
+ * isSocket.
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 6
+ * @permission N/A
+ * @returns {boolean} is or not
+ */
+ isSocket(): boolean;
+ /**
+ * isSymbolicLink.
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 6
+ * @permission N/A
+ * @returns {boolean} is or not
+ */
+ isSymbolicLink(): boolean;
+}
+
+/**
+ * Stat
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 6
+ * @permission N/A
+ */
+declare interface Stat {
+ /**
+ * @type {number}
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 6
+ * @permission N/A
+ * @readonly
+ */
+ readonly dev: number;
+ /**
+ * @type {number}
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 6
+ * @permission N/A
+ * @readonly
+ */
+ readonly ino: number;
+ /**
+ * @type {number}
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 6
+ * @permission N/A
+ * @readonly
+ */
+ readonly mode: number;
+ /**
+ * @type {number}
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 6
+ * @permission N/A
+ * @readonly
+ */
+ readonly nlink: number;
+ /**
+ * @type {number}
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 6
+ * @permission N/A
+ * @readonly
+ */
+ readonly uid: number;
+ /**
+ * @type {number}
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 6
+ * @permission N/A
+ * @readonly
+ */
+ readonly gid: number;
+ /**
+ * @type {number}
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 6
+ * @permission N/A
+ * @readonly
+ */
+ readonly rdev: number;
+ /**
+ * @type {number}
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 6
+ * @permission N/A
+ * @readonly
+ */
+ readonly size: number;
+ /**
+ * @type {number}
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 6
+ * @permission N/A
+ * @readonly
+ */
+ readonly blocks: number;
+ /**
+ * @type {number}
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 6
+ * @permission N/A
+ * @readonly
+ */
+ readonly atime: number;
+ /**
+ * @type {number}
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 6
+ * @permission N/A
+ * @readonly
+ */
+ readonly mtime: number;
+ /**
+ * @type {number}
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 6
+ * @permission N/A
+ * @readonly
+ */
+ readonly ctime: number;
+ /**
+ * isBlockDevice.
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 6
+ * @permission N/A
+ * @returns {boolean} is or not
+ */
+ isBlockDevice(): boolean;
+ /**
+ * isCharacterDevice.
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 6
+ * @permission N/A
+ * @returns {boolean} is or not
+ */
+ isCharacterDevice(): boolean;
+ /**
+ * isDirectory.
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 6
+ * @permission N/A
+ * @returns {boolean} is or not
+ */
+ isDirectory(): boolean;
+ /**
+ * isFIFO.
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 6
+ * @permission N/A
+ * @returns {boolean} is or not
+ */
+ isFIFO(): boolean;
+ /**
+ * isFile.
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 6
+ * @permission N/A
+ * @returns {boolean} is or not
+ */
+ isFile(): boolean;
+ /**
+ * isSocket.
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 6
+ * @permission N/A
+ * @returns {boolean} is or not
+ */
+ isSocket(): boolean;
+ /**
+ * isSymbolicLink.
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 6
+ * @permission N/A
+ * @returns {boolean} is or not
+ */
+ isSymbolicLink(): boolean;
+}
+
+/**
+ * Stream
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 6
+ * @permission N/A
+ */
+declare interface Stream {
+ /**
+ * close.
+ *
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 7
+ * @permission N/A
+ * @param {AsyncCallback} [callback] - callback.
+ * @returns {void | Promise} close success
+ * @throws {TypedError | Error} close fail
+ */
+ close(): Promise;
+ close(callback: AsyncCallback): void;
+ /**
+ * closeSync.
+ *
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 6
+ * @permission N/A
+ * @returns {void} close success
+ * @throws {TypedError | Error} close fail
+ */
+ closeSync(): void;
+ /**
+ * flush.
+ *
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 7
+ * @permission N/A
+ * @param {AsyncCallback} [callback] - callback.
+ * @returns {void | Promise} no callback return Promise otherwise return void
+ * @throws {TypedError} Parameter check failed
+ */
+ flush(): Promise;
+ flush(callback: AsyncCallback): void;
+ /**
+ * flushSync.
+ *
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 7
+ * @permission N/A
+ * @returns {void} flush success
+ * @throws {Error} flush fail
+ */
+ flushSync(): void;
+ /**
+ * write.
+ *
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 7
+ * @permission N/A
+ * @param {ArrayBuffer | string} buffer - file description.
+ * @param {Object} [options] - options.
+ * @param {number} [options.offset = 0] - offset(bytes) ignored when buffer is string.
+ * @param {number} [options.length = -1] - length(bytes) ignored when buffer is string.
+ * @param {number} [options.position = -1] - position(bytes) where start to write < 0 use read, else use pread.
+ * @param {string} [options.encoding = 'utf-8'] - encoding.
+ * @param {AsyncCallback} [callback] - callback.
+ * @returns {void | Promise} no callback return Promise otherwise return void
+ * @throws {TypedError} Parameter check failed
+ */
+ write(buffer: ArrayBuffer | string, options?: {
+ offset?: number;
+ length?: number;
+ position?: number;
+ encoding?: string;
+ }): Promise;
+ write(buffer: ArrayBuffer | string, callback: AsyncCallback): void;
+ write(buffer: ArrayBuffer | string, options: {
+ offset?: number;
+ length?: number;
+ position?: number;
+ encoding?: string;
+ }, callback: AsyncCallback): void;
+ /**
+ * writeSync.
+ *
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 7
+ * @permission N/A
+ * @param {ArrayBuffer | string} buffer - file description.
+ * @param {Object} [options] - options.
+ * @param {number} [options.offset = 0] - offset(bytes) ignored when buffer is string.
+ * @param {number} [options.length = -1] - length(bytes) ignored when buffer is string.
+ * @param {number} [options.position = -1] - position(bytes) where start to write < 0 use read, else use pread.
+ * @param {string} [options.encoding = 'utf-8'] - encoding.
+ * @returns {number} on success number of bytes written
+ * @throws {TypedError | Error} write fail
+ */
+ writeSync(buffer: ArrayBuffer | string, options?: {
+ offset?: number;
+ length?: number;
+ position?: number;
+ encoding?: string;
+ }): number;
+ /**
+ * read.
+ *
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 7
+ * @permission N/A
+ * @param {ArrayBuffer} buffer - file description.
+ * @param {Object} [options] - options.
+ * @param {number} [options.offset = 0] - offset.
+ * @param {number} [options.length = -1] - length.
+ * @param {AsyncCallback} [callback] - callback.
+ * @returns {void | Promise} no callback return Promise otherwise return void
+ * @throws {TypedError} Parameter check failed
+ */
+ read(buffer: ArrayBuffer, options?: {
+ position?: number;
+ offset?: number;
+ length?: number;
+ }): Promise;
+ read(buffer: ArrayBuffer, callback: AsyncCallback): void;
+ read(buffer: ArrayBuffer, options: {
+ position?: number;
+ offset?: number;
+ length?: number;
+ }, callback: AsyncCallback): void;
+ /**
+ * readSync.
+ *
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 7
+ * @permission N/A
+ * @param {ArrayBuffer} buffer - file description.
+ * @param {Object} [options] - options.
+ * @param {number} [options.offset = 0] - offset.
+ * @param {number} [options.length = -1] - length.
+ * @returns {number} number of bytesRead
+ * @throws {TypedError | Error} read fail
+ */
+ readSync(buffer: ArrayBuffer, options?: {
+ position?: number;
+ offset?: number;
+ length?: number;
+ }): number;
+}
+
+/**
+ * ReadOut
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 6
+ * @permission N/A
+ */
+declare interface ReadOut {
+ /**
+ * @type {number}
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 6
+ * @permission N/A
+ * @readonly
+ */
+ bytesRead: number;
+ /**
+ * @type {number}
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 6
+ * @permission N/A
+ * @readonly
+ */
+ offset: number;
+ /**
+ * @type {ArrayBuffer}
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 6
+ * @permission N/A
+ * @readonly
+ */
+ buffer: ArrayBuffer;
+}
+
+/**
+ * Watcher
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 7
+ * @permission N/A
+ */
+declare interface Watcher {
+ /**
+ * stop.
+ *
+ * @note N/A
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ * @since 7
+ * @permission N/A
+ * @param {AsyncCallback} [callback] - callback.
+ * @returns {void | Promise} stop success
+ * @throws {TypedError | Error} stop fail
+ */
+ stop(): Promise;
+ stop(callback: AsyncCallback): void;
+}
\ No newline at end of file
diff --git a/interfaces/kits/js/napi/@ohos.securityLabel.d.ts b/interfaces/kits/js/napi/@ohos.securityLabel.d.ts
new file mode 100644
index 0000000000000000000000000000000000000000..85c06ad2a019926fe6bfcace9f9e90392e079a11
--- /dev/null
+++ b/interfaces/kits/js/napi/@ohos.securityLabel.d.ts
@@ -0,0 +1,59 @@
+/*
+* 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 {AsyncCallback, Callback} from "./basic";
+
+/**
+ * Provides securityLabel APIs
+ *
+ * @since 9
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ */
+
+declare namespace securityLabel {
+
+ type dataLevel = 's0'|'s1'|'s2'|'s3'|'s4';
+ /**
+ * set the SecurityLabel.
+ *
+ * @since 9
+ */
+ function setSecurityLabel(path:string, type:dataLevel, callback: AsyncCallback): void;
+ function setSecurityLabel(path:string, type:dataLevel): Promise;
+
+ /**
+ * set the SecurityLabelSync.
+ *
+ * @since 9
+ */
+ function setSecurityLabelSync(path:string, type:dataLevel): void;
+
+ /**
+ * get the SecurityLabel.
+ *
+ * @since 9
+ */
+ function getSecurityLabel(path:string, callback: AsyncCallback): void;
+ function getSecurityLabel(path:string): Promise;
+
+ /**
+ * get the SecurityLabelSync.
+ *
+ * @since 9
+ */
+ function getSecurityLabelSync(path:string): string;
+}
+
+export default securityLabel;
\ No newline at end of file
diff --git a/interfaces/kits/js/@ohos.statfs.d.ts b/interfaces/kits/js/napi/@ohos.statfs.d.ts
similarity index 92%
rename from interfaces/kits/js/@ohos.statfs.d.ts
rename to interfaces/kits/js/napi/@ohos.statfs.d.ts
index 53a32c9eabdad6dccc590bab026a12559b86f90e..4a83f02b8e37d08348623e359707ad84a93daa99 100644
--- a/interfaces/kits/js/@ohos.statfs.d.ts
+++ b/interfaces/kits/js/napi/@ohos.statfs.d.ts
@@ -1,42 +1,41 @@
-/*
-* 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 {AsyncCallback, Callback} from "./basic";
-
-/**
- * Provides filesystem statistics APIs
- *
- * @since 8
- * @sysCap N/A
- * @devices phone, tablet
- */
-declare namespace Statfs {
- /**
- * Get the number of free bytes on the specified path.
- *
- * @since 8
- */
- function getFreeBytes(path: string, callback: AsyncCallback): void;
- function getFreeBytes(path: string): Promise;
- /**
- * Get the total number of bytes of the specified path.
- *
- * @since 8
- */
- function getTotalBytes(path: string, callback: AsyncCallback): void;
- function getTotalBytes(path: string): Promise;
-}
-
-export default Statfs;
+/*
+* 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 {AsyncCallback, Callback} from "./basic";
+
+/**
+ * Provides filesystem statistics APIs
+ *
+ * @since 8
+ * @syscap SystemCapability.FileManagement.File.FileIO
+ */
+declare namespace Statfs {
+ /**
+ * Get the number of free bytes on the specified path.
+ *
+ * @since 8
+ */
+ function getFreeBytes(path: string, callback: AsyncCallback): void;
+ function getFreeBytes(path: string): Promise;
+ /**
+ * Get the total number of bytes of the specified path.
+ *
+ * @since 8
+ */
+ function getTotalBytes(path: string, callback: AsyncCallback): void;
+ function getTotalBytes(path: string): Promise;
+}
+
+export default 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;
+}
diff --git a/interfaces/kits/js/src/common/ability_helper.cpp b/interfaces/kits/js/src/common/ability_helper.cpp
index c5aae1548bf0240a16147f25ad208ca7700a55fa..595bee685037846a54b02689bddf6258866b4675 100644
--- a/interfaces/kits/js/src/common/ability_helper.cpp
+++ b/interfaces/kits/js/src/common/ability_helper.cpp
@@ -29,7 +29,7 @@ Ability* AbilityHelper::GetJsAbility(napi_env env)
{
napi_value global = nullptr;
napi_value abilityContext = nullptr;
-
+
napi_status status = napi_get_global(env, &global);
if (status != napi_ok || global == nullptr) {
HILOGE("Cannot get global instance for %{public}d", status);
diff --git a/interfaces/kits/js/src/common/ability_helper.h b/interfaces/kits/js/src/common/ability_helper.h
index e998027c021b5d2d21cdbab1558a4718d100b888..d23285184d16bfebd9cb57a1eb65c5e2a370cec9 100644
--- a/interfaces/kits/js/src/common/ability_helper.h
+++ b/interfaces/kits/js/src/common/ability_helper.h
@@ -13,9 +13,9 @@
* limitations under the License.
*/
-#pragma once
+#ifndef INTERFACES_KITS_JS_SRC_COMMON_ABILITY_HELPER_H
+#define INTERFACES_KITS_JS_SRC_COMMON_ABILITY_HELPER_H
-#include "../common/napi/uni_header.h"
#include "ability.h"
namespace OHOS {
@@ -24,4 +24,5 @@ struct AbilityHelper {
static AppExecFwk::Ability *GetJsAbility(napi_env env);
};
} // namespace DistributedFS
-} // namespace OHOS
\ No newline at end of file
+} // namespace OHOS
+#endif // INTERFACES_KITS_JS_SRC_COMMON_ABILITY_HELPER_H
\ No newline at end of file
diff --git a/interfaces/kits/js/src/common/file_helper/fd_guard.cpp b/interfaces/kits/js/src/common/file_helper/fd_guard.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..6959b45a52f534f468561ff090199b2e3c5f8735
--- /dev/null
+++ b/interfaces/kits/js/src/common/file_helper/fd_guard.cpp
@@ -0,0 +1,75 @@
+/*
+ * 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.
+ */
+
+#include "fd_guard.h"
+
+#include
+
+#include "../log.h"
+
+namespace OHOS {
+namespace DistributedFS {
+FDGuard::FDGuard(int fd) : fd_(fd) {}
+
+FDGuard::FDGuard(int fd, bool autoClose) : fd_(fd), autoClose_(autoClose) {}
+
+FDGuard::FDGuard(FDGuard &&fdg) : fd_(fdg.fd_), autoClose_(fdg.autoClose_)
+{
+ fdg.fd_ = -1;
+}
+
+FDGuard &FDGuard::operator=(FDGuard &&fdg)
+{
+ if (this == &fdg) {
+ return *this;
+ }
+ this->fd_ = fdg.fd_;
+ this->autoClose_ = fdg.autoClose_;
+ fdg.fd_ = -1;
+ return *this;
+}
+
+FDGuard::~FDGuard()
+{
+ if (fd_ >= 0 && fd_ <= STDERR_FILENO) {
+ HILOGI("~FDGuard, fd_ = %{public}d", fd_);
+ }
+ if (fd_ >= 0 && autoClose_) {
+ close(fd_);
+ }
+}
+
+FDGuard::operator bool() const
+{
+ return fd_ >= 0;
+}
+
+int FDGuard::GetFD() const
+{
+ return fd_;
+}
+
+void FDGuard::SetFD(int fd, bool autoClose)
+{
+ fd_ = fd;
+ autoClose_ = autoClose;
+}
+
+void FDGuard::ClearFD()
+{
+ fd_ = -1;
+}
+} // namespace DistributedFS
+} // namespace OHOS
diff --git a/interfaces/kits/js/src/common/file_helper/fd_guard.h b/interfaces/kits/js/src/common/file_helper/fd_guard.h
new file mode 100644
index 0000000000000000000000000000000000000000..07c27b19d46a21d9e11eb999877be70306671699
--- /dev/null
+++ b/interfaces/kits/js/src/common/file_helper/fd_guard.h
@@ -0,0 +1,47 @@
+/*
+ * 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.
+ */
+
+#ifndef FD_GUARD_H
+#define FD_GUARD_H
+
+namespace OHOS {
+namespace DistributedFS {
+class FDGuard final {
+public:
+ FDGuard() = default;
+ explicit FDGuard(int fd);
+ FDGuard(int fd, bool autoClose);
+
+ FDGuard(const FDGuard &fdg) = delete;
+ FDGuard &operator=(const FDGuard &fdg) = delete;
+
+ FDGuard(FDGuard &&fdg);
+ FDGuard &operator=(FDGuard &&fdg);
+
+ operator bool() const;
+
+ ~FDGuard();
+
+ int GetFD() const;
+ void SetFD(int fd, bool autoClose = true);
+ void ClearFD();
+
+private:
+ int fd_ = -1;
+ bool autoClose_ = true;
+};
+} // namespace DistributedFS
+} // namespace OHOS
+#endif
\ No newline at end of file
diff --git a/interfaces/kits/js/src/common/file_helper/hash_file.cpp b/interfaces/kits/js/src/common/file_helper/hash_file.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..2bd54cc657cafbf6dbb1c3bb026eee2b118a118a
--- /dev/null
+++ b/interfaces/kits/js/src/common/file_helper/hash_file.cpp
@@ -0,0 +1,106 @@
+/*
+ * 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.
+ */
+
+#include "hash_file.h"
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+namespace OHOS {
+namespace DistributedFS {
+using namespace std;
+
+static tuple HashFinal(int err, const unique_ptr &hashBuf, size_t hashLen)
+{
+ if (err) {
+ return { err, "" };
+ }
+
+ stringstream ss;
+ for (size_t i = 0; i < hashLen; ++i) {
+ const int hexPerByte = 2;
+ ss << std::uppercase << std::setfill('0') << std::setw(hexPerByte) << std::hex <<
+ static_cast(hashBuf[i]);
+ }
+
+ return { err, ss.str() };
+}
+
+static int ForEachFileSegment(const string &fpath, function executor)
+{
+ unique_ptr filp = { fopen(fpath.c_str(), "r"), fclose };
+ if (!filp) {
+ return errno;
+ }
+
+ const size_t pageSize { getpagesize() };
+ auto buf = make_unique(pageSize);
+ size_t actLen;
+ do {
+ actLen = fread(buf.get(), 1, pageSize, filp.get());
+ if (actLen > 0) {
+ executor(buf.get(), actLen);
+ }
+ } while (actLen == pageSize);
+
+ return ferror(filp.get()) ? errno : 0;
+}
+
+tuple HashFile::HashWithMD5(const string &fpath)
+{
+ auto res = make_unique(MD5_DIGEST_LENGTH);
+ MD5_CTX ctx;
+ MD5_Init(&ctx);
+ auto md5Update = [ctx = &ctx](char *buf, size_t len) {
+ MD5_Update(ctx, buf, len);
+ };
+ int err = ForEachFileSegment(fpath, md5Update);
+ MD5_Final(res.get(), &ctx);
+ return HashFinal(err, res, MD5_DIGEST_LENGTH);
+}
+
+tuple HashFile::HashWithSHA1(const string &fpath)
+{
+ auto res = make_unique(SHA_DIGEST_LENGTH);
+ SHA_CTX ctx;
+ SHA1_Init(&ctx);
+ auto sha1Update = [ctx = &ctx](char *buf, size_t len) {
+ SHA1_Update(ctx, buf, len);
+ };
+ int err = ForEachFileSegment(fpath, sha1Update);
+ SHA1_Final(res.get(), &ctx);
+ return HashFinal(err, res, SHA_DIGEST_LENGTH);
+}
+
+tuple HashFile::HashWithSHA256(const string &fpath)
+{
+ auto res = make_unique(SHA256_DIGEST_LENGTH);
+ SHA256_CTX ctx;
+ SHA256_Init(&ctx);
+ auto sha256Update = [ctx = &ctx](char *buf, size_t len) {
+ SHA256_Update(ctx, buf, len);
+ };
+ int err = ForEachFileSegment(fpath, sha256Update);
+ SHA256_Final(res.get(), &ctx);
+ return HashFinal(err, res, SHA256_DIGEST_LENGTH);
+}
+} // namespace DistributedFS
+} // namespace OHOS
\ No newline at end of file
diff --git a/interfaces/innerkits/include/security_label.h b/interfaces/kits/js/src/common/file_helper/hash_file.h
similarity index 60%
rename from interfaces/innerkits/include/security_label.h
rename to interfaces/kits/js/src/common/file_helper/hash_file.h
index 3727c9a610d14be6d285f8c878717cf329efd016..81d68a2e4c3e1a3028c7569785706f97c9db02dc 100644
--- a/interfaces/innerkits/include/security_label.h
+++ b/interfaces/kits/js/src/common/file_helper/hash_file.h
@@ -13,25 +13,20 @@
* limitations under the License.
*/
-#ifndef FOUNDATION_FILEMANAGEMENT_FILEAPI_INTERFACES_INNERKITS_SECURITY_LABEL_H
-#define FOUNDATION_FILEMANAGEMENT_FILEAPI_INTERFACES_INNERKITS_SECURITY_LABEL_H
+#ifndef HASH_FILE_H
+#define HASH_FILE_H
#include
+#include
namespace OHOS {
-namespace FileIO {
-class SecurityLabel {
+namespace DistributedFS {
+class HashFile {
public:
- static bool SetSecurityLabel(std::string path, std::string dataLevel)
- {
- return true;
- }
- static std::string GetSecurityLabel(std::string path)
- {
- return "data.security.level";
- };
+ static std::tuple HashWithMD5(const std::string &fpath);
+ static std::tuple HashWithSHA1(const std::string &fpath);
+ static std::tuple HashWithSHA256(const std::string &fpath);
};
-} // namespace FileIO
+} // namespace DistributedFS
} // namespace OHOS
-
#endif
\ No newline at end of file
diff --git a/interfaces/kits/js/src/common/log.h b/interfaces/kits/js/src/common/log.h
index 32a09a751f6885a9ddca0cddfe3b31df3dc0ee21..48eb794a145f22d6c76a30a57268eb52b69023df 100644
--- a/interfaces/kits/js/src/common/log.h
+++ b/interfaces/kits/js/src/common/log.h
@@ -13,19 +13,20 @@
* limitations under the License.
*/
-#pragma once
+#ifndef INTERFACES_KITS_JS_SRC_COMMON_LOG_H
+#define INTERFACES_KITS_JS_SRC_COMMON_LOG_H
#include
#include
#include
-#ifndef FILE_SUBSYSTEM_DEV_ON_PC
+#ifndef FILE_SUBSYSTEM_DEBUG_LOCAL
#include "hilog/log.h"
#endif
namespace OHOS {
namespace DistributedFS {
-#ifndef FILE_SUBSYSTEM_DEV_ON_PC
+#ifndef FILE_SUBSYSTEM_DEBUG_LOCAL
static constexpr int FILEIO_DOMAIN_ID = 0;
static constexpr OHOS::HiviewDFX::HiLogLabel FILEIO_LABEL = { LOG_CORE, FILEIO_DOMAIN_ID, "distributedfilejs" };
@@ -77,7 +78,7 @@ static constexpr OHOS::HiviewDFX::HiLogLabel FILEIO_LABEL = { LOG_CORE, FILEIO_D
} \
str____ += "\n"; \
printf(str____.c_str(), ##__VA_ARGS__); \
- } while (0);
+ } while (0) \
#define HILOGD(fmt, ...) PCLOG("%{public}s: " fmt, __func__, ##__VA_ARGS__)
#define HILOGI(fmt, ...) PCLOG("%{public}s: " fmt, __func__, ##__VA_ARGS__)
@@ -87,4 +88,5 @@ static constexpr OHOS::HiviewDFX::HiLogLabel FILEIO_LABEL = { LOG_CORE, FILEIO_D
#endif
} // namespace DistributedFS
-} // namespace OHOS
\ No newline at end of file
+} // namespace OHOS
+#endif // INTERFACES_KITS_JS_SRC_COMMON_LOG_H
\ No newline at end of file
diff --git a/interfaces/kits/js/src/common/napi/n_async/n_async_context.h b/interfaces/kits/js/src/common/napi/n_async/n_async_context.h
index 7c45ce20a60e0377caef091ef15b9794b6b0ff7c..87339bbdddfdc837b658e60e7026f2bc10e6bdc7 100644
--- a/interfaces/kits/js/src/common/napi/n_async/n_async_context.h
+++ b/interfaces/kits/js/src/common/napi/n_async/n_async_context.h
@@ -16,8 +16,6 @@
#ifndef N_ASYNC_CONTEXT_H
#define N_ASYNC_CONTEXT_H
-#include
-
#include "../../uni_error.h"
#include "../n_val.h"
#include "n_ref.h"
@@ -43,7 +41,7 @@ public:
class NAsyncContextPromise : public NAsyncContext {
public:
- napi_deferred deferred_;
+ napi_deferred deferred_ = nullptr;
explicit NAsyncContextPromise(NVal thisPtr) : NAsyncContext(thisPtr) {}
~NAsyncContextPromise() = default;
};
diff --git a/interfaces/kits/js/src/common/napi/n_async/n_async_work_callback.cpp b/interfaces/kits/js/src/common/napi/n_async/n_async_work_callback.cpp
index 6b6d0b70a6fd54e7c9193d4867600aae41e70759..8c3af6149c68a3270987cb6e9c7c15710bcc1d2a 100644
--- a/interfaces/kits/js/src/common/napi/n_async/n_async_work_callback.cpp
+++ b/interfaces/kits/js/src/common/napi/n_async/n_async_work_callback.cpp
@@ -69,7 +69,7 @@ static void CallbackComplete(napi_env env, napi_status status, void *data)
NVal NAsyncWorkCallback::Schedule(string procedureName, NContextCBExec cbExec, NContextCBComplete cbComplete)
{
if (!ctx_->cb_ || !ctx_->cb_.Deref(env_).TypeIs(napi_function)) {
- UniError(EINVAL).ThrowErr(env_, "The callback shall be a funciton");
+ UniError(EINVAL).ThrowErr(env_, "The callback shall be a function");
return NVal();
}
@@ -91,7 +91,7 @@ NVal NAsyncWorkCallback::Schedule(string procedureName, NContextCBExec cbExec, N
return NVal();
}
- ctx_ = nullptr; // The ownership of ctx_ has been transfered
+ ctx_ = nullptr; // The ownership of ctx_ has been transferred
return NVal::CreateUndefined(env_);
}
} // namespace DistributedFS
diff --git a/interfaces/kits/js/src/common/napi/n_async/n_async_work_callback.h b/interfaces/kits/js/src/common/napi/n_async/n_async_work_callback.h
index 7b7f190c8f45636fdded6b81871ce5487bd30535..9bc6d5f3d7b7125e50fda9baedb4d70f2b397003 100644
--- a/interfaces/kits/js/src/common/napi/n_async/n_async_work_callback.h
+++ b/interfaces/kits/js/src/common/napi/n_async/n_async_work_callback.h
@@ -26,7 +26,7 @@ public:
~NAsyncWorkCallback() = default;
NVal Schedule(std::string procedureName, NContextCBExec cbExec, NContextCBComplete cbComplete) final;
- NAsyncWorkCallback(const NAsyncWorkCallback&) = delete;
+
private:
NAsyncContextCallback *ctx_ = nullptr;
};
diff --git a/interfaces/kits/js/src/common/napi/n_async/n_async_work_promise.cpp b/interfaces/kits/js/src/common/napi/n_async/n_async_work_promise.cpp
index 3809c1a4b0255236ceb8dadfb3d05c77b67366d9..f0ef6df4985a4e6b7b6618d3c917179c66625f7d 100644
--- a/interfaces/kits/js/src/common/napi/n_async/n_async_work_promise.cpp
+++ b/interfaces/kits/js/src/common/napi/n_async/n_async_work_promise.cpp
@@ -84,7 +84,7 @@ NVal NAsyncWorkPromise::Schedule(string procedureName, NContextCBExec cbExec, NC
return NVal();
}
- ctx_ = nullptr; // The ownership of ctx_ has been transfered
+ ctx_ = nullptr; // The ownership of ctx_ has been transferred
return { env_, result };
}
} // namespace DistributedFS
diff --git a/interfaces/kits/js/src/common/napi/n_async/n_async_work_promise.h b/interfaces/kits/js/src/common/napi/n_async/n_async_work_promise.h
index f2406913f1262b79307cf12091f494c2375e104e..8a049de65e913edaeb99a297acefacf6a1a6d4a0 100644
--- a/interfaces/kits/js/src/common/napi/n_async/n_async_work_promise.h
+++ b/interfaces/kits/js/src/common/napi/n_async/n_async_work_promise.h
@@ -26,7 +26,7 @@ public:
~NAsyncWorkPromise() = default;
NVal Schedule(std::string procedureName, NContextCBExec cbExec, NContextCBComplete cbComplete) final;
- NAsyncWorkPromise(const NAsyncWorkPromise&) = delete;
+
private:
NAsyncContextPromise *ctx_;
};
diff --git a/interfaces/kits/js/src/common/napi/n_class.cpp b/interfaces/kits/js/src/common/napi/n_class.cpp
index 0e9028b02e2bca7e956fe993da40425a34bbac84..dbda702d0e8dd2849d9ea5515138cd78b95e3faf 100644
--- a/interfaces/kits/js/src/common/napi/n_class.cpp
+++ b/interfaces/kits/js/src/common/napi/n_class.cpp
@@ -25,7 +25,7 @@ namespace DistributedFS {
using namespace std;
NClass &NClass::GetInstance()
{
- static NClass nClass;
+ static thread_local NClass nClass;
return nClass;
}
@@ -69,7 +69,7 @@ bool NClass::SaveClass(napi_env env, string className, napi_value exClass)
return res == napi_ok;
}
-napi_value NClass::InstantiateClass(napi_env env, string className, vector args)
+napi_value NClass::InstantiateClass(napi_env env, const string& className, const vector& args)
{
NClass &nClass = NClass::GetInstance();
lock_guard(nClass.exClassMapLock);
@@ -96,4 +96,4 @@ napi_value NClass::InstantiateClass(napi_env env, string className, vector
-#include
-#include
-#include
-#include
-#include
#include "../log.h"
@@ -39,7 +35,7 @@ public:
napi_callback constructor,
std::vector &&properties);
static bool SaveClass(napi_env env, std::string className, napi_value exClass);
- static napi_value InstantiateClass(napi_env env, std::string className, std::vector args);
+ static napi_value InstantiateClass(napi_env env, const std::string& className, const std::vector& args);
template static T *GetEntityOf(napi_env env, napi_value objStat)
{
@@ -79,4 +75,5 @@ private:
std::mutex exClassMapLock;
};
} // namespace DistributedFS
-} // namespace OHOS
\ No newline at end of file
+} // namespace OHOS
+#endif // INTERFACES_KITS_JS_SRC_COMMON_NAPI_N_CLASS_H
\ No newline at end of file
diff --git a/interfaces/kits/js/src/common/napi/n_exporter.h b/interfaces/kits/js/src/common/napi/n_exporter.h
index 2ade0c076d11ed9f64b8d578f9a11d34241210a8..11d2fd7c9c79b726521490a1dc3ea74f645b9fda 100644
--- a/interfaces/kits/js/src/common/napi/n_exporter.h
+++ b/interfaces/kits/js/src/common/napi/n_exporter.h
@@ -13,12 +13,8 @@
* limitations under the License.
*/
-#pragma once
-
-#include "uni_header.h"
-
-#include
-#include
+#ifndef INTERFACES_KITS_JS_SRC_COMMON_NAPI_N_EXPORTER_H
+#define INTERFACES_KITS_JS_SRC_COMMON_NAPI_N_EXPORTER_H
#include "n_val.h"
@@ -36,4 +32,5 @@ protected:
NVal exports_;
};
} // namespace DistributedFS
-} // namespace OHOS
\ No newline at end of file
+} // namespace OHOS
+#endif // INTERFACES_KITS_JS_SRC_COMMON_NAPI_N_EXPORTER_H
\ No newline at end of file
diff --git a/interfaces/kits/js/src/common/napi/n_func_arg.cpp b/interfaces/kits/js/src/common/napi/n_func_arg.cpp
index 123ef8d0ab67ee1bcbe2e3149f2eab6935c9d45e..1a3d6d8dd0058ac6f9590d40a638f823002aa14d 100644
--- a/interfaces/kits/js/src/common/napi/n_func_arg.cpp
+++ b/interfaces/kits/js/src/common/napi/n_func_arg.cpp
@@ -15,11 +15,7 @@
#include "n_func_arg.h"
-#include
-#include
-
#include "../log.h"
-#include "../uni_error.h"
namespace OHOS {
namespace DistributedFS {
@@ -33,6 +29,7 @@ void NFuncArg::SetArgc(size_t argc)
{
argc_ = argc;
}
+
void NFuncArg::SetThisVar(napi_value thisVar)
{
thisVar_ = thisVar;
diff --git a/interfaces/kits/js/src/common/napi/n_func_arg.h b/interfaces/kits/js/src/common/napi/n_func_arg.h
index 7ff5b29425721764591f7d706909fed35e117963..1192094e289a87fc180df49c713516d3661ac0f5 100644
--- a/interfaces/kits/js/src/common/napi/n_func_arg.h
+++ b/interfaces/kits/js/src/common/napi/n_func_arg.h
@@ -13,14 +13,9 @@
* limitations under the License.
*/
-#pragma once
+#ifndef INTERFACES_KITS_JS_SRC_COMMON_NAPI_N_FUNC_ARG_H
+#define INTERFACES_KITS_JS_SRC_COMMON_NAPI_N_FUNC_ARG_H
-#include
-#include