The **DataShare** module allows an application to manage its own data and share data with other applications on the same device.
The **DataShare** module allows an application to manage its own data and share data with other applications on the same device.
> **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.
> - 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
## Modules to Import
...
@@ -55,7 +56,7 @@ Observe the following when using this API:
...
@@ -55,7 +56,7 @@ Observe the following when using this API:
| 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. |
| 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.|
| 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:
...
@@ -105,7 +106,7 @@ Observe the following when using this API:
| type | string | Yes | Event type to unsubscribe from. The value is **dataChange**, which indicates data change events.|
| type | string | Yes | Event type to unsubscribe from. The value is **dataChange**, which indicates data change events.|
| uri | string | Yes | URI of the data.|
| 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.|
@@ -5,7 +5,7 @@ The **Preferences** module provides APIs for processing data in the form of key-
...
@@ -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.
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**<br/>
> **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.
...
@@ -22,8 +22,8 @@ import data_preferences from '@ohos.data.preferences';
...
@@ -22,8 +22,8 @@ import data_preferences from '@ohos.data.preferences';
| context | Context | Yes | Application context.<br>For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](js-apis-inner-application-uiAbilityContext.md). |
| context | Context | Yes | Application context.<br>For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).<br>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.|
| 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.|
| 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**
**Example**
...
@@ -213,7 +213,6 @@ Stage model:
...
@@ -213,7 +213,6 @@ Stage model:
```ts
```ts
importUIAbilityfrom'@ohos.app.ability.UIAbility';
importUIAbilityfrom'@ohos.app.ability.UIAbility';
classEntryAbilityextendsUIAbility{
classEntryAbilityextendsUIAbility{
onWindowStageCreate(windowStage){
onWindowStageCreate(windowStage){
try{
try{
...
@@ -289,7 +288,6 @@ Stage model:
...
@@ -289,7 +288,6 @@ Stage model:
```ts
```ts
importUIAbilityfrom'@ohos.app.ability.UIAbility';
importUIAbilityfrom'@ohos.app.ability.UIAbility';
classEntryAbilityextendsUIAbility{
classEntryAbilityextendsUIAbility{
onWindowStageCreate(windowStage){
onWindowStageCreate(windowStage){
try{
try{
...
@@ -350,7 +348,6 @@ Stage model:
...
@@ -350,7 +348,6 @@ Stage model:
```ts
```ts
importUIAbilityfrom'@ohos.app.ability.UIAbility';
importUIAbilityfrom'@ohos.app.ability.UIAbility';
classEntryAbilityextendsUIAbility{
classEntryAbilityextendsUIAbility{
onWindowStageCreate(windowStage){
onWindowStageCreate(windowStage){
try{
try{
...
@@ -973,7 +970,7 @@ Unsubscribes from data changes.
...
@@ -973,7 +970,7 @@ Unsubscribes from data changes.
| type | string | Yes | Event type to unsubscribe from. The value **change** indicates data change events. |
| 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.|
@@ -7,8 +7,8 @@ The **DataStorage** module provides applications with data processing capability
...
@@ -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 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.
> - The APIs of this module can be used only in the FA model.
...
@@ -24,8 +24,8 @@ import data_storage from '@ohos.data.storage';
...
@@ -24,8 +24,8 @@ import data_storage from '@ohos.data.storage';
@@ -4,7 +4,7 @@ The **Environment** module provides APIs for obtaining the root directories of t
...
@@ -4,7 +4,7 @@ The **Environment** module provides APIs for obtaining the root directories of t
> **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.
> - 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 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).
> - 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
...
@@ -26,7 +26,7 @@ Obtains the root directory of the storage. This API uses a promise to return the
| Type | Description |
| 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**
**Example**
...
@@ -50,7 +50,7 @@ Obtains the root directory of the storage. This API uses an asynchronous callbac
...
@@ -50,7 +50,7 @@ Obtains the root directory of the storage. This API uses an asynchronous callbac
| src | string\|number | Yes | Path or FD of the file to copy. |
| 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. |
| 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.<br>**0**: overwrite the file of the same name.|
| 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.<br>**0**: overwrite the file of the same name.|
| src | string\|number | Yes | Path or FD of the file to copy. |
| 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. |
| 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.<br>**0**: overwrite the file with the same name and truncate the part that is not overwritten.|
| 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.<br>**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. |
| callback | AsyncCallback<void> | Yes | Callback invoked when the file is copied asynchronously. |
**Example**
**Example**
...
@@ -383,11 +383,11 @@ Synchronously copies a file.
...
@@ -383,11 +383,11 @@ Synchronously copies a file.
| src | string\|number | Yes | Path or FD of the file to copy. |
| 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. |
| 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.<br>**0**: overwrite the file with the same name and truncate the part that is not overwritten.|
| 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.<br>**0**: overwrite the file with the same name and truncate the part that is not overwritten.|
**Example**
**Example**
...
@@ -414,9 +414,9 @@ Creates a directory. This API uses a promise to return the result.
...
@@ -414,9 +414,9 @@ Creates a directory. This API uses a promise to return the result.
| buffer | ArrayBuffer | Yes | Buffer used to store the file data read. |
| buffer | ArrayBuffer | Yes | Buffer used to store the file data read. |
| options | Object | No | The options are as follows:<br>- **offset** (number): position of the data to read in the file. This parameter is optional. By default, data is read from the current position.<br>- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length.|
| options | Object | No | The options are as follows:<br>- **offset** (number): position of the data to read in the file. This parameter is optional. By default, data is read from the current position.<br>- **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. |
| callback | AsyncCallback<number> | Yes | Callback invoked when the data is read asynchronously. |
**Example**
**Example**
...
@@ -654,17 +654,17 @@ Synchronously reads data from a file.
...
@@ -654,17 +654,17 @@ Synchronously reads data from a file.
| buffer | ArrayBuffer | Yes | Buffer used to store the file data read. |
| buffer | ArrayBuffer | Yes | Buffer used to store the file data read. |
| options | Object | No | The options are as follows:<br>- **offset** (number): position of the data to read in the file. This parameter is optional. By default, data is read from the current position.<br>- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length.|
| options | Object | No | The options are as follows:<br>- **offset** (number): position of the data to read in the file. This parameter is optional. By default, data is read from the current position.<br>- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length.|
**Return value**
**Return value**
| Type | Description |
| Type | Description |
| ------ | -------- |
| ------ | -------- |
| number | Length of the data read.|
| number | Length of the data read.|
**Example**
**Example**
...
@@ -693,9 +693,9 @@ Deletes a directory. This API uses a promise to return the result.
...
@@ -693,9 +693,9 @@ Deletes a directory. This API uses a promise to return the result.
| buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. |
| 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:<br>- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.<br>- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.<br>- **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.|
| options | Object | No | The options are as follows:<br>- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.<br>- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.<br>- **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**
**Return value**
| Type | Description |
| Type | Description |
| --------------------- | -------- |
| --------------------- | -------- |
| Promise<number> | Promise used to return the length of the data written.|
| Promise<number> | Promise used to return the length of the data written.|
**Example**
**Example**
...
@@ -889,12 +889,12 @@ Writes data into a file. This API uses an asynchronous callback to return the re
...
@@ -889,12 +889,12 @@ Writes data into a file. This API uses an asynchronous callback to return the re
| buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. |
| 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:<br>- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.<br>- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.<br>- **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.|
| options | Object | No | The options are as follows:<br>- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.<br>- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.<br>- **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. |
| callback | AsyncCallback<number> | Yes | Callback invoked when the data is written asynchronously. |
**Example**
**Example**
...
@@ -922,17 +922,17 @@ Synchronously writes data into a file.
...
@@ -922,17 +922,17 @@ Synchronously writes data into a file.
| buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. |
| 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:<br>- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.<br>- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.<br>- **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.|
| options | Object | No | The options are as follows:<br>- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.<br>- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.<br>- **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**
**Return value**
| Type | Description |
| Type | Description |
| ------ | -------- |
| ------ | -------- |
| number | Length of the data written in the file.|
| number | Length of the data written in the file.|
**Example**
**Example**
...
@@ -961,9 +961,9 @@ Truncates a file. This API uses a promise to return the result.
...
@@ -961,9 +961,9 @@ Truncates a file. This API uses a promise to return the result.
| recursion | boolean | No | Whether to list all files in subdirectories recursively. The default value is **false**.|
| recursion | boolean | No | Whether to list all files in subdirectories recursively. The default value is **false**.|
| listNum | number | No | Number of file names to list. The default value **0** means to list all files.|
| listNum | number | No | Number of file names to list. The default value **0** means to list all files.|
| filter | [Filter](#filter) | No | File filtering options. Currently, only the match by file name extension, fuzzy search by file name, and filter by file size or latest modification time are supported.|
| filter | [Filter](#filter) | No | File filtering options. Currently, only the match by file name extension, fuzzy search by file name, and filter by file size or latest modification time are supported.|
**Return value**
**Return value**
| Type | Description |
| Type | Description |
| --------------------- | ---------- |
| --------------------- | ---------- |
| Promise<string[]> | Promise used to return the files names listed.|
| Promise<string[]> | Promise used to return the files names listed.|
**Example**
**Example**
...
@@ -1627,19 +1627,19 @@ Lists all files in a directory. This API uses an asynchronous callback to return
...
@@ -1627,19 +1627,19 @@ Lists all files in a directory. This API uses an asynchronous callback to return
| recursion | boolean | No | Whether to list all files in subdirectories recursively. The default value is **false**.|
| recursion | boolean | No | Whether to list all files in subdirectories recursively. The default value is **false**.|
| listNum | number | No | Number of file names to list. The default value **0** means to list all files.|
| listNum | number | No | Number of file names to list. The default value **0** means to list all files.|
| filter | [Filter](#filter) | No | File filtering options. Currently, only the match by file name extension, fuzzy search by file name, and filter by file size or latest modification time are supported.|
| filter | [Filter](#filter) | No | File filtering options. Currently, only the match by file name extension, fuzzy search by file name, and filter by file size or latest modification time are supported.|
**Example**
**Example**
...
@@ -1678,24 +1678,24 @@ Lists all files in a directory synchronously. This API supports recursive listin
...
@@ -1678,24 +1678,24 @@ Lists all files in a directory synchronously. This API supports recursive listin
| recursion | boolean | No | Whether to list all files in subdirectories recursively. The default value is **false**.|
| recursion | boolean | No | Whether to list all files in subdirectories recursively. The default value is **false**.|
| listNum | number | No | Number of file names to list. The default value **0** means to list all files.|
| listNum | number | No | Number of file names to list. The default value **0** means to list all files.|
| filter | [Filter](#filter) | No | File filtering options. Currently, only the match by file name extension, fuzzy search by file name, and filter by file size or latest modification time are supported.|
| filter | [Filter](#filter) | No | File filtering options. Currently, only the match by file name extension, fuzzy search by file name, and filter by file size or latest modification time are supported.|
**Return value**
**Return value**
| Type | Description |
| Type | Description |
| --------------------- | ---------- |
| --------------------- | ---------- |
| string[] | File names listed.|
| string[] | File names listed.|
**Example**
**Example**
...
@@ -1726,11 +1726,11 @@ Moves a file. This API uses a promise to return the result.
...
@@ -1726,11 +1726,11 @@ Moves a file. This API uses a promise to return the result.
| src | string | Yes | Path of the file to move in the application sandbox.|
| src | string | Yes | Path of the file to move in the application sandbox.|
| dest | string | Yes | Destination path of the file in the application sandbox.|
| dest | string | Yes | Destination path of the file in the application sandbox.|
| mode | number | No | Whether to overwrite the file of the same name in the destination directory. The value **0** means to overwrite the file of the same name in the destination directory. The value **1** means to throw an exception if a file of the same name exists in the destination directory. The default value is **0**.|
| mode | number | No | Whether to overwrite the file of the same name in the destination directory. The value **0** means to overwrite the file of the same name in the destination directory. The value **1** means to throw an exception if a file of the same name exists in the destination directory. The default value is **0**.|
**Example**
**Example**
...
@@ -1752,12 +1752,12 @@ Moves a file. This API uses an asynchronous callback to return the result.
...
@@ -1752,12 +1752,12 @@ Moves a file. This API uses an asynchronous callback to return the result.
| src | string | Yes | Path of the file to move in the application sandbox.|
| src | string | Yes | Path of the file to move in the application sandbox.|
| dest | string | Yes | Destination path of the file in the application sandbox.|
| dest | string | Yes | Destination path of the file in the application sandbox.|
| mode | number | No | Whether to overwrite the file of the same name in the destination directory. The value **0** means to overwrite the file of the same name in the destination directory. The value **1** means to throw an exception if a file of the same name exists in the destination directory. The default value is **0**.|
| mode | number | No | Whether to overwrite the file of the same name in the destination directory. The value **0** means to overwrite the file of the same name in the destination directory. The value **1** means to throw an exception if a file of the same name exists in the destination directory. The default value is **0**.|
| callback | AsyncCallback<void> | Yes | Callback invoked when the file is moved. |
| callback | AsyncCallback<void> | Yes | Callback invoked when the file is moved. |
**Example**
**Example**
...
@@ -1781,11 +1781,11 @@ Moves a file synchronously.
...
@@ -1781,11 +1781,11 @@ Moves a file synchronously.
| src | string | Yes | Path of the file to move in the application sandbox.|
| src | string | Yes | Path of the file to move in the application sandbox.|
| dest | string | Yes | Destination path of the file in the application sandbox.|
| dest | string | Yes | Destination path of the file in the application sandbox.|
| mode | number | No | Whether to overwrite the file of the same name in the destination directory. The value **0** means to overwrite the file of the same name in the destination directory. The value **1** means to throw an exception if a file of the same name exists in the destination directory. The default value is **0**.|
| mode | number | No | Whether to overwrite the file of the same name in the destination directory. The value **0** means to overwrite the file of the same name in the destination directory. The value **1** means to throw an exception if a file of the same name exists in the destination directory. The default value is **0**.|
**Example**
**Example**
...
@@ -1804,15 +1804,15 @@ Creates a temporary directory. This API uses a promise to return the result.
...
@@ -1804,15 +1804,15 @@ Creates a temporary directory. This API uses a promise to return the result.
| mode | string | Yes | - **r**: Open a file for reading. The file must exist.<br>- **r+**: Open a file for both reading and writing. The file must exist.<br>- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **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.<br>- **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).<br>- **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).|
| mode | string | Yes | - **r**: Open a file for reading. The file must exist.<br>- **r+**: Open a file for both reading and writing. The file must exist.<br>- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **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.<br>- **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).<br>- **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**
**Return value**
| Type | Description |
| Type | Description |
| --------------------------------- | --------- |
| --------------------------------- | --------- |
| Promise<[Stream](#stream)> | Promise used to return the result.|
| Promise<[Stream](#stream)> | Promise used to return the result.|
**Example**
**Example**
...
@@ -2014,11 +2014,11 @@ Opens a file stream based on the file descriptor. This API uses an asynchronous
...
@@ -2014,11 +2014,11 @@ Opens a file stream based on the file descriptor. This API uses an asynchronous
| mode | string | Yes | - **r**: Open a file for reading. The file must exist.<br>- **r+**: Open a file for both reading and writing. The file must exist.<br>- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **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.<br>- **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).<br>- **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).|
| mode | string | Yes | - **r**: Open a file for reading. The file must exist.<br>- **r+**: Open a file for both reading and writing. The file must exist.<br>- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **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.<br>- **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).<br>- **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. |
| callback | AsyncCallback<[Stream](#stream)> | Yes | Callback invoked when the stream is open asynchronously. |
**Example**
**Example**
...
@@ -2045,16 +2045,16 @@ Synchronously opens a stream based on the file descriptor.
...
@@ -2045,16 +2045,16 @@ Synchronously opens a stream based on the file descriptor.
| mode | string | Yes | - **r**: Open a file for reading. The file must exist.<br>- **r+**: Open a file for both reading and writing. The file must exist.<br>- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **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.<br>- **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).<br>- **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).|
| mode | string | Yes | - **r**: Open a file for reading. The file must exist.<br>- **r+**: Open a file for both reading and writing. The file must exist.<br>- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **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.<br>- **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).<br>- **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**
**Return value**
| Type | Description |
| Type | Description |
| ------------------ | --------- |
| ------------------ | --------- |
| [Stream](#stream) | Stream opened.|
| [Stream](#stream) | Stream opened.|
**Example**
**Example**
...
@@ -2065,6 +2065,78 @@ Synchronously opens a stream based on the file descriptor.
...
@@ -2065,6 +2065,78 @@ Synchronously opens a stream based on the file descriptor.
| 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 (|).<br>- **0x1: IN_ACCESS**: A file is accessed.<br>- **0x2: IN_MODIFY**: The file content is modified.<br>- **0x4: IN_ATTRIB**: Metadata is changed.<br>- **0x8: IN_CLOSE_WRITE**: The file opened for writing is closed.<br>- **0x10: IN_CLOSE_NOWRITE**: The file or directory not opened for writing is closed.<br>- **0x20: IN_OPEN**: A file or directory is opened.<br>- **0x40: IN_MOVED_FROM**: A file in the observed directory is moved.<br>- **0x80: IN_MOVED_TO**: A file is moved to the observed directory.<br>- **0x100: IN_CREATE**: A file or directory is created in the observed directory.<br>- **0x200: IN_DELETE**: A file or directory is deleted form the observed directory.<br>- **0x400: IN_DELETE_SELF**: The observed directory is deleted. After the directory is deleted, the listening stops.<br>- **0x800: IN_MOVE_SELF**: The observed file or directory is moved. After the file or directory is moved, the listening continues.<br>- **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. |
| 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
## Stat
Represents detailed file information. Before calling any API of the **Stat()** class, use [stat()](#fsstat) to create a **Stat** instance synchronously or asynchronously.
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
...
@@ -2074,7 +2146,7 @@ Represents detailed file information. Before calling any API of the **Stat()** c
### Attributes
### Attributes
| Name | Type | Readable | Writable | Description |
| Name | Type | Readable | Writable | Description |
| ino | number | Yes | No | File ID. Different files on the same device have different **ino**s.| |
| 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:<br>- **0o400**: The owner has the read permission on a regular file or a directory entry.<br>- **0o200**: The owner has the permission to write a regular file or create and delete a directory entry.<br>- **0o100**: The owner has the permission to execute a regular file or search for the specified path in a directory.<br>- **0o040**: The user group has the read permission on a regular file or a directory entry.<br>- **0o020**: The user group has the permission to write a regular file or create and delete a directory entry.<br>- **0o010**: The user group has the permission to execute a regular file or search for the specified path in a directory.<br>- **0o004**: Other users have the permission to read a regular file or read a directory entry.<br>- **0o002**: Other users have the permission to write a regular file or create and delete a directory entry.<br>- **0o001**: Other users have the permission to execute a regular file or search for the specified path in a directory.|
| mode | number | Yes | No | File permissions. The meaning of each bit is as follows:<br>- **0o400**: The owner has the read permission on a regular file or a directory entry.<br>- **0o200**: The owner has the permission to write a regular file or create and delete a directory entry.<br>- **0o100**: The owner has the permission to execute a regular file or search for the specified path in a directory.<br>- **0o040**: The user group has the read permission on a regular file or a directory entry.<br>- **0o020**: The user group has the permission to write a regular file or create and delete a directory entry.<br>- **0o010**: The user group has the permission to execute a regular file or search for the specified path in a directory.<br>- **0o004**: Other users have the permission to read a regular file or read a directory entry.<br>- **0o002**: Other users have the permission to write a regular file or create and delete a directory entry.<br>- **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.|
| 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
...
@@ -2095,9 +2167,9 @@ Checks whether this file is a block special file. A block special file supports
**Return value**
**Return value**
| Type | Description |
| Type | Description |
| ------- | ---------------- |
| ------- | ---------------- |
| boolean | Whether the file is a block special file.|
| boolean | Whether the file is a block special file.|
**Example**
**Example**
...
@@ -2116,9 +2188,9 @@ Checks whether this file is a character special file. A character special file s
...
@@ -2116,9 +2188,9 @@ Checks whether this file is a character special file. A character special file s
**Return value**
**Return value**
| Type | Description |
| Type | Description |
| ------- | ----------------- |
| ------- | ----------------- |
| boolean | Whether the file is a character special file.|
| boolean | Whether the file is a character special file.|
**Example**
**Example**
...
@@ -2138,9 +2210,9 @@ Checks whether this file is a directory.
...
@@ -2138,9 +2210,9 @@ Checks whether this file is a directory.
**Return value**
**Return value**
| Type | Description |
| Type | Description |
| ------- | ------------- |
| ------- | ------------- |
| boolean | Whether the file is a directory.|
| boolean | Whether the file is a directory.|
**Example**
**Example**
...
@@ -2160,9 +2232,9 @@ Checks whether this file is a named pipe (or FIFO). Named pipes are used for int
...
@@ -2160,9 +2232,9 @@ Checks whether this file is a named pipe (or FIFO). Named pipes are used for int
**Return value**
**Return value**
| Type | Description |
| Type | Description |
| ------- | --------------------- |
| ------- | --------------------- |
| boolean | Whether the file is a FIFO.|
| boolean | Whether the file is a FIFO.|
**Example**
**Example**
...
@@ -2182,9 +2254,9 @@ Checks whether this file is a regular file.
...
@@ -2182,9 +2254,9 @@ Checks whether this file is a regular file.
**Return value**
**Return value**
| Type | Description |
| Type | Description |
| ------- | --------------- |
| ------- | --------------- |
| boolean | Whether the file is a regular file.|
| boolean | Whether the file is a regular file.|
**Example**
**Example**
...
@@ -2204,9 +2276,9 @@ Checks whether this file is a socket.
...
@@ -2204,9 +2276,9 @@ Checks whether this file is a socket.
**Return value**
**Return value**
| Type | Description |
| Type | Description |
| ------- | -------------- |
| ------- | -------------- |
| boolean | Whether the file is a socket.|
| boolean | Whether the file is a socket.|
**Example**
**Example**
...
@@ -2226,9 +2298,9 @@ Checks whether this file is a symbolic link.
...
@@ -2226,9 +2298,9 @@ Checks whether this file is a symbolic link.
**Return value**
**Return value**
| Type | Description |
| Type | Description |
| ------- | --------------- |
| ------- | --------------- |
| boolean | Whether the file is a symbolic link.|
| boolean | Whether the file is a symbolic link.|
**Example**
**Example**
...
@@ -2252,9 +2324,9 @@ Closes the stream. This API uses a promise to return the result.
...
@@ -2252,9 +2324,9 @@ Closes the stream. This API uses a promise to return the result.
**Return value**
**Return value**
| Type | Description |
| Type | Description |
| ------------------- | ------------- |
| ------------------- | ------------- |
| Promise<void> | Promise used to return the stream close result.|
| Promise<void> | Promise used to return the stream close result.|
**Example**
**Example**
...
@@ -2279,9 +2351,9 @@ Closes the stream. This API uses an asynchronous callback to return the result.
...
@@ -2279,9 +2351,9 @@ Closes the stream. This API uses an asynchronous callback to return the result.
| buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. |
| 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:<br>- **length** (number): length of the data to write. The default value is the buffer length.<br>- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.<br>- **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.|
| options | Object | No | The options are as follows:<br>- **length** (number): length of the data to write. The default value is the buffer length.<br>- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.<br>- **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**
**Return value**
| Type | Description |
| Type | Description |
| --------------------- | -------- |
| --------------------- | -------- |
| Promise<number> | Promise used to return the length of the data written.|
| Promise<number> | Promise used to return the length of the data written.|
**Example**
**Example**
...
@@ -2428,11 +2500,11 @@ Writes data into the stream. This API uses an asynchronous callback to return th
...
@@ -2428,11 +2500,11 @@ Writes data into the stream. This API uses an asynchronous callback to return th
| buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. |
| 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:<br>- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.<br>- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.<br>- **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.|
| options | Object | No | The options are as follows:<br>- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.<br>- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.<br>- **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. |
| callback | AsyncCallback<number> | Yes | Callback invoked when the data is written asynchronously. |
**Example**
**Example**
...
@@ -2460,16 +2532,16 @@ Synchronously writes data into the stream.
...
@@ -2460,16 +2532,16 @@ Synchronously writes data into the stream.
| buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. |
| 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:<br>- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.<br>- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.<br>- **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.|
| options | Object | No | The options are as follows:<br>- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.<br>- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.<br>- **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**
**Return value**
| Type | Description |
| Type | Description |
| ------ | -------- |
| ------ | -------- |
| number | Length of the data written in the file.|
| number | Length of the data written in the file.|
**Example**
**Example**
...
@@ -2489,16 +2561,16 @@ Reads data from the stream. This API uses a promise to return the result.
...
@@ -2489,16 +2561,16 @@ Reads data from the stream. This API uses a promise to return the result.
| buffer | ArrayBuffer | Yes | Buffer used to store the file read. |
| buffer | ArrayBuffer | Yes | Buffer used to store the file read. |
| options | Object | No | The options are as follows:<br>- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length.<br>- **offset** (number): position of the data to read in the file. By default, data is read from the current position.|
| options | Object | No | The options are as follows:<br>- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length.<br>- **offset** (number): position of the data to read in the file. By default, data is read from the current position.|
**Return value**
**Return value**
| Type | Description |
| Type | Description |
| ---------------------------------- | ------ |
| ---------------------------------- | ------ |
| Promise<number> | Promise used to return the data read.|
| Promise<number> | Promise used to return the data read.|
**Example**
**Example**
...
@@ -2525,11 +2597,11 @@ Reads data from the stream. This API uses an asynchronous callback to return the
...
@@ -2525,11 +2597,11 @@ Reads data from the stream. This API uses an asynchronous callback to return the
| buffer | ArrayBuffer | Yes | Buffer used to store the file read. |
| buffer | ArrayBuffer | Yes | Buffer used to store the file read. |
| options | Object | No | The options are as follows:<br>- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length.<br>- **offset** (number): position of the data to read in the file. This parameter is optional. By default, data is read from the current position.|
| options | Object | No | The options are as follows:<br>- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length.<br>- **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. |
| callback | AsyncCallback<number> | Yes | Callback invoked when data is read asynchronously from the stream. |
**Example**
**Example**
...
@@ -2557,16 +2629,16 @@ Synchronously reads data from the stream.
...
@@ -2557,16 +2629,16 @@ Synchronously reads data from the stream.
| buffer | ArrayBuffer | Yes | Buffer used to store the file read. |
| buffer | ArrayBuffer | Yes | Buffer used to store the file read. |
| options | Object | No | The options are as follows:<br>- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length.<br>- **offset** (number): position of the data to read in the file. This parameter is optional. By default, data is read from the current position.<br> |
| options | Object | No | The options are as follows:<br>- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length.<br>- **offset** (number): position of the data to read in the file. This parameter is optional. By default, data is read from the current position.<br> |
**Return value**
**Return value**
| Type | Description |
| Type | Description |
| ------ | -------- |
| ------ | -------- |
| number | Length of the data read.|
| number | Length of the data read.|
**Example**
**Example**
...
@@ -2598,15 +2670,15 @@ Applies an exclusive lock or a shared lock on this file in blocking mode. This A
...
@@ -2598,15 +2670,15 @@ Applies an exclusive lock or a shared lock on this file in blocking mode. This A
@@ -5,7 +5,7 @@ The **securityLabel** module provides APIs for managing data security levels of
...
@@ -5,7 +5,7 @@ The **securityLabel** module provides APIs for managing data security levels of
> **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.
> - 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
## Modules to Import
...
@@ -45,7 +45,7 @@ For details about how to obtain the FA model context, see [Context](js-apis-inne
...
@@ -45,7 +45,7 @@ For details about how to obtain the FA model context, see [Context](js-apis-inne
> 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 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.
...
@@ -1818,9 +1818,9 @@ Enumerates the user authentication types.
| 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 |
| 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.
...
@@ -2889,11 +2889,6 @@ Enumerates the error codes.
| HUKS_ERROR_NEW_ROOT_KEY_MATERIAL_EXIST | -36 |New root key material exists.|
| 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_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_VERIFICATION_FAILED | -38 |Failed to verify the certificate chain.|
| HUKS_ERROR_GET_USERIAM_SECINFO_FAILED<sup>9+</sup> | -40 |Failed to obtain the security attribute information of the user.|
| HUKS_ERROR_GET_USERIAM_AUTHINFO_FAILED<sup>9+</sup> | -41 |Failed to obtain the authentication information of the user.|
| HUKS_ERROR_USER_AUTH_TYPE_NOT_SUPPORT<sup>9+</sup> | -42 |The access control of the current authentication type is not supported.|
| HUKS_ERROR_KEY_AUTH_FAILED<sup>9+</sup> | -43 |The access control authentication has failed.|
| HUKS_ERROR_DEVICE_NO_CREDENTIAL<sup>9+</sup> | -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_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_KEY_SIZE_FAIL | -101 |Failed to obtain the key size.|
| HUKS_ERROR_CHECK_GET_PADDING_FAIL | -102 |Failed to obtain the padding algorithm.|
| HUKS_ERROR_CHECK_GET_PADDING_FAIL | -102 |Failed to obtain the padding algorithm.|
...
@@ -2920,7 +2915,5 @@ Enumerates the error codes.
...
@@ -2920,7 +2915,5 @@ Enumerates the error codes.
| HUKS_ERROR_INVALID_SALT | -123 |Invalid salt value.|
| HUKS_ERROR_INVALID_SALT | -123 |Invalid salt value.|