| elementName | [ElementName](js-apis-bundleManager-elementName.md#elementname) | Yes| Application description, which includes the bundle name and component name.|
| type | [CardType](#cardtype) | Yes| Application description, which includes the bundle name and component name.|
**Return value**
**Return value**
| **Type**| **Description**|
| **Type**| **Description**|
| -------- | -------- |
| -------- | -------- |
| boolean | Returns **true** if the application is the default payment application; returns **false** otherwise.|
| boolean | Returns **true** if HCE is supported; returns **false** otherwise.|
## HceService<sup>8+</sup>
Implements HCE, including receiving Application Protocol Data Units (APDUs) from the peer card reader and sending a response. Before using HCE-related APIs, check whether the device supports HCE.
### startHCE<sup>8+</sup>
startHCE(aidList: string[]): boolean
Starts HCE, including setting the application to be foreground preferred and dynamically registering the application identifier (AID) list.
| type | string | Yes | Event type to subscribe to. The value is **hceCmd**. |
| elementName | [ElementName](js-apis-bundleManager-elementName.md#elementname) | Yes| Application description, which consists of the bundle name and component name.|
| callback | AsyncCallback<number[]> | Yes | Callback invoked to return the APDU, which consists of hexadecimal numbers ranging from **0x00** to **0xFF**.|
| type | [CardType](#cardtype9) | Yes| Card emulation service type.|
| responseApdu | number[] | Yes | Response APDU sent to the peer card reader. The value consists of hexadecimal numbers ranging from **0x00** to **0xFF**.|
| boolean | Returns **true** if the application is the default payment application; returns **false** otherwise.|
@@ -184,6 +195,11 @@ Verifies the certificate signature. This API uses an asynchronous callback to re
...
@@ -184,6 +195,11 @@ Verifies the certificate signature. This API uses an asynchronous callback to re
| key | cryptoFramework.PubKey | Yes | Public key used for signature verification. |
| key | cryptoFramework.PubKey | Yes | Public key used for signature verification. |
| callback | AsyncCallback\<void> | Yes | Callback invoked to return the result. If **error** is **null**, the signature verification is successful. If **error** is not **null**, the signature verification fails.|
| callback | AsyncCallback\<void> | Yes | Callback invoked to return the result. If **error** is **null**, the signature verification is successful. If **error** is not **null**, the signature verification fails.|
**Error codes**
| ID| Error Message |
| -------- | ------------------ |
| 19030001 | Crypto operation error. |
**Example**
**Example**
...
@@ -235,6 +251,12 @@ Verifies the certificate signature. This API uses a promise to return the result
...
@@ -235,6 +251,12 @@ Verifies the certificate signature. This API uses a promise to return the result
| -------------- | ----------- |
| -------------- | ----------- |
| Promise\<void> | Promise used to return the result.|
| Promise\<void> | Promise used to return the result.|
**Error codes**
| ID| Error Message |
| -------- | ------------------ |
| 19030001 | Crypto operation error. |
**Example**
**Example**
```js
```js
...
@@ -275,6 +297,13 @@ Obtains the serialized X.509 certificate data. This API uses an asynchronous cal
...
@@ -275,6 +297,13 @@ Obtains the serialized X.509 certificate data. This API uses an asynchronous cal
| callback | AsyncCallback\<[EncodingBlob](#encodingblob)> | Yes | Callback invoked to return the result. Promise used to return the serialized X.509 certificate data obtained.|
| callback | AsyncCallback\<[EncodingBlob](#encodingblob)> | Yes | Callback invoked to return the result. Promise used to return the serialized X.509 certificate data obtained.|
| string | Start time of the X509 certificate validity period, in the YYMMDDHHMMSSZ or YYYYMMDDHHMMSSZ format. The value must end with **Z**, which indicates the UTC.|
| string | Start time of the X509 certificate validity period, in the YYMMDDHHMMSSZ or YYYYMMDDHHMMSSZ format. The value must end with **Z**, which indicates the UTC.|
| string | Expiration time of the X509 certificate validity period, in the YYMMDDHHMMSSZ or YYYYMMDDHHMMSSZ format. The value must end with **Z**, which indicates the UTC.|
| string | Expiration time of the X509 certificate validity period, in the YYMMDDHHMMSSZ or YYYYMMDDHHMMSSZ format. The value must end with **Z**, which indicates the UTC.|
| Promise\<EncodingBlob> | Promise used to return the serialized X.509 CRL data obtained.|
| Promise\<EncodingBlob> | Promise used to return the serialized X.509 CRL data obtained.|
**Error codes**
| ID| Error Message |
| -------- | ----------------------- |
| 19020001 | Memory error. |
| 19020002 | Runtime error. |
| 19030001 | Crypto operation error. |
**Example**
**Example**
```js
```js
...
@@ -1227,6 +1401,11 @@ Verifies the signature of the X.509 CRL. This API uses an asynchronous callback
...
@@ -1227,6 +1401,11 @@ Verifies the signature of the X.509 CRL. This API uses an asynchronous callback
| key | cryptoFramework.PubKey | Yes | Public key used for signature verification. |
| key | cryptoFramework.PubKey | Yes | Public key used for signature verification. |
| callback | AsyncCallback\<void> | Yes | Callback invoked to return the result. If **error** is **null**, the signature verification is successful. If **error** is not **null**, the signature verification fails.|
| callback | AsyncCallback\<void> | Yes | Callback invoked to return the result. If **error** is **null**, the signature verification is successful. If **error** is not **null**, the signature verification fails.|
**Error codes**
| ID| Error Message |
| -------- | ----------------------- |
| 19030001 | Crypto operation error. |
**Example**
**Example**
...
@@ -1279,6 +1458,12 @@ Verifies the signature of the X.509 CRL. This API uses a promise to return the r
...
@@ -1279,6 +1458,12 @@ Verifies the signature of the X.509 CRL. This API uses a promise to return the r
| callback | AsyncCallback<Array\<X509CrlEntry>> | Yes | Callback invoked to return the result. Promise used to return a list of revoked X.509 certificates.|
| callback | AsyncCallback<Array\<X509CrlEntry>> | Yes | Callback invoked to return the result. Promise used to return a list of revoked X.509 certificates.|
**Error codes**
| ID| Error Message |
| -------- | ----------------------- |
| 19020001 | Memory error. |
| 19030001 | Crypto operation error. |
**Example**
**Example**
...
@@ -1603,6 +1832,13 @@ Obtains all the revoked X.509 certificates. This API uses a promise to return th
...
@@ -1603,6 +1832,13 @@ Obtains all the revoked X.509 certificates. This API uses a promise to return th
Validates the X.509 certificate chain. This API uses an asynchronous callback to return the result.
Validates the X.509 certificate chain. This API uses an asynchronous callback to return the result.
The certificate chain validator does not verify the certificate validity period because the system time on the device is untrusted. To check the validity period of a certificate, use the [checkValidityWithDate()](#checkvaliditywithdate) API of the **X509Cert** class. For details, see [Certificate Specifications](../../security/cert-overview.md#certificate-specifications).
The certificate chain validator does not verify the certificate validity period because the system time on the device is untrusted. To check the validity period of a certificate, use the [checkValidityWithDate()](#checkvaliditywithdate) API of the **X509Cert** class. For details, see [Certificate Specifications](./../security/cert-overview.md#certificate-specifications).
| callback | AsyncCallback\<void> | Yes | Callback invoked to return the result. If **error** is **null**, the X.509 certificate chain is valid. If **error** is not **null**, the X.509 certificate chain is not valid.|
| callback | AsyncCallback\<void> | Yes | Callback invoked to return the result. If **error** is **null**, the X.509 certificate chain is valid. If **error** is not **null**, the X.509 certificate chain is not valid.|
Validates the X.509 certificate chain. This API uses a promise to return the result.
Validates the X.509 certificate chain. This API uses a promise to return the result.
The certificate chain validator does not verify the certificate validity period because the system time on the device is untrusted. To check the validity period of a certificate, use the [checkValidityWithDate()](#checkvaliditywithdate) API of the **X509Cert** class. For details, see [Certificate Specifications](../../security/cert-overview.md#certificate-specifications).
The certificate chain validator does not verify the certificate validity period because the system time on the device is untrusted. To check the validity period of a certificate, use the [checkValidityWithDate()](#checkvaliditywithdate) API of the **X509Cert** class. For details, see [Certificate Specifications](./../security/cert-overview.md#certificate-specifications).
| callback | AsyncCallback\<[EncodingBlob](#encodingblob)> | Yes | Callback invoked to return the result. Promise used to return the serialized data of the revoked certificate obtained.|
| callback | AsyncCallback\<[EncodingBlob](#encodingblob)> | Yes | Callback invoked to return the result. Promise used to return the serialized data of the revoked certificate obtained.|
**Error codes**
| ID| Error Message |
| -------- | ----------------------- |
| 19020001 | Memory error. |
| 19020002 | Runtime error. |
| 19030001 | Crypto operation error. |
**Example**
**Example**
...
@@ -2011,6 +2329,14 @@ Obtains the serialized data of this revoked certificate. This API uses a promise
...
@@ -2011,6 +2329,14 @@ Obtains the serialized data of this revoked certificate. This API uses a promise
| algName | string | Yes | Digest algorithm. For details about the supported algorithms, see [HMAC Algorithm Specifications](../../security/cryptoFramework-overview.md#hmac-algorithm-specifications).|
| algName | string | Yes | Digest algorithm. For details about the supported algorithms, see [HMAC Algorithm Specifications](../../security/cryptoFramework-overview.md#hmac-algorithm-specifications).|
**Return value**
**Return value**
...
@@ -483,7 +483,7 @@ For details about the supported specifications, see [MD Algorithm Specifications
...
@@ -483,7 +483,7 @@ For details about the supported specifications, see [MD Algorithm Specifications
| algName | string | Yes | Digest algorithm. For details about the supported algorithms, see [MD Algorithm Specifications](../../security/cryptoFramework-overview.md#md-algorithm-specifications).|
| algName | string | Yes | Digest algorithm. For details about the supported algorithms, see [MD Algorithm Specifications](../../security/cryptoFramework-overview.md#md-algorithm-specifications).|
**Return value**
**Return value**
...
@@ -1852,7 +1852,7 @@ Updates the data to encrypt or decrypt by segment. This API uses a promise to re
...
@@ -1852,7 +1852,7 @@ Updates the data to encrypt or decrypt by segment. This API uses a promise to re
@@ -8,7 +8,7 @@ The **relationalStore** module provides the following functions:
...
@@ -8,7 +8,7 @@ The **relationalStore** module provides the following functions:
-[RdbStore](#rdbstore): provides APIs for managing data in an RDB store.
-[RdbStore](#rdbstore): provides APIs for managing data in an RDB store.
-[Resultset](#resultset): provides APIs for accessing the result set obtained from the RDB store.
-[Resultset](#resultset): provides APIs for accessing the result set obtained from the RDB store.
> **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.
...
@@ -30,7 +30,7 @@ Obtains an RDB store. This API uses an asynchronous callback to return the resul
...
@@ -30,7 +30,7 @@ Obtains an RDB store. This API uses an asynchronous callback to return the resul
| 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-ability-context.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).|
| config | [StoreConfig](#storeconfig) | Yes | Configuration of the RDB store. |
| config | [StoreConfig](#storeconfig) | Yes | Configuration of the RDB store. |
| callback | AsyncCallback<[RdbStore](#rdbstore)> | Yes | Callback invoked to return the RDB store obtained. |
| callback | AsyncCallback<[RdbStore](#rdbstore)> | Yes | Callback invoked to return the RDB store obtained. |
...
@@ -108,7 +108,7 @@ Obtains an RDB store. This API uses a promise to return the result. You can set
...
@@ -108,7 +108,7 @@ Obtains an RDB store. This API uses a promise to return the result. You can set
| 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-ability-context.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).|
| config | [StoreConfig](#storeconfig) | Yes | Configuration of the RDB store. |
| config | [StoreConfig](#storeconfig) | Yes | Configuration of the RDB store. |
**Return value**
**Return value**
...
@@ -188,7 +188,7 @@ Deletes an RDB store. This API uses an asynchronous callback to return the resul
...
@@ -188,7 +188,7 @@ Deletes an RDB store. This API uses an asynchronous callback to return the resul
| 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-ability-context.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 RDB store to delete. |
| name | string | Yes | Name of the RDB store to delete. |
| callback | AsyncCallback<void> | Yes | Callback invoked to return the result. |
| callback | AsyncCallback<void> | Yes | Callback invoked to return the result. |
...
@@ -249,7 +249,7 @@ Deletes an RDB store. This API uses a promise to return the result.
...
@@ -249,7 +249,7 @@ Deletes an RDB store. This API uses a promise to return the result.
| 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-ability-context.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 RDB store to delete. |
| name | string | Yes | Name of the RDB store to delete. |
**Return value**
**Return value**
...
@@ -363,6 +363,8 @@ Defines the database synchronization mode.
...
@@ -363,6 +363,8 @@ Defines the database synchronization mode.
@@ -5,7 +5,6 @@ The **fs** module provides APIs for file operations, including basic file manage
...
@@ -5,7 +5,6 @@ The **fs** module provides APIs for file operations, including basic file manage
> **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
...
@@ -60,9 +59,9 @@ Obtains detailed file information. This API uses a promise to return the result.
...
@@ -60,9 +59,9 @@ Obtains detailed file information. This API uses a promise to return the result.
**Return value**
**Return value**
| Type | Description |
| Type | Description |
| ---------------------------- | ---------- |
| ---------------------------- | ---------- |
| Promise<[Stat](#stat)> | Promise used to return the file information obtained.|
| Promise<[Stat](#stat)> | Promise used to return the file information obtained.|
**Example**
**Example**
...
@@ -119,9 +118,9 @@ Obtains detailed file information synchronously.
...
@@ -119,9 +118,9 @@ Obtains detailed file information synchronously.
**Return value**
**Return value**
| Type | Description |
| Type | Description |
| ------------- | ---------- |
| ------------- | ---------- |
| [Stat](#stat) | File information obtained.|
| [Stat](#stat) | File information obtained.|
**Example**
**Example**
...
@@ -146,9 +145,9 @@ Checks whether a file exists. This API uses a promise to return the result.
...
@@ -146,9 +145,9 @@ Checks whether a file exists. This API uses a promise to return the result.
| 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 +382,11 @@ Synchronously copies a file.
...
@@ -383,11 +382,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 +413,9 @@ Creates a directory. This API uses a promise to return the result.
...
@@ -414,9 +413,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 +653,17 @@ Synchronously reads data from a file.
...
@@ -654,17 +653,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 +692,9 @@ Deletes a directory. This API uses a promise to return the result.
...
@@ -693,9 +692,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 +888,12 @@ Writes data into a file. This API uses an asynchronous callback to return the re
...
@@ -889,12 +888,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 +921,17 @@ Synchronously writes data into a file.
...
@@ -922,17 +921,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 +960,9 @@ Truncates a file. This API uses a promise to return the result.
...
@@ -961,9 +960,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**
...
@@ -1608,7 +1607,7 @@ Lists all files in a directory. This API uses a promise to return the result.<br
...
@@ -1608,7 +1607,7 @@ Lists all files in a directory. This API uses a promise to return the result.<br
};
};
fs.listFile(pathDir,options).then((filenames)=>{
fs.listFile(pathDir,options).then((filenames)=>{
console.info("listFile succeed");
console.info("listFile succeed");
for(leti=0;i<filenames.size;i++){
for(leti=0;i<filenames.length;i++){
console.info("fileName: %s",filenames[i]);
console.info("fileName: %s",filenames[i]);
}
}
}).catch((err)=>{
}).catch((err)=>{
...
@@ -1627,19 +1626,19 @@ Lists all files in a directory. This API uses an asynchronous callback to return
...
@@ -1627,19 +1626,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**
...
@@ -1659,7 +1658,7 @@ Lists all files in a directory. This API uses an asynchronous callback to return
...
@@ -1659,7 +1658,7 @@ Lists all files in a directory. This API uses an asynchronous callback to return
console.info("list file failed with error message: "+err.message+", error code: "+err.code);
console.info("list file failed with error message: "+err.message+", error code: "+err.code);
}else{
}else{
console.info("listFile succeed");
console.info("listFile succeed");
for(leti=0;i<filenames.size;i++){
for(leti=0;i<filenames.length;i++){
console.info("filename: %s",filenames[i]);
console.info("filename: %s",filenames[i]);
}
}
}
}
...
@@ -1678,24 +1677,24 @@ Lists all files in a directory synchronously. This API supports recursive listin
...
@@ -1678,24 +1677,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**
...
@@ -1712,7 +1711,7 @@ Lists all files in a directory synchronously. This API supports recursive listin
...
@@ -1712,7 +1711,7 @@ Lists all files in a directory synchronously. This API supports recursive listin
};
};
letfilenames=fs.listFileSync(pathDir,options);
letfilenames=fs.listFileSync(pathDir,options);
console.info("listFile succeed");
console.info("listFile succeed");
for(leti=0;i<filenames.size;i++){
for(leti=0;i<filenames.length;i++){
console.info("filename: %s",filenames[i]);
console.info("filename: %s",filenames[i]);
}
}
```
```
...
@@ -1726,15 +1725,17 @@ Moves a file. This API uses a promise to return the result.
...
@@ -1726,15 +1725,17 @@ 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**
```js
```js
letsrcPath=pathDir+'/source.txt';
letdestPath=pathDir+'/dest.txt';
fs.moveFile(srcPath,destPath,0).then(()=>{
fs.moveFile(srcPath,destPath,0).then(()=>{
console.info("move file succeed");
console.info("move file succeed");
}).catch((err)=>{
}).catch((err)=>{
...
@@ -1752,16 +1753,18 @@ Moves a file. This API uses an asynchronous callback to return the result.
...
@@ -1752,16 +1753,18 @@ 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**
```js
```js
letsrcPath=pathDir+'/source.txt';
letdestPath=pathDir+'/dest.txt';
fs.moveFile(srcPath,destPath,0,(err)=>{
fs.moveFile(srcPath,destPath,0,(err)=>{
if(err){
if(err){
console.info("move file failed with error message: "+err.message+", error code: "+err.code);
console.info("move file failed with error message: "+err.message+", error code: "+err.code);
...
@@ -1781,15 +1784,17 @@ Moves a file synchronously.
...
@@ -1781,15 +1784,17 @@ 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**
```js
```js
letsrcPath=pathDir+'/source.txt';
letdestPath=pathDir+'/dest.txt';
fs.moveFileSync(srcPath,destPath,0);
fs.moveFileSync(srcPath,destPath,0);
console.info("move file succeed");
console.info("move file succeed");
```
```
...
@@ -1804,15 +1809,15 @@ Creates a temporary directory. This API uses a promise to return the result.
...
@@ -1804,15 +1809,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 +2019,11 @@ Opens a file stream based on the file descriptor. This API uses an asynchronous
...
@@ -2014,11 +2019,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 +2050,16 @@ Synchronously opens a stream based on the file descriptor.
...
@@ -2045,16 +2050,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**
...
@@ -2095,9 +2100,9 @@ Checks whether this file is a block special file. A block special file supports
...
@@ -2095,9 +2100,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 +2121,9 @@ Checks whether this file is a character special file. A character special file s
...
@@ -2116,9 +2121,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 +2143,9 @@ Checks whether this file is a directory.
...
@@ -2138,9 +2143,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 +2165,9 @@ Checks whether this file is a named pipe (or FIFO). Named pipes are used for int
...
@@ -2160,9 +2165,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 +2187,9 @@ Checks whether this file is a regular file.
...
@@ -2182,9 +2187,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 +2209,9 @@ Checks whether this file is a socket.
...
@@ -2204,9 +2209,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 +2231,9 @@ Checks whether this file is a symbolic link.
...
@@ -2226,9 +2231,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 +2257,9 @@ Closes the stream. This API uses a promise to return the result.
...
@@ -2252,9 +2257,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 +2284,9 @@ Closes the stream. This API uses an asynchronous callback to return the result.
...
@@ -2279,9 +2284,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 +2433,11 @@ Writes data into the stream. This API uses an asynchronous callback to return th
...
@@ -2428,11 +2433,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 +2465,16 @@ Synchronously writes data into the stream.
...
@@ -2460,16 +2465,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 +2494,16 @@ Reads data from the stream. This API uses a promise to return the result.
...
@@ -2489,16 +2494,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 +2530,11 @@ Reads data from the stream. This API uses an asynchronous callback to return the
...
@@ -2525,11 +2530,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 +2562,16 @@ Synchronously reads data from the stream.
...
@@ -2557,16 +2562,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 +2603,15 @@ Applies an exclusive lock or a shared lock on this file in blocking mode. This A
...
@@ -2598,15 +2603,15 @@ Applies an exclusive lock or a shared lock on this file in blocking mode. This A
@@ -6,6 +6,7 @@ The **fileAccess** module is a framework for accessing and operating user files
...
@@ -6,6 +6,7 @@ The **fileAccess** module is a framework for accessing and operating user files
>
>
>- 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 and cannot be called by third-party applications. Currently, the APIs can be called only by **FilePicker** and **Files**.
>- The APIs provided by this module are system APIs and cannot be called by third-party applications. Currently, the APIs can be called only by **FilePicker** and **Files**.
>- 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
...
@@ -25,9 +26,9 @@ Obtains information about all wants with **extension** set to **fileAccess** in
...
@@ -25,9 +26,9 @@ Obtains information about all wants with **extension** set to **fileAccess** in
**Return value**
**Return value**
| Type| Description|
| Type| Description|
| --- | -- |
| --- | -- |
| Promise<Array<Want>> | Promise used to return the **want** information obtained.|
| Promise<Array<Want>> | Promise used to return the **want** information obtained.|
**Example**
**Example**
...
@@ -55,9 +56,9 @@ Obtains information about all wants with **extension** set to **fileAccess** in
...
@@ -55,9 +56,9 @@ Obtains information about all wants with **extension** set to **fileAccess** in
**Parameters**
**Parameters**
| Name| Type| Mandatory| Description|
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| --- | --- | --- | -- |
| callback | AsyncCallback<Array<Want>> | Yes| Promise used to return the **want** information obtained.|
| callback | AsyncCallback<Array<Want>> | Yes| Promise used to return the **want** information obtained.|
**Example**
**Example**
...
@@ -89,16 +90,16 @@ Synchronously creates a **Helper** object to connect to the specified wants. The
...
@@ -89,16 +90,16 @@ Synchronously creates a **Helper** object to connect to the specified wants. The
**Parameters**
**Parameters**
| Name| Type| Mandatory| Description|
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| --- | --- | --- | -- |
| context | Context | Yes| Context of the ability.|
| context | Context | Yes| Context of the ability.|
| wants | Array<Want> | Yes| Wants to connect.|
| wants | Array<Want> | Yes| Wants to connect.|
**Return value**
**Return value**
| Type| Description|
| Type| Description|
| --- | -- |
| --- | -- |
| FileAccessHelper | **Helper** object created.|
| FileAccessHelper | **Helper** object created.|
**Example**
**Example**
...
@@ -136,15 +137,15 @@ Synchronously creates a **Helper** object to connect to all file management serv
...
@@ -136,15 +137,15 @@ Synchronously creates a **Helper** object to connect to all file management serv
**Parameters**
**Parameters**
| Name| Type| Mandatory| Description|
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| --- | --- | --- | -- |
| context | Context | Yes| Context of the ability.|
| context | Context | Yes| Context of the ability.|
**Return value**
**Return value**
| Type| Description|
| Type| Description|
| --- | -- |
| --- | -- |
| FileAccessHelper | **Helper** object created.|
| FileAccessHelper | **Helper** object created.|
**Example**
**Example**
...
@@ -175,9 +176,9 @@ Obtains information about the device root nodes of the file management service t
...
@@ -175,9 +176,9 @@ Obtains information about the device root nodes of the file management service t
**Return value**
**Return value**
| Type| Description|
| Type| Description|
| --- | -- |
| --- | -- |
| Promise<RootIterator> | Promise used to return the **RootIterator** object obtained.|
| Promise<RootIterator> | Promise used to return the **RootIterator** object obtained.|
**Example**
**Example**
...
@@ -220,9 +221,9 @@ The callback has a **RootIterator** object, which returns [RootInfo](#rootinfo)
...
@@ -220,9 +221,9 @@ The callback has a **RootIterator** object, which returns [RootInfo](#rootinfo)
**Parameters**
**Parameters**
| Name| Type| Mandatory| Description|
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| --- | --- | --- | -- |
| callback | AsyncCallback<RootIterator> | Yes| Promise used to return the **RootIterator** object obtained.|
| callback | AsyncCallback<RootIterator> | Yes| Promise used to return the **RootIterator** object obtained.|
**Example**
**Example**
...
@@ -263,16 +264,16 @@ Synchronously obtains the **FileIterator** object of the first-level files (dire
...
@@ -263,16 +264,16 @@ Synchronously obtains the **FileIterator** object of the first-level files (dire
The **nfcController** module provides APIs for opening and closing Near-Field Communication (NFC) and reading the NFC state.
The **nfcController** module provides APIs for opening and closing Near-Field Communication (NFC) and reading the NFC state.
> **NOTE**<br>
> **NOTE**
>
> The initial APIs of this module are supported since API version 7. 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 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use canIUse("SystemCapability.Communication.NFC.Core").
| taginfo | [TagInfo](#taginfo) | Yes| Tag information including the technology type and related parameters, which are obtained from **tag.getTagInfo(want: Want)**.
| taginfo | [TagInfo](#taginfo) | Yes| Tag information including the technology type and related parameters, which are obtained from **tag.getTagInfo(want: Want)**.
| taginfo | [TagInfo](#taginfo) | Yes| Tag information including the technology type and related parameters, which are obtained from **tag.getTagInfo(want: Want)**.
| taginfo | [TagInfo](#taginfo) | Yes| Tag information including the technology type and related parameters, which are obtained from **tag.getTagInfo(want: Want)**.
| taginfo | [TagInfo](#taginfo) | Yes| Tag information including the technology type and related parameters, which are obtained from **tag.getTagInfo(want: Want)**.
| taginfo | [TagInfo](#taginfo) | Yes| Tag information including the technology type and related parameters, which are obtained from **tag.getTagInfo(want: Want)**.
| taginfo | [TagInfo](#taginfo) | Yes| Tag information including the technology type and related parameters, which are obtained from **tag.getTagInfo(want: Want)**.
| taginfo | [TagInfo](#taginfo) | Yes| Tag information including the technology type and related parameters, which are obtained from **tag.getTagInfo(want: Want)**.
Obtains the **tagInfo** object provided by the NFC service when the tag is dispatched.
Obtains the **tagInfo** object provided by the NFC service when the tag is dispatched.
> **NOTE**
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [tag.getTagInfo](js-apis-nfcTag.md#taggettaginfo9).
For details about the error codes, see [NFC Error Codes](../errorcodes/errorcode-nfc.md).
| ID| Error message|
| ------- | -------|
| 3100201 | Tag running state is abnormal in service. |
**Example**
```js
importtagfrom'@ohos.nfc.tag';
// tagInfo is an object provided by the NFC service when a tag is dispatched.
// getXXX can be getIsoDep, getNdef, getMifareClassic, or any other getter for NFC tags.
try{
tag.getIsoDep(tagInfo).connect();
console.log("tag connect success");
}catch(busiError){
console.log("tag connect busiError: "+busiError);
}
```
### tagSession.reset()
### tagSession.reset()
reset(): void
reset(): void
Resets the connection to this tag.
Resets the connection to this tag.
> **NOTE**
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [tagSession.resetConnection](#tagsessionresetconnection9).
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [tagSession.isConnected](#tagsessionisconnected9).
Obtains the maximum length of the data that can be sent to this tag.
Obtains the maximum length of the data that can be sent to this tag.
> **NOTE**
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [tagSession.getMaxTransmitSize](#tagsessiongetmaxtransmitsize9).
Obtains the timeout period for sending data to this tag, in milliseconds.
Obtains the timeout period for sending data to this tag, in milliseconds.
> **NOTE**
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [tagSession.getTimeout](#tagsessiongettimeout9).
Sets the timeout period for sending data to this tag, in milliseconds.
Sets the timeout period for sending data to this tag, in milliseconds.
> **NOTE**
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [tagSession.setTimeout](#tagsessionsettimeout9).
Sends data to this tag. This API uses an asynchronous callback to return the result.
Sends data to this tag. This API uses an asynchronous callback to return the result.
> **NOTE**
> This parameter is supported since API version 7 and discarded since API version 9. You are advised to use [tagSession.transmit](#tagsessiontransmit9-1).
| Promise<number[]> | Promise used to return the response from the tag. The response consists of hexadecimal numbers ranging from **0x00** to **0xFF**.|
**Error codes**
For details about the error codes, see [NFC Error Codes](../errorcodes/errorcode-nfc.md).
| ID| Error message|
| ------- | -------|
| 3100201 | Tag running state is abnormal in service. |
**Example**
```js
importtagfrom'@ohos.nfc.tag';
// tagInfo is an object provided by the NFC service when a tag is dispatched.
// getXXX can be getIsoDep, getNdef, getMifareClassic, or any other getter for NFC tags.
// Connect to the tag if it is not connected.
try{
if(!tag.getIsoDep(tagInfo).isConnected()){
tag.getIsoDep(tagInfo).connect();
}
}catch(busiError){
console.log("tag connect busiError: "+busiError);
return;
}
letcmdData=[0x01,0x02,0x03,0x04];// Change it as required.
| data | number[] | Yes| Data to send. The data consists of hexadecimal numbers ranging from **0x00** to **0xFF**.|
| callback | AsyncCallback<number[]> | Yes| Callback invoked to return the response from the tag. The response consists of hexadecimal numbers ranging from **0x00** to **0xFF**.|
**Error codes**
For details about the error codes, see [NFC Error Codes](../errorcodes/errorcode-nfc.md).
| ID| Error message|
| ------- | -------|
| 3100201 | Tag running state is abnormal in service. |
**Example**
```js
importtagfrom'@ohos.nfc.tag';
// tagInfo is an object provided by the NFC service when a tag is dispatched.
// getXXX can be getIsoDep, getNdef, getMifareClassic, or any other getter for NFC tags.
// Connect to the tag if it is not connected.
try{
if(!tag.getIsoDep(tagInfo).isConnected()){
tag.getIsoDep(tagInfo).connect();
}
}catch(busiError){
console.log("tag connect busiError: "+busiError);
return;
}
letcmdData=[0x01,0x02,0x03,0x04];// Change it as required.
# Changelog of NFC JS APIs in the Communication Subsystem
Compared with OpenHarmony 3.2 Beta4, OpenHarmony 3.2.10.2(Mr) has the following changes in NFC APIs:
## cl.nfc.1 API Change
Deprecated some NFC JS APIs in API versions 6 to 8 because the APIs cannot throw error codes, and added new APIs in API version 9 instead.
You need to adapt your application.
**Change Impact**
The deprecated JS APIs in API versions 6 to 8 are affected. Your application needs to adapt new APIs so that it can properly implement functions in the SDK environment of the new version.
**Key API/Component Changes**
| Module | Class | Method/Attribute/Enum/Constant | Change Type|