From 193ce95b3281a4aa6a8c9cec95d59f7af51b10e4 Mon Sep 17 00:00:00 2001 From: Annie_wang Date: Thu, 9 Mar 2023 16:12:44 +0800 Subject: [PATCH] update docs Signed-off-by: Annie_wang --- .../reference/apis/js-apis-data-dataShare.md | 22 +- .../apis/js-apis-data-preferences.md | 15 +- .../reference/apis/js-apis-data-storage.md | 24 +- .../apis/js-apis-file-environment.md | 6 +- .../reference/apis/js-apis-file-fs.md | 752 ++++++++++-------- .../apis/js-apis-file-securityLabel.md | 14 +- .../reference/apis/js-apis-huks.md | 23 +- 7 files changed, 481 insertions(+), 375 deletions(-) diff --git a/en/application-dev/reference/apis/js-apis-data-dataShare.md b/en/application-dev/reference/apis/js-apis-data-dataShare.md index 82a333b14b..b79161a08e 100644 --- a/en/application-dev/reference/apis/js-apis-data-dataShare.md +++ b/en/application-dev/reference/apis/js-apis-data-dataShare.md @@ -1,14 +1,15 @@ -# @ohos.data.dataShare (DataShare) +# @ohos.data.dataShare (Data Sharing) The **DataShare** module allows an application to manage its own data and share data with other applications on the same device. > **NOTE** > -> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. +> - The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. > -> The APIs provided by this module are system APIs. > -> The APIs of this module can be used only in the stage model. +> - The APIs provided by this module are system APIs. +> +> - The APIs of this module can be used only in the stage model. ## Modules to Import @@ -55,7 +56,7 @@ Observe the following when using this API: | Name | Type | Mandatory| Description | | -------- | -------------------------------------------------------- | ---- | ------------------------------------------------------------ | -| context | [Context](js-apis-application-context.md#context) | Yes | Context of an application. | +| context | [Context](js-apis-inner-application-context.md#context) | Yes | Context of an application. | | uri | string | Yes | Uniform Resource Identifier (URI) of the server application to connect. | | callback | AsyncCallback<[DataShareHelper](#datasharehelper)> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **undefined** and **data** is the **DataShareHelper** instance created. Otherwise, **err** is an error object.| @@ -105,7 +106,7 @@ Observe the following when using this API: | Name | Type | Mandatory| Description | | ------- | ------------------------------------------------- | ---- | ------------------------------ | -| context | [Context](js-apis-application-context.md#context) | Yes | Context of an application. | +| context | [Context](js-apis-inner-application-context.md#context) | Yes | Context of an application. | | uri | string | Yes | URI of the server application to connect.| **Return value** @@ -187,18 +188,19 @@ Unsubscribes from the changes of the specified data. This API uses an asynchrono | -------- | -------------------- | ---- | ------------------------ | | type | string | Yes | Event type to unsubscribe from. The value is **dataChange**, which indicates data change events.| | uri | string | Yes | URI of the data.| -| callback | AsyncCallback<void> | No | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.| +| callback | AsyncCallback<void> | No | Callback for the data change event. If this parameter is left empty, all notification events of the URI are unsubscribed from.| **Example** ```ts import UIAbility from '@ohos.app.ability.UIAbility'; -function offCallback() { - console.info("**** Observer off callback ****"); +function callback() { + console.info("**** Observer callback ****"); } let uri = ("datashare:///com.samples.datasharetest.DataShare"); -dataShareHelper.off("dataChange", uri, offCallback); +dataShareHelper.on("dataChange", uri, callback); +dataShareHelper.off("dataChange", uri, callback); ``` ### insert diff --git a/en/application-dev/reference/apis/js-apis-data-preferences.md b/en/application-dev/reference/apis/js-apis-data-preferences.md index b14256c20d..99e43bc6a0 100644 --- a/en/application-dev/reference/apis/js-apis-data-preferences.md +++ b/en/application-dev/reference/apis/js-apis-data-preferences.md @@ -5,7 +5,7 @@ The **Preferences** module provides APIs for processing data in the form of key- The key is of the string type, and the value can be a number, a string, a Boolean value, or an array of numbers, strings, or Boolean values. -> **NOTE**
+> **NOTE** > > The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. @@ -22,8 +22,8 @@ import data_preferences from '@ohos.data.preferences'; | Name | Type| Readable| Writable| Description | | ---------------- | -------- | ---- | ---- | --------------------------------------- | -| MAX_KEY_LENGTH | number | Yes | No | Maximum length of a key. The maximum key length is 80 bytes. | -| MAX_VALUE_LENGTH | number | Yes | No | Maximum length of a value. The maximum value length is 8192 bytes.| +| MAX_KEY_LENGTH | number | Yes | No | Maximum length of a key, which is 80 bytes. | +| MAX_VALUE_LENGTH | number | Yes | No | Maximum length of a value, which is 8192 bytes.| ## data_preferences.getPreferences @@ -38,8 +38,8 @@ Obtains a **Preferences** instance. This API uses an asynchronous callback to re | Name | Type | Mandatory| Description | | -------- | ------------------------------------------------ | ---- | ------------------------------------------------------------ | -| context | Context | Yes | Application context.
For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).
For details about the application context of the stage model, see [Context](js-apis-inner-application-uiAbilityContext.md). | -| name | string | Yes | Name of the **Preferences** instance.| +| context | Context | Yes | Application context.
For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).
For details about the application context of the stage model, see [Context](js-apis-inner-application-uiAbilityContext.md). | +| name | string | Yes | Name of the **Preferences** instance. | | callback | AsyncCallback<[Preferences](#preferences)> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **undefined** and **object** is the **Preferences** instance obtained. Otherwise, **err** is an error code.| **Example** @@ -213,7 +213,6 @@ Stage model: ```ts import UIAbility from '@ohos.app.ability.UIAbility'; - class EntryAbility extends UIAbility { onWindowStageCreate(windowStage) { try { @@ -289,7 +288,6 @@ Stage model: ```ts import UIAbility from '@ohos.app.ability.UIAbility'; - class EntryAbility extends UIAbility { onWindowStageCreate(windowStage) { try{ @@ -350,7 +348,6 @@ Stage model: ```ts import UIAbility from '@ohos.app.ability.UIAbility'; - class EntryAbility extends UIAbility { onWindowStageCreate(windowStage) { try { @@ -973,7 +970,7 @@ Unsubscribes from data changes. | Name | Type | Mandatory| Description | | -------- | -------------------------------- | ---- | ------------------------------------------ | | type | string | Yes | Event type to unsubscribe from. The value **change** indicates data change events. | -| callback | Callback<{ key : string }> | No | Callback to unregister. If this parameter is left blank, the callbacks used to subscribing to all data changes will be unregistered.| +| callback | Callback<{ key : string }> | No | Callback to unregister. If this parameter is left blank, the callbacks for all data changes will be unregistered.| **Example** diff --git a/en/application-dev/reference/apis/js-apis-data-storage.md b/en/application-dev/reference/apis/js-apis-data-storage.md index 75e9293ead..dbb9244fbe 100644 --- a/en/application-dev/reference/apis/js-apis-data-storage.md +++ b/en/application-dev/reference/apis/js-apis-data-storage.md @@ -7,8 +7,8 @@ The **DataStorage** module provides applications with data processing capability > > - The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version. > -> - The APIs of this module are no longer maintained since API version 9. You are advised to use [`@ohos.data.preferences`](js-apis-data-preferences.md). -> +> - The APIs of this module are no longer maintained since API version 9. You are advised to use [@ohos.data.preferences](js-apis-data-preferences.md). +> > - The APIs of this module can be used only in the FA model. @@ -24,8 +24,8 @@ import data_storage from '@ohos.data.storage'; | Name | Type| Readable| Writable| Description | | ---------------- | -------- | ---- | ---- | ------------------------------------- | -| MAX_KEY_LENGTH | number | Yes | No | Maximum length of a key. It must be less than 80 bytes. | -| MAX_VALUE_LENGTH | number | Yes | No | Maximum length of a value. It must be less than 8192 bytes.| +| MAX_KEY_LENGTH | number | Yes | No | Maximum length of a key, which is 80 bytes. | +| MAX_VALUE_LENGTH | number | Yes | No | Maximum length of a value, which is 8192 bytes.| ## data_storage.getStorageSync @@ -79,7 +79,7 @@ Reads the specified file and loads its data to the **Storage** instance for data | Name | Type | Mandatory| Description | | -------- | ---------------------------------------- | ---- | -------------------------- | | path | string | Yes | Path of the target file.| -| callback | AsyncCallback<[Storage](#storage)> | Yes | Callback used to return the execution result. | +| callback | AsyncCallback<[Storage](#storage)> | Yes | Callback invoked to return the result. | **Example** @@ -172,7 +172,7 @@ context.getFilesDir().then((filePath) => { console.info("======================>getFilesDirPromise====================>"); data_storage.deleteStorageSync(path + '/mystore'); -}); +}); ``` ## data_storage.deleteStorage @@ -276,9 +276,9 @@ let context = featureAbility.getContext(); context.getFilesDir().then((filePath) => { path = filePath; console.info("======================>getFilesDirPromise====================>"); - + data_storage.removeStorageFromCacheSync(path + '/mystore'); -}); +}); ``` @@ -406,7 +406,7 @@ Obtains the value corresponding to a key. If the value is null or not of the def | -------- | ------------------------------ | ---- | ----------------------------------------- | | key | string | Yes | Key of the data. It cannot be empty. | | defValue | [ValueType](#valuetype) | Yes | Default value to be returned. It can be a number, string, or Boolean value.| -| callback | AsyncCallback<ValueType> | Yes | Callback used to return the execution result. | +| callback | AsyncCallback<ValueType> | Yes | Callback invoked to return the result. | **Example** @@ -581,7 +581,7 @@ Checks whether the storage object contains data with a given key. This API uses | Name | Type | Mandatory| Description | | -------- | ---------------------------- | ---- | ------------------------------- | | key | string | Yes | Key of the data. It cannot be empty.| -| callback | AsyncCallback<boolean> | Yes | Callback used to return the execution result. | +| callback | AsyncCallback<boolean> | Yes | Callback invoked to return the result. | **Return value** @@ -867,7 +867,7 @@ Subscribes to data changes. The **StorageObserver** needs to be implemented. Whe | Name | Type | Mandatory| Description | | -------- | --------------------------------------------------- | ------ |---------------------------------------- | | type | string |Yes| Event type. The value **change** indicates data change events.| -| callback | Callback<[StorageObserver](#storageobserver)> | Yes|Callback used to return data changes. | +| callback | Callback<[StorageObserver](#storageobserver)> | Yes|Callback invoked to return the data change. | **Example** @@ -894,7 +894,7 @@ Unsubscribes from data changes. | Name | Type | Mandatory| Description | | -------- | --------------------------------------------------- | ------ |---------------------------------------- | | type | string |Yes| Event type. The value **change** indicates data change events.| -| callback | Callback<[StorageObserver](#storageobserver)> | Yes|Callback used to return data changes. | +| callback | Callback<[StorageObserver](#storageobserver)> | Yes|Callback for the data change. | **Example** diff --git a/en/application-dev/reference/apis/js-apis-file-environment.md b/en/application-dev/reference/apis/js-apis-file-environment.md index 9c340eef39..c87c8465d7 100644 --- a/en/application-dev/reference/apis/js-apis-file-environment.md +++ b/en/application-dev/reference/apis/js-apis-file-environment.md @@ -4,7 +4,7 @@ The **Environment** module provides APIs for obtaining the root directories of t > **NOTE** > -> - The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. +> - The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. > - The APIs of this module are system APIs and cannot be called by third-party applications. > - The APIs of this module support processing of error codes. For details, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). @@ -26,7 +26,7 @@ Obtains the root directory of the storage. This API uses a promise to return the | Type | Description | | --------------------- | ---------------- | -| Promise<string> | Promise returned with the root directory of the storage.| +| Promise<string> | Promise used to return the root directory of the storage.| **Example** @@ -50,7 +50,7 @@ Obtains the root directory of the storage. This API uses an asynchronous callbac | Name | Type | Mandatory| Description | | -------- | --------------------------- | ---- | -------------------------------- | -| callback | AsyncCallback<string> | Yes | Asynchronous callback used to return the root directory of the storage.| +| callback | AsyncCallback<string> | Yes | Asynchronous callback invoked to return the root directory of the storage.| **Example** diff --git a/en/application-dev/reference/apis/js-apis-file-fs.md b/en/application-dev/reference/apis/js-apis-file-fs.md index 806f2178ad..306d752c6d 100644 --- a/en/application-dev/reference/apis/js-apis-file-fs.md +++ b/en/application-dev/reference/apis/js-apis-file-fs.md @@ -60,9 +60,9 @@ Obtains detailed file information. This API uses a promise to return the result. **Return value** - | Type | Description | - | ---------------------------- | ---------- | - | Promise<[Stat](#stat)> | Promise used to return the file information obtained.| +| Type | Description | +| ---------------------------- | ---------- | +| Promise<[Stat](#stat)> | Promise used to return the file information obtained.| **Example** @@ -119,9 +119,9 @@ Obtains detailed file information synchronously. **Return value** - | Type | Description | - | ------------- | ---------- | - | [Stat](#stat) | File information obtained.| +| Type | Description | +| ------------- | ---------- | +| [Stat](#stat) | File information obtained.| **Example** @@ -146,9 +146,9 @@ Checks whether a file exists. This API uses a promise to return the result. **Return value** - | Type | Description | - | ------------------- | ---------------------------- | - | Promise<boolean> | Promise used to return a Boolean value.| +| Type | Description | +| ------------------- | ---------------------------- | +| Promise<boolean> | Promise used to return a Boolean value.| **Example** @@ -233,15 +233,15 @@ Closes a file. This API uses a promise to return the result. **Parameters** - | Name | Type | Mandatory | Description | - | ---- | ------ | ---- | ------------ | - | file | [File](#file)\|number | Yes | File object or FD of the file to close.| +| Name | Type | Mandatory | Description | +| ---- | ------ | ---- | ------------ | +| file | [File](#file)\|number | Yes | File object or FD of the file to close.| **Return value** - | Type | Description | - | ------------------- | ---------------------------- | - | Promise<void> | Promise that returns no value.| +| Type | Description | +| ------------------- | ---------------------------- | +| Promise<void> | Promise that returns no value.| **Example** @@ -266,10 +266,10 @@ Closes a file. This API uses an asynchronous callback to return the result. **Parameters** - | Name | Type | Mandatory | Description | - | -------- | ------------------------- | ---- | ------------ | - | file | [File](#file)\|number | Yes | File object or FD of the file to close.| - | callback | AsyncCallback<void> | Yes | Callback invoked when the file is closed asynchronously.| +| Name | Type | Mandatory | Description | +| -------- | ------------------------- | ---- | ------------ | +| file | [File](#file)\|number | Yes | File object or FD of the file to close.| +| callback | AsyncCallback<void> | Yes | Callback invoked when the file is closed asynchronously.| **Example** @@ -295,9 +295,9 @@ Synchronously closes a file. **Parameters** - | Name | Type | Mandatory | Description | - | ---- | ------ | ---- | ------------ | - | file | [File](#file)\|number | Yes | File object or FD of the file to close.| +| Name | Type | Mandatory | Description | +| ---- | ------ | ---- | ------------ | +| file | [File](#file)\|number | Yes | File object or FD of the file to close.| **Example** @@ -317,17 +317,17 @@ Copies a file. This API uses a promise to return the result. **Parameters** - | Name | Type | Mandatory | Description | - | ---- | -------------------------- | ---- | ---------------------------------------- | - | src | string\|number | Yes | Path or FD of the file to copy. | - | dest | string\|number | Yes | Destination path of the file or FD of the file created. | - | mode | number | No | Whether to overwrite the file of the same name in the destination path. The default value is **0**, which is the only value supported.
**0**: overwrite the file of the same name.| +| Name | Type | Mandatory | Description | +| ---- | -------------------------- | ---- | ---------------------------------------- | +| src | string\|number | Yes | Path or FD of the file to copy. | +| dest | string\|number | Yes | Destination path of the file or FD of the file created. | +| mode | number | No | Whether to overwrite the file of the same name in the destination path. The default value is **0**, which is the only value supported.
**0**: overwrite the file of the same name.| **Return value** - | Type | Description | - | ------------------- | ---------------------------- | - | Promise<void> | Promise that returns no value.| +| Type | Description | +| ------------------- | ---------------------------- | +| Promise<void> | Promise that returns no value.| **Example** @@ -351,12 +351,12 @@ Copies a file. This API uses an asynchronous callback to return the result. **Parameters** - | Name | Type | Mandatory | Description | - | -------- | -------------------------- | ---- | ---------------------------------------- | - | src | string\|number | Yes | Path or FD of the file to copy. | - | dest | string\|number | Yes | Destination path of the file or FD of the file created. | - | mode | number | No | Whether to overwrite the file of the same name in the destination path. The default value is **0**, which is the only value supported.
**0**: overwrite the file with the same name and truncate the part that is not overwritten.| - | callback | AsyncCallback<void> | Yes | Callback invoked when the file is copied asynchronously. | +| Name | Type | Mandatory | Description | +| -------- | -------------------------- | ---- | ---------------------------------------- | +| src | string\|number | Yes | Path or FD of the file to copy. | +| dest | string\|number | Yes | Destination path of the file or FD of the file created. | +| mode | number | No | Whether to overwrite the file of the same name in the destination path. The default value is **0**, which is the only value supported.
**0**: overwrite the file with the same name and truncate the part that is not overwritten.| +| callback | AsyncCallback<void> | Yes | Callback invoked when the file is copied asynchronously. | **Example** @@ -383,11 +383,11 @@ Synchronously copies a file. **Parameters** - | Name | Type | Mandatory | Description | - | ---- | -------------------------- | ---- | ---------------------------------------- | - | src | string\|number | Yes | Path or FD of the file to copy. | - | dest | string\|number | Yes | Destination path of the file or FD of the file created. | - | mode | number | No | Whether to overwrite the file of the same name in the destination path. The default value is **0**, which is the only value supported.
**0**: overwrite the file with the same name and truncate the part that is not overwritten.| +| Name | Type | Mandatory | Description | +| ---- | -------------------------- | ---- | ---------------------------------------- | +| src | string\|number | Yes | Path or FD of the file to copy. | +| dest | string\|number | Yes | Destination path of the file or FD of the file created. | +| mode | number | No | Whether to overwrite the file of the same name in the destination path. The default value is **0**, which is the only value supported.
**0**: overwrite the file with the same name and truncate the part that is not overwritten.| **Example** @@ -414,9 +414,9 @@ Creates a directory. This API uses a promise to return the result. **Return value** - | Type | Description | - | ------------------- | ---------------------------- | - | Promise<void> | Promise that returns no value.| +| Type | Description | +| ------------------- | ---------------------------- | +| Promise<void> | Promise that returns no value.| **Example** @@ -498,9 +498,9 @@ Opens a file. This API uses a promise to return the result. File uniform resourc **Return value** - | Type | Description | - | --------------------- | ----------- | - | Promise<[File](#file)> | Promise used to return the file object.| +| Type | Description | +| --------------------- | ----------- | +| Promise<[File](#file)> | Promise used to return the file object.| **Example** @@ -559,9 +559,9 @@ Synchronously opens a file. File URIs are supported. **Return value** - | Type | Description | - | ------ | ----------- | - | [File](#file) | File object opened.| +| Type | Description | +| ------ | ----------- | +| [File](#file) | File object opened.| **Example** @@ -590,9 +590,9 @@ Reads data from a file. This API uses a promise to return the result. **Return value** - | Type | Description | - | ---------------------------------- | ------ | - | Promise<number> | Promise used to return the data read.| +| Type | Description | +| ---------------------------------- | ------ | +| Promise<number> | Promise used to return the data read.| **Example** @@ -619,12 +619,12 @@ Reads data from a file. This API uses an asynchronous callback to return the res **Parameters** - | Name | Type | Mandatory | Description | - | -------- | ---------------------------------------- | ---- | ---------------------------------------- | - | fd | number | Yes | FD of the file. | - | buffer | ArrayBuffer | Yes | Buffer used to store the file data read. | - | options | Object | No | The options are as follows:
- **offset** (number): position of the data to read in the file. This parameter is optional. By default, data is read from the current position.
- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length.| - | callback | AsyncCallback<number> | Yes | Callback invoked when the data is read asynchronously. | +| Name | Type | Mandatory | Description | +| -------- | ---------------------------------------- | ---- | ---------------------------------------- | +| fd | number | Yes | FD of the file. | +| buffer | ArrayBuffer | Yes | Buffer used to store the file data read. | +| options | Object | No | The options are as follows:
- **offset** (number): position of the data to read in the file. This parameter is optional. By default, data is read from the current position.
- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length.| +| callback | AsyncCallback<number> | Yes | Callback invoked when the data is read asynchronously. | **Example** @@ -654,17 +654,17 @@ Synchronously reads data from a file. **Parameters** - | Name | Type | Mandatory | Description | - | ------- | ----------- | ---- | ---------------------------------------- | - | fd | number | Yes | FD of the file. | - | buffer | ArrayBuffer | Yes | Buffer used to store the file data read. | - | options | Object | No | The options are as follows:
- **offset** (number): position of the data to read in the file. This parameter is optional. By default, data is read from the current position.
- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length.| +| Name | Type | Mandatory | Description | +| ------- | ----------- | ---- | ---------------------------------------- | +| fd | number | Yes | FD of the file. | +| buffer | ArrayBuffer | Yes | Buffer used to store the file data read. | +| options | Object | No | The options are as follows:
- **offset** (number): position of the data to read in the file. This parameter is optional. By default, data is read from the current position.
- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length.| **Return value** - | Type | Description | - | ------ | -------- | - | number | Length of the data read.| +| Type | Description | +| ------ | -------- | +| number | Length of the data read.| **Example** @@ -693,9 +693,9 @@ Deletes a directory. This API uses a promise to return the result. **Return value** - | Type | Description | - | ------------------- | ---------------------------- | - | Promise<void> | Promise that returns no value.| +| Type | Description | +| ------------------- | ---------------------------- | +| Promise<void> | Promise that returns no value.| **Example** @@ -776,9 +776,9 @@ Deletes a file. This API uses a promise to return the result. **Return value** - | Type | Description | - | ------------------- | ---------------------------- | - | Promise<void> | Promise that returns no value.| +| Type | Description | +| ------------------- | ---------------------------- | +| Promise<void> | Promise that returns no value.| **Example** @@ -853,17 +853,17 @@ Writes data into a file. This API uses a promise to return the result. **Parameters** - | Name | Type | Mandatory | Description | - | ------- | ------------------------------- | ---- | ---------------------------------------- | - | fd | number | Yes | FD of the file. | - | buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. | - | options | Object | No | The options are as follows:
- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.
- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.
- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.| +| Name | Type | Mandatory | Description | +| ------- | ------------------------------- | ---- | ---------------------------------------- | +| fd | number | Yes | FD of the file. | +| buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. | +| options | Object | No | The options are as follows:
- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.
- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.
- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.| **Return value** - | Type | Description | - | --------------------- | -------- | - | Promise<number> | Promise used to return the length of the data written.| +| Type | Description | +| --------------------- | -------- | +| Promise<number> | Promise used to return the length of the data written.| **Example** @@ -889,12 +889,12 @@ Writes data into a file. This API uses an asynchronous callback to return the re **Parameters** - | Name | Type | Mandatory | Description | - | -------- | ------------------------------- | ---- | ---------------------------------------- | - | fd | number | Yes | FD of the file. | - | buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. | - | options | Object | No | The options are as follows:
- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.
- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.
- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.| - | callback | AsyncCallback<number> | Yes | Callback invoked when the data is written asynchronously. | +| Name | Type | Mandatory | Description | +| -------- | ------------------------------- | ---- | ---------------------------------------- | +| fd | number | Yes | FD of the file. | +| buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. | +| options | Object | No | The options are as follows:
- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.
- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.
- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.| +| callback | AsyncCallback<number> | Yes | Callback invoked when the data is written asynchronously. | **Example** @@ -922,17 +922,17 @@ Synchronously writes data into a file. **Parameters** - | Name | Type | Mandatory | Description | - | ------- | ------------------------------- | ---- | ---------------------------------------- | - | fd | number | Yes | FD of the file. | - | buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. | - | options | Object | No | The options are as follows:
- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.
- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.
- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.| +| Name | Type | Mandatory | Description | +| ------- | ------------------------------- | ---- | ---------------------------------------- | +| fd | number | Yes | FD of the file. | +| buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. | +| options | Object | No | The options are as follows:
- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.
- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.
- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.| **Return value** - | Type | Description | - | ------ | -------- | - | number | Length of the data written in the file.| +| Type | Description | +| ------ | -------- | +| number | Length of the data written in the file.| **Example** @@ -961,9 +961,9 @@ Truncates a file. This API uses a promise to return the result. **Return value** - | Type | Description | - | ------------------- | ---------------------------- | - | Promise<void> | Promise that returns no value.| +| Type | Description | +| ------------------- | ---------------------------- | +| Promise<void> | Promise that returns no value.| **Example** @@ -1050,9 +1050,9 @@ Reads the text content of a file. This API uses a promise to return the result. **Return value** - | Type | Description | - | --------------------- | ---------- | - | Promise<string> | Promise used to return the content read.| +| Type | Description | +| --------------------- | ---------- | +| Promise<string> | Promise used to return the content read.| **Example** @@ -1113,9 +1113,9 @@ Synchronously reads the text of a file. **Return value** - | Type | Description | - | ------ | -------------------- | - | string | Promise used to return the content of the file read.| +| Type | Description | +| ------ | -------------------- | +| string | Promise used to return the content of the file read.| **Example** @@ -1141,9 +1141,9 @@ Obtains information about a symbolic link. This API uses a promise to return the **Return value** - | Type | Description | - | ---------------------------- | ---------- | - | Promise<[Stat](#stat)> | Promise used to return the symbolic link information obtained. For details, see **stat**.| +| Type | Description | +| ---------------------------- | ---------- | +| Promise<[Stat](#stat)> | Promise used to return the symbolic link information obtained. For details, see **stat**.| **Example** @@ -1201,9 +1201,9 @@ Obtains information about a symbolic link synchronously. **Return value** - | Type | Description | - | ------------- | ---------- | - | [Stat](#stat) | File information obtained.| +| Type | Description | +| ------------- | ---------- | +| [Stat](#stat) | File information obtained.| **Example** @@ -1229,9 +1229,9 @@ Renames a file or directory. This API uses a promise to return the result. **Return value** - | Type | Description | - | ------------------- | ---------------------------- | - | Promise<void> | Promise that returns no value.| +| Type | Description | +| ------------------- | ---------------------------- | +| Promise<void> | Promise that returns no value.| **Example** @@ -1309,15 +1309,15 @@ Flushes data of a file to disk. This API uses a promise to return the result. **Parameters** - | Name | Type | Mandatory | Description | - | ---- | ------ | ---- | ------------ | - | fd | number | Yes | FD of the file.| +| Name | Type | Mandatory | Description | +| ---- | ------ | ---- | ------------ | +| fd | number | Yes | FD of the file.| **Return value** - | Type | Description | - | ------------------- | ---------------------------- | - | Promise<void> | Promise that returns no value.| +| Type | Description | +| ------------------- | ---------------------------- | +| Promise<void> | Promise that returns no value.| **Example** @@ -1342,10 +1342,10 @@ Flushes data of a file to disk. This API uses an asynchronous callback to return **Parameters** - | Name | Type | Mandatory | Description | - | -------- | ------------------------- | ---- | --------------- | - | fd | number | Yes | FD of the file. | - | Callback | AsyncCallback<void> | Yes | Callback invoked when the file data is synchronized in asynchronous mode.| +| Name | Type | Mandatory | Description | +| -------- | ------------------------- | ---- | --------------- | +| fd | number | Yes | FD of the file. | +| Callback | AsyncCallback<void> | Yes | Callback invoked when the file data is synchronized in asynchronous mode.| **Example** @@ -1373,9 +1373,9 @@ Flushes data of a file to disk synchronously. **Parameters** - | Name | Type | Mandatory | Description | - | ---- | ------ | ---- | ------------ | - | fd | number | Yes | FD of the file.| +| Name | Type | Mandatory | Description | +| ---- | ------ | ---- | ------------ | +| fd | number | Yes | FD of the file.| **Example** @@ -1397,15 +1397,15 @@ Flushes data of a file to disk. This API uses a promise to return the result. ** **Parameters** - | Name | Type | Mandatory | Description | - | ---- | ------ | ---- | ------------ | - | fd | number | Yes | FD of the file.| +| Name | Type | Mandatory | Description | +| ---- | ------ | ---- | ------------ | +| fd | number | Yes | FD of the file.| **Return value** - | Type | Description | - | ------------------- | ---------------------------- | - | Promise<void> | Promise that returns no value.| +| Type | Description | +| ------------------- | ---------------------------- | +| Promise<void> | Promise that returns no value.| **Example** @@ -1431,10 +1431,10 @@ Flushes data of a file to disk. This API uses an asynchronous callback to return **Parameters** - | Name | Type | Mandatory | Description | - | -------- | ------------------------------- | ---- | ----------------- | - | fd | number | Yes | FD of the file. | - | callback | AsyncCallback<void> | Yes | Callback invoked when the file data is synchronized in asynchronous mode.| +| Name | Type | Mandatory | Description | +| -------- | ------------------------------- | ---- | ----------------- | +| fd | number | Yes | FD of the file. | +| callback | AsyncCallback<void> | Yes | Callback invoked when the file data is synchronized in asynchronous mode.| **Example** @@ -1461,9 +1461,9 @@ Synchronizes data in a file synchronously. **Parameters** - | Name | Type | Mandatory | Description | - | ---- | ------ | ---- | ------------ | - | fd | number | Yes | FD of the file.| +| Name | Type | Mandatory | Description | +| ---- | ------ | ---- | ------------ | +| fd | number | Yes | FD of the file.| **Example** @@ -1492,9 +1492,9 @@ Creates a symbolic link based on a file path. This API uses a promise to return **Return value** - | Type | Description | - | ------------------- | ---------------------------- | - | Promise<void> | Promise that returns no value.| +| Type | Description | +| ------------------- | ---------------------------- | +| Promise<void> | Promise that returns no value.| **Example** @@ -1574,24 +1574,24 @@ Lists all files in a directory. This API uses a promise to return the result.
- **r+**: Open a file for both reading and writing. The file must exist.
- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.
- **w+**: Open a file for both reading and writing. If the file exists, clear its content. If the file does not exist, create a file.
- **a**: Open a file in append mode for writing at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).
- **a+**: Open a file in append mode for reading or updating at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).| +| Name | Type | Mandatory | Description | +| ---- | ------ | ---- | ---------------------------------------- | +| fd | number | Yes | FD of the file. | +| mode | string | Yes | - **r**: Open a file for reading. The file must exist.
- **r+**: Open a file for both reading and writing. The file must exist.
- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.
- **w+**: Open a file for both reading and writing. If the file exists, clear its content. If the file does not exist, create a file.
- **a**: Open a file in append mode for writing at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).
- **a+**: Open a file in append mode for reading or updating at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).| **Return value** - | Type | Description | - | --------------------------------- | --------- | - | Promise<[Stream](#stream)> | Promise used to return the result.| +| Type | Description | +| --------------------------------- | --------- | +| Promise<[Stream](#stream)> | Promise used to return the result.| **Example** @@ -2014,11 +2014,11 @@ Opens a file stream based on the file descriptor. This API uses an asynchronous **Parameters** - | Name | Type | Mandatory | Description | - | -------- | ---------------------------------------- | ---- | ---------------------------------------- | - | fd | number | Yes | FD of the file. | - | mode | string | Yes | - **r**: Open a file for reading. The file must exist.
- **r+**: Open a file for both reading and writing. The file must exist.
- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.
- **w+**: Open a file for both reading and writing. If the file exists, clear its content. If the file does not exist, create a file.
- **a**: Open a file in append mode for writing at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).
- **a+**: Open a file in append mode for reading or updating at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).| - | callback | AsyncCallback<[Stream](#stream)> | Yes | Callback invoked when the stream is open asynchronously. | +| Name | Type | Mandatory | Description | +| -------- | ---------------------------------------- | ---- | ---------------------------------------- | +| fd | number | Yes | FD of the file. | +| mode | string | Yes | - **r**: Open a file for reading. The file must exist.
- **r+**: Open a file for both reading and writing. The file must exist.
- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.
- **w+**: Open a file for both reading and writing. If the file exists, clear its content. If the file does not exist, create a file.
- **a**: Open a file in append mode for writing at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).
- **a+**: Open a file in append mode for reading or updating at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).| +| callback | AsyncCallback<[Stream](#stream)> | Yes | Callback invoked when the stream is open asynchronously. | **Example** @@ -2045,16 +2045,16 @@ Synchronously opens a stream based on the file descriptor. **Parameters** - | Name | Type | Mandatory | Description | - | ---- | ------ | ---- | ---------------------------------------- | - | fd | number | Yes | FD of the file. | - | mode | string | Yes | - **r**: Open a file for reading. The file must exist.
- **r+**: Open a file for both reading and writing. The file must exist.
- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.
- **w+**: Open a file for both reading and writing. If the file exists, clear its content. If the file does not exist, create a file.
- **a**: Open a file in append mode for writing at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).
- **a+**: Open a file in append mode for reading or updating at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).| +| Name | Type | Mandatory | Description | +| ---- | ------ | ---- | ---------------------------------------- | +| fd | number | Yes | FD of the file. | +| mode | string | Yes | - **r**: Open a file for reading. The file must exist.
- **r+**: Open a file for both reading and writing. The file must exist.
- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.
- **w+**: Open a file for both reading and writing. If the file exists, clear its content. If the file does not exist, create a file.
- **a**: Open a file in append mode for writing at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).
- **a+**: Open a file in append mode for reading or updating at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).| **Return value** - | Type | Description | - | ------------------ | --------- | - | [Stream](#stream) | Stream opened.| +| Type | Description | +| ------------------ | --------- | +| [Stream](#stream) | Stream opened.| **Example** @@ -2065,6 +2065,78 @@ Synchronously opens a stream based on the file descriptor. fs.closeSync(file); ``` +## fs.createWatcher10+ + +createWatcher(path: string, events: number, listener: WatchEventListener): Watcher + +Creates a **Watcher** object to observe file or directory changes. + +**System API**: This is a system API. + +**System capability**: SystemCapability.FileManagement.File.FileIO + +**Parameters** + +| Name | Type | Mandatory | Description | +| ---- | ------ | ---- | ---------------------------------------- | +| path | string | Yes | Path of the file or directory to observe in the application sandbox. | +| events | number | Yes | Events to observe. Multiple events can be separated|by a bitwise OR operator (|).
- **0x1: IN_ACCESS**: A file is accessed.
- **0x2: IN_MODIFY**: The file content is modified.
- **0x4: IN_ATTRIB**: Metadata is changed.
- **0x8: IN_CLOSE_WRITE**: The file opened for writing is closed.
- **0x10: IN_CLOSE_NOWRITE**: The file or directory not opened for writing is closed.
- **0x20: IN_OPEN**: A file or directory is opened.
- **0x40: IN_MOVED_FROM**: A file in the observed directory is moved.
- **0x80: IN_MOVED_TO**: A file is moved to the observed directory.
- **0x100: IN_CREATE**: A file or directory is created in the observed directory.
- **0x200: IN_DELETE**: A file or directory is deleted form the observed directory.
- **0x400: IN_DELETE_SELF**: The observed directory is deleted. After the directory is deleted, the listening stops.
- **0x800: IN_MOVE_SELF**: The observed file or directory is moved. After the file or directory is moved, the listening continues.
- **0xfff: IN_ALL_EVENTS**: All events.| +| listener | WatchEventListener | Yes | Callback invoked when an observed event occurs. The callback will be invoked each time an observed event occurs. | + +**Return value** + +| Type | Description | +| ------------------ | --------- | +| [Watcher](#watcher10) | **Watcher** object created.| + +**Example** + + ```js + let filePath = pathDir + "/test.txt"; + let file = fs.openSync(filePath, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE); + let watcher = fs.createWatcher(filePath, 0x2 | 0x10, (watchEvent) => { + if (watchEvent.event == 0x2) { + console.info(watchEvent.fileName + 'was modified'); + } else if (watchEvent.event == 0x10) { + console.info(watchEvent.fileName + 'was closed'); + } + }); + watcher.start(); + fs.writeSync(file.fd, 'test'); + fs.closeSync(file); + watcher.stop(); + ``` + +## WatchEventListener10+ + +(event: WatchEvent): void + +Called when an observed event occurs. + +**System API**: This is a system API. + +**System capability**: SystemCapability.FileManagement.File.FileIO + +**Parameters** + +| Name | Type | Mandatory | Description | +| ---- | ------ | ---- | ---------------------------------------- | +| event | WatchEvent | Yes | Event for the callback to invoke. | + +## WatchEvent10+ + +Defines the event to observe. + +**System API**: This is a system API. + +**System capability**: SystemCapability.FileManagement.File.FileIO + +| Name | Type | Readable | Writable | Description | +| ---- | ------ | ---- | ---- | ------- | +| fileName | string | Yes | No | Name of the file for which the event occurs.| +| event | number | Yes | No | Events to observe. For details, see **events** in [createWatcher](#fscreatewatcher10).| +| cookie | number | Yes | No | Cookie bound with the event. Currently, only the **IN_MOVED_FROM** and **IN_MOVED_TO** events are supported. The **IN_MOVED_FROM** and **IN_MOVED_TO** events of the same file have the same **cookie** value.| + ## Stat Represents detailed file information. Before calling any API of the **Stat()** class, use [stat()](#fsstat) to create a **Stat** instance synchronously or asynchronously. @@ -2074,7 +2146,7 @@ Represents detailed file information. Before calling any API of the **Stat()** c ### Attributes | Name | Type | Readable | Writable | Description | -| ------ | ------ | ---- | ---- | ---------------------------------------- | +| ------ | ------ | ---- | ---- | ---------------------------------------- | | ino | number | Yes | No | File ID. Different files on the same device have different **ino**s.| | | mode | number | Yes | No | File permissions. The meaning of each bit is as follows:
- **0o400**: The owner has the read permission on a regular file or a directory entry.
- **0o200**: The owner has the permission to write a regular file or create and delete a directory entry.
- **0o100**: The owner has the permission to execute a regular file or search for the specified path in a directory.
- **0o040**: The user group has the read permission on a regular file or a directory entry.
- **0o020**: The user group has the permission to write a regular file or create and delete a directory entry.
- **0o010**: The user group has the permission to execute a regular file or search for the specified path in a directory.
- **0o004**: Other users have the permission to read a regular file or read a directory entry.
- **0o002**: Other users have the permission to write a regular file or create and delete a directory entry.
- **0o001**: Other users have the permission to execute a regular file or search for the specified path in a directory.| | uid | number | Yes | No | ID of the file owner.| @@ -2095,9 +2167,9 @@ Checks whether this file is a block special file. A block special file supports **Return value** - | Type | Description | - | ------- | ---------------- | - | boolean | Whether the file is a block special file.| +| Type | Description | +| ------- | ---------------- | +| boolean | Whether the file is a block special file.| **Example** @@ -2116,9 +2188,9 @@ Checks whether this file is a character special file. A character special file s **Return value** - | Type | Description | - | ------- | ----------------- | - | boolean | Whether the file is a character special file.| +| Type | Description | +| ------- | ----------------- | +| boolean | Whether the file is a character special file.| **Example** @@ -2138,9 +2210,9 @@ Checks whether this file is a directory. **Return value** - | Type | Description | - | ------- | ------------- | - | boolean | Whether the file is a directory.| +| Type | Description | +| ------- | ------------- | +| boolean | Whether the file is a directory.| **Example** @@ -2160,9 +2232,9 @@ Checks whether this file is a named pipe (or FIFO). Named pipes are used for int **Return value** - | Type | Description | - | ------- | --------------------- | - | boolean | Whether the file is a FIFO.| +| Type | Description | +| ------- | --------------------- | +| boolean | Whether the file is a FIFO.| **Example** @@ -2182,9 +2254,9 @@ Checks whether this file is a regular file. **Return value** - | Type | Description | - | ------- | --------------- | - | boolean | Whether the file is a regular file.| +| Type | Description | +| ------- | --------------- | +| boolean | Whether the file is a regular file.| **Example** @@ -2204,9 +2276,9 @@ Checks whether this file is a socket. **Return value** - | Type | Description | - | ------- | -------------- | - | boolean | Whether the file is a socket.| +| Type | Description | +| ------- | -------------- | +| boolean | Whether the file is a socket.| **Example** @@ -2226,9 +2298,9 @@ Checks whether this file is a symbolic link. **Return value** - | Type | Description | - | ------- | --------------- | - | boolean | Whether the file is a symbolic link.| +| Type | Description | +| ------- | --------------- | +| boolean | Whether the file is a symbolic link.| **Example** @@ -2252,9 +2324,9 @@ Closes the stream. This API uses a promise to return the result. **Return value** - | Type | Description | - | ------------------- | ------------- | - | Promise<void> | Promise used to return the stream close result.| +| Type | Description | +| ------------------- | ------------- | +| Promise<void> | Promise used to return the stream close result.| **Example** @@ -2279,9 +2351,9 @@ Closes the stream. This API uses an asynchronous callback to return the result. **Parameters** - | Name | Type | Mandatory | Description | - | -------- | ------------------------- | ---- | ------------- | - | callback | AsyncCallback<void> | Yes | Callback invoked when the stream is closed asynchronously.| +| Name | Type | Mandatory | Description | +| -------- | ------------------------- | ---- | ------------- | +| callback | AsyncCallback<void> | Yes | Callback invoked when the stream is closed asynchronously.| **Example** @@ -2323,9 +2395,9 @@ Flushes the stream. This API uses a promise to return the result. **Return value** - | Type | Description | - | ------------------- | ------------- | - | Promise<void> | Promise used to return the stream flushing result.| +| Type | Description | +| ------------------- | ------------- | +| Promise<void> | Promise used to return the stream flushing result.| **Example** @@ -2350,9 +2422,9 @@ Flushes the stream. This API uses an asynchronous callback to return the result. **Parameters** - | Name | Type | Mandatory | Description | - | -------- | ------------------------- | ---- | -------------- | - | callback | AsyncCallback<void> | Yes | Callback invoked when the stream is asynchronously flushed.| +| Name | Type | Mandatory | Description | +| -------- | ------------------------- | ---- | -------------- | +| callback | AsyncCallback<void> | Yes | Callback invoked when the stream is asynchronously flushed.| **Example** @@ -2394,16 +2466,16 @@ Writes data into the stream. This API uses a promise to return the result. **Parameters** - | Name | Type | Mandatory | Description | - | ------- | ------------------------------- | ---- | ---------------------------------------- | - | buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. | - | options | Object | No | The options are as follows:
- **length** (number): length of the data to write. The default value is the buffer length.
- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.
- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.| +| Name | Type | Mandatory | Description | +| ------- | ------------------------------- | ---- | ---------------------------------------- | +| buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. | +| options | Object | No | The options are as follows:
- **length** (number): length of the data to write. The default value is the buffer length.
- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.
- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.| **Return value** - | Type | Description | - | --------------------- | -------- | - | Promise<number> | Promise used to return the length of the data written.| +| Type | Description | +| --------------------- | -------- | +| Promise<number> | Promise used to return the length of the data written.| **Example** @@ -2428,11 +2500,11 @@ Writes data into the stream. This API uses an asynchronous callback to return th **Parameters** - | Name | Type | Mandatory| Description | - | -------- | ------------------------------- | ---- | ------------------------------------------------------------ | - | buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. | - | options | Object | No | The options are as follows:
- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.
- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.
- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.| - | callback | AsyncCallback<number> | Yes | Callback invoked when the data is written asynchronously. | +| Name | Type | Mandatory| Description | +| -------- | ------------------------------- | ---- | ------------------------------------------------------------ | +| buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. | +| options | Object | No | The options are as follows:
- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.
- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.
- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.| +| callback | AsyncCallback<number> | Yes | Callback invoked when the data is written asynchronously. | **Example** @@ -2460,16 +2532,16 @@ Synchronously writes data into the stream. **Parameters** - | Name | Type | Mandatory | Description | - | ------- | ------------------------------- | ---- | ---------------------------------------- | - | buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. | - | options | Object | No | The options are as follows:
- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.
- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.
- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.| +| Name | Type | Mandatory | Description | +| ------- | ------------------------------- | ---- | ---------------------------------------- | +| buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. | +| options | Object | No | The options are as follows:
- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.
- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.
- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.| **Return value** - | Type | Description | - | ------ | -------- | - | number | Length of the data written in the file.| +| Type | Description | +| ------ | -------- | +| number | Length of the data written in the file.| **Example** @@ -2489,16 +2561,16 @@ Reads data from the stream. This API uses a promise to return the result. **Parameters** - | Name | Type | Mandatory | Description | - | ------- | ----------- | ---- | ---------------------------------------- | - | buffer | ArrayBuffer | Yes | Buffer used to store the file read. | - | options | Object | No | The options are as follows:
- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length.
- **offset** (number): position of the data to read in the file. By default, data is read from the current position.| +| Name | Type | Mandatory | Description | +| ------- | ----------- | ---- | ---------------------------------------- | +| buffer | ArrayBuffer | Yes | Buffer used to store the file read. | +| options | Object | No | The options are as follows:
- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length.
- **offset** (number): position of the data to read in the file. By default, data is read from the current position.| **Return value** - | Type | Description | - | ---------------------------------- | ------ | - | Promise<number> | Promise used to return the data read.| +| Type | Description | +| ---------------------------------- | ------ | +| Promise<number> | Promise used to return the data read.| **Example** @@ -2525,11 +2597,11 @@ Reads data from the stream. This API uses an asynchronous callback to return the **Parameters** - | Name | Type | Mandatory | Description | - | -------- | ---------------------------------------- | ---- | ---------------------------------------- | - | buffer | ArrayBuffer | Yes | Buffer used to store the file read. | - | options | Object | No | The options are as follows:
- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length.
- **offset** (number): position of the data to read in the file. This parameter is optional. By default, data is read from the current position.| - | callback | AsyncCallback<number> | Yes | Callback invoked when data is read asynchronously from the stream. | +| Name | Type | Mandatory | Description | +| -------- | ---------------------------------------- | ---- | ---------------------------------------- | +| buffer | ArrayBuffer | Yes | Buffer used to store the file read. | +| options | Object | No | The options are as follows:
- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length.
- **offset** (number): position of the data to read in the file. This parameter is optional. By default, data is read from the current position.| +| callback | AsyncCallback<number> | Yes | Callback invoked when data is read asynchronously from the stream. | **Example** @@ -2557,16 +2629,16 @@ Synchronously reads data from the stream. **Parameters** - | Name | Type | Mandatory | Description | - | ------- | ----------- | ---- | ---------------------------------------- | - | buffer | ArrayBuffer | Yes | Buffer used to store the file read. | - | options | Object | No | The options are as follows:
- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length.
- **offset** (number): position of the data to read in the file. This parameter is optional. By default, data is read from the current position.
| +| Name | Type | Mandatory | Description | +| ------- | ----------- | ---- | ---------------------------------------- | +| buffer | ArrayBuffer | Yes | Buffer used to store the file read. | +| options | Object | No | The options are as follows:
- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length.
- **offset** (number): position of the data to read in the file. This parameter is optional. By default, data is read from the current position.
| **Return value** - | Type | Description | - | ------ | -------- | - | number | Length of the data read.| +| Type | Description | +| ------ | -------- | +| number | Length of the data read.| **Example** @@ -2598,15 +2670,15 @@ Applies an exclusive lock or a shared lock on this file in blocking mode. This A **Parameters** - | Name | Type | Mandatory | Description | - | ------- | ----------- | ---- | ---------------------------------------- | - | exclusive | boolean | No | Lock to apply. The value **true** means an exclusive lock, and the value **false** (default) means a shared lock. | +| Name | Type | Mandatory | Description | +| ------- | ----------- | ---- | ---------------------------------------- | +| exclusive | boolean | No | Lock to apply. The value **true** means an exclusive lock, and the value **false** (default) means a shared lock. | **Return value** - | Type | Description | - | ---------------------------------- | ------ | - | Promise<void> | Promise that returns no value.| +| Type | Description | +| ---------------------------------- | ------ | +| Promise<void> | Promise that returns no value.| **Example** @@ -2629,10 +2701,10 @@ Applies an exclusive lock or a shared lock on this file in blocking mode. This A **Parameters** - | Name | Type | Mandatory | Description | - | ------- | ----------- | ---- | ---------------------------------------- | - | exclusive | boolean | No | Lock to apply. The value **true** means an exclusive lock, and the value **false** (default) means a shared lock. | - | callback | AsyncCallback<void> | Yes | Callback invoked when the file is locked. | +| Name | Type | Mandatory | Description | +| ------- | ----------- | ---- | ---------------------------------------- | +| exclusive | boolean | No | Lock to apply. The value **true** means an exclusive lock, and the value **false** (default) means a shared lock. | +| callback | AsyncCallback<void> | Yes | Callback invoked when the file is locked. | **Example** @@ -2657,9 +2729,9 @@ Applies an exclusive lock or a shared lock on this file in non-blocking mode. **Parameters** - | Name | Type | Mandatory | Description | - | ------- | ----------- | ---- | ---------------------------------------- | - | exclusive | boolean | No | Lock to apply. The value **true** means an exclusive lock, and the value **false** (default) means a shared lock. | +| Name | Type | Mandatory | Description | +| ------- | ----------- | ---- | ---------------------------------------- | +| exclusive | boolean | No | Lock to apply. The value **true** means an exclusive lock, and the value **false** (default) means a shared lock. | **Example** @@ -2686,6 +2758,48 @@ Unlocks this file synchronously. console.log("unlock file successful"); ``` +## Watcher10+ + +Provides APIs for file or directory listening. Before using the APIs of **Watcher** , call **createWatcher()** to create a **Watcher** object. + +### start10+ + +start(): void + +Starts file or directory listening. + +**System API**: This is a system API. + +**System capability**: SystemCapability.FileManagement.File.FileIO + +**Example** + + ```js + let filePath = pathDir + "/test.txt"; + let watcher = fs.createWatcher(filePath, 0xfff, () => {}); + watcher.start(); + watcher.stop(); + ``` + +### stop10+ + +stop(): void + +Stops file or directory listening. + +**System API**: This is a system API. + +**System capability**: SystemCapability.FileManagement.File.FileIO + +**Example** + + ```js + let filePath = pathDir + "/test.txt"; + let watcher = fs.createWatcher(filePath, 0xfff, () => {}); + watcher.start(); + watcher.stop(); + ``` + ## OpenMode Defines the constants of the **mode** parameter used in **open()**. It species the mode for opening a file. diff --git a/en/application-dev/reference/apis/js-apis-file-securityLabel.md b/en/application-dev/reference/apis/js-apis-file-securityLabel.md index b9071ecc64..13fd25683a 100644 --- a/en/application-dev/reference/apis/js-apis-file-securityLabel.md +++ b/en/application-dev/reference/apis/js-apis-file-securityLabel.md @@ -5,7 +5,7 @@ The **securityLabel** module provides APIs for managing data security levels of > **NOTE** > > - The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. ->- The APIs of this module support processing of error codes. For details, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). +> - The APIs of this module support processing of error codes. For details, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). ## Modules to Import @@ -45,7 +45,7 @@ For details about how to obtain the FA model context, see [Context](js-apis-inne ## securityLabel.setSecurityLabel -setSecurityLabel(path:string, type:dataLevel):Promise<void> +setSecurityLabel(path:string, type:DataLevel):Promise<void> Sets a security label for a file in asynchronous mode. This API uses a promise to return the result. @@ -56,7 +56,7 @@ Sets a security label for a file in asynchronous mode. This API uses a promise t | Name | Type | Mandatory| Description | | --------- | ------ | ---- | -------------------------------------------- | | path | string | Yes | Path of the target file. | -| type | dataLevel | Yes | File security level to set, which can be **s0**, **s1**, **s2**, **s3**, or **s4**.| +| type | DataLevel | Yes | File security level to set, which can be **s0**, **s1**, **s2**, **s3**, or **s4**.| **Return value** @@ -76,7 +76,7 @@ Sets a security label for a file in asynchronous mode. This API uses a promise t ## securityLabel.setSecurityLabel -setSecurityLabel(path:string, type:dataLevel, callback: AsyncCallback<void>):void +setSecurityLabel(path:string, type:DataLevel, callback: AsyncCallback<void>):void Sets a security label for a file in asynchronous mode. This API uses an asynchronous callback to return the result. @@ -87,7 +87,7 @@ Sets a security label for a file in asynchronous mode. This API uses an asynchro | Name | Type | Mandatory| Description | | --------- | ------------------------- | ---- | -------------------------------------------- | | path | string | Yes | Path of the target file. | -| type | dataLevel | Yes | File security level to set, which can be **s0**, **s1**, **s2**, **s3**, or **s4**.| +| type | DataLevel | Yes | File security level to set, which can be **s0**, **s1**, **s2**, **s3**, or **s4**.| | callback | AsyncCallback<void> | Yes | Callback invoked to return the result. | **Example** @@ -104,7 +104,7 @@ Sets a security label for a file in asynchronous mode. This API uses an asynchro ## securityLabel.setSecurityLabelSync -setSecurityLabelSync(path:string, type:dataLevel):void +setSecurityLabelSync(path:string, type:DataLevel):void Sets a security label for a file in synchronous mode. @@ -115,7 +115,7 @@ Sets a security label for a file in synchronous mode. | Name | Type | Mandatory| Description | | --------- | ------ | ---- | -------------------------------------------- | | path | string | Yes | Path of the target file. | -| type | dataLevel | Yes | File security level to set, which can be **s0**, **s1**, **s2**, **s3**, or **s4**.| +| type | DataLevel | Yes | File security level to set, which can be **s0**, **s1**, **s2**, **s3**, or **s4**.| **Example** diff --git a/en/application-dev/reference/apis/js-apis-huks.md b/en/application-dev/reference/apis/js-apis-huks.md index cad81d4e80..0dfcc793a2 100644 --- a/en/application-dev/reference/apis/js-apis-huks.md +++ b/en/application-dev/reference/apis/js-apis-huks.md @@ -3,7 +3,7 @@ The **HUKS** module provides KeyStore (KS) capabilities for applications, including key management and key cryptography operations. The keys managed by OpenHarmony Universal KeyStore (HUKS) can be imported by applications or generated by calling the HUKS APIs. -> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
+> **NOTE** > > The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. @@ -1818,9 +1818,9 @@ Enumerates the user authentication types. | Name | Value | Description | | ------------------------------- | ---- | ------------------------- | -| HUKS_USER_AUTH_TYPE_FINGERPRINT | 1 | Fingerprint authentication. | -| HUKS_USER_AUTH_TYPE_FACE | 2 | Facial authentication.| -| HUKS_USER_AUTH_TYPE_PIN | 4 | PIN authentication.| +| HUKS_USER_AUTH_TYPE_FINGERPRINT | 1 << 0 | Fingerprint authentication. | +| HUKS_USER_AUTH_TYPE_FACE | 1 << 1 | Facial authentication.| +| HUKS_USER_AUTH_TYPE_PIN | 1 << 2 | PIN authentication.| ## HuksAuthAccessType9+ @@ -1830,8 +1830,8 @@ Enumerates the access control types. | Name | Value | Description | | --------------------------------------- | ---- | ------------------------------------------------ | -| HUKS_AUTH_ACCESS_INVALID_CLEAR_PASSWORD | 1 | The key becomes invalid after the password is cleared. | -| HUKS_AUTH_ACCESS_INVALID_NEW_BIO_ENROLL | 2 | The key becomes invalid after a new biometric feature is added.| +| HUKS_AUTH_ACCESS_INVALID_CLEAR_PASSWORD | 1 << 0 | The key becomes invalid after the password is cleared. | +| HUKS_AUTH_ACCESS_INVALID_NEW_BIO_ENROLL | 1 << 1 | The key becomes invalid after a new biometric feature is added.| ## HuksChallengeType9+ @@ -1892,7 +1892,7 @@ Enumerates the tags used to invoke parameters. | Name | Value | Description | | -------------------------------------------- | ---------------------------------------- | -------------------------------------- | | HUKS_TAG_INVALID | HuksTagType.HUKS_TAG_TYPE_INVALID \| 0 | Invalid tag. | -| HUKS_TAG_ALGORITHM | HUKS_TAG_TYPE_UINT \| 1 | Algorithm. | +| HUKS_TAG_ALGORITHM | HuksTagType.HUKS_TAG_TYPE_UINT \| 1 | Algorithm. | | HUKS_TAG_PURPOSE | HuksTagType.HUKS_TAG_TYPE_UINT \| 2 | Purpose of the key. | | HUKS_TAG_KEY_SIZE | HuksTagType.HUKS_TAG_TYPE_UINT \| 3 | Key size. | | HUKS_TAG_DIGEST | HuksTagType.HUKS_TAG_TYPE_UINT \| 4 | Digest algorithm. | @@ -1922,7 +1922,7 @@ Enumerates the tags used to invoke parameters. | HUKS_TAG_ORIGINATION_EXPIRE_DATETIME | HuksTagType.HUKS_TAG_TYPE_ULONG \| 202 | Reserved. | | HUKS_TAG_USAGE_EXPIRE_DATETIME | HuksTagType.HUKS_TAG_TYPE_ULONG \| 203 | Reserved. | | HUKS_TAG_CREATION_DATETIME | HuksTagType.HUKS_TAG_TYPE_ULONG \| 204 | Reserved. | -| HUKS_TAG_ALL_USERS | ksTagType.HUKS_TAG_TYPE_BOOL \| 301 | Reserved. | +| HUKS_TAG_ALL_USERS | HuksTagType.HUKS_TAG_TYPE_BOOL \| 301 | Reserved. | | HUKS_TAG_USER_ID | HuksTagType.HUKS_TAG_TYPE_UINT \| 302 | Reserved. | | HUKS_TAG_NO_AUTH_REQUIRED | HuksTagType.HUKS_TAG_TYPE_BOOL \| 303 | Reserved. | | HUKS_TAG_USER_AUTH_TYPE | HuksTagType.HUKS_TAG_TYPE_UINT \| 304 | User authentication type. For details, see [HuksUserAuthType](#huksuserauthtype9). This parameter must be set together with [HuksAuthAccessType](#huksauthaccesstype9). You can set a maximum of two user authentication types at a time. For example, if **HuksAuthAccessType** is **HKS_SECURE_ACCESS_INVALID_NEW_BIO_ENROLL**, you can set two of **HKS_USER_AUTH_TYPE_FACE**, **HKS_USER_AUTH_TYPE_FINGERPRINT**, and **HKS_USER_AUTH_TYPE_FACE\**.| HKS_USER_AUTH_TYPE_FINGERPRINT | @@ -2889,11 +2889,6 @@ Enumerates the error codes. | HUKS_ERROR_NEW_ROOT_KEY_MATERIAL_EXIST | -36 |New root key material exists.| | HUKS_ERROR_UPDATE_ROOT_KEY_MATERIAL_FAIL | -37 |Failed to update the root key material.| | HUKS_ERROR_VERIFICATION_FAILED | -38 |Failed to verify the certificate chain.| -| HUKS_ERROR_GET_USERIAM_SECINFO_FAILED9+ | -40 |Failed to obtain the security attribute information of the user.| -| HUKS_ERROR_GET_USERIAM_AUTHINFO_FAILED9+ | -41 |Failed to obtain the authentication information of the user.| -| HUKS_ERROR_USER_AUTH_TYPE_NOT_SUPPORT9+ | -42 |The access control of the current authentication type is not supported.| -| HUKS_ERROR_KEY_AUTH_FAILED9+ | -43 |The access control authentication has failed.| -| HUKS_ERROR_DEVICE_NO_CREDENTIAL9+ | -44 |No credential has been enrolled for the device.| | HUKS_ERROR_CHECK_GET_ALG_FAIL | -100 |Failed to obtain the ALG. | | HUKS_ERROR_CHECK_GET_KEY_SIZE_FAIL | -101 |Failed to obtain the key size.| | HUKS_ERROR_CHECK_GET_PADDING_FAIL | -102 |Failed to obtain the padding algorithm.| @@ -2920,7 +2915,5 @@ Enumerates the error codes. | HUKS_ERROR_INVALID_SALT | -123 |Invalid salt value.| | HUKS_ERROR_INVALID_ITERATION | -124 |Invalid iteration count.| | HUKS_ERROR_INVALID_OPERATION | -125 |Invalid operation.| -| HUKS_ERROR_INVALID_WRAPPED_FORMAT9+ | -126 |Incorrect format of the wrapped key being imported.| -| HUKS_ERROR_INVALID_USAGE_OF_KEY9+ | -127 |Incorrect purpose of the wrapped key being imported.| | HUKS_ERROR_INTERNAL_ERROR | -999 |Internal error.| | HUKS_ERROR_UNKNOWN_ERROR | -1000 |Unknown error.| -- GitLab