未验证 提交 405eeba9 编写于 作者: O openharmony_ci 提交者: Gitee

!4961 #I57M8E完成

Merge pull request !4961 from Annie_wang/OpenHarmony-3.1-Release
...@@ -636,7 +636,7 @@ Sets the **RdbPredicates** to match the specified string. ...@@ -636,7 +636,7 @@ Sets the **RdbPredicates** to match the specified string.
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| field | string | Yes| Column name in the database table.| | field | string | Yes| Column name in the database table.|
| value | string | Yes| Value to match the **RdbPredicates**.<br><br>Wildcards are supported. ***** indicates zero, one, or multiple digits or characters. **?** indicates a single digit or character.| | value | string | Yes| Value to match the **RdbPredicates**.<br><br>Wildcards are supported. * indicates zero, one, or multiple digits or characters. ? indicates a single digit or character.|
**Return value** **Return value**
| Type| Description| | Type| Description|
...@@ -1390,7 +1390,7 @@ promise.then((resultSet) => { ...@@ -1390,7 +1390,7 @@ promise.then((resultSet) => {
executeSql(sql: string, bindArgs: Array&lt;ValueType&gt;, callback: AsyncCallback&lt;void&gt;):void executeSql(sql: string, bindArgs: Array&lt;ValueType&gt;, callback: AsyncCallback&lt;void&gt;):void
Runs the SQL statement that contains the specified parameters but does not return a value. This API uses a callback to return the execution result. Runs the SQL statement that contains the specified parameters but does not return a value. This API uses a callback to return the result.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
...@@ -1555,9 +1555,9 @@ rdbStore.setDistributedTables(["EMPLOYEE"], function (err) { ...@@ -1555,9 +1555,9 @@ rdbStore.setDistributedTables(["EMPLOYEE"], function (err) {
console.info('setDistributedTables failed, err: ' + err) console.info('setDistributedTables failed, err: ' + err)
return return
} }
console.info('setDistributedTables successful.') console.info('setDistributedTables successfully.')
}) })
``` ```
### setDistributedTables<sup>8+</sup> ### setDistributedTables<sup>8+</sup>
...@@ -1582,7 +1582,7 @@ Sets a list of distributed tables. This API uses a promise to return the result. ...@@ -1582,7 +1582,7 @@ Sets a list of distributed tables. This API uses a promise to return the result.
```js ```js
let promise = rdbStore.setDistributedTables(["EMPLOYEE"]) let promise = rdbStore.setDistributedTables(["EMPLOYEE"])
promise.then(() => { promise.then(() => {
console.info("setDistributedTables successful.") console.info("setDistributedTables successfully.")
}).catch((err) => { }).catch((err) => {
console.info("setDistributedTables failed, err: " + err) console.info("setDistributedTables failed, err: " + err)
}) })
...@@ -1610,7 +1610,7 @@ rdbStore.obtainDistributedTableName(deviceId, "EMPLOYEE", function (err, tableNa ...@@ -1610,7 +1610,7 @@ rdbStore.obtainDistributedTableName(deviceId, "EMPLOYEE", function (err, tableNa
console.info('obtainDistributedTableName failed, err: ' + err) console.info('obtainDistributedTableName failed, err: ' + err)
return return
} }
console.info('obtainDistributedTableName successful, tableName=.' + tableName) console.info('obtainDistributedTableName successfully, tableName=.' + tableName)
}) })
``` ```
...@@ -1638,7 +1638,7 @@ Obtains the distributed table name for a remote device based on the local table ...@@ -1638,7 +1638,7 @@ Obtains the distributed table name for a remote device based on the local table
```js ```js
let promise = rdbStore.obtainDistributedTableName(deviceId, "EMPLOYEE") let promise = rdbStore.obtainDistributedTableName(deviceId, "EMPLOYEE")
promise.then((tableName) => { promise.then((tableName) => {
console.info('obtainDistributedTableName successful, tableName=' + tableName) console.info('obtainDistributedTableName successfully, tableName=' + tableName)
}).catch((err) => { }).catch((err) => {
console.info('obtainDistributedTableName failed, err: ' + err) console.info('obtainDistributedTableName failed, err: ' + err)
}) })
......
...@@ -7,7 +7,7 @@ Lightweight storage provides applications with data processing capability and al ...@@ -7,7 +7,7 @@ Lightweight storage provides applications with data processing capability and al
> >
> 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.
> >
>
## Modules to Import ## Modules to Import
...@@ -22,15 +22,15 @@ import dataStorage from '@ohos.data.storage'; ...@@ -22,15 +22,15 @@ import dataStorage from '@ohos.data.storage';
| Name| Type| Readable| Writable| Description| | Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| MAX_KEY_LENGTH | string | Yes| No| Maximum length of a key. It is 80 bytes.| | MAX_KEY_LENGTH | string | Yes| No| Maximum length of a key. It must be less than 80 bytes.|
| MAX_VALUE_LENGTH | string | Yes| No| Maximum length of a value. It is 8192 bytes.| | MAX_VALUE_LENGTH | string | Yes| No| Maximum length of a value. It must be less than 8192 bytes.|
## dataStorage.getStorageSync ## dataStorage.getStorageSync
getStorageSync(path: string): Storage getStorageSync(path: string): Storage
Reads the specified file and load its data to the **Storage** instance for data operations. Reads the specified file and loads its data to the **Storage** instance for data operations.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
Distributed data management provides collaboration between databases of different devices for applications. The APIs provided by distributed data management can be used to save data to the distributed database and perform operations such as adding, deleting, modifying, and querying data in the distributed database. Distributed data management provides collaboration between databases of different devices for applications. The APIs provided by distributed data management can be used to save data to the distributed database and perform operations such as adding, deleting, modifying, and querying data in the distributed database.
>**NOTE**<br/> >**NOTE**<br/>
>
>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.
...@@ -610,14 +611,14 @@ Defines the KV store constants. ...@@ -610,14 +611,14 @@ Defines the KV store constants.
| --- | ---- | ----------------------- | | --- | ---- | ----------------------- |
| MAX_KEY_LENGTH | 1024 | Maximum length (in bytes) of a key in the KV store. | | MAX_KEY_LENGTH | 1024 | Maximum length (in bytes) of a key in the KV store. |
| MAX_VALUE_LENGTH | 4194303 | Maximum length (in bytes) of a value in the KV store. | | MAX_VALUE_LENGTH | 4194303 | Maximum length (in bytes) of a value in the KV store. |
| MAX_KEY_LENGTH_DEVICE | 896 | Maximum length of the device coordinate key. | | MAX_KEY_LENGTH_DEVICE | 896 | Maximum length of the device coordinate key, in bytes.|
| MAX_STORE_ID_LENGTH | 128 | Maximum length (in bytes) of a KV store ID. | | MAX_STORE_ID_LENGTH | 128 | Maximum length (in bytes) of a KV store ID. |
| MAX_QUERY_LENGTH | 512000 | Maximum query length. | | MAX_QUERY_LENGTH | 512000 | Maximum query length, in bytes.|
| MAX_BATCH_SIZE | 128 | Maximum size of a batch operation. | | MAX_BATCH_SIZE | 128 | Maximum number of batch operations.|
## Schema<sup>8+</sup> ## ## Schema<sup>8+</sup> ##
Defines a database schema. When creating or opening a KV store, you can create a **Schema** object and put it into **Options**. Defines the schema of a KV store. When creating or opening a KV store, you can create a **Schema** object and put it in [Options](#options).
**System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore **System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
...@@ -731,15 +732,15 @@ let kvStore; ...@@ -731,15 +732,15 @@ let kvStore;
try { try {
let resultSet; let resultSet;
kvStore.getResultSet('batch_test_string_key').then((result) => { kvStore.getResultSet('batch_test_string_key').then((result) => {
console.log('getResultSet success'); console.log('getResultSet succeed.');
resultSet = result; resultSet = result;
}).catch((err) => { }).catch((err) => {
console.log('getResultSet fail ' + err); console.log('getResultSet failed:' + err);
}); });
const count = resultSet.getCount(); const count = resultSet.getCount();
console.log("GetCount " + count); console.log("getCount succeed:" + count);
} catch (e) { } catch (e) {
console.log("GetCount fail " + e); console.log("getCount failed: " + e);
} }
``` ```
...@@ -764,15 +765,15 @@ let kvStore; ...@@ -764,15 +765,15 @@ let kvStore;
try { try {
let resultSet; let resultSet;
kvStore.getResultSet('batch_test_string_key').then((result) => { kvStore.getResultSet('batch_test_string_key').then((result) => {
console.log('getResultSet success'); console.log('getResultSet succeeed.');
resultSet = result; resultSet = result;
}).catch((err) => { }).catch((err) => {
console.log('getResultSet fail ' + err); console.log('getResultSet failed:' + err);
}); });
const position = resultSet.getPosition(); const position = resultSet.getPosition();
console.log("getPosition " + position); console.log("getPosition succeed:" + position);
} catch (e) { } catch (e) {
console.log("GetPosition fail " + e); console.log("getPosition failed: " + e);
} }
``` ```
...@@ -798,15 +799,15 @@ let kvStore; ...@@ -798,15 +799,15 @@ let kvStore;
try { try {
let resultSet; let resultSet;
kvStore.getResultSet('batch_test_string_key').then((result) => { kvStore.getResultSet('batch_test_string_key').then((result) => {
console.log('getResultSet success'); console.log('getResultSet succeed.');
resultSet = result; resultSet = result;
}).catch((err) => { }).catch((err) => {
console.log('getResultSet fail ' + err); console.log('getResultSet failed: ' + err);
}); });
const moved = resultSet.moveToFirst(); const moved1 = resultSet.moveToFirst();
console.log("moveToFirst " + moved); console.log("moveToFirst succeed: " + moved1);
} catch (e) { } catch (e) {
console.log("MoveToFirst fail " + e); console.log("moveToFirst failed " + e);
} }
``` ```
...@@ -832,15 +833,15 @@ let kvStore; ...@@ -832,15 +833,15 @@ let kvStore;
try { try {
let resultSet; let resultSet;
kvStore.getResultSet('batch_test_string_key').then((result) => { kvStore.getResultSet('batch_test_string_key').then((result) => {
console.log('getResultSet success'); console.log('getResultSet succeed.');
resultSet = result; resultSet = result;
}).catch((err) => { }).catch((err) => {
console.log('getResultSet fail ' + err); console.log('getResultSet failed: ' + err);
}); });
const moved = resultSet.moveToLast(); const moved2 = resultSet.moveToLast();
console.log("moveToLast " + moved); console.log("moveToLast succeed:" + moved2);
} catch (e) { } catch (e) {
console.log("moveToLast fail " + e); console.log("moveToLast failed: " + e);
} }
``` ```
...@@ -866,15 +867,15 @@ let kvStore; ...@@ -866,15 +867,15 @@ let kvStore;
try { try {
let resultSet; let resultSet;
kvStore.getResultSet('batch_test_string_key').then((result) => { kvStore.getResultSet('batch_test_string_key').then((result) => {
console.log('getResultSet success'); console.log('getResultSet succeed.');
resultSet = result; resultSet = result;
}).catch((err) => { }).catch((err) => {
console.log('getResultSet fail ' + err); console.log('getResultSet failed: ' + err);
}); });
const moved = resultSet.moveToNext(); const moved3 = resultSet.moveToNext();
console.log("moveToNext " + moved); console.log("moveToNext succeed: " + moved3);
} catch (e) { } catch (e) {
console.log("moveToNext fail " + e); console.log("moveToNext failed: " + e);
} }
``` ```
...@@ -900,15 +901,15 @@ let kvStore; ...@@ -900,15 +901,15 @@ let kvStore;
try { try {
let resultSet; let resultSet;
kvStore.getResultSet('batch_test_string_key').then((result) => { kvStore.getResultSet('batch_test_string_key').then((result) => {
console.log('getResultSet success'); console.log('getResultSet succeed.');
resultSet = result; resultSet = result;
}).catch((err) => { }).catch((err) => {
console.log('getResultSet fail ' + err); console.log('getResultSet failed: ' + err);
}); });
const moved = resultSet.moveToPrevious(); const moved4 = resultSet.moveToPrevious();
console.log("moveToPrevious " + moved); console.log("moveToPrevious succeed:" + moved4);
} catch (e) { } catch (e) {
console.log("moveToPrevious fail " + e); console.log("moveToPrevious failed: " + e);
} }
``` ```
...@@ -940,15 +941,15 @@ let kvStore; ...@@ -940,15 +941,15 @@ let kvStore;
try { try {
let resultSet; let resultSet;
kvStore.getResultSet('batch_test_string_key').then((result) => { kvStore.getResultSet('batch_test_string_key').then((result) => {
console.log('getResultSet success'); console.log('getResultSet succeed.');
resultSet = result; resultSet = result;
}).catch((err) => { }).catch((err) => {
console.log('getResultSet fail ' + err); console.log('getResultSet failed: ' + err);
}); });
const moved = resultSet.move(); const moved5 = resultSet.move();
console.log("move " + moved); console.log("move succeed:" + moved5);
} catch (e) { } catch (e) {
console.log("move fail " + e); console.log("move failed: " + e);
} }
``` ```
...@@ -980,15 +981,15 @@ let kvStore; ...@@ -980,15 +981,15 @@ let kvStore;
try { try {
let resultSet; let resultSet;
kvStore.getResultSet('batch_test_string_key').then((result) => { kvStore.getResultSet('batch_test_string_key').then((result) => {
console.log('getResultSet success'); console.log('getResultSet succeed.');
resultSet = result; resultSet = result;
}).catch((err) => { }).catch((err) => {
console.log('getResultSet fail ' + err); console.log('getResultSet failed: ' + err);
}); });
const moved = resultSet.moveToPosition(); const moved6 = resultSet.moveToPosition();
console.log("moveToPosition " + moved); console.log("moveToPosition succeed: " + moved6);
} catch (e) { } catch (e) {
console.log("moveToPosition fail " + e); console.log("moveToPosition failed: " + e);
} }
``` ```
...@@ -1014,15 +1015,15 @@ let kvStore; ...@@ -1014,15 +1015,15 @@ let kvStore;
try { try {
let resultSet; let resultSet;
kvStore.getResultSet('batch_test_string_key').then((result) => { kvStore.getResultSet('batch_test_string_key').then((result) => {
console.log('getResultSet success'); console.log('getResultSet succeed.');
resultSet = result; resultSet = result;
}).catch((err) => { }).catch((err) => {
console.log('getResultSet fail ' + err); console.log('getResultSet failed: ' + err);
}); });
const moved = resultSet.isFirst(); const isfirst = resultSet.isFirst();
console.log("isFirst " + moved); console.log("Check isFirst succeed:" + isfirst);
} catch (e) { } catch (e) {
console.log("isFirst fail " + e); console.log("Check isFirst failed: " + e);
} }
``` ```
...@@ -1048,15 +1049,15 @@ let kvStore; ...@@ -1048,15 +1049,15 @@ let kvStore;
try { try {
let resultSet; let resultSet;
kvStore.getResultSet('batch_test_string_key').then((result) => { kvStore.getResultSet('batch_test_string_key').then((result) => {
console.log('getResultSet success'); console.log('getResultSet succeed.');
resultSet = result; resultSet = result;
}).catch((err) => { }).catch((err) => {
console.log('getResultSet fail ' + err); console.log('getResultSet failed: ' + err);
}); });
const moved = resultSet.isLast(); const islast = resultSet.isLast();
console.log("isLast " + moved); console.log("Check isLast succeed: " + islast);
} catch (e) { } catch (e) {
console.log("isLast fail " + e); console.log("Check isLast failed: " + e);
} }
``` ```
...@@ -1081,15 +1082,15 @@ let kvStore; ...@@ -1081,15 +1082,15 @@ let kvStore;
try { try {
let resultSet; let resultSet;
kvStore.getResultSet('batch_test_string_key').then((result) => { kvStore.getResultSet('batch_test_string_key').then((result) => {
console.log('getResultSet success'); console.log('getResultSet succeed.');
resultSet = result; resultSet = result;
}).catch((err) => { }).catch((err) => {
console.log('getResultSet fail ' + err); console.log('getResultSet failed: ' + err);
}); });
const moved = resultSet.isBeforeFirst(); const isbeforefirst = resultSet.isBeforeFirst();
console.log("isBeforeFirst " + moved); console.log("Check isBeforeFirst succeed: " + isbeforefirst);
} catch (e) { } catch (e) {
console.log("isBeforeFirst fail " + e); console.log("Check isBeforeFirst failed: " + e);
} }
``` ```
...@@ -1115,15 +1116,15 @@ let kvStore; ...@@ -1115,15 +1116,15 @@ let kvStore;
try { try {
let resultSet; let resultSet;
kvStore.getResultSet('batch_test_string_key').then((result) => { kvStore.getResultSet('batch_test_string_key').then((result) => {
console.log('getResultSet success'); console.log('getResultSet succeed.');
resultSet = result; resultSet = result;
}).catch((err) => { }).catch((err) => {
console.log('getResultSet fail ' + err); console.log('getResultSet failed: ' + err);
}); });
const moved = resultSet.isAfterLast(); const isafterlast = resultSet.isAfterLast();
console.log("isAfterLast " + moved); console.log("Check isAfterLast succeed:" + isafterlast);
} catch (e) { } catch (e) {
console.log("isAfterLast fail " + e); console.log("Check isAfterLast failed: " + e);
} }
``` ```
...@@ -1149,16 +1150,15 @@ let kvStore; ...@@ -1149,16 +1150,15 @@ let kvStore;
try { try {
let resultSet; let resultSet;
kvStore.getResultSet('batch_test_string_key').then((result) => { kvStore.getResultSet('batch_test_string_key').then((result) => {
console.log('getResultSet success'); console.log('getResultSet succeed.');
resultSet = result; resultSet = result;
}).catch((err) => { }).catch((err) => {
console.log('getResultSet fail ' + err); console.log('getResultSet failed: ' + err);
}); });
const moved = resultSet.moveToNext();
const entry = resultSet.getEntry(); const entry = resultSet.getEntry();
console.log("getEntry " + JSON.stringify(entry)); console.log("getEntry succeed:" + JSON.stringify(entry));
} catch (e) { } catch (e) {
console.log("getEntry fail " + e); console.log("getEntry failed: " + e);
} }
``` ```
...@@ -1221,7 +1221,7 @@ Creates a **Query** object to match the specified field whose value is equal to ...@@ -1221,7 +1221,7 @@ Creates a **Query** object to match the specified field whose value is equal to
| Name | Type| Mandatory | Description | | Name | Type| Mandatory | Description |
| ----- | ------ | ---- | ----------------------- | | ----- | ------ | ---- | ----------------------- |
| fieId | string | Yes |Field to match. It must start with $ and cannot contain ^. | | fieId | string | Yes |Field to match. It cannot contain '^'. |
| value | number\|string\|boolean | Yes | Value specified.| | value | number\|string\|boolean | Yes | Value specified.|
**Return value** **Return value**
...@@ -1256,7 +1256,7 @@ Creates a **Query** object to match the specified field whose value is not equal ...@@ -1256,7 +1256,7 @@ Creates a **Query** object to match the specified field whose value is not equal
| Name | Type| Mandatory | Description | | Name | Type| Mandatory | Description |
| ----- | ------ | ---- | ----------------------- | | ----- | ------ | ---- | ----------------------- |
| fieId | string | Yes |Field to match. It must start with $ and cannot contain ^. | | fieId | string | Yes |Field to match. It cannot contain '^'. |
| value | number\|string\|boolean | Yes | Value specified.| | value | number\|string\|boolean | Yes | Value specified.|
**Return value** **Return value**
...@@ -1291,7 +1291,7 @@ Creates a **Query** object to match the specified field whose value is greater t ...@@ -1291,7 +1291,7 @@ Creates a **Query** object to match the specified field whose value is greater t
| Name | Type| Mandatory | Description | | Name | Type| Mandatory | Description |
| ----- | ------ | ---- | ----------------------- | | ----- | ------ | ---- | ----------------------- |
| fieId | string | Yes |Field to match. It must start with $ and cannot contain ^. | | fieId | string | Yes |Field to match. It cannot contain '^'. |
| value | number\|string\|boolean | Yes | Value specified.| | value | number\|string\|boolean | Yes | Value specified.|
**Return value** **Return value**
...@@ -1326,7 +1326,7 @@ Creates a **Query** object to match the specified field whose value is less than ...@@ -1326,7 +1326,7 @@ Creates a **Query** object to match the specified field whose value is less than
| Name | Type| Mandatory | Description | | Name | Type| Mandatory | Description |
| ----- | ------ | ---- | ----------------------- | | ----- | ------ | ---- | ----------------------- |
| fieId | string | Yes |Field to match. It must start with $ and cannot contain ^. | | fieId | string | Yes |Field to match. It cannot contain '^'. |
| value | number\|string\|boolean | Yes | Value specified.| | value | number\|string\|boolean | Yes | Value specified.|
**Return value** **Return value**
...@@ -1361,7 +1361,7 @@ Creates a **Query** object to match the specified field whose value is greater t ...@@ -1361,7 +1361,7 @@ Creates a **Query** object to match the specified field whose value is greater t
| Name | Type| Mandatory | Description | | Name | Type| Mandatory | Description |
| ----- | ------ | ---- | ----------------------- | | ----- | ------ | ---- | ----------------------- |
| fieId | string | Yes |Field to match. It must start with $ and cannot contain ^. | | fieId | string | Yes |Field to match. It cannot contain '^'. |
| value | number\|string\|boolean | Yes | Value specified.| | value | number\|string\|boolean | Yes | Value specified.|
**Return value** **Return value**
...@@ -1396,7 +1396,7 @@ Creates a **Query** object to match the specified field whose value is less than ...@@ -1396,7 +1396,7 @@ Creates a **Query** object to match the specified field whose value is less than
| Name | Type| Mandatory | Description | | Name | Type| Mandatory | Description |
| ----- | ------ | ---- | ----------------------- | | ----- | ------ | ---- | ----------------------- |
| fieId | string | Yes |Field to match. It must start with $ and cannot contain ^. | | fieId | string | Yes |Field to match. It cannot contain '^'. |
| value | number\|string\|boolean | Yes | Value specified.| | value | number\|string\|boolean | Yes | Value specified.|
**Return value** **Return value**
...@@ -1432,7 +1432,7 @@ Creates a **Query** object to match the specified field whose value is **null**. ...@@ -1432,7 +1432,7 @@ Creates a **Query** object to match the specified field whose value is **null**.
| Name | Type| Mandatory | Description | | Name | Type| Mandatory | Description |
| ----- | ------ | ---- | ----------------------- | | ----- | ------ | ---- | ----------------------- |
| fieId | string | Yes |Field to match. It must start with $ and cannot contain ^. | | fieId | string | Yes |Field to match. It cannot contain '^'. |
**Return value** **Return value**
...@@ -1467,7 +1467,7 @@ Creates a **Query** object to match the specified field whose value is within th ...@@ -1467,7 +1467,7 @@ Creates a **Query** object to match the specified field whose value is within th
| Name | Type| Mandatory | Description | | Name | Type| Mandatory | Description |
| ----- | ------ | ---- | ----------------------- | | ----- | ------ | ---- | ----------------------- |
| fieId | string | Yes |Field to match. It must start with $ and cannot contain ^. | | fieId | string | Yes |Field to match. It cannot contain '^'. |
| valueList | number[] | Yes | List of numbers.| | valueList | number[] | Yes | List of numbers.|
**Return value** **Return value**
...@@ -1502,7 +1502,7 @@ Creates a **Query** object to match the specified field whose value is within th ...@@ -1502,7 +1502,7 @@ Creates a **Query** object to match the specified field whose value is within th
| Name | Type| Mandatory | Description | | Name | Type| Mandatory | Description |
| ----- | ------ | ---- | ----------------------- | | ----- | ------ | ---- | ----------------------- |
| fieId | string | Yes |Field to match. It must start with $ and cannot contain ^. | | fieId | string | Yes |Field to match. It cannot contain '^'. |
| valueList | string[] | Yes | List of strings.| | valueList | string[] | Yes | List of strings.|
**Return value** **Return value**
...@@ -1537,7 +1537,7 @@ Creates a **Query** object to match the specified field whose value is not withi ...@@ -1537,7 +1537,7 @@ Creates a **Query** object to match the specified field whose value is not withi
| Name | Type| Mandatory | Description | | Name | Type| Mandatory | Description |
| ----- | ------ | ---- | ----------------------- | | ----- | ------ | ---- | ----------------------- |
| fieId | string | Yes |Field to match. It must start with $ and cannot contain ^. | | fieId | string | Yes |Field to match. It cannot contain '^'. |
| valueList | number[] | Yes | List of numbers.| | valueList | number[] | Yes | List of numbers.|
**Return value** **Return value**
...@@ -1572,7 +1572,7 @@ Creates a **Query** object to match the specified field whose value is not withi ...@@ -1572,7 +1572,7 @@ Creates a **Query** object to match the specified field whose value is not withi
| Name | Type| Mandatory | Description | | Name | Type| Mandatory | Description |
| ----- | ------ | ---- | ----------------------- | | ----- | ------ | ---- | ----------------------- |
| fieId | string | Yes |Field to match. It must start with $ and cannot contain ^. | | fieId | string | Yes |Field to match. It cannot contain '^'. |
| valueList | string[] | Yes | List of strings.| | valueList | string[] | Yes | List of strings.|
**Return value** **Return value**
...@@ -1607,8 +1607,8 @@ Creates a **Query** object to match the specified field whose value is similar t ...@@ -1607,8 +1607,8 @@ Creates a **Query** object to match the specified field whose value is similar t
| Name | Type| Mandatory | Description | | Name | Type| Mandatory | Description |
| ----- | ------ | ---- | ----------------------- | | ----- | ------ | ---- | ----------------------- |
| fieId | string | Yes |Field to match. It must start with $ and cannot contain ^. | | fieId | string | Yes Field to match. It cannot contain '^'. |
| valueList | string | Yes | String specified.| | value | string | Yes | String specified.|
**Return value** **Return value**
...@@ -1642,8 +1642,8 @@ Creates a **Query** object to match the specified field whose value is not simil ...@@ -1642,8 +1642,8 @@ Creates a **Query** object to match the specified field whose value is not simil
| Name | Type| Mandatory | Description | | Name | Type| Mandatory | Description |
| ----- | ------ | ---- | ----------------------- | | ----- | ------ | ---- | ----------------------- |
| fieId | string | Yes |Field to match. It must start with $ and cannot contain ^. | | fieId | string | Yes |Field to match. It cannot contain '^'. |
| valueList | string | Yes | String specified.| | value | string | Yes | String specified.|
**Return value** **Return value**
...@@ -1737,7 +1737,7 @@ Creates a **Query** object to sort the query results in ascending order. ...@@ -1737,7 +1737,7 @@ Creates a **Query** object to sort the query results in ascending order.
| Name | Type| Mandatory | Description | | Name | Type| Mandatory | Description |
| ----- | ------ | ---- | ----------------------- | | ----- | ------ | ---- | ----------------------- |
| fieId | string | Yes |Field to match. It must start with $ and cannot contain ^. | | fieId | string | Yes |Field to match. It cannot contain '^'. |
**Return value** **Return value**
...@@ -1772,7 +1772,7 @@ Creates a **Query** object to sort the query results in descending order. ...@@ -1772,7 +1772,7 @@ Creates a **Query** object to sort the query results in descending order.
| Name | Type| Mandatory | Description | | Name | Type| Mandatory | Description |
| ----- | ------ | ---- | ----------------------- | | ----- | ------ | ---- | ----------------------- |
| fieId | string | Yes |Field to match. It must start with $ and cannot contain ^. | | fieId | string | Yes |Field to match. It cannot contain '^'. |
**Return value** **Return value**
...@@ -2041,7 +2041,7 @@ Obtains the query statement of this **Query** object. ...@@ -2041,7 +2041,7 @@ Obtains the query statement of this **Query** object.
| Type | Description | | Type | Description |
| ------ | ------- | | ------ | ------- |
| [Query](#query8) |**Query** object Created.| | string |Query statement obtained.|
**Example** **Example**
...@@ -2058,9 +2058,7 @@ try { ...@@ -2058,9 +2058,7 @@ try {
## KVStore ## KVStore
Provides methods to manage data in a KV store, for example, adding or deleting data and subscribing to data changes or completion of data synchronization. Before calling any method in **KVStore**, you must use **getKVStore** to obtain a **KVStore** object. Provides methods to manage data in a KV store, for example, adding or deleting data and subscribing to data changes or completion of data synchronization. Before calling any method in **KVStore**, you must use [getKVStore](#getkvstore) to obtain a **KVStore** object.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
### put ### put
...@@ -2927,8 +2925,6 @@ These value types can be used only by internal applications. ...@@ -2927,8 +2925,6 @@ These value types can be used only by internal applications.
Provides methods to query and synchronize data in a single KV store. This class inherits from **KVStore**. Before calling any method in **SingleKVStore**, you must use [getKVStore](#getkvstore) to obtain a **SingleKVStore** object. Provides methods to query and synchronize data in a single KV store. This class inherits from **KVStore**. Before calling any method in **SingleKVStore**, you must use [getKVStore](#getkvstore) to obtain a **SingleKVStore** object.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
### get ### get
get(key: string, callback: AsyncCallback&lt;Uint8Array | string | boolean | number&gt;): void get(key: string, callback: AsyncCallback&lt;Uint8Array | string | boolean | number&gt;): void
...@@ -3222,7 +3218,7 @@ try { ...@@ -3222,7 +3218,7 @@ try {
``` ```
### getResultSet<sup>8+</sup> ### ### getResultSet<sup>8+</sup><a name="singlekvstore_getresultset"></a> ###
getResultSet(keyPrefix: string, callback: AsyncCallback&lt;KvStoreResultSet&gt;): void getResultSet(keyPrefix: string, callback: AsyncCallback&lt;KvStoreResultSet&gt;): void
...@@ -3258,7 +3254,7 @@ try { ...@@ -3258,7 +3254,7 @@ try {
kvStore.putBatch(entries, async function (err, data) { kvStore.putBatch(entries, async function (err, data) {
console.log('GetResultSet putBatch success'); console.log('GetResultSet putBatch success');
await kvStore.getResultSet('batch_test_string_key', async function (err, result) { await kvStore.getResultSet('batch_test_string_key', async function (err, result) {
console.log('GetResultSet getResultSet success'); console.log('GetResultSet getResultSet succeed.');
resultSet = result; resultSet = result;
kvStore.closeResultSet(resultSet, function (err, data) { kvStore.closeResultSet(resultSet, function (err, data) {
console.log('GetResultSet closeResultSet success'); console.log('GetResultSet closeResultSet success');
...@@ -3315,10 +3311,10 @@ try { ...@@ -3315,10 +3311,10 @@ try {
console.log('PutBatch putBatch fail ' + JSON.stringify(err)); console.log('PutBatch putBatch fail ' + JSON.stringify(err));
}); });
kvStore.getResultSet('batch_test_string_key').then((result) => { kvStore.getResultSet('batch_test_string_key').then((result) => {
console.log('GetResult getResultSet success'); console.log('GetResult getResultSet succeed.');
resultSet = result; resultSet = result;
}).catch((err) => { }).catch((err) => {
console.log('getResultSet fail ' + JSON.stringify(err)); console.log('getResultSet failed: ' + JSON.stringify(err));
}); });
kvStore.closeResultSet(resultSet).then((err) => { kvStore.closeResultSet(resultSet).then((err) => {
console.log('GetResult closeResultSet success'); console.log('GetResult closeResultSet success');
...@@ -3369,7 +3365,7 @@ try { ...@@ -3369,7 +3365,7 @@ try {
const query = new distributedData.Query(); const query = new distributedData.Query();
query.prefixKey("batch_test"); query.prefixKey("batch_test");
await kvStore.getResultSet(query, async function (err, result) { await kvStore.getResultSet(query, async function (err, result) {
console.log('getResultSet success'); console.log('getResultSet succeed.');
resultSet = result; resultSet = result;
}); });
}); });
...@@ -3425,10 +3421,10 @@ try { ...@@ -3425,10 +3421,10 @@ try {
const query = new distributedData.Query(); const query = new distributedData.Query();
query.prefixKey("batch_test"); query.prefixKey("batch_test");
kvStore.getResultSet(query).then((result) => { kvStore.getResultSet(query).then((result) => {
console.log(' getResultSet success'); console.log(' getResultSet succeed.');
resultSet = result; resultSet = result;
}).catch((err) => { }).catch((err) => {
console.log('getResultSet fail ' + JSON.stringify(err)); console.log('getResultSet failed: ' + JSON.stringify(err));
}); });
}catch(e) { }catch(e) {
console.log('GetResultSet e ' + e); console.log('GetResultSet e ' + e);
...@@ -3439,7 +3435,7 @@ try { ...@@ -3439,7 +3435,7 @@ try {
closeResultSet(resultSet: KvStoreResultSet, callback: AsyncCallback&lt;void&gt;): void closeResultSet(resultSet: KvStoreResultSet, callback: AsyncCallback&lt;void&gt;): void
Closes the **KvStoreResultSet** object obtained by **getResultSet**. This API uses an asynchronous callback to return the result. Closes the **KvStoreResultSet** object obtained by [SingleKvStore.getResultSet](#singlekvstore_getresultset). This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core **System capability**: SystemCapability.DistributedDataManager.KVStore.Core
...@@ -3473,7 +3469,7 @@ try { ...@@ -3473,7 +3469,7 @@ try {
closeResultSet(resultSet: KvStoreResultSet): Promise&lt;void&gt; closeResultSet(resultSet: KvStoreResultSet): Promise&lt;void&gt;
Closes the **KvStoreResultSet** object obtained by **getResultSet**. This API uses a promise to return the result. Closes the **KvStoreResultSet** object obtained by [SingleKvStore.getResultSet](#singlekvstore_getresultset). This API uses a promise to return the result.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core **System capability**: SystemCapability.DistributedDataManager.KVStore.Core
...@@ -3543,7 +3539,7 @@ try { ...@@ -3543,7 +3539,7 @@ try {
const query = new distributedData.Query(); const query = new distributedData.Query();
query.prefixKey("batch_test"); query.prefixKey("batch_test");
await kvStore.getResultSize(query, async function (err, resultSize) { await kvStore.getResultSize(query, async function (err, resultSize) {
console.log('getResultSet success'); console.log('getResultSet succeed.');
}); });
}); });
} catch(e) { } catch(e) {
...@@ -3597,9 +3593,9 @@ try { ...@@ -3597,9 +3593,9 @@ try {
const query = new distributedData.Query(); const query = new distributedData.Query();
query.prefixKey("batch_test"); query.prefixKey("batch_test");
kvStore.getResultSize(query).then((resultSize) => { kvStore.getResultSize(query).then((resultSize) => {
console.log('getResultSet success'); console.log('getResultSet succeed.');
}).catch((err) => { }).catch((err) => {
console.log('getResultSet fail ' + JSON.stringify(err)); console.log('getResultSet failed: ' + JSON.stringify(err));
}); });
}catch(e) { }catch(e) {
console.log('GetResultSize e ' + e); console.log('GetResultSize e ' + e);
...@@ -3769,7 +3765,7 @@ try { ...@@ -3769,7 +3765,7 @@ try {
sync(deviceIdList: string[], mode: SyncMode, allowedDelayMs?: number): void sync(deviceIdList: string[], mode: SyncMode, allowedDelayMs?: number): void
Manually triggers KV store synchronization synchronously. Manually triggers KV store synchronization synchronously. For details about the synchronization mode of the distributed data service, see [Distributed Data Service Overview] (../../database/database-mdds-overview.md).
**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC **Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC
...@@ -3794,7 +3790,7 @@ kvStore.sync('deviceIds', distributedData.SyncMode.PULL_ONLY, 1000); ...@@ -3794,7 +3790,7 @@ kvStore.sync('deviceIds', distributedData.SyncMode.PULL_ONLY, 1000);
setSyncParam(defaultAllowedDelayMs: number, callback: AsyncCallback&lt;void&gt;): void setSyncParam(defaultAllowedDelayMs: number, callback: AsyncCallback&lt;void&gt;): void
Sets the default delay of database synchronization. This API uses an asynchronous callback to return the result. Sets the default delay allowed for KV store synchronization. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core **System capability**: SystemCapability.DistributedDataManager.KVStore.Core
...@@ -3824,7 +3820,7 @@ try { ...@@ -3824,7 +3820,7 @@ try {
setSyncParam(defaultAllowedDelayMs: number): Promise&lt;void&gt; setSyncParam(defaultAllowedDelayMs: number): Promise&lt;void&gt;
Sets the default delay of database synchronization. This API uses a promise to return the result. Sets the default delay allowed for KV store synchronization. This API uses a promise to return the result.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core **System capability**: SystemCapability.DistributedDataManager.KVStore.Core
...@@ -3898,7 +3894,7 @@ Obtains the security level of this KV store. This API uses a promise to return t ...@@ -3898,7 +3894,7 @@ Obtains the security level of this KV store. This API uses a promise to return t
| Type | Description | | Type | Description |
| ------ | ------- | | ------ | ------- |
|Promise&lt;[SecurityLevel](#securitylevel)&gt; |Promise used to return the security level obtained.| |Promise&lt;[SecurityLevel](#securitylevel)&gt; |Promise used to return the value obtained.|
**Example** **Example**
...@@ -3920,8 +3916,6 @@ try { ...@@ -3920,8 +3916,6 @@ try {
Provides methods to manage distributed data by device in the distributed system. This class inherits from **KVStore** and provides data query and synchronization methods. Before calling any method in **DeviceKVStore**, you must use [getKVStore](#getkvstore) to obtain a **DeviceKVStore** object. Provides methods to manage distributed data by device in the distributed system. This class inherits from **KVStore** and provides data query and synchronization methods. Before calling any method in **DeviceKVStore**, you must use [getKVStore](#getkvstore) to obtain a **DeviceKVStore** object.
**System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
### get<sup>8+</sup> ### ### get<sup>8+</sup> ###
get(deviceId: string, key: string, callback: AsyncCallback&lt;boolean|string|number|Uint8Array&gt;): void get(deviceId: string, key: string, callback: AsyncCallback&lt;boolean|string|number|Uint8Array&gt;): void
...@@ -4333,7 +4327,7 @@ try { ...@@ -4333,7 +4327,7 @@ try {
``` ```
### getResultSet<sup>8+</sup> ### ### getResultSet<sup>8+</sup><a name="devicekvstore_getresultset"></a> ###
getResultSet(deviceId: string, keyPrefix: string, callback: AsyncCallback&lt;KvStoreResultSet&gt;): void getResultSet(deviceId: string, keyPrefix: string, callback: AsyncCallback&lt;KvStoreResultSet&gt;): void
...@@ -4356,7 +4350,7 @@ let kvStore; ...@@ -4356,7 +4350,7 @@ let kvStore;
try { try {
let resultSet; let resultSet;
kvStore.getResultSet('localDeviceId', 'batch_test_string_key', async function (err, result) { kvStore.getResultSet('localDeviceId', 'batch_test_string_key', async function (err, result) {
console.log('getResultSet success'); console.log('getResultSet succeed.');
resultSet = result; resultSet = result;
await kvStore.closeResultSet(resultSet, function (err, data) { await kvStore.closeResultSet(resultSet, function (err, data) {
console.log('closeResultSet success'); console.log('closeResultSet success');
...@@ -4396,10 +4390,10 @@ let kvStore; ...@@ -4396,10 +4390,10 @@ let kvStore;
try { try {
let resultSet; let resultSet;
kvStore.getResultSet('localDeviceId', 'batch_test_string_key').then((result) => { kvStore.getResultSet('localDeviceId', 'batch_test_string_key').then((result) => {
console.log('getResultSet success'); console.log('getResultSet succeed.');
resultSet = result; resultSet = result;
}).catch((err) => { }).catch((err) => {
console.log('getResultSet fail ' + JSON.stringify(err)); console.log('getResultSet failed: ' + JSON.stringify(err));
}); });
kvStore.closeResultSet(resultSet).then((err) => { kvStore.closeResultSet(resultSet).then((err) => {
console.log('closeResultSet success'); console.log('closeResultSet success');
...@@ -4451,7 +4445,7 @@ try { ...@@ -4451,7 +4445,7 @@ try {
query.prefixKey("batch_test"); query.prefixKey("batch_test");
query.deviceId('localDeviceId'); query.deviceId('localDeviceId');
await kvStore.getResultSet(query, async function (err, result) { await kvStore.getResultSet(query, async function (err, result) {
console.log('getResultSet success'); console.log('getResultSet succeed.');
resultSet = result; resultSet = result;
await kvStore.closeResultSet(resultSet, function (err, data) { await kvStore.closeResultSet(resultSet, function (err, data) {
console.log('closeResultSet success'); console.log('closeResultSet success');
...@@ -4512,10 +4506,10 @@ try { ...@@ -4512,10 +4506,10 @@ try {
query.prefixKey("batch_test"); query.prefixKey("batch_test");
console.log("GetResultSet " + query.getSqlLike()); console.log("GetResultSet " + query.getSqlLike());
kvStore.getResultSet(query).then((result) => { kvStore.getResultSet(query).then((result) => {
console.log('getResultSet success'); console.log('getResultSet succeed.');
resultSet = result; resultSet = result;
}).catch((err) => { }).catch((err) => {
console.log('getResultSet fail ' + JSON.stringify(err)); console.log('getResultSet failed: ' + JSON.stringify(err));
}); });
kvStore.closeResultSet(resultSet).then((err) => { kvStore.closeResultSet(resultSet).then((err) => {
console.log('closeResultSet success'); console.log('closeResultSet success');
...@@ -4567,7 +4561,7 @@ try { ...@@ -4567,7 +4561,7 @@ try {
const query = new distributedData.Query(); const query = new distributedData.Query();
query.prefixKey("batch_test"); query.prefixKey("batch_test");
await kvStore.getResultSet('localDeviceId', query, async function (err, result) { await kvStore.getResultSet('localDeviceId', query, async function (err, result) {
console.log('getResultSet success'); console.log('getResultSet succeed.');
resultSet = result; resultSet = result;
await kvStore.closeResultSet(resultSet, function (err, data) { await kvStore.closeResultSet(resultSet, function (err, data) {
console.log('closeResultSet success'); console.log('closeResultSet success');
...@@ -4627,10 +4621,10 @@ try { ...@@ -4627,10 +4621,10 @@ try {
const query = new distributedData.Query(); const query = new distributedData.Query();
query.prefixKey("batch_test"); query.prefixKey("batch_test");
kvStore.getResultSet('localDeviceId', query).then((result) => { kvStore.getResultSet('localDeviceId', query).then((result) => {
console.log('GetResultSet getResultSet success'); console.log('GetResultSet getResultSet succeed.');
resultSet = result; resultSet = result;
}).catch((err) => { }).catch((err) => {
console.log('GetResultSet getResultSet fail ' + JSON.stringify(err)); console.log('GetResultSet getResultSet failed: ' + JSON.stringify(err));
}); });
query.deviceId('localDeviceId'); query.deviceId('localDeviceId');
console.log("GetResultSet " + query.getSqlLike()); console.log("GetResultSet " + query.getSqlLike());
...@@ -4650,7 +4644,7 @@ try { ...@@ -4650,7 +4644,7 @@ try {
closeResultSet(resultSet: KvStoreResultSet, callback: AsyncCallback&lt;void&gt;): void closeResultSet(resultSet: KvStoreResultSet, callback: AsyncCallback&lt;void&gt;): void
Closes the **KvStoreResultSet** object obtained by **getResultSet**. This API uses an asynchronous callback to return the result. Closes the **KvStoreResultSet** object obtained by [DeviceKVStore.getResultSet](#devicekvstore_getresultset). This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore **System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
...@@ -4685,7 +4679,7 @@ try { ...@@ -4685,7 +4679,7 @@ try {
closeResultSet(resultSet: KvStoreResultSet): Promise&lt;void&gt; closeResultSet(resultSet: KvStoreResultSet): Promise&lt;void&gt;
Closes the **KvStoreResultSet** object obtained by **getResultSet**. This API uses a promise to return the result. Closes the **KvStoreResultSet** object obtained by [DeviceKVStore.getResultSet](#devicekvstore_getresultset). This API uses a promise to return the result.
**System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore **System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
...@@ -4757,7 +4751,7 @@ try { ...@@ -4757,7 +4751,7 @@ try {
query.prefixKey("batch_test"); query.prefixKey("batch_test");
query.deviceId('localDeviceId'); query.deviceId('localDeviceId');
await kvStore.getResultSize(query, async function (err, resultSize) { await kvStore.getResultSize(query, async function (err, resultSize) {
console.log('getResultSet success'); console.log('getResultSet succeed.');
}); });
}); });
} catch(e) { } catch(e) {
...@@ -4812,9 +4806,9 @@ try { ...@@ -4812,9 +4806,9 @@ try {
query.prefixKey("batch_test"); query.prefixKey("batch_test");
query.deviceId('localDeviceId'); query.deviceId('localDeviceId');
kvStore.getResultSize(query).then((resultSize) => { kvStore.getResultSize(query).then((resultSize) => {
console.log('getResultSet success'); console.log('getResultSet succeed.');
}).catch((err) => { }).catch((err) => {
console.log('getResultSet fail ' + JSON.stringify(err)); console.log('getResultSet failed: ' + JSON.stringify(err));
}); });
}catch(e) { }catch(e) {
console.log('GetResultSize e ' + e); console.log('GetResultSize e ' + e);
...@@ -4860,7 +4854,7 @@ try { ...@@ -4860,7 +4854,7 @@ try {
const query = new distributedData.Query(); const query = new distributedData.Query();
query.prefixKey("batch_test"); query.prefixKey("batch_test");
await kvStore.getResultSize('localDeviceId', query, async function (err, resultSize) { await kvStore.getResultSize('localDeviceId', query, async function (err, resultSize) {
console.log('getResultSet success'); console.log('getResultSet succeed.');
}); });
}); });
} catch(e) { } catch(e) {
...@@ -4915,9 +4909,9 @@ try { ...@@ -4915,9 +4909,9 @@ try {
var query = new distributedData.Query(); var query = new distributedData.Query();
query.prefixKey("batch_test"); query.prefixKey("batch_test");
kvStore.getResultSize('localDeviceId', query).then((resultSize) => { kvStore.getResultSize('localDeviceId', query).then((resultSize) => {
console.log('getResultSet success'); console.log('getResultSet succeed.');
}).catch((err) => { }).catch((err) => {
console.log('getResultSet fail ' + JSON.stringify(err)); console.log('getResultSet failed: ' + JSON.stringify(err));
}); });
}catch(e) { }catch(e) {
console.log('GetResultSize e ' + e); console.log('GetResultSize e ' + e);
...@@ -5020,7 +5014,7 @@ try { ...@@ -5020,7 +5014,7 @@ try {
sync(deviceIdList: string[], mode: SyncMode, allowedDelayMs?: number): void sync(deviceIdList: string[], mode: SyncMode, allowedDelayMs?: number): void
Manually triggers KV store synchronization synchronously. Manually triggers KV store synchronization synchronously. For details about the synchronization mode of the distributed data service, see [Distributed Data Service Overview] (../../database/database-mdds-overview.md).
**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC **Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC
...@@ -5031,7 +5025,7 @@ Manually triggers KV store synchronization synchronously. ...@@ -5031,7 +5025,7 @@ Manually triggers KV store synchronization synchronously.
| Name | Type| Mandatory | Description | | Name | Type| Mandatory | Description |
| ----- | ------ | ---- | ----------------------- | | ----- | ------ | ---- | ----------------------- |
| deviceIdList |string[] | Yes |IDs of the devices to be synchronized.| | deviceIdList |string[] | Yes |IDs of the devices to be synchronized.|
| mode |[SyncMode](#syncmode) | Yes |Data synchronization mode, which can be **PUSH**, **PULL**, or **PUSH_PULL**. | | mode |[SyncMode](#syncmode) | Yes |Synchronization mode. |
| allowedDelayMs |number | No |Allowed synchronization delay time, in ms. | | allowedDelayMs |number | No |Allowed synchronization delay time, in ms. |
**Example** **Example**
...@@ -5123,7 +5117,7 @@ try { ...@@ -5123,7 +5117,7 @@ try {
## SyncMode ## SyncMode
Defines the synchronization mode. Enumerates the synchronization modes.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core **System capability**: SystemCapability.DistributedDataManager.KVStore.Core
......
# File Management # File Management
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br/> > **NOTE**<br>
> 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.
This module provides file storage functions. It provides JS I/O APIs, including basic file management APIs, basic directory management APIs, statistical APIs for obtaining file information, and streaming APIs for reading and writing files.
## Modules to Import ## Modules to Import
```js ```js
...@@ -10,18 +12,13 @@ import fileio from '@ohos.fileio'; ...@@ -10,18 +12,13 @@ import fileio from '@ohos.fileio';
``` ```
## Required Permissions
None
## Guidelines ## Guidelines
Before using this module to perform operations on a file or directory, obtain the absolute path of the file or directory. For details, see [getOrCreateLocalDir of the Context module](js-apis-Context.md). Before using the APIs provided by this module to perform operations on a file or directory, obtain the path of the application sandbox. For details, see [getOrCreateLocalDir of the Context module](js-apis-Context.md).
Absolute file or directory path = Application directory + File name or directory name Application sandbox path of a file or directory = Application directory + File name or directory name
For example, if the application directory obtained by using **getOrCreateLocalDir** is **dir** and the file name is **xxx.txt**, the absolute path of the file is as follows: For example, if the application directory obtained by using **getOrCreateLocalDir** is **dir** and the file name is **xxx.txt**, the application sandbox path of the file is as follows:
```js ```js
let path = dir + "/xxx.txt"; let path = dir + "/xxx.txt";
...@@ -40,21 +37,23 @@ let fd = fileio.openSync(path); ...@@ -40,21 +37,23 @@ let fd = fileio.openSync(path);
stat(path: string): Promise&lt;Stat&gt; stat(path: string): Promise&lt;Stat&gt;
Asynchronously obtains file information. This method uses a promise to return the result. Asynchronously obtains file information. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ----------- | | Name| Type | Mandatory| Description |
| path | string | Yes | Absolute path of the target file.| | ------ | ------ | ---- | -------------------------- |
| path | string | Yes | Application sandbox path of the target file.|
**Return value**
- Return value
| Type | Description | | Type | Description |
| ---------------------------- | ---------- | | ---------------------------- | ---------- |
| Promise&lt;[Stat](#stat)&gt; | Promise used to return the file information obtained.| | Promise&lt;[Stat](#stat)&gt; | Promise used to return the file information obtained.|
- Example **Example**
```js ```js
fileio.stat(path).then(function(stat){ fileio.stat(path).then(function(stat){
console.info("getFileInfo successfully:"+ JSON.stringify(stat)); console.info("getFileInfo successfully:"+ JSON.stringify(stat));
...@@ -68,17 +67,17 @@ Asynchronously obtains file information. This method uses a promise to return th ...@@ -68,17 +67,17 @@ Asynchronously obtains file information. This method uses a promise to return th
stat(path:string, callback:AsyncCallback&lt;Stat&gt;): void stat(path:string, callback:AsyncCallback&lt;Stat&gt;): void
Asynchronously obtains file information. This method uses a callback to return the result. Asynchronously obtains file information. This API uses a callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| -------- | ---------------------------------- | ---- | --------------- | | -------- | ---------------------------------- | ---- | ------------------------------ |
| path | string | Yes | Absolute path of the target file. | | path | string | Yes | Application sandbox path of the target file. |
| callback | AsyncCallback&lt;[Stat](#stat)&gt; | Yes | Callback invoked to return the file information obtained.| | callback | AsyncCallback&lt;[Stat](#stat)&gt; | Yes | Callback invoked to return the file information obtained.|
- Example **Example**
```js ```js
fileio.stat(path, function (err, stat) { fileio.stat(path, function (err, stat) {
// Example code in Stat // Example code in Stat
...@@ -94,18 +93,18 @@ Synchronously obtains file information. ...@@ -94,18 +93,18 @@ Synchronously obtains file information.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name| Type | Mandatory| Description |
| ---- | ------ | ---- | ----------- | | ------ | ------ | ---- | -------------------------- |
| path | string | Yes | Absolute path of the target file.| | path | string | Yes | Application sandbox path of the target file.|
- Return value **Return value**
| Type | Description | | Type | Description |
| ------------- | ---------- | | ------------- | ---------- |
| [Stat](#stat) | File information obtained.| | [Stat](#stat) | File information obtained.|
- Example **Example**
```js ```js
let stat = fileio.statSync(path); let stat = fileio.statSync(path);
// Example code in Stat // Example code in Stat
...@@ -116,21 +115,21 @@ Synchronously obtains file information. ...@@ -116,21 +115,21 @@ Synchronously obtains file information.
opendir(path: string): Promise&lt;Dir&gt; opendir(path: string): Promise&lt;Dir&gt;
Asynchronously opens a directory. This method uses a promise to return the result. Asynchronously opens a directory. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name| Type | Mandatory| Description |
| ---- | ------ | ---- | ------------- | | ------ | ------ | ---- | ------------------------------ |
| path | string | Yes | Absolute path of the directory to open.| | path | string | Yes | Application sandbox path of the directory to open.|
- Return value **Return value**
| Type | Description | | Type | Description |
| -------------------------- | -------- | | -------------------------- | -------- |
| Promise&lt;[Dir](#dir)&gt; | A **Dir** instance corresponding to the directory.| | Promise&lt;[Dir](#dir)&gt; | A **Dir** instance corresponding to the directory.|
- Example **Example**
```js ```js
fileio.opendir(path).then(function(dir){ fileio.opendir(path).then(function(dir){
console.info("opendir successfully:"+ JSON.stringify(dir)); console.info("opendir successfully:"+ JSON.stringify(dir));
...@@ -144,17 +143,18 @@ Asynchronously opens a directory. This method uses a promise to return the resul ...@@ -144,17 +143,18 @@ Asynchronously opens a directory. This method uses a promise to return the resul
opendir(path: string, callback: AsyncCallback&lt;Dir&gt;): void opendir(path: string, callback: AsyncCallback&lt;Dir&gt;): void
Asynchronously opens a directory. This method uses a callback to return the result. Asynchronously opens a directory. This API uses a callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description |
| -------- | -------------------------------- | ---- | -------------- |
| path | string | Yes | Absolute path of the directory to open. |
| callback | AsyncCallback&lt;[Dir](#dir)&gt; | Yes | Callback invoked when the directory is open asynchronously.|
- Example | Name | Type | Mandatory| Description |
| -------- | -------------------------------- | ---- | ------------------------------ |
| path | string | Yes | Application sandbox path of the directory to open.|
| callback | AsyncCallback&lt;[Dir](#dir)&gt; | Yes | Callback invoked when the directory is open asynchronously. |
**Example**
```js ```js
fileio.opendir(path, function (err, dir) { fileio.opendir(path, function (err, dir) {
// Example code in Dir struct // Example code in Dir struct
...@@ -172,17 +172,18 @@ Synchronously opens a directory. ...@@ -172,17 +172,18 @@ Synchronously opens a directory.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ------------- | | Name| Type | Mandatory| Description |
| path | string | Yes | Absolute path of the directory to open.| | ------ | ------ | ---- | ------------------------------ |
| path | string | Yes | Application sandbox path of the directory to open.|
- Return value **Return value**
| Type | Description | | Type | Description |
| ----------- | -------- | | ----------- | -------- |
| [Dir](#dir) | A **Dir** instance corresponding to the directory.| | [Dir](#dir) | A **Dir** instance corresponding to the directory.|
- Example **Example**
```js ```js
let dir = fileio.opendirSync(path); let dir = fileio.opendirSync(path);
// Example code in Dir struct // Example code in Dir struct
...@@ -194,22 +195,23 @@ Synchronously opens a directory. ...@@ -194,22 +195,23 @@ Synchronously opens a directory.
access(path: string, mode?: number): Promise&lt;void&gt; access(path: string, mode?: number): Promise&lt;void&gt;
Asynchronously checks whether the current process can access a file. This method uses a promise to return the result. Asynchronously checks whether the current process can access a file. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ---------------------------------------- |
| path | string | Yes | Absolute path of the target file. |
| mode | number | No | Options for accessing the file. You can specify multiple options, separated with a bitwise OR operator (&#124;). The default value is **0**.<br>The options are as follows:<br>-&nbsp;**0**: check whether the file exists.<br>-&nbsp;**1**: check whether the current process has the execute permission on the file.<br>-&nbsp;**2**: check whether the current process has the write permission on the file.<br>-&nbsp;**4**: check whether the current process has the read permission on the file.|
- Return value | Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------------------------------------------ |
| path | string | Yes | Application sandbox path of the target file. |
| mode | number | No | Options for accessing the file. You can specify multiple options, separated with a bitwise OR operator (&#124;). The default value is **0**.<br>The options are as follows:<br>-&nbsp;**0**: check whether the file exists.<br>-&nbsp;**1**: check whether the current process has the execute permission on the file.<br>-&nbsp;**2**: check whether the current process has the write permission on the file.<br>-&nbsp;**4**: check whether the current process has the read permission on the file.|
**Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise used to return the result. An empty value is returned.| | Promise&lt;void&gt; | Promise used to return the result. An empty value is returned.|
- Example **Example**
```js ```js
fileio.access(path).then(function() { fileio.access(path).then(function() {
console.info("access successfully"); console.info("access successfully");
...@@ -223,18 +225,18 @@ Asynchronously checks whether the current process can access a file. This method ...@@ -223,18 +225,18 @@ Asynchronously checks whether the current process can access a file. This method
access(path: string, mode: number, callback: AsyncCallback&lt;void&gt;): void access(path: string, mode: number, callback: AsyncCallback&lt;void&gt;): void
Asynchronously checks whether the current process can access a file. This method uses a callback to return the result. Asynchronously checks whether the current process can access a file. This API uses a callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ---------------------------------------- | | -------- | ------------------------- | ---- | ------------------------------------------------------------ |
| path | string | Yes | Absolute path of the target file. | | path | string | Yes | Application sandbox path of the target file. |
| mode | number | No | Options for accessing the file. You can specify multiple options, separated with a bitwise OR operator (&#124;). The default value is **0**.<br>The options are as follows:<br>-&nbsp;**0**: check whether the file exists.<br>-&nbsp;**1**: check whether the current process has the execute permission on the file.<br>-&nbsp;**2**: check whether the current process has the write permission on the file.<br>-&nbsp;**4**: check whether the current process has the read permission on the file.| | mode | number | No | Options for accessing the file. You can specify multiple options, separated with a bitwise OR operator (&#124;). The default value is **0**.<br>The options are as follows:<br>-&nbsp;**0**: check whether the file exists.<br>-&nbsp;**1**: check whether the current process has the execute permission on the file.<br>-&nbsp;**2**: check whether the current process has the write permission on the file.<br>-&nbsp;**4**: check whether the current process has the read permission on the file.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file is asynchronously checked. | | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file is asynchronously checked. |
- Example **Example**
```js ```js
fileio.access(path, function (err) { fileio.access(path, function (err) {
// Do something. // Do something.
...@@ -250,13 +252,13 @@ Synchronously checks whether the current process can access the specified file. ...@@ -250,13 +252,13 @@ Synchronously checks whether the current process can access the specified file.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name| Type | Mandatory| Description |
| ---- | ------ | ---- | ---------------------------------------- | | ------ | ------ | ---- | ------------------------------------------------------------ |
| path | string | Yes | Absolute path of the target file. | | path | string | Yes | Application sandbox path of the target file. |
| mode | number | No | Options for accessing the file. You can specify multiple options, separated with a bitwise OR operator (&#124;). The default value is **0**.<br>The options are as follows:<br>-&nbsp;**0**: check whether the file exists.<br>-&nbsp;**1**: check whether the current process has the execute permission on the file.<br>-&nbsp;**2**: check whether the current process has the write permission on the file.<br>-&nbsp;**4**: check whether the current process has the read permission on the file.| | mode | number | No | Options for accessing the file. You can specify multiple options, separated with a bitwise OR operator (&#124;). The default value is **0**.<br>The options are as follows:<br>-&nbsp;**0**: check whether the file exists.<br>-&nbsp;**1**: check whether the current process has the execute permission on the file.<br>-&nbsp;**2**: check whether the current process has the write permission on the file.<br>-&nbsp;**4**: check whether the current process has the read permission on the file.|
- Example **Example**
```js ```js
try { try {
fileio.accessSync(path); fileio.accessSync(path);
...@@ -270,21 +272,21 @@ Synchronously checks whether the current process can access the specified file. ...@@ -270,21 +272,21 @@ Synchronously checks whether the current process can access the specified file.
close(fd: number):Promise&lt;void&gt; close(fd: number):Promise&lt;void&gt;
Asynchronously closes a file. This method uses a promise to return the result. Asynchronously closes a file. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ------------ | | ---- | ------ | ---- | ------------ |
| fd | number | Yes | File descriptor of the file to close.| | fd | number | Yes | File descriptor of the file to close.|
- Return value **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise used to return the result. An empty value is returned.| | Promise&lt;void&gt; | Promise used to return the result. An empty value is returned.|
- Example **Example**
```js ```js
let fd = fileio.openSync(path); let fd = fileio.openSync(path);
fileio.close(fd).then(function(){ fileio.close(fd).then(function(){
...@@ -299,17 +301,17 @@ Asynchronously closes a file. This method uses a promise to return the result. ...@@ -299,17 +301,17 @@ Asynchronously closes a file. This method uses a promise to return the result.
close(fd: number, callback:AsyncCallback&lt;void&gt;): void close(fd: number, callback:AsyncCallback&lt;void&gt;): void
Asynchronously closes a file. This method uses a callback to return the result. Asynchronously closes a file. This API uses a callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | ------------ | | -------- | ------------------------- | ---- | ------------ |
| fd | number | Yes | File descriptor of the file to close.| | fd | number | Yes | File descriptor of the file to close.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file is closed asynchronously.| | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file is closed asynchronously.|
- Example **Example**
```js ```js
let fd = fileio.openSync(path); let fd = fileio.openSync(path);
fileio.close(fd, function (err) { fileio.close(fd, function (err) {
...@@ -326,12 +328,12 @@ Synchronously closes a file. ...@@ -326,12 +328,12 @@ Synchronously closes a file.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ------------ | | ---- | ------ | ---- | ------------ |
| fd | number | Yes | File descriptor of the file to close.| | fd | number | Yes | File descriptor of the file to close.|
- Example **Example**
```js ```js
fileio.closeSync(fd); fileio.closeSync(fd);
``` ```
...@@ -341,16 +343,16 @@ Synchronously closes a file. ...@@ -341,16 +343,16 @@ Synchronously closes a file.
close(): Promise&lt;void&gt; close(): Promise&lt;void&gt;
Asynchronously closes the stream. This method uses a promise to return the result. Asynchronously closes the stream. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Return value **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise used to return the result. An empty value is returned.| | Promise&lt;void&gt; | Promise used to return the result. An empty value is returned.|
- Example **Example**
```js ```js
fileio.close().then(function(){ fileio.close().then(function(){
console.info("close file stream successfully"); console.info("close file stream successfully");
...@@ -364,16 +366,16 @@ Asynchronously closes the stream. This method uses a promise to return the resul ...@@ -364,16 +366,16 @@ Asynchronously closes the stream. This method uses a promise to return the resul
close(callback: AsyncCallback&lt;void&gt;): void close(callback: AsyncCallback&lt;void&gt;): void
Asynchronously closes the stream. This method uses a callback to return the result. Asynchronously closes the stream. This API uses a callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | ------------- | | -------- | ------------------------- | ---- | ------------- |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the stream is closed asynchronously.| | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the stream is closed asynchronously.|
- Example **Example**
```js ```js
fileio.close(function(err){ fileio.close(function(err){
// Do something. // Do something.
...@@ -385,23 +387,23 @@ Asynchronously closes the stream. This method uses a callback to return the resu ...@@ -385,23 +387,23 @@ Asynchronously closes the stream. This method uses a callback to return the resu
copyFile(src:string | number, dest:string | number, mode?:number):Promise&lt;void&gt; copyFile(src:string | number, dest:string | number, mode?:number):Promise&lt;void&gt;
Asynchronously copies a file. This method uses a promise to return the result. Asynchronously copies a file. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | -------------------------- | ---- | ---------------------------------------- | | ---- | -------------------------- | ---- | ---------------------------------------- |
| src | string&nbsp;\|&nbsp;number | Yes | Path or file descriptor of the file to copy. | | src | string&nbsp;\|&nbsp;number | Yes | Path or file descriptor of the file to copy. |
| dest | string&nbsp;\|&nbsp;number | Yes | Path or file descriptor of the new file. | | dest | string&nbsp;\|&nbsp;number | Yes | Path or file descriptor of the new file. |
| mode | number | No | Option for overwriting the file of the same name in the destination path. The default value is **0**, which is the only value supported.<br>**0**: Completely overwrite the file with the same name and truncate the part that is not overwritten.| | mode | number | No | Option for overwriting the file of the same name in the destination path. The default value is **0**, which is the only value supported.<br>**0**: Completely overwrite the file with the same name and truncate the part that is not overwritten.|
- Return value **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise used to return the result. An empty value is returned.| | Promise&lt;void&gt; | Promise used to return the result. An empty value is returned.|
- Example **Example**
```js ```js
fileio.copyFile(src, dest).then(function(){ fileio.copyFile(src, dest).then(function(){
console.info("copyFile successfully"); console.info("copyFile successfully");
...@@ -415,11 +417,11 @@ Asynchronously copies a file. This method uses a promise to return the result. ...@@ -415,11 +417,11 @@ Asynchronously copies a file. This method uses a promise to return the result.
copyFile(src: string | number, dest: string | number, mode: number, callback: AsyncCallback&lt;void&gt;): void copyFile(src: string | number, dest: string | number, mode: number, callback: AsyncCallback&lt;void&gt;): void
Asynchronously copies a file. This method uses a callback to return the result. Asynchronously copies a file. This API uses a callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | -------------------------- | ---- | ---------------------------------------- | | -------- | -------------------------- | ---- | ---------------------------------------- |
| src | string&nbsp;\|&nbsp;number | Yes | Path or file descriptor of the file to copy. | | src | string&nbsp;\|&nbsp;number | Yes | Path or file descriptor of the file to copy. |
...@@ -427,7 +429,7 @@ Asynchronously copies a file. This method uses a callback to return the result. ...@@ -427,7 +429,7 @@ Asynchronously copies a file. This method uses a callback to return the result.
| mode | number | No | Option for overwriting the file of the same name in the destination path. The default value is **0**, which is the only value supported.<br>**0**: Completely overwrite the file with the same name and truncate the part that is not overwritten.| | mode | number | No | Option for overwriting the file of the same name in the destination path. The default value is **0**, which is the only value supported.<br>**0**: Completely overwrite the file with the same name and truncate the part that is not overwritten.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file is copied asynchronously. | | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file is copied asynchronously. |
- Example **Example**
```js ```js
fileio.copyFile(src, dest, function (err) { fileio.copyFile(src, dest, function (err) {
// Do something. // Do something.
...@@ -443,14 +445,14 @@ Synchronously copies a file. ...@@ -443,14 +445,14 @@ Synchronously copies a file.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | -------------------------- | ---- | ---------------------------------------- | | ---- | -------------------------- | ---- | ---------------------------------------- |
| src | string&nbsp;\|&nbsp;number | Yes | Path or file descriptor of the file to copy. | | src | string&nbsp;\|&nbsp;number | Yes | Path or file descriptor of the file to copy. |
| dest | string&nbsp;\|&nbsp;number | Yes | Path or file descriptor of the new file. | | dest | string&nbsp;\|&nbsp;number | Yes | Path or file descriptor of the new file. |
| mode | number | No | Option for overwriting the file of the same name in the destination path. The default value is **0**, which is the only value supported.<br>**0**: Completely overwrite the file with the same name and truncate the part that is not overwritten.| | mode | number | No | Option for overwriting the file of the same name in the destination path. The default value is **0**, which is the only value supported.<br>**0**: Completely overwrite the file with the same name and truncate the part that is not overwritten.|
- Example **Example**
```js ```js
fileio.copyFileSync(src, dest); fileio.copyFileSync(src, dest);
``` ```
...@@ -460,22 +462,22 @@ Synchronously copies a file. ...@@ -460,22 +462,22 @@ Synchronously copies a file.
mkdir(path:string, mode?: number): Promise&lt;void&gt; mkdir(path:string, mode?: number): Promise&lt;void&gt;
Asynchronously creates a directory. This method uses a promise to return the result. Asynchronously creates a directory. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name| Type | Mandatory| Description |
| ---- | ------ | ---- | ---------------------------------------- | | ------ | ------ | ---- | ------------------------------------------------------------ |
| path | string | Yes | Absolute path of the directory to create. | | path | string | Yes | Application sandbox path of the directory to create. |
| mode | number | No | Permission on the directory to create. You can specify multiple permissions, separated using a bitwise OR operator (&#124;). The default value is **0o775**.<br>-&nbsp;**0o775**: The owner has the read, write, and execute permissions, and other users have the read and execute permissions.<br>-&nbsp;**0o700**: The owner has the read, write, and execute permissions.<br>- &nbsp;**0o400**: The owner has the read permission.<br>-&nbsp;**0o200**: The owner has the write permission.<br>-&nbsp;**0o100**: The owner has the execute permission.<br>-&nbsp;**0o070**: The user group has the read, write, and execute permissions.<br>-&nbsp;**0o040**: The user group has the read permission.<br>-&nbsp;**0o020**: The user group has the write permission.<br>-&nbsp;**0o010**: The user group has the execute permission.<br>-&nbsp;**0o007**: Other users have the read, write, and execute permissions.<br>-&nbsp;**0o004**: Other users have the read permission.<br>-&nbsp;**0o002**: Other users have the write permission.<br>-&nbsp;**0o001**: Other users have the execute permission.| | mode | number | No | Permission on the directory to create. You can specify multiple permissions, separated using a bitwise OR operator (&#124;). The default value is **0o775**.<br>-&nbsp;**0o775**: The owner has the read, write, and execute permissions, and other users have the read and execute permissions.<br>-&nbsp;**0o700**: The owner has the read, write, and execute permissions.<br>- &nbsp;**0o400**: The owner has the read permission.<br>-&nbsp;**0o200**: The owner has the write permission.<br>-&nbsp;**0o100**: The owner has the execute permission.<br>-&nbsp;**0o070**: The user group has the read, write, and execute permissions.<br>-&nbsp;**0o040**: The user group has the read permission.<br>-&nbsp;**0o020**: The user group has the write permission.<br>-&nbsp;**0o010**: The user group has the execute permission.<br>-&nbsp;**0o007**: Other users have the read, write, and execute permissions.<br>-&nbsp;**0o004**: Other users have the read permission.<br>-&nbsp;**0o002**: Other users have the write permission.<br>-&nbsp;**0o001**: Other users have the execute permission.|
- Return value **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise used to return the result. An empty value is returned.| | Promise&lt;void&gt; | Promise used to return the result. An empty value is returned.|
- Example **Example**
```js ```js
fileio.mkdir(path).then(function() { fileio.mkdir(path).then(function() {
console.info("mkdir successfully"); console.info("mkdir successfully");
...@@ -489,18 +491,18 @@ Asynchronously creates a directory. This method uses a promise to return the res ...@@ -489,18 +491,18 @@ Asynchronously creates a directory. This method uses a promise to return the res
mkdir(path: string, mode: number, callback: AsyncCallback&lt;void&gt;): void mkdir(path: string, mode: number, callback: AsyncCallback&lt;void&gt;): void
Asynchronously creates a directory. This method uses a callback to return the result. Asynchronously creates a directory. This API uses a callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ---------------------------------------- | | -------- | ------------------------- | ---- | ------------------------------------------------------------ |
| path | string | Yes | Absolute path of the directory to create. | | path | string | Yes | Application sandbox path of the directory to create. |
| mode | number | No | Permission on the directory to create. You can specify multiple permissions, separated using a bitwise OR operator (&#124;). The default value is **0o775**.<br>-&nbsp;**0o775**: The owner has the read, write, and execute permissions, and other users have the read and execute permissions.<br>-&nbsp;**0o700**: The owner has the read, write, and execute permissions.<br>- &nbsp;**0o400**: The owner has the read permission.<br>-&nbsp;**0o200**: The owner has the write permission.<br>-&nbsp;**0o100**: The owner has the execute permission.<br>-&nbsp;**0o070**: The user group has the read, write, and execute permissions.<br>-&nbsp;**0o040**: The user group has the read permission.<br>-&nbsp;**0o020**: The user group has the write permission.<br>-&nbsp;**0o010**: The user group has the execute permission.<br>-&nbsp;**0o007**: Other users have the read, write, and execute permissions.<br>-&nbsp;**0o004**: Other users have the read permission.<br>-&nbsp;**0o002**: Other users have the write permission.<br>-&nbsp;**0o001**: Other users have the execute permission.| | mode | number | No | Permission on the directory to create. You can specify multiple permissions, separated using a bitwise OR operator (&#124;). The default value is **0o775**.<br>-&nbsp;**0o775**: The owner has the read, write, and execute permissions, and other users have the read and execute permissions.<br>-&nbsp;**0o700**: The owner has the read, write, and execute permissions.<br>- &nbsp;**0o400**: The owner has the read permission.<br>-&nbsp;**0o200**: The owner has the write permission.<br>-&nbsp;**0o100**: The owner has the execute permission.<br>-&nbsp;**0o070**: The user group has the read, write, and execute permissions.<br>-&nbsp;**0o040**: The user group has the read permission.<br>-&nbsp;**0o020**: The user group has the write permission.<br>-&nbsp;**0o010**: The user group has the execute permission.<br>-&nbsp;**0o007**: Other users have the read, write, and execute permissions.<br>-&nbsp;**0o004**: Other users have the read permission.<br>-&nbsp;**0o002**: Other users have the write permission.<br>-&nbsp;**0o001**: Other users have the execute permission.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the directory is created asynchronously. | | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the directory is created asynchronously. |
- Example **Example**
```js ```js
fileio.mkdir(path, function(err) { fileio.mkdir(path, function(err) {
console.info("mkdir successfully"); console.info("mkdir successfully");
...@@ -516,13 +518,13 @@ Synchronously creates a directory. ...@@ -516,13 +518,13 @@ Synchronously creates a directory.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name| Type | Mandatory| Description |
| ---- | ------ | ---- | ---------------------------------------- | | ------ | ------ | ---- | ------------------------------------------------------------ |
| path | string | Yes | Absolute path of the directory to create. | | path | string | Yes | Application sandbox path of the directory to create. |
| mode | number | No | Permission on the directory to create. You can specify multiple permissions, separated using a bitwise OR operator (&#124;). The default value is **0o775**.<br>-&nbsp;**0o775**: The owner has the read, write, and execute permissions, and other users have the read and execute permissions.<br>-&nbsp;**0o700**: The owner has the read, write, and execute permissions.<br>- &nbsp;**0o400**: The owner has the read permission.<br>-&nbsp;**0o200**: The owner has the write permission.<br>-&nbsp;**0o100**: The owner has the execute permission.<br>-&nbsp;**0o070**: The user group has the read, write, and execute permissions.<br>-&nbsp;**0o040**: The user group has the read permission.<br>-&nbsp;**0o020**: The user group has the write permission.<br>-&nbsp;**0o010**: The user group has the execute permission.<br>-&nbsp;**0o007**: Other users have the read, write, and execute permissions.<br>-&nbsp;**0o004**: Other users have the read permission.<br>-&nbsp;**0o002**: Other users have the write permission.<br>-&nbsp;**0o001**: Other users have the execute permission.| | mode | number | No | Permission on the directory to create. You can specify multiple permissions, separated using a bitwise OR operator (&#124;). The default value is **0o775**.<br>-&nbsp;**0o775**: The owner has the read, write, and execute permissions, and other users have the read and execute permissions.<br>-&nbsp;**0o700**: The owner has the read, write, and execute permissions.<br>- &nbsp;**0o400**: The owner has the read permission.<br>-&nbsp;**0o200**: The owner has the write permission.<br>-&nbsp;**0o100**: The owner has the execute permission.<br>-&nbsp;**0o070**: The user group has the read, write, and execute permissions.<br>-&nbsp;**0o040**: The user group has the read permission.<br>-&nbsp;**0o020**: The user group has the write permission.<br>-&nbsp;**0o010**: The user group has the execute permission.<br>-&nbsp;**0o007**: Other users have the read, write, and execute permissions.<br>-&nbsp;**0o004**: Other users have the read permission.<br>-&nbsp;**0o002**: Other users have the write permission.<br>-&nbsp;**0o001**: Other users have the execute permission.|
- Example **Example**
```js ```js
fileio.mkdirSync(path); fileio.mkdirSync(path);
``` ```
...@@ -532,23 +534,23 @@ Synchronously creates a directory. ...@@ -532,23 +534,23 @@ Synchronously creates a directory.
open(path: string, flags?: number, mode?: number): Promise&lt;number&gt; open(path: string, flags?: number, mode?: number): Promise&lt;number&gt;
Asynchronously opens a file. This method uses a promise to return the result. Asynchronously opens a file. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name| Type | Mandatory| Description |
| ----- | ------ | ---- | ---------------------------------------- | | ------ | ------ | ---- | ------------------------------------------------------------ |
| path | string | Yes | Absolute path of the target file. | | path | string | Yes | Application sandbox path of the target file. |
| flags | number | No | Option for opening the file. You must specify one of the following options. By default, the file is open in read-only mode.<br>-&nbsp;**0o0**: Open the file in read-only mode.<br>-&nbsp;**0o1**: Open the file in write-only mode.<br>-&nbsp;**0o2**: Open the file in read/write mode.<br>In addition, you can specify the following options, separated using a bitwise OR operator (&#124;). By default, no additional option is specified.<br>-&nbsp;**0o100**: If the file does not exist, create it. If you use this option, you must also specify **mode**.<br>-&nbsp;**0o200**: If **0o100** is added and the file already exists, throw an exception.<br>-&nbsp;**0o1000**: If the file exists and is open in write-only or read/write mode, truncate the file length to 0.<br>-&nbsp;**0o2000**: Open the file in append mode. New data will be appended to the file (added to the end of the file).<br>-&nbsp;**0o4000**: If **path** points to a named pipe (also known as a FIFO), block special file, or character special file, perform non-blocking operations on the open file and in subsequent I/Os.<br>-&nbsp;**0o200000**: If **path** points to a directory, throw an exception.<br><br/>-&nbsp;**0o400000**: If **path** points to a symbolic link, throw an exception.<br>-&nbsp;**0o4010000**: Open the file in synchronous I/O mode.| | flags | number | No | Option for opening the file. You must specify one of the following options. By default, the file is open in read-only mode.<br>-&nbsp;**0o0**: Open the file in read-only mode.<br>-&nbsp;**0o1**: Open the file in write-only mode.<br>-&nbsp;**0o2**: Open the file in read/write mode.<br>In addition, you can specify the following options, separated using a bitwise OR operator (&#124;). By default, no additional option is specified.<br>-&nbsp;**0o100**: If the file does not exist, create it. If you use this option, you must also specify **mode**.<br>-&nbsp;**0o200**: If **0o100** is added and the file already exists, throw an exception.<br>-&nbsp;**0o1000**: If the file exists and is open in write-only or read/write mode, truncate the file length to 0.<br>-&nbsp;**0o2000**: Open the file in append mode. New data will be appended to the file (added to the end of the file).<br>-&nbsp;**0o4000**: If **path** points to a named pipe (also known as a FIFO), block special file, or character special file, perform non-blocking operations on the open file and in subsequent I/Os.<br>-&nbsp;**0o200000**: If **path** points to a directory, throw an exception.<br><br>-&nbsp;**0o400000**: If **path** points to a symbolic link, throw an exception.<br>-&nbsp;**0o4010000**: Open the file in synchronous I/O mode.|
| mode | number | No | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (&#124;). The default value is **0o666**.<br>-&nbsp;**0o666**: The owner, user group, and other users have the read and write permissions on the file.<br>-&nbsp;**0o700**: The owner has the read, write, and execute permissions.<br>- &nbsp;**0o400**: The owner has the read permission.<br>-&nbsp;**0o200**: The owner has the write permission.<br>-&nbsp;**0o100**: The owner has the execute permission.<br>-&nbsp;**0o070**: The user group has the read, write, and execute permissions.<br>-&nbsp;**0o040**: The user group has the read permission.<br>-&nbsp;**0o020**: The user group has the write permission.<br>-&nbsp;**0o010**: The user group has the execute permission.<br>-&nbsp;**0o007**: Other users have the read, write, and execute permissions.<br>-&nbsp;**0o004**: Other users have the read permission.<br>-&nbsp;**0o002**: Other users have the write permission.<br>-&nbsp;**0o001**: Other users have the execute permission.| | mode | number | No | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (&#124;). The default value is **0o666**.<br>-&nbsp;**0o666**: The owner, user group, and other users have the read and write permissions on the file.<br>-&nbsp;**0o700**: The owner has the read, write, and execute permissions.<br>- &nbsp;**0o400**: The owner has the read permission.<br>-&nbsp;**0o200**: The owner has the write permission.<br>-&nbsp;**0o100**: The owner has the execute permission.<br>-&nbsp;**0o070**: The user group has the read, write, and execute permissions.<br>-&nbsp;**0o040**: The user group has the read permission.<br>-&nbsp;**0o020**: The user group has the write permission.<br>-&nbsp;**0o010**: The user group has the execute permission.<br>-&nbsp;**0o007**: Other users have the read, write, and execute permissions.<br>-&nbsp;**0o004**: Other users have the read permission.<br>-&nbsp;**0o002**: Other users have the write permission.<br>-&nbsp;**0o001**: Other users have the execute permission.|
- Return value **Return value**
| Type | Description | | Type | Description |
| --------------------- | ----------- | | --------------------- | ----------- |
| Promise&lt;number&gt; | File descriptor of the file opened.| | Promise&lt;number&gt; | File descriptor of the file opened.|
- Example **Example**
```js ```js
fileio.open(path, 0o1, 0o0200).then(function(number){ fileio.open(path, 0o1, 0o0200).then(function(number){
console.info("open file successfully"); console.info("open file successfully");
...@@ -562,19 +564,19 @@ Asynchronously opens a file. This method uses a promise to return the result. ...@@ -562,19 +564,19 @@ Asynchronously opens a file. This method uses a promise to return the result.
open(path: string, flags: number, mode: number, callback: AsyncCallback&lt;number&gt;): void open(path: string, flags: number, mode: number, callback: AsyncCallback&lt;number&gt;): void
Asynchronously opens a file. This method uses a callback to return the result. Asynchronously opens a file. This API uses a callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------------- | ---- | ---------------------------------------- | | -------- | ------------------------------- | ---- | ------------------------------------------------------------ |
| path | string | Yes | Absolute path of the target file. | | path | string | Yes | Application sandbox path of the target file. |
| flags | number | Yes | Option for opening the file. You must specify one of the following options. By default, the file is open in read-only mode.<br>-&nbsp;**0o0**: Open the file in read-only mode.<br>-&nbsp;**0o1**: Open the file in write-only mode.<br>-&nbsp;**0o2**: Open the file in read/write mode.<br>In addition, you can specify the following options, separated using a bitwise OR operator (&#124;). By default, no additional option is specified.<br>-&nbsp;**0o100**: If the file does not exist, create it. If you use this option, you must also specify **mode**.<br>-&nbsp;**0o200**: If **0o100** is added and the file already exists, throw an exception.<br>-&nbsp;**0o1000**: If the file exists and is open in write-only or read/write mode, truncate the file length to 0.<br>-&nbsp;**0o2000**: Open the file in append mode. New data will be appended to the file (added to the end of the file).<br>-&nbsp;**0o4000**: If **path** points to a named pipe (also known as a FIFO), block special file, or character special file, perform non-blocking operations on the open file and in subsequent I/Os.<br>-&nbsp;**0o200000**: If **path** points to a directory, throw an exception.<br><br/>-&nbsp;**0o400000**: If **path** points to a symbolic link, throw an exception.<br>-&nbsp;**0o4010000**: Open the file in synchronous I/O mode.| | flags | number | Yes | Option for opening the file. You must specify one of the following options. By default, the file is open in read-only mode.<br>-&nbsp;**0o0**: Open the file in read-only mode.<br>-&nbsp;**0o1**: Open the file in write-only mode.<br>-&nbsp;**0o2**: Open the file in read/write mode.<br>In addition, you can specify the following options, separated using a bitwise OR operator (&#124;). By default, no additional option is specified.<br>-&nbsp;**0o100**: If the file does not exist, create it. If you use this option, you must also specify **mode**.<br>-&nbsp;**0o200**: If **0o100** is added and the file already exists, throw an exception.<br>-&nbsp;**0o1000**: If the file exists and is open in write-only or read/write mode, truncate the file length to 0.<br>-&nbsp;**0o2000**: Open the file in append mode. New data will be appended to the file (added to the end of the file).<br>-&nbsp;**0o4000**: If **path** points to a named pipe (also known as a FIFO), block special file, or character special file, perform non-blocking operations on the open file and in subsequent I/Os.<br>-&nbsp;**0o200000**: If **path** points to a directory, throw an exception.<br><br>-&nbsp;**0o400000**: If **path** points to a symbolic link, throw an exception.<br>-&nbsp;**0o4010000**: Open the file in synchronous I/O mode.|
| mode | number | Yes | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (&#124;). The default value is **0o666**.<br>-&nbsp;**0o666**: The owner, user group, and other users have the read and write permissions on the file.<br>-&nbsp;**0o700**: The owner has the read, write, and execute permissions.<br>- &nbsp;**0o400**: The owner has the read permission.<br>-&nbsp;**0o200**: The owner has the write permission.<br>-&nbsp;**0o100**: The owner has the execute permission.<br>-&nbsp;**0o070**: The user group has the read, write, and execute permissions.<br>-&nbsp;**0o040**: The user group has the read permission.<br>-&nbsp;**0o020**: The user group has the write permission.<br>-&nbsp;**0o010**: The user group has the execute permission.<br>-&nbsp;**0o007**: Other users have the read, write, and execute permissions.<br>-&nbsp;**0o004**: Other users have the read permission.<br>-&nbsp;**0o002**: Other users have the write permission.<br>-&nbsp;**0o001**: Other users have the execute permission.| | mode | number | Yes | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (&#124;). The default value is **0o666**.<br>-&nbsp;**0o666**: The owner, user group, and other users have the read and write permissions on the file.<br>-&nbsp;**0o700**: The owner has the read, write, and execute permissions.<br>- &nbsp;**0o400**: The owner has the read permission.<br>-&nbsp;**0o200**: The owner has the write permission.<br>-&nbsp;**0o100**: The owner has the execute permission.<br>-&nbsp;**0o070**: The user group has the read, write, and execute permissions.<br>-&nbsp;**0o040**: The user group has the read permission.<br>-&nbsp;**0o020**: The user group has the write permission.<br>-&nbsp;**0o010**: The user group has the execute permission.<br>-&nbsp;**0o007**: Other users have the read, write, and execute permissions.<br>-&nbsp;**0o004**: Other users have the read permission.<br>-&nbsp;**0o002**: Other users have the write permission.<br>-&nbsp;**0o001**: Other users have the execute permission.|
| callback | AsyncCallback&nbsp;&lt;void&gt; | Yes | Callback invoked when the file is open asynchronously. | | callback | AsyncCallback&nbsp;&lt;void&gt; | Yes | Callback invoked when the file is open asynchronously. |
- Example **Example**
```js ```js
fileio.open(path, 0, function(err, fd) { fileio.open(path, 0, function(err, fd) {
// Do something. // Do something.
...@@ -590,19 +592,19 @@ Synchronously opens a file. ...@@ -590,19 +592,19 @@ Synchronously opens a file.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name| Type | Mandatory| Description |
| ----- | ------ | ---- | ---------------------------------------- | | ------ | ------ | ---- | ------------------------------------------------------------ |
| path | string | Yes | Absolute path of the target file. | | path | string | Yes | Application sandbox path of the target file. |
| flags | number | No | Option for opening the file. You must specify one of the following options. By default, the file is open in read-only mode.<br>-&nbsp;**0o0**: Open the file in read-only mode.<br>-&nbsp;**0o1**: Open the file in write-only mode.<br>-&nbsp;**0o2**: Open the file in read/write mode.<br>In addition, you can specify the following options, separated using a bitwise OR operator (&#124;). By default, no additional option is specified.<br>-&nbsp;**0o100**: If the file does not exist, create it. If you use this option, you must also specify **mode**.<br>-&nbsp;**0o200**: If **0o100** is added and the file already exists, throw an exception.<br>-&nbsp;**0o1000**: If the file exists and is open in write-only or read/write mode, truncate the file length to 0.<br>-&nbsp;**0o2000**: Open the file in append mode. New data will be appended to the file (added to the end of the file).<br>-&nbsp;**0o4000**: If **path** points to a named pipe (also known as a FIFO), block special file, or character special file, perform non-blocking operations on the open file and in subsequent I/Os.<br>-&nbsp;**0o200000**: If **path** points to a directory, throw an exception.<br><br/>-&nbsp;**0o400000**: If **path** points to a symbolic link, throw an exception.<br>-&nbsp;**0o4010000**: Open the file in synchronous I/O mode.| | flags | number | No | Option for opening the file. You must specify one of the following options. By default, the file is open in read-only mode.<br>-&nbsp;**0o0**: Open the file in read-only mode.<br>-&nbsp;**0o1**: Open the file in write-only mode.<br>-&nbsp;**0o2**: Open the file in read/write mode.<br>In addition, you can specify the following options, separated using a bitwise OR operator (&#124;). By default, no additional option is specified.<br>-&nbsp;**0o100**: If the file does not exist, create it. If you use this option, you must also specify **mode**.<br>-&nbsp;**0o200**: If **0o100** is added and the file already exists, throw an exception.<br>-&nbsp;**0o1000**: If the file exists and is open in write-only or read/write mode, truncate the file length to 0.<br>-&nbsp;**0o2000**: Open the file in append mode. New data will be appended to the file (added to the end of the file).<br>-&nbsp;**0o4000**: If **path** points to a named pipe (also known as a FIFO), block special file, or character special file, perform non-blocking operations on the open file and in subsequent I/Os.<br>-&nbsp;**0o200000**: If **path** points to a directory, throw an exception.<br><br>-&nbsp;**0o400000**: If **path** points to a symbolic link, throw an exception.<br>-&nbsp;**0o4010000**: Open the file in synchronous I/O mode.|
| mode | number | No | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (&#124;). The default value is **0o666**.<br>-&nbsp;**0o666**: The owner, user group, and other users have the read and write permissions on the file.<br>-&nbsp;**0o700**: The owner has the read, write, and execute permissions.<br>- &nbsp;**0o400**: The owner has the read permission.<br>-&nbsp;**0o200**: The owner has the write permission.<br>-&nbsp;**0o100**: The owner has the execute permission.<br>-&nbsp;**0o070**: The user group has the read, write, and execute permissions.<br>-&nbsp;**0o040**: The user group has the read permission.<br>-&nbsp;**0o020**: The user group has the write permission.<br>-&nbsp;**0o010**: The user group has the execute permission.<br>-&nbsp;**0o007**: Other users have the read, write, and execute permissions.<br>-&nbsp;**0o004**: Other users have the read permission.<br>-&nbsp;**0o002**: Other users have the write permission.<br>-&nbsp;**0o001**: Other users have the execute permission.<br>The file permissions on newly created files are affected by umask, which is set as the process starts. Currently, the modification of umask is not open.| | mode | number | No | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (&#124;). The default value is **0o666**.<br>-&nbsp;**0o666**: The owner, user group, and other users have the read and write permissions on the file.<br>-&nbsp;**0o700**: The owner has the read, write, and execute permissions.<br>- &nbsp;**0o400**: The owner has the read permission.<br>-&nbsp;**0o200**: The owner has the write permission.<br>-&nbsp;**0o100**: The owner has the execute permission.<br>-&nbsp;**0o070**: The user group has the read, write, and execute permissions.<br>-&nbsp;**0o040**: The user group has the read permission.<br>-&nbsp;**0o020**: The user group has the write permission.<br>-&nbsp;**0o010**: The user group has the execute permission.<br>-&nbsp;**0o007**: Other users have the read, write, and execute permissions.<br>-&nbsp;**0o004**: Other users have the read permission.<br>-&nbsp;**0o002**: Other users have the write permission.<br>-&nbsp;**0o001**: Other users have the execute permission.<br>The file permissions on newly created files are affected by umask, which is set as the process starts. Currently, the modification of umask is not open.|
- Return value **Return value**
| Type | Description | | Type | Description |
| ------ | ----------- | | ------ | ----------- |
| number | File descriptor of the file opened.| | number | File descriptor of the file opened.|
- Example **Example**
```js ```js
let fd = fileio.openSync(path); let fd = fileio.openSync(path);
``` ```
...@@ -616,23 +618,24 @@ read(fd: number, buffer: ArrayBuffer, options?: { ...@@ -616,23 +618,24 @@ read(fd: number, buffer: ArrayBuffer, options?: {
position?: number; position?: number;
}): Promise&lt;ReadOut&gt; }): Promise&lt;ReadOut&gt;
Asynchronously reads data from a file. This method uses a promise to return the result. Asynchronously reads data from a file. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| ------- | ----------- | ---- | ---------------------------------------- | | ------- | ----------- | ---- | ------------------------------------------------------------ |
| fd | number | Yes | File descriptor of the file to read. | | fd | number | Yes | File descriptor of the file to read. |
| 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>-&nbsp;**offset** (number): position to store the data read in the buffer in reference to the start address of the buffer. The default value is **0**.<br>-&nbsp;**length** (number): length of the data to read. The default value is the buffer length minus the offset.<br>-&nbsp;**position** (number): position of the data to read in the file. By default, data is read from the current position.<br>- &nbsp;The sum of **offset** and **length** must be less than or equal to the buffer size. | | options | Object | No | The options are as follows:<br>-&nbsp;**offset** (number): position to store the data read in the buffer in reference to the start address of the buffer. The default value is **0**.<br>-&nbsp;**length** (number): length of the data to read. The default value is the buffer length minus the offset.<br>-&nbsp;**position** (number): position of the data to read in the file. By default, data is read from the current position.<br>Constraints: offset + length <= Buffer size|
**Return value**
- Return value
| Type | Description | | Type | Description |
| ---------------------------------- | ------ | | ---------------------------------- | ------ |
| Promise&lt;[ReadOut](#readout)&gt; | Data read.| | Promise&lt;[ReadOut](#readout)&gt; | Data read.|
- Example **Example**
```js ```js
let fd = fileio.openSync(path, 0o2); let fd = fileio.openSync(path, 0o2);
let buf = new ArrayBuffer(4096); let buf = new ArrayBuffer(4096);
...@@ -653,19 +656,19 @@ read(fd: number, buffer: ArrayBuffer, options: { ...@@ -653,19 +656,19 @@ read(fd: number, buffer: ArrayBuffer, options: {
position?: number; position?: number;
}, callback: AsyncCallback&lt;ReadOut&gt;): void }, callback: AsyncCallback&lt;ReadOut&gt;): void
Asynchronously reads data from a file. This method uses a callback to return the result. Asynchronously reads data from a file. This API uses a callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- | | -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| fd | number | Yes | File descriptor of the file to read. | | fd | number | Yes | File descriptor of the file to read. |
| 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>-&nbsp;**offset** (number): position to store the data read in the buffer in reference to the start address of the buffer. The default value is **0**.<br>-&nbsp;**length** (number): length of the data to read. The default value is the buffer length minus the offset.<br>-&nbsp;**position** (number): position of the data to read in the file. By default, data is read from the current position.<br>- &nbsp;The sum of **offset** and **length** must be less than or equal to the buffer size. | | options | Object | No | The options are as follows:<br>-&nbsp;**offset** (number): position to store the data read in the buffer in reference to the start address of the buffer. The default value is **0**.<br>-&nbsp;**length** (number): length of the data to read. The default value is the buffer length minus the offset.<br>-&nbsp;**position** (number): position of the data to read in the file. By default, data is read from the current position.<br>Constraints: offset + length <= Buffer size |
| callback | AsyncCallback&lt;[ReadOut](#readout)&gt; | Yes | Callback invoked when the data is read asynchronously. | | callback | AsyncCallback&lt;[ReadOut](#readout)&gt; | Yes | Callback invoked when the data is read asynchronously. |
- Example **Example**
```js ```js
let fd = fileio.openSync(path, 0o2); let fd = fileio.openSync(path, 0o2);
let buf = new ArrayBuffer(4096); let buf = new ArrayBuffer(4096);
...@@ -690,19 +693,19 @@ Synchronously reads data from a file. ...@@ -690,19 +693,19 @@ Synchronously reads data from a file.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------- | ----------- | ---- | ---------------------------------------- | | ------- | ----------- | ---- | ---------------------------------------- |
| fd | number | Yes | File descriptor of the file to read. | | fd | number | Yes | File descriptor of the file to read. |
| 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>-&nbsp;**offset** (number): position to store the data read in the buffer in reference to the start address of the buffer. The default value is **0**.<br>-&nbsp;**length** (number): length of the data to read. The default value is the buffer length minus the offset.<br>-&nbsp;**position** (number): position of the data to read in the file. By default, data is read from the current position.<br>- &nbsp;The sum of **offset** and **length** must be less than or equal to the buffer size. | | options | Object | No | The options are as follows:<br>-&nbsp;**offset** (number): position to store the data read in the buffer in reference to the start address of the buffer. The default value is **0**.<br>-&nbsp;**length** (number): length of the data to read. The default value is the buffer length minus the offset.<br>-&nbsp;**position** (number): position of the data to read in the file. By default, data is read from the current position.<br>Constraints: offset + length <= Buffer size |
- Return value **Return value**
| Type | Description | | Type | Description |
| ------ | -------- | | ------ | -------- |
| number | Length of the data read.| | number | Length of the data read.|
- Example **Example**
```js ```js
let fd = fileio.openSync(path, 0o2); let fd = fileio.openSync(path, 0o2);
let buf = new ArrayBuffer(4096); let buf = new ArrayBuffer(4096);
...@@ -714,21 +717,21 @@ Synchronously reads data from a file. ...@@ -714,21 +717,21 @@ Synchronously reads data from a file.
rmdir(path: string): Promise&lt;void&gt; rmdir(path: string): Promise&lt;void&gt;
Asynchronously deletes a directory. This method uses a promise to return the result. Asynchronously deletes a directory. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name| Type | Mandatory| Description |
| ---- | ------ | ---- | ----------- | | ------ | ------ | ---- | -------------------------- |
| path | string | Yes | Absolute path of the directory to delete.| | path | string | Yes | Application sandbox path of the directory to delete.|
- Return value **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise used to return the result. An empty value is returned.| | Promise&lt;void&gt; | Promise used to return the result. An empty value is returned.|
- Example **Example**
```js ```js
fileio.rmdir(path).then(function() { fileio.rmdir(path).then(function() {
console.info("rmdir successfully"); console.info("rmdir successfully");
...@@ -742,17 +745,17 @@ Asynchronously deletes a directory. This method uses a promise to return the res ...@@ -742,17 +745,17 @@ Asynchronously deletes a directory. This method uses a promise to return the res
rmdir(path: string, callback:AsyncCallback&lt;void&gt;): void rmdir(path: string, callback:AsyncCallback&lt;void&gt;): void
Asynchronously deletes a directory. This method uses a callback to return the result. Asynchronously deletes a directory. This API uses a callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ------------ | | -------- | ------------------------- | ---- | -------------------------- |
| path | string | Yes | Absolute path of the directory to delete. | | path | string | Yes | Application sandbox path of the directory to delete.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the directory is deleted asynchronously.| | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the directory is deleted asynchronously. |
- Example **Example**
```js ```js
fileio.rmdir(path, function(err){ fileio.rmdir(path, function(err){
// Do something. // Do something.
...@@ -769,12 +772,12 @@ Synchronously deletes a directory. ...@@ -769,12 +772,12 @@ Synchronously deletes a directory.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name| Type | Mandatory| Description |
| ---- | ------ | ---- | ----------- | | ------ | ------ | ---- | -------------------------- |
| path | string | Yes | Absolute path of the directory to delete.| | path | string | Yes | Application sandbox path of the directory to delete.|
- Example **Example**
```js ```js
fileio.rmdirSync(path); fileio.rmdirSync(path);
``` ```
...@@ -784,21 +787,21 @@ Synchronously deletes a directory. ...@@ -784,21 +787,21 @@ Synchronously deletes a directory.
unlink(path:string): Promise&lt;void&gt; unlink(path:string): Promise&lt;void&gt;
Asynchronously deletes a file. This method uses a promise to return the result. Asynchronously deletes a file. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name| Type | Mandatory| Description |
| ---- | ------ | ---- | ----------- | | ------ | ------ | ---- | -------------------------- |
| path | string | Yes | Absolute path of the file to delete.| | path | string | Yes | Application sandbox path of the file to delete.|
- Return value **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise used to return the result. An empty value is returned.| | Promise&lt;void&gt; | Promise used to return the result. An empty value is returned.|
- Example **Example**
```js ```js
fileio.unlink(path).then(function(){ fileio.unlink(path).then(function(){
console.info("remove file successfully"); console.info("remove file successfully");
...@@ -812,17 +815,17 @@ Asynchronously deletes a file. This method uses a promise to return the result. ...@@ -812,17 +815,17 @@ Asynchronously deletes a file. This method uses a promise to return the result.
unlink(path:string, callback:AsyncCallback&lt;void&gt;): void unlink(path:string, callback:AsyncCallback&lt;void&gt;): void
Asynchronously deletes a file. This method uses a callback to return the result. Asynchronously deletes a file. This API uses a callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ------------ | | -------- | ------------------------- | ---- | -------------------------- |
| path | string | Yes | Absolute path of the file to delete. | | path | string | Yes | Application sandbox path of the file to delete.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file is deleted asynchronously.| | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file is deleted asynchronously. |
- Example **Example**
```js ```js
fileio.unlink(path, function(err) { fileio.unlink(path, function(err) {
console.info("remove file successfully"); console.info("remove file successfully");
...@@ -838,12 +841,12 @@ Synchronously deletes a file. ...@@ -838,12 +841,12 @@ Synchronously deletes a file.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name| Type | Mandatory| Description |
| ---- | ------ | ---- | ----------- | | ------ | ------ | ---- | -------------------------- |
| path | string | Yes | Absolute path of the file to delete.| | path | string | Yes | Application sandbox path of the file to delete.|
- Example **Example**
```js ```js
fileio.unlinkSync(path); fileio.unlinkSync(path);
``` ```
...@@ -858,23 +861,23 @@ write(fd: number, buffer: ArrayBuffer | string, options?: { ...@@ -858,23 +861,23 @@ write(fd: number, buffer: ArrayBuffer | string, options?: {
encoding?: string; encoding?: string;
}): Promise&lt;number&gt; }): Promise&lt;number&gt;
Asynchronously writes data into a file. This method uses a promise to return the result. Asynchronously writes data into a file. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------- | ------------------------------- | ---- | ---------------------------------------- | | ------- | ------------------------------- | ---- | ---------------------------------------- |
| fd | number | Yes | File descriptor of the file to write. | | fd | number | Yes | File descriptor of the file to write. |
| buffer | ArrayBuffer&nbsp;\|&nbsp;string | Yes | Data to write. It can be a string or data from a buffer. | | buffer | ArrayBuffer&nbsp;\|&nbsp;string | Yes | Data to write. It can be a string or data from a buffer. |
| options | Object | No | The options are as follows:<br>-&nbsp;**offset** (number): position of the data to write in reference to the start address of the data. The default value is **0**.<br>-&nbsp;**length** (number): length of the data to write. The default value is the buffer length minus the offset.<br>-&nbsp;**position** (number): start position to write the data in the file. By default, data is written from the current position.<br>-&nbsp;**encoding** (string): format of the string to be encoded. The default value is **utf-8**, which is the only value supported.<br>- &nbsp;The sum of **offset** and **length** must be less than or equal to the buffer size.| | options | Object | No | The options are as follows:<br>-&nbsp;**offset** (number): position of the data to write in reference to the start address of the data. The default value is **0**.<br>-&nbsp;**length** (number): length of the data to write. The default value is the buffer length minus the offset.<br>-&nbsp;**position** (number): start position to write the data in the file. By default, data is written from the current position.<br>-&nbsp;**encoding** (string): format of the string to be encoded. The default value is **utf-8**, which is the only value supported.<br>Constraints: offset + length <= Buffer size|
- Return value **Return value**
| Type | Description | | Type | Description |
| --------------------- | -------- | | --------------------- | -------- |
| Promise&lt;number&gt; | Length of the data written in the file.| | Promise&lt;number&gt; | Length of the data written in the file.|
- Example **Example**
```js ```js
let fd = fileio.openSync(fpath, 0o100 | 0o2, 0o666); let fd = fileio.openSync(fpath, 0o100 | 0o2, 0o666);
fileio.write(fd, "hello, world").then(function(number){ fileio.write(fd, "hello, world").then(function(number){
...@@ -894,19 +897,19 @@ write(fd: number, buffer: ArrayBuffer | string, options: { ...@@ -894,19 +897,19 @@ write(fd: number, buffer: ArrayBuffer | string, options: {
encoding?: string; encoding?: string;
}, callback: AsyncCallback&lt;number&gt;): void }, callback: AsyncCallback&lt;number&gt;): void
Asynchronously writes data into a file. This method uses a callback to return the result. Asynchronously writes data into a file. This API uses a callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ------------------------------- | ---- | ---------------------------------------- | | -------- | ------------------------------- | ---- | ---------------------------------------- |
| fd | number | Yes | File descriptor of the file to write. | | fd | number | Yes | File descriptor of the file to write. |
| buffer | ArrayBuffer&nbsp;\|&nbsp;string | Yes | Data to write. It can be a string or data from a buffer. | | buffer | ArrayBuffer&nbsp;\|&nbsp;string | Yes | Data to write. It can be a string or data from a buffer. |
| options | Object | No | The options are as follows:<br>-&nbsp;**offset** (number): position of the data to write in reference to the start address of the data. The default value is **0**.<br>-&nbsp;**length** (number): length of the data to write. The default value is the buffer length minus the offset.<br>-&nbsp;**position** (number): start position to write the data in the file. By default, data is written from the current position.<br>-&nbsp;**encoding** (string): format of the string to be encoded. The default value is **utf-8**, which is the only value supported.<br>- &nbsp;The sum of **offset** and **length** must be less than or equal to the buffer size.| | options | Object | No | The options are as follows:<br>-&nbsp;**offset** (number): position of the data to write in reference to the start address of the data. The default value is **0**.<br>-&nbsp;**length** (number): length of the data to write. The default value is the buffer length minus the offset.<br>-&nbsp;**position** (number): start position to write the data in the file. By default, data is written from the current position.<br>-&nbsp;**encoding** (string): format of the string to be encoded. The default value is **utf-8**, which is the only value supported.<br>Constraints: offset + length <= Buffer size|
| callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked when the data is written asynchronously. | | callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked when the data is written asynchronously. |
- Example **Example**
```js ```js
let fd = fileio.openSync(path, 0o100 | 0o2, 0o666); let fd = fileio.openSync(path, 0o100 | 0o2, 0o666);
fileio.write(fd, "hello, world", function (err, bytesWritten) { fileio.write(fd, "hello, world", function (err, bytesWritten) {
...@@ -930,19 +933,19 @@ Synchronously writes data into a file. ...@@ -930,19 +933,19 @@ Synchronously writes data into a file.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------- | ------------------------------- | ---- | ---------------------------------------- | | ------- | ------------------------------- | ---- | ---------------------------------------- |
| fd | number | Yes | File descriptor of the file to write. | | fd | number | Yes | File descriptor of the file to write. |
| buffer | ArrayBuffer&nbsp;\|&nbsp;string | Yes | Data to write. It can be a string or data from a buffer. | | buffer | ArrayBuffer&nbsp;\|&nbsp;string | Yes | Data to write. It can be a string or data from a buffer. |
| options | Object | No | The options are as follows:<br>-&nbsp;**offset** (number): position of the data to write in reference to the start address of the data. The default value is **0**.<br>-&nbsp;**length** (number): length of the data to write. The default value is the buffer length minus the offset.<br>-&nbsp;**position** (number): start position to write the data in the file. By default, data is written from the current position.<br>-&nbsp;**encoding** (string): format of the string to be encoded. The default value is **utf-8**, which is the only value supported.<br>- &nbsp;The sum of **offset** and **length** must be less than or equal to the buffer size.| | options | Object | No | The options are as follows:<br>-&nbsp;**offset** (number): position of the data to write in reference to the start address of the data. The default value is **0**.<br>-&nbsp;**length** (number): length of the data to write. The default value is the buffer length minus the offset.<br>-&nbsp;**position** (number): start position to write the data in the file. By default, data is written from the current position.<br>-&nbsp;**encoding** (string): format of the string to be encoded. The default value is **utf-8**, which is the only value supported.<br>Constraints: offset + length <= Buffer size|
- 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**
```js ```js
let fd = fileio.openSync(path, 0o100 | 0o2, 0o666); let fd = fileio.openSync(path, 0o100 | 0o2, 0o666);
let num = fileio.writeSync(fd, "hello, world"); let num = fileio.writeSync(fd, "hello, world");
...@@ -953,22 +956,22 @@ Synchronously writes data into a file. ...@@ -953,22 +956,22 @@ Synchronously writes data into a file.
hash(path: string, algorithm: string): Promise&lt;string&gt; hash(path: string, algorithm: string): Promise&lt;string&gt;
Asynchronously calculates the hash value of a file. This method uses a promise to return the result. Asynchronously calculates the hash value of a file. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| --------- | ------ | ---- | ---------------------------------------- | | --------- | ------ | ---- | ------------------------------------------------------------ |
| path | string | Yes | Absolute path of the target file. | | path | string | Yes | Application sandbox path of the target file. |
| algorithm | string | Yes | Algorithm used to calculate the hash value. The value can be **md5**, **sha1**, or **sha256**.<br/>**sha256** is recommended for security purposes.| | algorithm | string | Yes | Algorithm used to calculate the hash value. The value can be **md5**, **sha1**, or **sha256**. **sha256** is recommended for security purposes.|
- Return value **Return value**
| Type | Description | | Type | Description |
| --------------------- | -------------------------- | | --------------------- | -------------------------- |
| Promise&lt;string&gt; | Promise used to return the hash value of the file. The hash value is a hexadecimal string consisting of digits and uppercase letters.| | Promise&lt;string&gt; | Promise used to return the hash value of the file. The hash value is a hexadecimal string consisting of digits and uppercase letters.|
- Example **Example**
```js ```js
fileio.hash(path, "sha256").then(function(str){ fileio.hash(path, "sha256").then(function(str){
console.info("calculate file hash successfully:"+ str); console.info("calculate file hash successfully:"+ str);
...@@ -982,18 +985,18 @@ Asynchronously calculates the hash value of a file. This method uses a promise t ...@@ -982,18 +985,18 @@ Asynchronously calculates the hash value of a file. This method uses a promise t
hash(path: string, algorithm: string, callback: AsyncCallback&lt;string&gt;): void hash(path: string, algorithm: string, callback: AsyncCallback&lt;string&gt;): void
Asynchronously calculates the hash value of a file. This method uses a callback to return the result. Asynchronously calculates the hash value of a file. This API uses a callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| --------- | --------------------------- | ---- | ---------------------------------------- | | --------- | --------------------------- | ---- | ------------------------------------------------------------ |
| path | string | Yes | Absolute path of the target file. | | path | string | Yes | Application sandbox path of the target file. |
| algorithm | string | Yes | Algorithm used to calculate the hash value. The value can be **md5**, **sha1**, or **sha256**.<br/>**sha256** is recommended for security purposes.| | algorithm | string | Yes | Algorithm used to calculate the hash value. The value can be **md5**, **sha1**, or **sha256**. **sha256** is recommended for security purposes.|
| callback | AsyncCallback&lt;string&gt; | Yes | Callback used to return the hash value. The hash value is a hexadecimal string consisting of digits and uppercase letters.| | callback | AsyncCallback&lt;string&gt; | Yes | Callback used to return the hash value. The hash value is a hexadecimal string consisting of digits and uppercase letters.|
- Example **Example**
```js ```js
fileio.hash(fpath, "sha256", function(err, hashStr) { fileio.hash(fpath, "sha256", function(err, hashStr) {
if (hashStr) { if (hashStr) {
...@@ -1007,22 +1010,22 @@ Asynchronously calculates the hash value of a file. This method uses a callback ...@@ -1007,22 +1010,22 @@ Asynchronously calculates the hash value of a file. This method uses a callback
chmod(path: string, mode: number):Promise&lt;void&gt; chmod(path: string, mode: number):Promise&lt;void&gt;
Asynchronously changes the file permissions based on its path. This method uses a promise to return the result. Asynchronously changes the file permissions based on its path. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name| Type | Mandatory| Description |
| ---- | ------ | ---- | ---------------------------------------- | | ------ | ------ | ---- | ------------------------------------------------------------ |
| path | string | Yes | Absolute path of the target file. | | path | string | Yes | Application sandbox path of the target file. |
| mode | number | Yes | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (&#124;).<br>-&nbsp;**0o700**: The owner has the read, write, and execute permissions.<br>- &nbsp;**0o400**: The owner has the read permission.<br>-&nbsp;**0o200**: The owner has the write permission.<br>-&nbsp;**0o100**: The owner has the execute permission.<br>-&nbsp;**0o070**: The user group has the read, write, and execute permissions.<br>-&nbsp;**0o040**: The user group has the read permission.<br>-&nbsp;**0o020**: The user group has the write permission.<br>-&nbsp;**0o010**: The user group has the execute permission.<br>-&nbsp;**0o007**: Other users have the read, write, and execute permissions.<br>-&nbsp;**0o004**: Other users have the read permission.<br>-&nbsp;**0o002**: Other users have the write permission.<br>-&nbsp;**0o001**: Other users have the execute permission.| | mode | number | Yes | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (&#124;).<br>-&nbsp;**0o700**: The owner has the read, write, and execute permissions.<br>- &nbsp;**0o400**: The owner has the read permission.<br>-&nbsp;**0o200**: The owner has the write permission.<br>-&nbsp;**0o100**: The owner has the execute permission.<br>-&nbsp;**0o070**: The user group has the read, write, and execute permissions.<br>-&nbsp;**0o040**: The user group has the read permission.<br>-&nbsp;**0o020**: The user group has the write permission.<br>-&nbsp;**0o010**: The user group has the execute permission.<br>-&nbsp;**0o007**: Other users have the read, write, and execute permissions.<br>-&nbsp;**0o004**: Other users have the read permission.<br>-&nbsp;**0o002**: Other users have the write permission.<br>-&nbsp;**0o001**: Other users have the execute permission.|
- Return value **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise used to return the result. An empty value is returned.| | Promise&lt;void&gt; | Promise used to return the result. An empty value is returned.|
- Example **Example**
```js ```js
fileio.chmod(path, mode).then(function() { fileio.chmod(path, mode).then(function() {
console.info("chmod successfully"); console.info("chmod successfully");
...@@ -1036,18 +1039,18 @@ Asynchronously changes the file permissions based on its path. This method uses ...@@ -1036,18 +1039,18 @@ Asynchronously changes the file permissions based on its path. This method uses
chmod(path: string, mode: number, callback: AsyncCallback&lt;void&gt;): void chmod(path: string, mode: number, callback: AsyncCallback&lt;void&gt;): void
Asynchronously changes the file permissions based on its path. This method uses a callback to return the result. Asynchronously changes the file permissions based on its path. This API uses a callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ---------------------------------------- | | -------- | ------------------------- | ---- | ------------------------------------------------------------ |
| path | string | Yes | Absolute path of the target file. | | path | string | Yes | Application sandbox path of the target file. |
| mode | number | Yes | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (&#124;).<br>-&nbsp;**0o700**: The owner has the read, write, and execute permissions.<br>- &nbsp;**0o400**: The owner has the read permission.<br>-&nbsp;**0o200**: The owner has the write permission.<br>-&nbsp;**0o100**: The owner has the execute permission.<br>-&nbsp;**0o070**: The user group has the read, write, and execute permissions.<br>-&nbsp;**0o040**: The user group has the read permission.<br>-&nbsp;**0o020**: The user group has the write permission.<br>-&nbsp;**0o010**: The user group has the execute permission.<br>-&nbsp;**0o007**: Other users have the read, write, and execute permissions.<br>-&nbsp;**0o004**: Other users have the read permission.<br>-&nbsp;**0o002**: Other users have the write permission.<br>-&nbsp;**0o001**: Other users have the execute permission.| | mode | number | Yes | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (&#124;).<br>-&nbsp;**0o700**: The owner has the read, write, and execute permissions.<br>- &nbsp;**0o400**: The owner has the read permission.<br>-&nbsp;**0o200**: The owner has the write permission.<br>-&nbsp;**0o100**: The owner has the execute permission.<br>-&nbsp;**0o070**: The user group has the read, write, and execute permissions.<br>-&nbsp;**0o040**: The user group has the read permission.<br>-&nbsp;**0o020**: The user group has the write permission.<br>-&nbsp;**0o010**: The user group has the execute permission.<br>-&nbsp;**0o007**: Other users have the read, write, and execute permissions.<br>-&nbsp;**0o004**: Other users have the read permission.<br>-&nbsp;**0o002**: Other users have the write permission.<br>-&nbsp;**0o001**: Other users have the execute permission.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file permissions are changed asynchronously. | | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file permissions are changed asynchronously. |
- Example **Example**
```js ```js
fileio.chmod(path, mode, function (err) { fileio.chmod(path, mode, function (err) {
// Do something. // Do something.
...@@ -1063,13 +1066,13 @@ Synchronously changes the file permissions based on its path. ...@@ -1063,13 +1066,13 @@ Synchronously changes the file permissions based on its path.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name| Type | Mandatory| Description |
| ---- | ------ | ---- | ---------------------------------------- | | ------ | ------ | ---- | ------------------------------------------------------------ |
| path | string | Yes | Absolute path of the target file. | | path | string | Yes | Application sandbox path of the target file. |
| mode | number | Yes | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (&#124;).<br>-&nbsp;**0o700**: The owner has the read, write, and execute permissions.<br>- &nbsp;**0o400**: The owner has the read permission.<br>-&nbsp;**0o200**: The owner has the write permission.<br>-&nbsp;**0o100**: The owner has the execute permission.<br>-&nbsp;**0o070**: The user group has the read, write, and execute permissions.<br>-&nbsp;**0o040**: The user group has the read permission.<br>-&nbsp;**0o020**: The user group has the write permission.<br>-&nbsp;**0o010**: The user group has the execute permission.<br>-&nbsp;**0o007**: Other users have the read, write, and execute permissions.<br>-&nbsp;**0o004**: Other users have the read permission.<br>-&nbsp;**0o002**: Other users have the write permission.<br>-&nbsp;**0o001**: Other users have the execute permission.| | mode | number | Yes | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (&#124;).<br>-&nbsp;**0o700**: The owner has the read, write, and execute permissions.<br>- &nbsp;**0o400**: The owner has the read permission.<br>-&nbsp;**0o200**: The owner has the write permission.<br>-&nbsp;**0o100**: The owner has the execute permission.<br>-&nbsp;**0o070**: The user group has the read, write, and execute permissions.<br>-&nbsp;**0o040**: The user group has the read permission.<br>-&nbsp;**0o020**: The user group has the write permission.<br>-&nbsp;**0o010**: The user group has the execute permission.<br>-&nbsp;**0o007**: Other users have the read, write, and execute permissions.<br>-&nbsp;**0o004**: Other users have the read permission.<br>-&nbsp;**0o002**: Other users have the write permission.<br>-&nbsp;**0o001**: Other users have the execute permission.|
- Example **Example**
```js ```js
fileio.chmodSync(fpath, mode); fileio.chmodSync(fpath, mode);
``` ```
...@@ -1079,21 +1082,21 @@ Synchronously changes the file permissions based on its path. ...@@ -1079,21 +1082,21 @@ Synchronously changes the file permissions based on its path.
fstat(fd: number): Promise&lt;Stat&gt; fstat(fd: number): Promise&lt;Stat&gt;
Asynchronously obtains file status information based on the file descriptor. This method uses a promise to return the result. Asynchronously obtains file information based on the file descriptor. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ------------ | | ---- | ------ | ---- | ------------ |
| fd | number | Yes | File descriptor of the target file.| | fd | number | Yes | File descriptor of the target file.|
- Return value **Return value**
| Type | Description | | Type | Description |
| ---------------------------- | ---------- | | ---------------------------- | ---------- |
| Promise&lt;[Stat](#stat)&gt; | Promise used to return the file status information obtained.| | Promise&lt;[Stat](#stat)&gt; | Promise used to return the file information obtained.|
- Example **Example**
```js ```js
fileio.fstat(fd).then(function(stat){ fileio.fstat(fd).then(function(stat){
console.info("fstat successfully:"+ JSON.stringify(stat)); console.info("fstat successfully:"+ JSON.stringify(stat));
...@@ -1107,17 +1110,17 @@ Asynchronously obtains file status information based on the file descriptor. Thi ...@@ -1107,17 +1110,17 @@ Asynchronously obtains file status information based on the file descriptor. Thi
fstat(fd: number, callback: AsyncCallback&lt;Stat&gt;): void fstat(fd: number, callback: AsyncCallback&lt;Stat&gt;): void
Asynchronously obtains file status information based on the file descriptor. This method uses a callback to return the result. Asynchronously obtains file information based on the file descriptor. This API uses a callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------------------- | ---- | ---------------- | | -------- | ---------------------------------- | ---- | ---------------- |
| fd | number | Yes | File descriptor of the target file. | | fd | number | Yes | File descriptor of the target file. |
| callback | AsyncCallback&lt;[Stat](#stat)&gt; | Yes | Callback invoked when the file status information is obtained asynchronously.| | callback | AsyncCallback&lt;[Stat](#stat)&gt; | Yes | Callback invoked to return the file information obtained.|
- Example **Example**
```js ```js
let fd = fileio.openSync(path); let fd = fileio.openSync(path);
fileio.fstat(fd, function (err) { fileio.fstat(fd, function (err) {
...@@ -1130,21 +1133,21 @@ Asynchronously obtains file status information based on the file descriptor. Thi ...@@ -1130,21 +1133,21 @@ Asynchronously obtains file status information based on the file descriptor. Thi
fstatSync(fd: number): Stat fstatSync(fd: number): Stat
Synchronously obtains file status information based on the file descriptor. Synchronously obtains file information based on the file descriptor.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ------------ | | ---- | ------ | ---- | ------------ |
| fd | number | Yes | File descriptor of the target file.| | fd | number | Yes | File descriptor of the target file.|
- Return value **Return value**
| Type | Description | | Type | Description |
| ------------- | ---------- | | ------------- | ---------- |
| [Stat](#stat) | File status information obtained.| | [Stat](#stat) | File information obtained.|
- Example **Example**
```js ```js
let fd = fileio.openSync(path); let fd = fileio.openSync(path);
let stat = fileio.fstatSync(fd); let stat = fileio.fstatSync(fd);
...@@ -1155,22 +1158,22 @@ Synchronously obtains file status information based on the file descriptor. ...@@ -1155,22 +1158,22 @@ Synchronously obtains file status information based on the file descriptor.
ftruncate(fd: number, len?: number): Promise&lt;void&gt; ftruncate(fd: number, len?: number): Promise&lt;void&gt;
Asynchronously truncates a file based on the file descriptor. This method uses a promise to return the result. Asynchronously truncates a file based on the file descriptor. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ---------------- | | ---- | ------ | ---- | ---------------- |
| fd | number | Yes | File descriptor of the file to truncate. | | fd | number | Yes | File descriptor of the file to truncate. |
| len | number | Yes | File length, in bytes, after truncation.| | len | number | Yes | File length, in bytes, after truncation.|
- Return value **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise used to return the result. An empty value is returned.| | Promise&lt;void&gt; | Promise used to return the result. An empty value is returned.|
- Example **Example**
```js ```js
let fd = fileio.openSync(path); let fd = fileio.openSync(path);
fileio.ftruncate(fd, 5).then(function(err) { fileio.ftruncate(fd, 5).then(function(err) {
...@@ -1185,18 +1188,18 @@ Asynchronously truncates a file based on the file descriptor. This method uses a ...@@ -1185,18 +1188,18 @@ Asynchronously truncates a file based on the file descriptor. This method uses a
ftruncate(fd: number, len: number, callback:AsyncCallback&lt;void&gt;): void ftruncate(fd: number, len: number, callback:AsyncCallback&lt;void&gt;): void
Asynchronously truncates a file based on the file descriptor. This method uses a callback to return the result. Asynchronously truncates a file based on the file descriptor. This API uses a callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | ---------------- | | -------- | ------------------------- | ---- | ---------------- |
| fd | number | Yes | File descriptor of the file to truncate. | | fd | number | Yes | File descriptor of the file to truncate. |
| len | number | Yes | File length, in bytes, after truncation.| | len | number | Yes | File length, in bytes, after truncation.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file is truncated asynchronously. | | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file is truncated asynchronously. |
- Example **Example**
```js ```js
fileio.ftruncate(fd, len, function(err){ fileio.ftruncate(fd, len, function(err){
// Do something. // Do something.
...@@ -1212,13 +1215,13 @@ Synchronously truncates a file based on the file descriptor. ...@@ -1212,13 +1215,13 @@ Synchronously truncates a file based on the file descriptor.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ---------------- | | ---- | ------ | ---- | ---------------- |
| fd | number | Yes | File descriptor of the file to truncate. | | fd | number | Yes | File descriptor of the file to truncate. |
| len | number | No | File length, in bytes, after truncation.| | len | number | No | File length, in bytes, after truncation.|
- Example **Example**
```js ```js
fileio.ftruncateSync(fd, len); fileio.ftruncateSync(fd, len);
``` ```
...@@ -1228,22 +1231,22 @@ Synchronously truncates a file based on the file descriptor. ...@@ -1228,22 +1231,22 @@ Synchronously truncates a file based on the file descriptor.
truncate(path: string, len?: number): Promise&lt;void&gt; truncate(path: string, len?: number): Promise&lt;void&gt;
Asynchronously truncates a file based on its path. This method uses a promise to return the result. Asynchronously truncates a file based on its path. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name| Type | Mandatory| Description |
| ---- | ------ | ---- | ---------------- | | ------ | ------ | ---- | -------------------------------- |
| path | string | Yes | Absolute path of the file to truncate. | | path | string | Yes | Application sandbox path of the file to truncate. |
| len | number | Yes | File length, in bytes, after truncation.| | len | number | Yes | File length, in bytes, after truncation.|
- Return value **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise used to return the result. An empty value is returned.| | Promise&lt;void&gt; | Promise used to return the result. An empty value is returned.|
- Example **Example**
```js ```js
fileio.truncate(path, len).then(function(){ fileio.truncate(path, len).then(function(){
console.info("File truncated successfully."); console.info("File truncated successfully.");
...@@ -1257,18 +1260,18 @@ Asynchronously truncates a file based on its path. This method uses a promise to ...@@ -1257,18 +1260,18 @@ Asynchronously truncates a file based on its path. This method uses a promise to
truncate(path: string, len: number, callback:AsyncCallback&lt;void&gt;): void truncate(path: string, len: number, callback:AsyncCallback&lt;void&gt;): void
Asynchronously truncates a file based on its path. This method uses a callback to return the result. Asynchronously truncates a file based on its path. This API uses a callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ---------------- | | -------- | ------------------------- | ---- | -------------------------------- |
| path | string | Yes | Absolute path of the file to truncate. | | path | string | Yes | Application sandbox path of the file to truncate. |
| len | number | Yes | File length, in bytes, after truncation.| | len | number | Yes | File length, in bytes, after truncation.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file is truncated asynchronously. | | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file is truncated asynchronously. |
- Example **Example**
```js ```js
fileio.truncate(path, len, function(err){ fileio.truncate(path, len, function(err){
// Do something. // Do something.
...@@ -1284,13 +1287,13 @@ Synchronously truncates a file based on the file path. ...@@ -1284,13 +1287,13 @@ Synchronously truncates a file based on the file path.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name| Type | Mandatory| Description |
| ---- | ------ | ---- | ---------------- | | ------ | ------ | ---- | -------------------------------- |
| path | string | Yes | Absolute path of the file to truncate. | | path | string | Yes | Application sandbox path of the file to be truncate. |
| len | number | No | File length, in bytes, after truncation.| | len | number | No | File length, in bytes, after truncation.|
- Example **Example**
```js ```js
fileio.truncateSync(path, len); fileio.truncateSync(path, len);
``` ```
...@@ -1304,22 +1307,22 @@ readText(filePath: string, options?: { ...@@ -1304,22 +1307,22 @@ readText(filePath: string, options?: {
encoding?: string; encoding?: string;
}): Promise&lt;string&gt; }): Promise&lt;string&gt;
Asynchronously reads the text of a file. This method uses a promise to return the result. Asynchronously reads the text of a file. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| -------- | ------ | ---- | ---------------------------------------- | | -------- | ------ | ---- | ------------------------------------------------------------ |
| filePath | string | Yes | Absolute path of the file to read. | | filePath | string | Yes | Application sandbox path of the file to read. |
| options | Object | No | The options are as follows:<br>-&nbsp;**position** (number): position of the data to read in the file. By default, data is read from the current position.<br>-&nbsp;**length** (number): length of the data to read. The default value is the buffer length minus the offset.<br>-&nbsp;**encoding** (string): format of the data (string) to be encoded. The default value is **utf-8**, which is the only value supported.| | options | Object | No | The options are as follows:<br>-&nbsp;**position** (number): position of the data to read in the file. By default, data is read from the current position.<br>-&nbsp;**length** (number): length of the data to read. The default value is the buffer length minus the offset.<br>-&nbsp;**encoding** (string): format of the data (string) to be encoded. The default value is **utf-8**, which is the only value supported.|
- Return value **Return value**
| Type | Description | | Type | Description |
| --------------------- | ---------- | | --------------------- | ---------- |
| Promise&lt;string&gt; | Promise used to return the content of the file read.| | Promise&lt;string&gt; | Promise used to return the content of the file read.|
- Example **Example**
```js ```js
fileio.readText(path).then(function(str) { fileio.readText(path).then(function(str) {
console.info("readText successfully:"+ str); console.info("readText successfully:"+ str);
...@@ -1337,18 +1340,18 @@ readText(filePath: string, options: { ...@@ -1337,18 +1340,18 @@ readText(filePath: string, options: {
encoding?: string; encoding?: string;
}, callback: AsyncCallback&lt;string&gt;): void }, callback: AsyncCallback&lt;string&gt;): void
Asynchronously reads the text of a file. This method uses a callback to return the result. Asynchronously reads the text of a file. This API uses a callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| -------- | --------------------------- | ---- | ---------------------------------------- | | -------- | --------------------------- | ---- | ------------------------------------------------------------ |
| filePath | string | Yes | Absolute path of the file to read. | | filePath | string | Yes | Application sandbox path of the file to read. |
| options | Object | No | The options are as follows:<br>-&nbsp;**position** (number): position of the data to read in the file. By default, data is read from the current position.<br>-&nbsp;**length** (number): length of the data to read. The default value is the buffer length minus the offset.<br>-&nbsp;**encoding** (string): format of the data (string) to be encoded. The default value is **utf-8**, which is the only value supported.| | options | Object | No | The options are as follows:<br>-&nbsp;**position** (number): position of the data to read in the file. By default, data is read from the current position.<br>-&nbsp;**length** (number): length of the data to read. The default value is the buffer length minus the offset.<br>-&nbsp;**encoding** (string): format of the data (string) to be encoded. The default value is **utf-8**, which is the only value supported.|
| callback | AsyncCallback&lt;string&gt; | Yes | Callback invoked when the file is read asynchronously. | | callback | AsyncCallback&lt;string&gt; | Yes | Callback invoked when the file is read asynchronously. |
- Example **Example**
```js ```js
fileio.readText(path, function(err, str){ fileio.readText(path, function(err, str){
// Do something. // Do something.
...@@ -1368,18 +1371,18 @@ Synchronously reads the text of a file. ...@@ -1368,18 +1371,18 @@ Synchronously reads the text of a file.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| -------- | ------ | ---- | ---------------------------------------- | | -------- | ------ | ---- | ------------------------------------------------------------ |
| filePath | string | Yes | Absolute path of the file to read. | | filePath | string | Yes | Application sandbox path of the file to be read. |
| options | Object | No | The options are as follows:<br>-&nbsp;**position** (number): position of the data to read in the file. By default, data is read from the current position.<br>-&nbsp;**length** (number): length of the data to read. The default value is the buffer length minus the offset.<br>-&nbsp;**encoding** (string): format of the data (string) to be encoded. The default value is **utf-8**, which is the only value supported.| | options | Object | No | The options are as follows:<br>-&nbsp;**position** (number): position of the data to read in the file. By default, data is read from the current position.<br>-&nbsp;**length** (number): length of the data to read. The default value is the buffer length minus the offset.<br>-&nbsp;**encoding** (string): format of the data (string) to be encoded. The default value is **utf-8**, which is the only value supported.|
- Return value **Return value**
| Type | Description | | Type | Description |
| ------ | -------------------- | | ------ | -------------------- |
| string | Content of the file read.| | string | Promise used to return the content of the file read.|
- Example **Example**
```js ```js
let str = fileio.readTextSync(path, {position: 1, length: 3}); let str = fileio.readTextSync(path, {position: 1, length: 3});
``` ```
...@@ -1389,21 +1392,21 @@ Synchronously reads the text of a file. ...@@ -1389,21 +1392,21 @@ Synchronously reads the text of a file.
lstat(path: string): Promise&lt;Stat&gt; lstat(path: string): Promise&lt;Stat&gt;
Asynchronously obtains link status information. This method uses a promise to return the result. Asynchronously obtains link information. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name| Type | Mandatory| Description |
| ---- | ------ | ---- | ----------------- | | ------ | ------ | ---- | -------------------------------------- |
| path | string | Yes | Absolute path of the target file, pointing to the link status.| | path | string | Yes | Application sandbox path of the target file, pointing to the link.|
- Return value **Return value**
| Type | Description | | Type | Description |
| ---------------------------- | ---------- | | ---------------------------- | ---------- |
| Promise&lt;[Stat](#stat)&gt; | Promise used to return the link status obtained.| | Promise&lt;[Stat](#stat)&gt; | Promise used to return the link information obtained.|
- Example **Example**
```js ```js
fileio.lstat(path).then(function(stat){ fileio.lstat(path).then(function(stat){
console.info("Link status obtained:"+ number); console.info("Link status obtained:"+ number);
...@@ -1417,17 +1420,17 @@ Asynchronously obtains link status information. This method uses a promise to re ...@@ -1417,17 +1420,17 @@ Asynchronously obtains link status information. This method uses a promise to re
lstat(path:string, callback:AsyncCallback&lt;Stat&gt;): void lstat(path:string, callback:AsyncCallback&lt;Stat&gt;): void
Asynchronously obtains link status information. This method uses a callback to return the result. Asynchronously obtains link information. This API uses a callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| -------- | ---------------------------------- | ---- | ----------------- | | -------- | ---------------------------------- | ---- | -------------------------------------- |
| path | string | Yes | Absolute path of the target file, pointing to the link status.| | path | string | Yes | Application sandbox path of the target file, pointing to the link.|
| callback | AsyncCallback&lt;[Stat](#stat)&gt; | Yes | Callback invoked when the link status information is obtained asynchronously. | | callback | AsyncCallback&lt;[Stat](#stat)&gt; | Yes | Callback invoked to return the link information obtained. |
- Example **Example**
```js ```js
fileio.lstat(path, function (err, stat) { fileio.lstat(path, function (err, stat) {
// Do something. // Do something.
...@@ -1439,21 +1442,21 @@ Asynchronously obtains link status information. This method uses a callback to r ...@@ -1439,21 +1442,21 @@ Asynchronously obtains link status information. This method uses a callback to r
lstatSync(path:string): Stat lstatSync(path:string): Stat
Synchronously obtains link status information. Synchronously obtains the link information.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name| Type | Mandatory| Description |
| ---- | ------ | ---- | ----------------- | | ------ | ------ | ---- | -------------------------------------- |
| path | string | Yes | Absolute path of the target file, pointing to the link status.| | path | string | Yes | Application sandbox path of the target file, pointing to the link.|
- Return value **Return value**
| Type | Description | | Type | Description |
| ------------- | ---------- | | ------------- | ---------- |
| [Stat](#stat) | Link status obtained.| | [Stat](#stat) | Link information obtained.|
- Example **Example**
```js ```js
let stat = fileio.lstatSync(path); let stat = fileio.lstatSync(path);
``` ```
...@@ -1467,22 +1470,22 @@ read(buffer: ArrayBuffer, options?: { ...@@ -1467,22 +1470,22 @@ read(buffer: ArrayBuffer, options?: {
length?: number; length?: number;
}): Promise&lt;ReadOut&gt; }): Promise&lt;ReadOut&gt;
Asynchronously reads data from a file. This method uses a promise to return the result. Asynchronously reads data from a file. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ------- | ----------- | ---- | ------------------------------------------------------------ | | ------- | ----------- | ---- | ------------------------------------------------------------ |
| 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>-&nbsp;**offset** (number): position to store the data read in the buffer in reference to the start address of the buffer. The default value is **0**.<br>-&nbsp;**length** (number): length of the data to read. The default value is the buffer length minus the offset.<br>- &nbsp;The sum of **offset** and **length** must be less than or equal to the buffer size.| | options | Object | No | The options are as follows:<br>-&nbsp;**offset** (number): position to store the data read in the buffer in reference to the start address of the buffer. The default value is **0**.<br>-&nbsp;**length** (number): length of the data to read. The default value is the buffer length minus the offset.<br>Constraints: offset + length <= Buffer size|
- Return value **Return value**
| Type | Description | | Type | Description |
| ---------------------------------- | ------ | | ---------------------------------- | ------ |
| Promise&lt;[ReadOut](#readout)&gt; | Data read.| | Promise&lt;[ReadOut](#readout)&gt; | Data read.|
- Example **Example**
```js ```js
fileio.read(new ArrayBuffer(4096)).then(function(readout){ fileio.read(new ArrayBuffer(4096)).then(function(readout){
console.info("read file data successfully"); console.info("read file data successfully");
...@@ -1501,18 +1504,18 @@ read(buffer: ArrayBuffer, options: { ...@@ -1501,18 +1504,18 @@ read(buffer: ArrayBuffer, options: {
length?: number; length?: number;
}, callback: AsyncCallback&lt;ReadOut&gt;): void }, callback: AsyncCallback&lt;ReadOut&gt;): void
Asynchronously reads data from a file. This method uses a callback to return the result. Asynchronously reads data from a file. This API uses a callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- | | -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| 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>-&nbsp;**offset** (number): position to store the data read in the buffer in reference to the start address of the buffer. The default value is **0**.<br>-&nbsp;**length** (number): length of the data to read. The default value is the buffer length minus the offset.<br>- &nbsp;The sum of **offset** and **length** must be less than or equal to the buffer size.| | options | Object | No | The options are as follows:<br>-&nbsp;**offset** (number): position to store the data read in the buffer in reference to the start address of the buffer. The default value is **0**.<br>-&nbsp;**length** (number): length of the data to read. The default value is the buffer length minus the offset.<br>Constraints: offset + length <= Buffer size|
| callback | AsyncCallback&lt;[ReadOut](#readout)&gt; | Yes | Callback invoked when the data is read asynchronously from the file. | | callback | AsyncCallback&lt;[ReadOut](#readout)&gt; | Yes | Callback invoked when the data is read asynchronously from the file. |
- Example **Example**
```js ```js
let buf = new ArrayBuffer(4096); let buf = new ArrayBuffer(4096);
fileio.read(buf, function (err, readOut) { fileio.read(buf, function (err, readOut) {
...@@ -1528,22 +1531,22 @@ Asynchronously reads data from a file. This method uses a callback to return the ...@@ -1528,22 +1531,22 @@ Asynchronously reads data from a file. This method uses a callback to return the
rename(oldPath: string, newPath: string): Promise&lt;void&gt; rename(oldPath: string, newPath: string): Promise&lt;void&gt;
Asynchronously renames a file. This method uses a promise to return the result. Asynchronously renames a file. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ------- | ------ | ---- | ------------------------ | | ------- | ------ | ---- | ---------------------------- |
| oldPath | string | Yes | Absolute path of the file to rename.| | oldPath | string | Yes | Application sandbox path of the file to rename.|
| newPath | String | Yes | Absolute path of the file renamed. | | newPath | String | Yes | Application sandbox path of the file renamed. |
- Return value **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise used to return the result. An empty value is returned.| | Promise&lt;void&gt; | Promise used to return the result. An empty value is returned.|
- Example **Example**
```js ```js
fileio.rename(oldPath, newPath).then(function() { fileio.rename(oldPath, newPath).then(function() {
console.info("rename successfully"); console.info("rename successfully");
...@@ -1557,18 +1560,18 @@ Asynchronously renames a file. This method uses a promise to return the result. ...@@ -1557,18 +1560,18 @@ Asynchronously renames a file. This method uses a promise to return the result.
rename(oldPath: string, newPath: string, callback: AsyncCallback&lt;void&gt;): void rename(oldPath: string, newPath: string, callback: AsyncCallback&lt;void&gt;): void
Asynchronously renames a file. This method uses a callback to return the result. Asynchronously renames a file. This API uses a callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ------------- | | -------- | ------------------------- | ---- | ---------------------------- |
| oldPath | string | Yes | Absolute path of the file to rename. | | oldPath | string | Yes | Application sandbox path of the file to rename.|
| newPath | String | Yes | Absolute path of the file renamed. | | newPath | String | Yes | Application sandbox path of the file renamed. |
| Callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file is asynchronously renamed.| | Callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file is asynchronously renamed. |
- Example **Example**
```js ```js
fileio.rename(oldPath, newPath, function(err){ fileio.rename(oldPath, newPath, function(err){
}); });
...@@ -1583,13 +1586,13 @@ Synchronously renames a file. ...@@ -1583,13 +1586,13 @@ Synchronously renames a file.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| ------- | ------ | ---- | ------------ | | ------- | ------ | ---- | ---------------------------- |
| oldPath | string | Yes | Absolute path of the file to rename.| | oldPath | string | Yes | Application sandbox path of the file to rename.|
| newPath | String | Yes | Absolute path of the file renamed. | | newPath | String | Yes | Application sandbox path of the file renamed. |
- Example **Example**
```js ```js
fileio.renameSync(oldPath, newPath); fileio.renameSync(oldPath, newPath);
``` ```
...@@ -1599,21 +1602,21 @@ Synchronously renames a file. ...@@ -1599,21 +1602,21 @@ Synchronously renames a file.
fsync(fd: number): Promise&lt;void&gt; fsync(fd: number): Promise&lt;void&gt;
Asynchronously synchronizes a file. This method uses a promise to return the result. Asynchronously synchronizes a file. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ------------ | | ---- | ------ | ---- | ------------ |
| fd | number | Yes | File descriptor of the file to synchronize.| | fd | number | Yes | File descriptor of the file to synchronize.|
- Return value **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise used to return the result. An empty value is returned.| | Promise&lt;void&gt; | Promise used to return the result. An empty value is returned.|
- Example **Example**
```js ```js
fileio.fsync(fd).then(function(){ fileio.fsync(fd).then(function(){
console.info("sync data successfully"); console.info("sync data successfully");
...@@ -1627,17 +1630,17 @@ Asynchronously synchronizes a file. This method uses a promise to return the res ...@@ -1627,17 +1630,17 @@ Asynchronously synchronizes a file. This method uses a promise to return the res
fsync(fd: number, callback: AsyncCallback&lt;void&gt;): void fsync(fd: number, callback: AsyncCallback&lt;void&gt;): void
Asynchronously synchronizes a file. This method uses a callback to return the result. Asynchronously synchronizes a file. This API uses a callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | --------------- | | -------- | ------------------------- | ---- | --------------- |
| fd | number | Yes | File descriptor of the file to synchronize. | | fd | number | Yes | File descriptor of the file to synchronize. |
| Callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file is synchronized in asynchronous mode.| | Callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file is synchronized in asynchronous mode.|
- Example **Example**
```js ```js
fileio.fsync(fd, function(err){ fileio.fsync(fd, function(err){
// Do something. // Do something.
...@@ -1653,12 +1656,12 @@ Synchronizes a file in synchronous mode. ...@@ -1653,12 +1656,12 @@ Synchronizes a file in synchronous mode.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ------------ | | ---- | ------ | ---- | ------------ |
| fd | number | Yes | File descriptor of the file to synchronize.| | fd | number | Yes | File descriptor of the file to synchronize.|
- Example **Example**
```js ```js
fileio.fyncsSync(fd); fileio.fyncsSync(fd);
``` ```
...@@ -1668,21 +1671,21 @@ Synchronizes a file in synchronous mode. ...@@ -1668,21 +1671,21 @@ Synchronizes a file in synchronous mode.
fdatasync(fd: number): Promise&lt;void&gt; fdatasync(fd: number): Promise&lt;void&gt;
Asynchronously synchronizes data in a file. This method uses a promise to return the result. Asynchronously synchronizes data in a file. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ------------ | | ---- | ------ | ---- | ------------ |
| fd | number | Yes | File descriptor of the file to synchronize.| | fd | number | Yes | File descriptor of the file to synchronize.|
- Return value **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise used to return the result asynchronously. An empty value is returned.| | Promise&lt;void&gt; | Promise used to return the result asynchronously. An empty value is returned.|
- Example **Example**
```js ```js
fileio.fdatasync(fd).then(function(err) { fileio.fdatasync(fd).then(function(err) {
console.info("sync data successfully"); console.info("sync data successfully");
...@@ -1696,17 +1699,17 @@ Asynchronously synchronizes data in a file. This method uses a promise to return ...@@ -1696,17 +1699,17 @@ Asynchronously synchronizes data in a file. This method uses a promise to return
fdatasync(fd: number, callback:AsyncCallback&lt;void&gt;): void fdatasync(fd: number, callback:AsyncCallback&lt;void&gt;): void
Asynchronously synchronizes data in a file. This method uses a callback to return the result. Asynchronously synchronizes data in a file. This API uses a callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ------------------------------- | ---- | ----------------- | | -------- | ------------------------------- | ---- | ----------------- |
| fd | number | Yes | File descriptor of the file to synchronize. | | fd | number | Yes | File descriptor of the file to synchronize. |
| callback | AsyncCallback&nbsp;&lt;void&gt; | Yes | Callback invoked when the file data is synchronized in asynchronous mode.| | callback | AsyncCallback&nbsp;&lt;void&gt; | Yes | Callback invoked when the file data is synchronized in asynchronous mode.|
- Example **Example**
```js ```js
fileio.fdatasync (fd, function (err) { fileio.fdatasync (fd, function (err) {
// Do something. // Do something.
...@@ -1722,12 +1725,12 @@ Synchronizes data in a file in synchronous mode. ...@@ -1722,12 +1725,12 @@ Synchronizes data in a file in synchronous mode.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ------------ | | ---- | ------ | ---- | ------------ |
| fd | number | Yes | File descriptor of the file to synchronize.| | fd | number | Yes | File descriptor of the file to synchronize.|
- Example **Example**
```js ```js
let stat = fileio.fdatasyncSync(fd); let stat = fileio.fdatasyncSync(fd);
``` ```
...@@ -1737,22 +1740,22 @@ Synchronizes data in a file in synchronous mode. ...@@ -1737,22 +1740,22 @@ Synchronizes data in a file in synchronous mode.
symlink(target: string, srcPath: string): Promise&lt;void&gt; symlink(target: string, srcPath: string): Promise&lt;void&gt;
Asynchronously creates a symbolic link based on a path. This method uses a promise to return the result. Asynchronously creates a symbolic link based on a path. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| ------- | ------ | ---- | ------------ | | ------- | ------ | ---- | ---------------------------- |
| target | string | Yes | Absolute path of the symbolic link. | | target | string | Yes | Application sandbox path of the symbolic link. |
| srcPath | string | Yes | Absolute path of the referenced file or directory contained in the symbolic link.| | srcPath | string | Yes | Application sandbox path of the referenced file or directory contained in the symbolic link.|
- Return value **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise used to return the result asynchronously. An empty value is returned.| | Promise&lt;void&gt; | Promise used to return the result asynchronously. An empty value is returned.|
- Example **Example**
```js ```js
fileio.symlink(target, srcPath).then(function() { fileio.symlink(target, srcPath).then(function() {
console.info("symlink successfully"); console.info("symlink successfully");
...@@ -1766,18 +1769,18 @@ Asynchronously creates a symbolic link based on a path. This method uses a promi ...@@ -1766,18 +1769,18 @@ Asynchronously creates a symbolic link based on a path. This method uses a promi
symlink(target: string, srcPath: string, callback: AsyncCallback&lt;void&gt;): void symlink(target: string, srcPath: string, callback: AsyncCallback&lt;void&gt;): void
Asynchronously creates a symbolic link based on a path. This method uses a callback to return the result. Asynchronously creates a symbolic link based on a path. This API uses a callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ---------------- | | -------- | ------------------------- | ---- | -------------------------------- |
| target | string | Yes | Absolute path of the symbolic link. | | target | string | Yes | Application sandbox path of the symbolic link. |
| srcPath | string | Yes | Absolute path of the referenced file or directory contained in the symbolic link. | | srcPath | string | Yes | Application sandbox path of the referenced file or directory contained in the symbolic link. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the symbolic link is created asynchronously.| | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the symbolic link is created asynchronously.|
- Example **Example**
```js ```js
fileio.symlink(target, srcPath, function (err) { fileio.symlink(target, srcPath, function (err) {
// Do something. // Do something.
...@@ -1793,13 +1796,13 @@ Synchronously creates a symbolic link based on a specified path. ...@@ -1793,13 +1796,13 @@ Synchronously creates a symbolic link based on a specified path.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| ------- | ------ | ---- | ------------ | | ------- | ------ | ---- | ---------------------------- |
| target | string | Yes | Absolute path of the symbolic link. | | target | string | Yes | Application sandbox path of the symbolic link. |
| srcPath | string | Yes | Absolute path of the referenced file or directory contained in the symbolic link.| | srcPath | string | Yes | Application sandbox path the referenced file or directory contained in the symbolic link.|
- Example **Example**
```js ```js
fileio.symlinkSync(target, srcPath); fileio.symlinkSync(target, srcPath);
``` ```
...@@ -1809,23 +1812,23 @@ Synchronously creates a symbolic link based on a specified path. ...@@ -1809,23 +1812,23 @@ Synchronously creates a symbolic link based on a specified path.
chown(path: string, uid: number, gid: number): Promise&lt;void&gt; chown(path: string, uid: number, gid: number): Promise&lt;void&gt;
Asynchronously changes the file owner based on its path. This method uses a promise to return the result. Asynchronously changes the file owner based on its path. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name| Type | Mandatory| Description |
| ---- | ------ | ---- | --------------- | | ------ | ------ | ---- | -------------------------- |
| path | string | Yes | Absolute path of the target file. | | path | string | Yes | Application sandbox path of the target file.|
| uid | number | Yes | New user ID (UID). | | uid | number | Yes | New user ID (UID). |
| gid | number | Yes | New group ID (GID).| | gid | number | Yes | New group ID (GID). |
- Return value **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise used to return the result asynchronously. An empty value is returned.| | Promise&lt;void&gt; | Promise used to return the result asynchronously. An empty value is returned.|
- Example **Example**
```js ```js
let stat = fileio.statSync(path); let stat = fileio.statSync(path);
fileio.chown(path, stat.uid, stat.gid).then(function(){ fileio.chown(path, stat.uid, stat.gid).then(function(){
...@@ -1840,19 +1843,19 @@ Asynchronously changes the file owner based on its path. This method uses a prom ...@@ -1840,19 +1843,19 @@ Asynchronously changes the file owner based on its path. This method uses a prom
chown(path: string, uid: number, gid: number, callback: AsyncCallback&lt;void&gt;): void chown(path: string, uid: number, gid: number, callback: AsyncCallback&lt;void&gt;): void
Asynchronously changes the file owner based on its path. This method uses a callback to return the result. Asynchronously changes the file owner based on its path. This API uses a callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | --------------- | | -------- | ------------------------- | ---- | ------------------------------ |
| path | string | Yes | Absolute path of the target file. | | path | string | Yes | Application sandbox path of the target file. |
| uid | number | Yes | New UID. | | uid | number | Yes | New UID. |
| gid | number | Yes | New GID. | | gid | number | Yes | New GID. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file owner is changed asynchronously.| | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file owner is changed asynchronously.|
- Example **Example**
```js ```js
let stat = fileio.statSync(fpath) let stat = fileio.statSync(fpath)
fileio.chown(path, stat.uid, stat.gid, function (err){ fileio.chown(path, stat.uid, stat.gid, function (err){
...@@ -1869,14 +1872,14 @@ Synchronously changes the file owner based on its path. ...@@ -1869,14 +1872,14 @@ Synchronously changes the file owner based on its path.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name| Type | Mandatory| Description |
| ---- | ------ | ---- | ----------- | | ------ | ------ | ---- | -------------------------- |
| path | string | Yes | Absolute path of the target file.| | path | string | Yes | Application sandbox path of the target file.|
| uid | number | Yes | New UID. | | uid | number | Yes | New UID. |
| gid | number | Yes | New GID. | | gid | number | Yes | New GID. |
- Example **Example**
```js ```js
let stat = fileio.statSync(fpath) let stat = fileio.statSync(fpath)
fileio.chownSync(path, stat.uid, stat.gid); fileio.chownSync(path, stat.uid, stat.gid);
...@@ -1887,21 +1890,21 @@ Synchronously changes the file owner based on its path. ...@@ -1887,21 +1890,21 @@ Synchronously changes the file owner based on its path.
mkdtemp(prefix: string): Promise&lt;string&gt; mkdtemp(prefix: string): Promise&lt;string&gt;
Asynchronously creates a temporary directory. This method uses a promise to return the result. Asynchronously creates a temporary directory. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- | | ------ | ------ | ---- | --------------------------- |
| prefix | string | Yes | A randomly generated string used to replace "XXXXXX" in a directory.| | prefix | string | Yes | A randomly generated string used to replace "XXXXXX" in a directory.|
- Return value **Return value**
| Name | Description | | Name | Description |
| --------------------- | ---------- | | --------------------- | ---------- |
| Promise&lt;string&gt; | Unique path generated.| | Promise&lt;string&gt; | Unique path generated.|
- Example **Example**
```js ```js
fileio.mkdtemp(path + "XXXX").then(function(path){ fileio.mkdtemp(path + "XXXX").then(function(path){
console.info("mkdtemp successfully:"+ path); console.info("mkdtemp successfully:"+ path);
...@@ -1915,17 +1918,17 @@ Asynchronously creates a temporary directory. This method uses a promise to retu ...@@ -1915,17 +1918,17 @@ Asynchronously creates a temporary directory. This method uses a promise to retu
mkdtemp(prefix: string, callback: AsyncCallback&lt;string&gt;): void mkdtemp(prefix: string, callback: AsyncCallback&lt;string&gt;): void
Asynchronously creates a temporary directory. This method uses a callback to return the result. Asynchronously creates a temporary directory. This API uses a callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | --------------------------- | ---- | --------------------------- | | -------- | --------------------------- | ---- | --------------------------- |
| prefix | string | Yes | A randomly generated string used to replace "XXXXXX" in a directory.| | prefix | string | Yes | A randomly generated string used to replace "XXXXXX" in a directory.|
| callback | AsyncCallback&lt;string&gt; | Yes | Callback invoked when a temporary directory is created asynchronously. | | callback | AsyncCallback&lt;string&gt; | Yes | Callback invoked when a temporary directory is created asynchronously. |
- Example **Example**
```js ```js
fileio.mkdtemp(path + "XXXX", function (err, res) { fileio.mkdtemp(path + "XXXX", function (err, res) {
// Do something. // Do something.
...@@ -1941,17 +1944,17 @@ Synchronously creates a temporary directory. ...@@ -1941,17 +1944,17 @@ Synchronously creates a temporary directory.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- | | ------ | ------ | ---- | --------------------------- |
| prefix | string | Yes | A randomly generated string used to replace "XXXXXX" in a directory.| | prefix | string | Yes | A randomly generated string used to replace "XXXXXX" in a directory.|
- Return value **Return value**
| Name | Description | | Name | Description |
| ------ | ---------- | | ------ | ---------- |
| string | Unique path generated.| | string | Unique path generated.|
- Example **Example**
```js ```js
let res = fileio.mkdtempSync(path + "XXXX"); let res = fileio.mkdtempSync(path + "XXXX");
``` ```
...@@ -1961,22 +1964,22 @@ Synchronously creates a temporary directory. ...@@ -1961,22 +1964,22 @@ Synchronously creates a temporary directory.
fchmod(fd: number, mode: number): Promise&lt;void&gt; fchmod(fd: number, mode: number): Promise&lt;void&gt;
Asynchronously changes the file permissions based on the file descriptor. This method uses a promise to return the result. Asynchronously changes the file permissions based on the file descriptor. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ---------------------------------------- | | ---- | ------ | ---- | ---------------------------------------- |
| fd | number | Yes | File descriptor of the target file. | | fd | number | Yes | File descriptor of the target file. |
| mode | number | Yes | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (&#124;).<br>-&nbsp;**0o700**: The owner has the read, write, and execute permissions.<br>- &nbsp;**0o400**: The owner has the read permission.<br>-&nbsp;**0o200**: The owner has the write permission.<br>-&nbsp;**0o100**: The owner has the execute permission.<br>-&nbsp;**0o070**: The user group has the read, write, and execute permissions.<br>-&nbsp;**0o040**: The user group has the read permission.<br>-&nbsp;**0o020**: The user group has the write permission.<br>-&nbsp;**0o010**: The user group has the execute permission.<br>-&nbsp;**0o007**: Other users have the read, write, and execute permissions.<br>-&nbsp;**0o004**: Other users have the read permission.<br>-&nbsp;**0o002**: Other users have the write permission.<br>-&nbsp;**0o001**: Other users have the execute permission.| | mode | number | Yes | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (&#124;).<br>-&nbsp;**0o700**: The owner has the read, write, and execute permissions.<br>- &nbsp;**0o400**: The owner has the read permission.<br>-&nbsp;**0o200**: The owner has the write permission.<br>-&nbsp;**0o100**: The owner has the execute permission.<br>-&nbsp;**0o070**: The user group has the read, write, and execute permissions.<br>-&nbsp;**0o040**: The user group has the read permission.<br>-&nbsp;**0o020**: The user group has the write permission.<br>-&nbsp;**0o010**: The user group has the execute permission.<br>-&nbsp;**0o007**: Other users have the read, write, and execute permissions.<br>-&nbsp;**0o004**: Other users have the read permission.<br>-&nbsp;**0o002**: Other users have the write permission.<br>-&nbsp;**0o001**: Other users have the execute permission.|
- Return value **Return value**
| Name | Description | | Name | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise used to return the result asynchronously. An empty value is returned.| | Promise&lt;void&gt; | Promise used to return the result asynchronously. An empty value is returned.|
- Example **Example**
```js ```js
fileio.fchmod(fd, mode).then(function() { fileio.fchmod(fd, mode).then(function() {
console.info("chmod successfully"); console.info("chmod successfully");
...@@ -1990,18 +1993,18 @@ Asynchronously changes the file permissions based on the file descriptor. This m ...@@ -1990,18 +1993,18 @@ Asynchronously changes the file permissions based on the file descriptor. This m
fchmod(fd: number, mode: number, callback: AsyncCallback&lt;void&gt;): void fchmod(fd: number, mode: number, callback: AsyncCallback&lt;void&gt;): void
Asynchronously changes the file permissions based on the file descriptor. This method uses a callback to return the result. Asynchronously changes the file permissions based on the file descriptor. This API uses a callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ------------------------------- | ---- | ---------------------------------------- | | -------- | ------------------------------- | ---- | ---------------------------------------- |
| fd | number | Yes | File descriptor of the target file. | | fd | number | Yes | File descriptor of the target file. |
| mode | number | Yes | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (&#124;).<br>-&nbsp;**0o700**: The owner has the read, write, and execute permissions.<br>- &nbsp;**0o400**: The owner has the read permission.<br>-&nbsp;**0o200**: The owner has the write permission.<br>-&nbsp;**0o100**: The owner has the execute permission.<br>-&nbsp;**0o070**: The user group has the read, write, and execute permissions.<br>-&nbsp;**0o040**: The user group has the read permission.<br>-&nbsp;**0o020**: The user group has the write permission.<br>-&nbsp;**0o010**: The user group has the execute permission.<br>-&nbsp;**0o007**: Other users have the read, write, and execute permissions.<br>-&nbsp;**0o004**: Other users have the read permission.<br>-&nbsp;**0o002**: Other users have the write permission.<br>-&nbsp;**0o001**: Other users have the execute permission.| | mode | number | Yes | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (&#124;).<br>-&nbsp;**0o700**: The owner has the read, write, and execute permissions.<br>- &nbsp;**0o400**: The owner has the read permission.<br>-&nbsp;**0o200**: The owner has the write permission.<br>-&nbsp;**0o100**: The owner has the execute permission.<br>-&nbsp;**0o070**: The user group has the read, write, and execute permissions.<br>-&nbsp;**0o040**: The user group has the read permission.<br>-&nbsp;**0o020**: The user group has the write permission.<br>-&nbsp;**0o010**: The user group has the execute permission.<br>-&nbsp;**0o007**: Other users have the read, write, and execute permissions.<br>-&nbsp;**0o004**: Other users have the read permission.<br>-&nbsp;**0o002**: Other users have the write permission.<br>-&nbsp;**0o001**: Other users have the execute permission.|
| callback | AsyncCallback&nbsp;&lt;void&gt; | Yes | Callback invoked when the file permissions are changed asynchronously. | | callback | AsyncCallback&nbsp;&lt;void&gt; | Yes | Callback invoked when the file permissions are changed asynchronously. |
- Example **Example**
```js ```js
fileio.fchmod(fd, mode, function (err) { fileio.fchmod(fd, mode, function (err) {
// Do something. // Do something.
...@@ -2017,13 +2020,13 @@ Synchronously changes the file permissions based on the file descriptor. ...@@ -2017,13 +2020,13 @@ Synchronously changes the file permissions based on the file descriptor.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ---------------------------------------- | | ---- | ------ | ---- | ---------------------------------------- |
| fd | number | Yes | File descriptor of the target file. | | fd | number | Yes | File descriptor of the target file. |
| mode | number | Yes | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (&#124;).<br>-&nbsp;**0o700**: The owner has the read, write, and execute permissions.<br>- &nbsp;**0o400**: The owner has the read permission.<br>-&nbsp;**0o200**: The owner has the write permission.<br>-&nbsp;**0o100**: The owner has the execute permission.<br>-&nbsp;**0o070**: The user group has the read, write, and execute permissions.<br>-&nbsp;**0o040**: The user group has the read permission.<br>-&nbsp;**0o020**: The user group has the write permission.<br>-&nbsp;**0o010**: The user group has the execute permission.<br>-&nbsp;**0o007**: Other users have the read, write, and execute permissions.<br>-&nbsp;**0o004**: Other users have the read permission.<br>-&nbsp;**0o002**: Other users have the write permission.<br>-&nbsp;**0o001**: Other users have the execute permission.| | mode | number | Yes | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (&#124;).<br>-&nbsp;**0o700**: The owner has the read, write, and execute permissions.<br>- &nbsp;**0o400**: The owner has the read permission.<br>-&nbsp;**0o200**: The owner has the write permission.<br>-&nbsp;**0o100**: The owner has the execute permission.<br>-&nbsp;**0o070**: The user group has the read, write, and execute permissions.<br>-&nbsp;**0o040**: The user group has the read permission.<br>-&nbsp;**0o020**: The user group has the write permission.<br>-&nbsp;**0o010**: The user group has the execute permission.<br>-&nbsp;**0o007**: Other users have the read, write, and execute permissions.<br>-&nbsp;**0o004**: Other users have the read permission.<br>-&nbsp;**0o002**: Other users have the write permission.<br>-&nbsp;**0o001**: Other users have the execute permission.|
- Example **Example**
```js ```js
fileio.fchmodSync(fd, mode); fileio.fchmodSync(fd, mode);
``` ```
...@@ -2033,22 +2036,22 @@ Synchronously changes the file permissions based on the file descriptor. ...@@ -2033,22 +2036,22 @@ Synchronously changes the file permissions based on the file descriptor.
createStream(path: string, mode: string): Promise&lt;Stream&gt; createStream(path: string, mode: string): Promise&lt;Stream&gt;
Asynchronously opens a stream based on the file path. This method uses a promise to return the result. Asynchronously opens a stream based on the file path. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name| Type | Mandatory| Description |
| ---- | ------ | ---- | ---------------------------------------- | | ------ | ------ | ---- | ------------------------------------------------------------ |
| path | string | Yes | Absolute path of the target file. | | path | string | Yes | Application sandbox path of the target file. |
| mode | string | Yes | -&nbsp;**r**: Open a file for reading. The file must exist.<br>-&nbsp;**r+**: Open a file for both reading and writing. The file must exist.<br>-&nbsp;**w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.<br>-&nbsp;**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>-&nbsp;**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>-&nbsp;**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 | -&nbsp;**r**: Open a file for reading. The file must exist.<br>-&nbsp;**r+**: Open a file for both reading and writing. The file must exist.<br>-&nbsp;**w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.<br>-&nbsp;**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>-&nbsp;**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>-&nbsp;**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&lt;[Stream](#stream7)&gt; | Promise used to return the result.| | Promise&lt;[Stream](#stream7)&gt; | Promise used to return the result.|
- Example **Example**
```js ```js
fileio.createStream(path, "r+").then(function(stream){ fileio.createStream(path, "r+").then(function(stream){
console.info("createStream successfully"); console.info("createStream successfully");
...@@ -2062,18 +2065,18 @@ Asynchronously opens a stream based on the file path. This method uses a promise ...@@ -2062,18 +2065,18 @@ Asynchronously opens a stream based on the file path. This method uses a promise
createStream(path: string, mode: string, callback: AsyncCallback&lt;Stream&gt;): void createStream(path: string, mode: string, callback: AsyncCallback&lt;Stream&gt;): void
Asynchronously opens a stream based on the file path. This method uses a callback to return the result. Asynchronously opens a stream based on the file path. This API uses a callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ---------------------------------------- | | -------- | --------------------------------------- | ---- | ------------------------------------------------------------ |
| path | string | Yes | Absolute path of the target file. | | path | string | Yes | Application sandbox path of the target file. |
| mode | string | Yes | -&nbsp;**r**: Open a file for reading. The file must exist.<br>-&nbsp;**r+**: Open a file for both reading and writing. The file must exist.<br>-&nbsp;**w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.<br>-&nbsp;**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>-&nbsp;**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>-&nbsp;**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 | -&nbsp;**r**: Open a file for reading. The file must exist.<br>-&nbsp;**r+**: Open a file for both reading and writing. The file must exist.<br>-&nbsp;**w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.<br>-&nbsp;**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>-&nbsp;**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>-&nbsp;**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&lt;[Stream](#stream7)&gt; | Yes | Callback invoked when the stream is open asynchronously. | | callback | AsyncCallback&lt;[Stream](#stream7)&gt; | Yes | Callback invoked when the stream is open asynchronously. |
- Example **Example**
```js ```js
fileio.createStream(path, mode, function(err, stream){ fileio.createStream(path, mode, function(err, stream){
// Do something. // Do something.
...@@ -2089,18 +2092,18 @@ Synchronously opens a stream based on the file path. ...@@ -2089,18 +2092,18 @@ Synchronously opens a stream based on the file path.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name| Type | Mandatory| Description |
| ---- | ------ | ---- | ---------------------------------------- | | ------ | ------ | ---- | ------------------------------------------------------------ |
| path | string | Yes | Absolute path of the target file. | | path | string | Yes | Application sandbox path of the target file. |
| mode | string | Yes | -&nbsp;**r**: Open a file for reading. The file must exist.<br>-&nbsp;**r+**: Open a file for both reading and writing. The file must exist.<br>-&nbsp;**w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.<br>-&nbsp;**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>-&nbsp;**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>-&nbsp;**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 | -&nbsp;**r**: Open a file for reading. The file must exist.<br>-&nbsp;**r+**: Open a file for both reading and writing. The file must exist.<br>-&nbsp;**w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.<br>-&nbsp;**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>-&nbsp;**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>-&nbsp;**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**
| Name | Description | | Name | Description |
| ------------------ | --------- | | ------------------ | --------- |
| [Stream](#stream7) | Stream opened.| | [Stream](#stream7) | Stream opened.|
- Example **Example**
```js ```js
let ss = fileio.createStreamSync(path, "r+"); let ss = fileio.createStreamSync(path, "r+");
``` ```
...@@ -2110,22 +2113,22 @@ Synchronously opens a stream based on the file path. ...@@ -2110,22 +2113,22 @@ Synchronously opens a stream based on the file path.
fdopenStream(fd: number, mode: string): Promise&lt;Stream&gt; fdopenStream(fd: number, mode: string): Promise&lt;Stream&gt;
Asynchronously opens a stream based on the file descriptor. This method uses a promise to return the result. Asynchronously opens a stream based on the file descriptor. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ---------------------------------------- | | ---- | ------ | ---- | ---------------------------------------- |
| fd | number | Yes | File descriptor of the target file. | | fd | number | Yes | File descriptor of the target file. |
| mode | string | Yes | -&nbsp;**r**: Open a file for reading. The file must exist.<br>-&nbsp;**r+**: Open a file for both reading and writing. The file must exist.<br>-&nbsp;**w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.<br>-&nbsp;**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>-&nbsp;**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>-&nbsp;**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 | -&nbsp;**r**: Open a file for reading. The file must exist.<br>-&nbsp;**r+**: Open a file for both reading and writing. The file must exist.<br>-&nbsp;**w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.<br>-&nbsp;**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>-&nbsp;**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>-&nbsp;**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**
| Name | Description | | Name | Description |
| --------------------------------- | --------- | | --------------------------------- | --------- |
| Promise&lt;[Stream](#stream7)&gt; | Promise used to return the result.| | Promise&lt;[Stream](#stream7)&gt; | Promise used to return the result.|
- Example **Example**
```js ```js
fileio.fdopenStream(fd, mode).then(function(stream){ fileio.fdopenStream(fd, mode).then(function(stream){
console.info("openStream successfully"); console.info("openStream successfully");
...@@ -2139,18 +2142,18 @@ Asynchronously opens a stream based on the file descriptor. This method uses a p ...@@ -2139,18 +2142,18 @@ Asynchronously opens a stream based on the file descriptor. This method uses a p
fdopenStream(fd: number, mode: string, callback: AsyncCallback&lt;Stream&gt;): void fdopenStream(fd: number, mode: string, callback: AsyncCallback&lt;Stream&gt;): void
Asynchronously opens a stream based on the file descriptor. This method uses a callback to return the result. Asynchronously opens a stream based on the file descriptor. This API uses a callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- | | -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| fd | number | Yes | File descriptor of the target file. | | fd | number | Yes | File descriptor of the target file. |
| mode | string | Yes | -&nbsp;**r**: Open a file for reading. The file must exist.<br>-&nbsp;**r+**: Open a file for both reading and writing. The file must exist.<br>-&nbsp;**w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.<br>-&nbsp;**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>-&nbsp;**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>-&nbsp;**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 | -&nbsp;**r**: Open a file for reading. The file must exist.<br>-&nbsp;**r+**: Open a file for both reading and writing. The file must exist.<br>-&nbsp;**w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.<br>-&nbsp;**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>-&nbsp;**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>-&nbsp;**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&nbsp;&lt;[Stream](#stream7)&gt; | Yes | Callback invoked when the stream is open asynchronously. | | callback | AsyncCallback&nbsp;&lt;[Stream](#stream7)&gt; | Yes | Callback invoked when the stream is open asynchronously. |
- Example **Example**
```js ```js
fileio.fdopenStream(fd, mode, function (err, stream) { fileio.fdopenStream(fd, mode, function (err, stream) {
// Do something. // Do something.
...@@ -2166,18 +2169,18 @@ Synchronously opens a stream based on the file descriptor. ...@@ -2166,18 +2169,18 @@ Synchronously opens a stream based on the file descriptor.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ---------------------------------------- | | ---- | ------ | ---- | ---------------------------------------- |
| fd | number | Yes | File descriptor of the target file. | | fd | number | Yes | File descriptor of the target file. |
| mode | string | Yes | -&nbsp;**r**: Open a file for reading. The file must exist.<br>-&nbsp;**r+**: Open a file for both reading and writing. The file must exist.<br>-&nbsp;**w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.<br>-&nbsp;**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>-&nbsp;**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>-&nbsp;**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 | -&nbsp;**r**: Open a file for reading. The file must exist.<br>-&nbsp;**r+**: Open a file for both reading and writing. The file must exist.<br>-&nbsp;**w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.<br>-&nbsp;**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>-&nbsp;**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>-&nbsp;**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**
| Name | Description | | Type | Description |
| ------------------ | --------- | | ------------------ | --------- |
| [Stream](#stream7) | Stream opened.| | [Stream](#stream7) | Stream opened.|
- Example **Example**
```js ```js
let ss = fileio.fdopenStreamSync(fd, "r+"); let ss = fileio.fdopenStreamSync(fd, "r+");
``` ```
...@@ -2187,23 +2190,23 @@ Synchronously opens a stream based on the file descriptor. ...@@ -2187,23 +2190,23 @@ Synchronously opens a stream based on the file descriptor.
fchown(fd: number, uid: number, gid: number): Promise&lt;void&gt; fchown(fd: number, uid: number, gid: number): Promise&lt;void&gt;
Asynchronously changes the file owner based on the file descriptor. This method uses a promise to return the result. Asynchronously changes the file owner based on the file descriptor. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ------------ | | ---- | ------ | ---- | ------------ |
| fd | number | Yes | File descriptor of the target file.| | fd | number | Yes | File descriptor of the target file.|
| uid | number | Yes | New UID. | | uid | number | Yes | New UID. |
| gid | number | Yes | New GID. | | gid | number | Yes | New GID. |
- Return value **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise used to return the result. An empty value is returned.| | Promise&lt;void&gt; | Promise used to return the result. An empty value is returned.|
- Example **Example**
```js ```js
let stat = fileio.statSync(path); let stat = fileio.statSync(path);
fileio.fchown(fd, stat.uid, stat.gid).then(function() { fileio.fchown(fd, stat.uid, stat.gid).then(function() {
...@@ -2218,11 +2221,11 @@ Asynchronously changes the file owner based on the file descriptor. This method ...@@ -2218,11 +2221,11 @@ Asynchronously changes the file owner based on the file descriptor. This method
fchown(fd: number, uid: number, gid: number, callback: AsyncCallback&lt;void&gt;): void fchown(fd: number, uid: number, gid: number, callback: AsyncCallback&lt;void&gt;): void
Asynchronously changes the file owner based on the file descriptor. This method uses a callback to return the result. Asynchronously changes the file owner based on the file descriptor. This API uses a callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | --------------- | | -------- | ------------------------- | ---- | --------------- |
| fd | number | Yes | File descriptor of the target file. | | fd | number | Yes | File descriptor of the target file. |
...@@ -2230,7 +2233,7 @@ Asynchronously changes the file owner based on the file descriptor. This method ...@@ -2230,7 +2233,7 @@ Asynchronously changes the file owner based on the file descriptor. This method
| gid | number | Yes | New GID. | | gid | number | Yes | New GID. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file owner is changed asynchronously.| | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file owner is changed asynchronously.|
- Example **Example**
```js ```js
let stat = fileio.statSync(fpath); let stat = fileio.statSync(fpath);
fileio.fchown(fd, stat.uid, stat.gid, function (err){ fileio.fchown(fd, stat.uid, stat.gid, function (err){
...@@ -2247,14 +2250,14 @@ Synchronously changes the file owner based on the file descriptor. ...@@ -2247,14 +2250,14 @@ Synchronously changes the file owner based on the file descriptor.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ------------ | | ---- | ------ | ---- | ------------ |
| fd | number | Yes | File descriptor of the target file.| | fd | number | Yes | File descriptor of the target file.|
| uid | number | Yes | New UID. | | uid | number | Yes | New UID. |
| gid | number | Yes | New GID. | | gid | number | Yes | New GID. |
- Example **Example**
```js ```js
let stat = fileio.statSync(fpath); let stat = fileio.statSync(fpath);
fileio.fchownSync(fd, stat.uid, stat.gid); fileio.fchownSync(fd, stat.uid, stat.gid);
...@@ -2269,19 +2272,19 @@ Asynchronously changes the file owner based on the file path, changes the owner ...@@ -2269,19 +2272,19 @@ Asynchronously changes the file owner based on the file path, changes the owner
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name| Type | Mandatory| Description |
| ---- | ------ | ---- | ----------- | | ------ | ------ | ---- | -------------------------- |
| path | string | Yes | Absolute path of the target file.| | path | string | Yes | Application sandbox path of the target file.|
| uid | number | Yes | New UID. | | uid | number | Yes | New UID. |
| gid | number | Yes | New GID. | | gid | number | Yes | New GID. |
- Return value **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise used to return the result. An empty value is returned.| | Promise&lt;void&gt; | Promise used to return the result. An empty value is returned.|
- Example **Example**
```js ```js
let stat = fileio.statSync(path); let stat = fileio.statSync(path);
fileio.lchown(path, stat.uid, stat.gid).then(function() { fileio.lchown(path, stat.uid, stat.gid).then(function() {
...@@ -2300,15 +2303,15 @@ Asynchronously changes the file owner based on the file path, changes the owner ...@@ -2300,15 +2303,15 @@ Asynchronously changes the file owner based on the file path, changes the owner
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | --------------- | | -------- | ------------------------- | ---- | ------------------------------ |
| path | string | Yes | Absolute path of the target file. | | path | string | Yes | Application sandbox path of the target file. |
| uid | number | Yes | New UID. | | uid | number | Yes | New UID. |
| gid | number | Yes | New GID. | | gid | number | Yes | New GID. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file owner is changed asynchronously.| | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file owner is changed asynchronously.|
- Example **Example**
```js ```js
let stat = fileio.statSync(path); let stat = fileio.statSync(path);
fileio.lchown(path, stat.uid, stat.gid, function (err){ fileio.lchown(path, stat.uid, stat.gid, function (err){
...@@ -2325,14 +2328,14 @@ Synchronously changes the file owner based on the file path and changes the owne ...@@ -2325,14 +2328,14 @@ Synchronously changes the file owner based on the file path and changes the owne
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name| Type | Mandatory| Description |
| ---- | ------ | ---- | ----------- | | ------ | ------ | ---- | -------------------------- |
| path | string | Yes | Absolute path of the target file.| | path | string | Yes | Application sandbox path of the target file.|
| uid | number | Yes | New UID. | | uid | number | Yes | New UID. |
| gid | number | Yes | New GID. | | gid | number | Yes | New GID. |
- Example **Example**
```js ```js
let stat = fileio.statSync(path); let stat = fileio.statSync(path);
fileio.lchownSync(path, stat.uid, stat.gid); fileio.lchownSync(path, stat.uid, stat.gid);
...@@ -2343,23 +2346,23 @@ Synchronously changes the file owner based on the file path and changes the owne ...@@ -2343,23 +2346,23 @@ Synchronously changes the file owner based on the file path and changes the owne
createWatcher(filename: string, events: number, callback: AsyncCallback&lt;number&gt;): Watcher createWatcher(filename: string, events: number, callback: AsyncCallback&lt;number&gt;): Watcher
Asynchronously listens for the changes of a file or directory. This method uses a callback to return the result. Asynchronously listens for the changes of a file or directory. This API uses a callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| -------- | --------------------------------- | ---- | ---------------------------------------- | | -------- | --------------------------------- | ---- | ------------------------------------------------------------ |
| filename | string | Yes | Absolute path of the target file. | | filename | string | Yes | Application sandbox path of the target file. |
| events | Number | Yes | -&nbsp;**1**: The file or directory is renamed.<br>-&nbsp;**2**: The file or directory is modified.<br>-&nbsp;**3**: The file or directory is modified and renamed.| | events | Number | Yes | -&nbsp;**1**: The file or directory is renamed.<br>-&nbsp;**2**: The file or directory is modified.<br>-&nbsp;**3**: The file or directory is modified and renamed.|
| callback | AsyncCallback&lt;number&nbsp;&gt; | Yes | Called each time a change is detected. | | callback | AsyncCallback&lt;number&nbsp;&gt; | Yes | Called each time a change is detected. |
- Return value **Return value**
| Name | Description | | Name | Description |
| -------------------- | ---------- | | -------------------- | ---------- |
| [Watcher](#watcher7) | Instance for listening for a file change event.| | [Watcher](#watcher7) | Instance for listening for a file change event.|
- Example **Example**
```js ```js
fileio.createWatcher(filename, events, function(watcher){ fileio.createWatcher(filename, events, function(watcher){
// Do something. // Do something.
...@@ -2412,12 +2415,12 @@ Checks whether this file is a block special file. A block special file supports ...@@ -2412,12 +2415,12 @@ Checks whether this file is a block special file. A block special file supports
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- 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**
```js ```js
let isBLockDevice = fileio.statSync(path).isBlockDevice(); let isBLockDevice = fileio.statSync(path).isBlockDevice();
``` ```
...@@ -2431,12 +2434,12 @@ Checks whether this file is a character special file. A character special file s ...@@ -2431,12 +2434,12 @@ Checks whether this file is a character special file. A character special file s
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- 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**
```js ```js
let isCharacterDevice = fileio.statSync(path).isCharacterDevice(); let isCharacterDevice = fileio.statSync(path).isCharacterDevice();
``` ```
...@@ -2450,12 +2453,12 @@ Checks whether this file is a directory. ...@@ -2450,12 +2453,12 @@ Checks whether this file is a directory.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Return value **Return value**
| Type | Description | | Type | Description |
| ------- | ------------- | | ------- | ------------- |
| boolean | Whether the file is a directory.| | boolean | Whether the file is a directory.|
- Example **Example**
```js ```js
let isDirectory = fileio.statSync(path).isDirectory(); let isDirectory = fileio.statSync(path).isDirectory();
``` ```
...@@ -2469,12 +2472,12 @@ Checks whether this file is a named pipe (or FIFO). Named pipes are used for int ...@@ -2469,12 +2472,12 @@ Checks whether this file is a named pipe (or FIFO). Named pipes are used for int
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Return value **Return value**
| Type | Description | | Type | Description |
| ------- | --------------------- | | ------- | --------------------- |
| boolean | Whether the file is an FIFO.| | boolean | Whether the file is an FIFO.|
- Example **Example**
```js ```js
let isFIFO = fileio.statSync(path).isFIFO(); let isFIFO = fileio.statSync(path).isFIFO();
``` ```
...@@ -2488,12 +2491,12 @@ Checks whether this file is a regular file. ...@@ -2488,12 +2491,12 @@ Checks whether this file is a regular file.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- 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**
```js ```js
let isFile = fileio.statSync(fpath).isFile(); let isFile = fileio.statSync(fpath).isFile();
``` ```
...@@ -2507,12 +2510,12 @@ Checks whether this file is a socket. ...@@ -2507,12 +2510,12 @@ Checks whether this file is a socket.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Return value **Return value**
| Type | Description | | Type | Description |
| ------- | -------------- | | ------- | -------------- |
| boolean | Whether the file is a socket.| | boolean | Whether the file is a socket.|
- Example **Example**
```js ```js
let isSocket = fileio.statSync(path).isSocket(); let isSocket = fileio.statSync(path).isSocket();
``` ```
...@@ -2526,12 +2529,12 @@ Checks whether this file is a symbolic link. ...@@ -2526,12 +2529,12 @@ Checks whether this file is a symbolic link.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- 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**
```js ```js
let isSymbolicLink = fileio.statSync(path).isSymbolicLink(); let isSymbolicLink = fileio.statSync(path).isSymbolicLink();
``` ```
...@@ -2546,11 +2549,11 @@ Listens for the changes of a file. You can call the **Watcher.stop()** method sy ...@@ -2546,11 +2549,11 @@ Listens for the changes of a file. You can call the **Watcher.stop()** method sy
stop(): Promise&lt;void&gt; stop(): Promise&lt;void&gt;
Asynchronously stops **watcher**. This method uses a promise to return the result. Asynchronously stops **watcher**. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Example **Example**
```js ```js
fileio.stop(); fileio.stop();
``` ```
...@@ -2560,16 +2563,16 @@ Asynchronously stops **watcher**. This method uses a promise to return the resul ...@@ -2560,16 +2563,16 @@ Asynchronously stops **watcher**. This method uses a promise to return the resul
stop(callback: AsyncCallback&lt;void&gt;): void stop(callback: AsyncCallback&lt;void&gt;): void
Asynchronously stops **watcher**. This method uses a callback to return the result. Asynchronously stops **watcher**. This API uses a callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | ---------------------- | | -------- | ------------------------- | ---- | ---------------------- |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when **watcher** is stopped asynchronously.| | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when **watcher** is stopped asynchronously.|
- Example **Example**
```js ```js
fileio.stop(function(err){ fileio.stop(function(err){
// Do something. // Do something.
...@@ -2587,16 +2590,16 @@ File stream. Before calling a method of the **Stream** class, use the **createSt ...@@ -2587,16 +2590,16 @@ File stream. Before calling a method of the **Stream** class, use the **createSt
close(): Promise&lt;void&gt; close(): Promise&lt;void&gt;
Asynchronously closes the stream. This method uses a promise to return the result. Asynchronously closes the stream. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Return value **Return value**
| Type | Description | | Type | Description |
| ------------------- | ------------- | | ------------------- | ------------- |
| Promise&lt;void&gt; | Promise used to return the stream close result.| | Promise&lt;void&gt; | Promise used to return the stream close result.|
- Example **Example**
```js ```js
let ss= fileio.createStreamSync(path); let ss= fileio.createStreamSync(path);
ss.close().then(function(){ ss.close().then(function(){
...@@ -2611,16 +2614,16 @@ Asynchronously closes the stream. This method uses a promise to return the resul ...@@ -2611,16 +2614,16 @@ Asynchronously closes the stream. This method uses a promise to return the resul
close(callback: AsyncCallback&lt;void&gt;): void close(callback: AsyncCallback&lt;void&gt;): void
Asynchronously closes the stream. This method uses a callback to return the result. Asynchronously closes the stream. This API uses a callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | ------------- | | -------- | ------------------------- | ---- | ------------- |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the stream is closed asynchronously.| | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the stream is closed asynchronously.|
- Example **Example**
```js ```js
let ss= fileio.createStreamSync(path); let ss= fileio.createStreamSync(path);
ss.close(function (err) { ss.close(function (err) {
...@@ -2637,7 +2640,7 @@ Synchronously closes the stream. ...@@ -2637,7 +2640,7 @@ Synchronously closes the stream.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Example **Example**
```js ```js
let ss= fileio.createStreamSync(path); let ss= fileio.createStreamSync(path);
ss.closeSync(); ss.closeSync();
...@@ -2648,16 +2651,16 @@ Synchronously closes the stream. ...@@ -2648,16 +2651,16 @@ Synchronously closes the stream.
flush(): Promise&lt;void&gt; flush(): Promise&lt;void&gt;
Asynchronously flushes the stream. This method uses a promise to return the result. Asynchronously flushes the stream. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Return value **Return value**
| Type | Description | | Type | Description |
| ------------------- | ------------- | | ------------------- | ------------- |
| Promise&lt;void&gt; | Promise used to return the stream flushing result.| | Promise&lt;void&gt; | Promise used to return the stream flushing result.|
- Example **Example**
```js ```js
let ss= fileio.createStreamSync(path); let ss= fileio.createStreamSync(path);
ss.flush().then(function (){ ss.flush().then(function (){
...@@ -2672,16 +2675,16 @@ Asynchronously flushes the stream. This method uses a promise to return the resu ...@@ -2672,16 +2675,16 @@ Asynchronously flushes the stream. This method uses a promise to return the resu
flush(callback: AsyncCallback&lt;void&gt;): void flush(callback: AsyncCallback&lt;void&gt;): void
Asynchronously flushes the stream. This method uses a callback to return the result. Asynchronously flushes the stream. This API uses a callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | -------------- | | -------- | ------------------------- | ---- | -------------- |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the stream is asynchronously flushed.| | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the stream is asynchronously flushed.|
- Example **Example**
```js ```js
let ss= fileio.createStreamSync(path); let ss= fileio.createStreamSync(path);
ss.flush(function (err) { ss.flush(function (err) {
...@@ -2698,7 +2701,7 @@ Synchronously flushes the stream. ...@@ -2698,7 +2701,7 @@ Synchronously flushes the stream.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Example **Example**
```js ```js
let ss= fileio.createStreamSync(path); let ss= fileio.createStreamSync(path);
ss.flushSync(); ss.flushSync();
...@@ -2714,22 +2717,22 @@ write(buffer: ArrayBuffer | string, options?: { ...@@ -2714,22 +2717,22 @@ write(buffer: ArrayBuffer | string, options?: {
encoding?: string; encoding?: string;
}): Promise&lt;number&gt; }): Promise&lt;number&gt;
Asynchronously writes data into the stream. This method uses a promise to return the result. Asynchronously writes data into the stream. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------- | ------------------------------- | ---- | ---------------------------------------- | | ------- | ------------------------------- | ---- | ---------------------------------------- |
| buffer | ArrayBuffer&nbsp;\|&nbsp;string | Yes | Data to write. It can be a string or data from a buffer. | | buffer | ArrayBuffer&nbsp;\|&nbsp;string | Yes | Data to write. It can be a string or data from a buffer. |
| options | Object | No | The options are as follows:<br>-&nbsp;**offset** (number): position of the data to write in reference to the start address of the data. The default value is **0**.<br>-&nbsp;**length** (number): length of the data to write. The default value is the buffer length minus the offset.<br>-&nbsp;**position** (number): start position to write the data in the file. By default, data is written from the current position.<br>-&nbsp;**encoding** (string): format of the string to be encoded. The default value is **utf-8**, which is the only value supported.<br>- &nbsp;The sum of **offset** and **length** must be less than or equal to the buffer size. | | options | Object | No | The options are as follows:<br>-&nbsp;**offset** (number): position of the data to write in reference to the start address of the data. The default value is **0**.<br>-&nbsp;**length** (number): length of the data to write. The default value is the buffer length minus the offset.<br>-&nbsp;**position** (number): start position to write the data in the file. By default, data is written from the current position.<br>-&nbsp;**encoding** (string): format of the string to be encoded. The default value is **utf-8**, which is the only value supported.<br>Constraints: offset + length <= Buffer size |
- Return value **Return value**
| Type | Description | | Type | Description |
| --------------------- | -------- | | --------------------- | -------- |
| Promise&lt;number&gt; | Length of the data written in the file.| | Promise&lt;number&gt; | Length of the data written in the file.|
- Example **Example**
```js ```js
let ss= fileio.createStreamSync(fpath, "r+"); let ss= fileio.createStreamSync(fpath, "r+");
ss.write("hello, world",{offset: 1,length: 5,position: 5,encoding :'utf-8'}).then(function (number){ ss.write("hello, world",{offset: 1,length: 5,position: 5,encoding :'utf-8'}).then(function (number){
...@@ -2749,18 +2752,18 @@ write(buffer: ArrayBuffer | string, options: { ...@@ -2749,18 +2752,18 @@ write(buffer: ArrayBuffer | string, options: {
encoding?: string; encoding?: string;
}, callback: AsyncCallback&lt;number&gt;): void }, callback: AsyncCallback&lt;number&gt;): void
Asynchronously writes data into the stream. This method uses a callback to return the result. Asynchronously writes data into the stream. This API uses a callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------------- | ---- | ------------------------------------------------------------ | | -------- | ------------------------------- | ---- | ------------------------------------------------------------ |
| buffer | ArrayBuffer&nbsp;\|&nbsp;string | Yes | Data to write. It can be a string or data from a buffer. | | buffer | ArrayBuffer&nbsp;\|&nbsp;string | Yes | Data to write. It can be a string or data from a buffer. |
| options | Object | No | The options are as follows:<br>-&nbsp;**offset** (number): position of the data to write in reference to the start address of the data. The default value is **0**.<br>-&nbsp;**length** (number): length of the data to write. The default value is the buffer length minus the offset.<br>-&nbsp;**position** (number): start position to write the data in the file. By default, data is written from the current position.<br>-&nbsp;**encoding** (string): format of the string to be encoded. The default value is **utf-8**, which is the only value supported.<br>- &nbsp;The sum of **offset** and **length** must be less than or equal to the buffer size.| | options | Object | No | The options are as follows:<br>-&nbsp;**offset** (number): position of the data to write in reference to the start address of the data. The default value is **0**.<br>-&nbsp;**length** (number): length of the data to write. The default value is the buffer length minus the offset.<br>-&nbsp;**position** (number): start position to write the data in the file. By default, data is written from the current position.<br>-&nbsp;**encoding** (string): format of the string to be encoded. The default value is **utf-8**, which is the only value supported.<br>Constraints: offset + length <= Buffer size|
| callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked when the data is written asynchronously. | | callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked when the data is written asynchronously. |
- Example **Example**
```js ```js
let ss= fileio.createStreamSync(fpath, "r+"); let ss= fileio.createStreamSync(fpath, "r+");
ss.write("hello, world", {offset: 1, length: 5, position: 5, encoding :'utf-8'}, function (err, bytesWritten) { ss.write("hello, world", {offset: 1, length: 5, position: 5, encoding :'utf-8'}, function (err, bytesWritten) {
...@@ -2785,18 +2788,18 @@ Synchronously writes data into the stream. ...@@ -2785,18 +2788,18 @@ Synchronously writes data into the stream.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------- | ------------------------------- | ---- | ---------------------------------------- | | ------- | ------------------------------- | ---- | ---------------------------------------- |
| buffer | ArrayBuffer&nbsp;\|&nbsp;string | Yes | Data to write. It can be a string or data from a buffer. | | buffer | ArrayBuffer&nbsp;\|&nbsp;string | Yes | Data to write. It can be a string or data from a buffer. |
| options | Object | No | The options are as follows:<br>-&nbsp;**offset** (number): position of the data to write in reference to the start address of the data. The default value is **0**.<br>-&nbsp;**length** (number): length of the data to write. The default value is the buffer length minus the offset.<br>-&nbsp;**position** (number): start position to write the data in the file. By default, data is written from the current position.<br>-&nbsp;**encoding** (string): format of the string to be encoded. The default value is **utf-8**, which is the only value supported.<br>- &nbsp;The sum of **offset** and **length** must be less than or equal to the buffer size. | | options | Object | No | The options are as follows:<br>-&nbsp;**offset** (number): position of the data to write in reference to the start address of the data. The default value is **0**.<br>-&nbsp;**length** (number): length of the data to write. The default value is the buffer length minus the offset.<br>-&nbsp;**position** (number): start position to write the data in the file. By default, data is written from the current position.<br>-&nbsp;**encoding** (string): format of the string to be encoded. The default value is **utf-8**, which is the only value supported.<br>Constraints: offset + length <= Buffer size |
- 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**
```js ```js
let ss= fileio.createStreamSync(fpath,"r+"); let ss= fileio.createStreamSync(fpath,"r+");
let num = ss.writeSync("hello, world", {offset: 1, length: 5, position: 5, encoding :'utf-8'}); let num = ss.writeSync("hello, world", {offset: 1, length: 5, position: 5, encoding :'utf-8'});
...@@ -2811,22 +2814,22 @@ read(buffer: ArrayBuffer, options?: { ...@@ -2811,22 +2814,22 @@ read(buffer: ArrayBuffer, options?: {
length?: number; length?: number;
}): Promise&lt;ReadOut&gt; }): Promise&lt;ReadOut&gt;
Asynchronously reads data from the stream. This method uses a promise to return the result. Asynchronously reads data from the stream. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------- | ----------- | ---- | ---------------------------------------- | | ------- | ----------- | ---- | ---------------------------------------- |
| 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>-&nbsp;**offset** (number): position to store the data read in the buffer in reference to the start address of the buffer. The default value is **0**.<br>-&nbsp;**length** (number): length of the data to read. The default value is the buffer length minus the offset.<br>-&nbsp;**position** (number): position of the data to read in the file. By default, data is read from the current position.<br>- &nbsp;The sum of **offset** and **length** must be less than or equal to the buffer size. | | options | Object | No | The options are as follows:<br>-&nbsp;**offset** (number): position to store the data read in the buffer in reference to the start address of the buffer. The default value is **0**.<br>-&nbsp;**length** (number): length of the data to read. The default value is the buffer length minus the offset.<br>-&nbsp;**position** (number): position of the data to read in the file. By default, data is read from the current position.<br>Constraints: offset + length <= Buffer size |
- Return value **Return value**
| Type | Description | | Type | Description |
| ---------------------------------- | ------ | | ---------------------------------- | ------ |
| Promise&lt;[ReadOut](#readout)&gt; | Data read.| | Promise&lt;[ReadOut](#readout)&gt; | Data read.|
- Example **Example**
```js ```js
let ss = fileio.createStreamSync(fpath, "r+"); let ss = fileio.createStreamSync(fpath, "r+");
ss.read(new ArrayBuffer(4096), {offset: 1, length: 5, position: 5}).then(function (readout){ ss.read(new ArrayBuffer(4096), {offset: 1, length: 5, position: 5}).then(function (readout){
...@@ -2846,18 +2849,18 @@ read(buffer: ArrayBuffer, options: { ...@@ -2846,18 +2849,18 @@ read(buffer: ArrayBuffer, options: {
length?: number; length?: number;
}, callback: AsyncCallback&lt;ReadOut&gt;): void }, callback: AsyncCallback&lt;ReadOut&gt;): void
Asynchronously reads data from the stream. This method uses a callback to return the result. Asynchronously reads data from the stream. This API uses a callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- | | -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| 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>-&nbsp;**offset** (number): position to store the data read in the buffer in reference to the start address of the buffer. The default value is **0**.<br>-&nbsp;**length** (number): length of the data to read. The default value is the buffer length minus the offset.<br>-&nbsp;**position** (number): position of the data to read in the file. By default, data is read from the current position.<br>- &nbsp;The sum of **offset** and **length** must be less than or equal to the buffer size. | | options | Object | No | The options are as follows:<br>-&nbsp;**offset** (number): position to store the data read in the buffer in reference to the start address of the buffer. The default value is **0**.<br>-&nbsp;**length** (number): length of the data to read. The default value is the buffer length minus the offset.<br>-&nbsp;**position** (number): position of the data to read in the file. By default, data is read from the current position.<br>Constraints: offset + length <= Buffer size |
| callback | AsyncCallback&lt;[ReadOut](#readout)&gt; | Yes | Callback invoked when data is read asynchronously from the stream. | | callback | AsyncCallback&lt;[ReadOut](#readout)&gt; | Yes | Callback invoked when data is read asynchronously from the stream. |
- Example **Example**
```js ```js
let ss = fileio.createStreamSync(fpath, "r+"); let ss = fileio.createStreamSync(fpath, "r+");
ss.read(new ArrayBuffer(4096),{offset: 1, length: 5, position: 5},function (err, readOut) { ss.read(new ArrayBuffer(4096),{offset: 1, length: 5, position: 5},function (err, readOut) {
...@@ -2881,18 +2884,20 @@ Synchronously reads data from the stream. ...@@ -2881,18 +2884,20 @@ Synchronously reads data from the stream.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------- | ----------- | ---- | ---------------------------------------- | | ------- | ----------- | ---- | ---------------------------------------- |
| 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>-&nbsp;**offset** (number): position to store the data read in the buffer in reference to the start address of the buffer. The default value is **0**.<br>-&nbsp;**length** (number): length of the data to read. The default value is the buffer length minus the offset.<br>-&nbsp;**position** (number): position of the data to read in the file. By default, data is read from the current position.<br>- &nbsp;The sum of **offset** and **length** must be less than or equal to the buffer size. | | options | Object | No | The options are as follows:<br>-&nbsp;**offset** (number): position to store the data read in the buffer in reference to the start address of the buffer. The default value is **0**.<br>-&nbsp;**length** (number): length of the data to read. The default value is the buffer length minus the offset.<br>-&nbsp;**position** (number): position of the data to read in the file. By default, data is read from the current position.<br>Constraints: offset + length <= Buffer size |
**Return value**
- Return value
| Type | Description | | Type | Description |
| ------ | -------- | | ------ | -------- |
| number | Length of the data read.| | number | Length of the data read.|
- Example **Example**
```js ```js
let ss = fileio.createStreamSync(fpath, "r+"); let ss = fileio.createStreamSync(fpath, "r+");
let num = ss.readSync(new ArrayBuffer(4096), {offset: 1, length: 5, position: 5}); let num = ss.readSync(new ArrayBuffer(4096), {offset: 1, length: 5, position: 5});
...@@ -2908,16 +2913,16 @@ Manages directories. Before calling a method of the **Dir** class, use the [open ...@@ -2908,16 +2913,16 @@ Manages directories. Before calling a method of the **Dir** class, use the [open
read(): Promise&lt;Dirent&gt; read(): Promise&lt;Dirent&gt;
Asynchronously reads the next directory entry. This method uses a promise to return the result. Asynchronously reads the next directory entry. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Return value **Return value**
| Type | Description | | Type | Description |
| -------------------------------- | ------------- | | -------------------------------- | ------------- |
| Promise&lt;[Dirent](#dirent)&gt; | Directory entry that is read asynchronously.| | Promise&lt;[Dirent](#dirent)&gt; | Directory entry that is read asynchronously.|
- Example **Example**
```js ```js
let dir = fileio.opendirSync(path); let dir = fileio.opendirSync(path);
dir.read().then(function (dirent){ dir.read().then(function (dirent){
...@@ -2932,16 +2937,16 @@ Asynchronously reads the next directory entry. This method uses a promise to ret ...@@ -2932,16 +2937,16 @@ Asynchronously reads the next directory entry. This method uses a promise to ret
read(callback: AsyncCallback&lt;Dirent&gt;): void read(callback: AsyncCallback&lt;Dirent&gt;): void
Asynchronously reads the next directory entry. This method uses a callback to return the result. Asynchronously reads the next directory entry. This API uses a callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | -------------------------------------- | ---- | ---------------- | | -------- | -------------------------------------- | ---- | ---------------- |
| callback | AsyncCallback&lt;[Dirent](#dirent)&gt; | Yes | Callback invoked when the next directory entry is asynchronously read.| | callback | AsyncCallback&lt;[Dirent](#dirent)&gt; | Yes | Callback invoked when the next directory entry is asynchronously read.|
- Example **Example**
```js ```js
let dir = fileio.opendirSync(path); let dir = fileio.opendirSync(path);
dir.read(function (err, dirent) { dir.read(function (err, dirent) {
...@@ -2961,12 +2966,12 @@ Synchronously reads the next directory entry. ...@@ -2961,12 +2966,12 @@ Synchronously reads the next directory entry.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Return value **Return value**
| Type | Description | | Type | Description |
| ----------------- | -------- | | ----------------- | -------- |
| [Dirent](#dirent) | Directory entry read.| | [Dirent](#dirent) | Directory entry read.|
- Example **Example**
```js ```js
let dir = fileio.opendirSync(path); let dir = fileio.opendirSync(path);
let dirent = dir.readSync(); let dirent = dir.readSync();
...@@ -2981,7 +2986,7 @@ Closes a directory. After a directory is closed, the file descriptor in Dir will ...@@ -2981,7 +2986,7 @@ Closes a directory. After a directory is closed, the file descriptor in Dir will
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Example **Example**
```js ```js
let dir = fileio.opendirSync(path); let dir = fileio.opendirSync(path);
dir.closeSync(); dir.closeSync();
...@@ -3009,12 +3014,12 @@ Checks whether the current directory entry is a block special file. A block spec ...@@ -3009,12 +3014,12 @@ Checks whether the current directory entry is a block special file. A block spec
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Return value **Return value**
| Type | Description | | Type | Description |
| ------- | ---------------- | | ------- | ---------------- |
| boolean | Whether the directory entry is a block special file.| | boolean | Whether the directory entry is a block special file.|
- Example **Example**
```js ```js
let dir = fileio.opendirSync(path); let dir = fileio.opendirSync(path);
let isBLockDevice = dir.readSync().isBlockDevice(); let isBLockDevice = dir.readSync().isBlockDevice();
...@@ -3029,12 +3034,12 @@ Checks whether a directory entry is a character special file. A character specia ...@@ -3029,12 +3034,12 @@ Checks whether a directory entry is a character special file. A character specia
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Return value **Return value**
| Type | Description | | Type | Description |
| ------- | ----------------- | | ------- | ----------------- |
| boolean | Whether the directory entry is a character special file.| | boolean | Whether the directory entry is a character special file.|
- Example **Example**
```js ```js
let dir = fileio.opendirSync(path); let dir = fileio.opendirSync(path);
let isCharacterDevice = dir.readSync().isCharacterDevice(); let isCharacterDevice = dir.readSync().isCharacterDevice();
...@@ -3049,12 +3054,12 @@ Checks whether a directory entry is a directory. ...@@ -3049,12 +3054,12 @@ Checks whether a directory entry is a directory.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Return value **Return value**
| Type | Description | | Type | Description |
| ------- | ------------- | | ------- | ------------- |
| boolean | Whether the directory entry is a directory.| | boolean | Whether the directory entry is a directory.|
- Example **Example**
```js ```js
let dir = fileio.opendirSync(path); let dir = fileio.opendirSync(path);
let isDirectory = dir.readSync().isDirectory(); let isDirectory = dir.readSync().isDirectory();
...@@ -3069,12 +3074,12 @@ Checks whether the current directory entry is a named pipe (or FIFO). Named pipe ...@@ -3069,12 +3074,12 @@ Checks whether the current directory entry is a named pipe (or FIFO). Named pipe
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Return value **Return value**
| Type | Description | | Type | Description |
| ------- | --------------- | | ------- | --------------- |
| boolean | Whether the directory entry is a FIFO.| | boolean | Whether the directory entry is a FIFO.|
- Example **Example**
```js ```js
let dir = fileio.opendirSync(path); let dir = fileio.opendirSync(path);
let isFIFO = dir.readSync().isFIFO(); let isFIFO = dir.readSync().isFIFO();
...@@ -3089,12 +3094,12 @@ Checks whether a directory entry is a regular file. ...@@ -3089,12 +3094,12 @@ Checks whether a directory entry is a regular file.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Return value **Return value**
| Type | Description | | Type | Description |
| ------- | --------------- | | ------- | --------------- |
| boolean | Whether the directory entry is a regular file.| | boolean | Whether the directory entry is a regular file.|
- Example **Example**
```js ```js
let dir = fileio.opendirSync(path); let dir = fileio.opendirSync(path);
let isFile = dir.readSync().isFile(); let isFile = dir.readSync().isFile();
...@@ -3109,12 +3114,12 @@ Checks whether a directory entry is a socket. ...@@ -3109,12 +3114,12 @@ Checks whether a directory entry is a socket.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Return value **Return value**
| Type | Description | | Type | Description |
| ------- | -------------- | | ------- | -------------- |
| boolean | Whether the directory entry is a socket.| | boolean | Whether the directory entry is a socket.|
- Example **Example**
```js ```js
let dir = fileio.opendirSync(dpath); let dir = fileio.opendirSync(dpath);
let isSocket = dir.readSync().isSocket(); let isSocket = dir.readSync().isSocket();
...@@ -3129,12 +3134,12 @@ Checks whether a directory entry is a symbolic link. ...@@ -3129,12 +3134,12 @@ Checks whether a directory entry is a symbolic link.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
- Return value **Return value**
| Type | Description | | Type | Description |
| ------- | --------------- | | ------- | --------------- |
| boolean | Whether the directory entry is a symbolic link.| | boolean | Whether the directory entry is a symbolic link.|
- Example **Example**
```js ```js
let dir = fileio.opendirSync(path); let dir = fileio.opendirSync(path);
let isSymbolicLink = dir.readSync().isSymbolicLink(); let isSymbolicLink = dir.readSync().isSymbolicLink();
......
# User File Access and Management # User File Access and Management
>![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br/> >**NOTE**<br/>
> >
>- 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 9. 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. Currently, these APIs can be called only by **filepicker**. >- The APIs of this module are system APIs and cannot be called by third-party applications. Currently, these APIs can be called only by **filepicker**.
This module provides service APIs for accessing and managing user files. It interworks with the underlying file management services to implement media library and external card management, and provides capabilities for applications to query and create user files.
## Modules to Import ## Modules to Import
```js ```js
...@@ -81,8 +83,8 @@ Obtains information about the second-level album or files in asynchronous mode. ...@@ -81,8 +83,8 @@ Obtains information about the second-level album or files in asynchronous mode.
- Parameters - Parameters
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| --- | --- | --- | -- | | --- | --- | --- | -- |
| path | string | Yes| URI of the directory to query.| | path | promise<string>| Yes| URI of the directory to query.|
| type | string | Yes| Type of the files to query. The file type can be **file**, **image**, **audio**, or **video**.| | type | promise<string>| Yes| Type of the files to query. The file type can be **file**, **image**, **audio**, or **video**.|
| options | Object | No| The options are as follows:<br>- &nbsp;**dev**: See [DevInfo](#devinfo). It is **dev = {name: "local"}** by default if not specified. Currently, only 'local' is supported.<br>- &nbsp;**offset**: position to start the query. The value is a number.<br>- &nbsp;**count**: number of files to query.| | options | Object | No| The options are as follows:<br>- &nbsp;**dev**: See [DevInfo](#devinfo). It is **dev = {name: "local"}** by default if not specified. Currently, only 'local' is supported.<br>- &nbsp;**offset**: position to start the query. The value is a number.<br>- &nbsp;**count**: number of files to query.|
- Return value - Return value
...@@ -128,8 +130,8 @@ Obtains information about the second-level album or files in asynchronous mode. ...@@ -128,8 +130,8 @@ Obtains information about the second-level album or files in asynchronous mode.
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ------------------------------------------------------------ | | -------- | ------------------------- | ---- | ------------------------------------------------------------ |
| path | string | Yes | URI of the directory to query. | | path | promise<string> | Yes | URI of the directory to query. |
| type | string | Yes | Type of the files to query. The file type can be **file**, **image**, **audio**, or **video**.| | type | promise<string> | Yes | Type of the files to query. The file type can be **file**, **image**, **audio**, or **video**.|
| options | Object | No| The options are as follows:<br>- &nbsp;**dev**: See [DevInfo](#devinfo). It is **dev = {name: "local"}** by default if not specified. Currently, only 'local' is supported.<br>- &nbsp;**offset**: position to start the query. The value is a number.<br>- &nbsp;**count**: number of files to query.| | options | Object | No| The options are as follows:<br>- &nbsp;**dev**: See [DevInfo](#devinfo). It is **dev = {name: "local"}** by default if not specified. Currently, only 'local' is supported.<br>- &nbsp;**offset**: position to start the query. The value is a number.<br>- &nbsp;**count**: number of files to query.|
| callback | AsyncCallback&lt;[FileInfo](#fileinfo)[]&gt; | Yes | Callback invoked to return the file information obtained. | | callback | AsyncCallback&lt;[FileInfo](#fileinfo)[]&gt; | Yes | Callback invoked to return the file information obtained. |
- Error - Error
...@@ -156,7 +158,7 @@ Obtains information about the second-level album or files in asynchronous mode. ...@@ -156,7 +158,7 @@ Obtains information about the second-level album or files in asynchronous mode.
## filemanager.createFile ## filemanager.createFile
filemanager.createFile(path : string, filename : string, options? : {dev? : DevInfo}) : Promise&lt;string&gt; createFile(path : string, filename : string, options? : {dev? : DevInfo}) : Promise&lt;string&gt;
Creates a file in the specified path in asynchronous mode. This API uses a promise to return the result. Creates a file in the specified path in asynchronous mode. This API uses a promise to return the result.
...@@ -165,8 +167,8 @@ Creates a file in the specified path in asynchronous mode. This API uses a promi ...@@ -165,8 +167,8 @@ Creates a file in the specified path in asynchronous mode. This API uses a promi
- Parameters - Parameters
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| --- | --- | --- | -- | | --- | --- | --- | -- |
| filename | string | Yes| Name of the file to create.| | filename | promise<string>| Yes| Name of the file to create.|
| path | string | Yes| URI of the file to create.| | path | promise<string>| Yes| URI of the file to create.|
| options | Object | No| The options are as follows:<br>- &nbsp;**dev**: See [DevInfo](#devinfo). It is **dev = {name: "local"}** by default if not specified. Currently, only 'local' is supported.| | options | Object | No| The options are as follows:<br>- &nbsp;**dev**: See [DevInfo](#devinfo). It is **dev = {name: "local"}** by default if not specified. Currently, only 'local' is supported.|
- Return value - Return value
...@@ -209,8 +211,8 @@ Creates a file in the specified path in asynchronous mode. This API uses a callb ...@@ -209,8 +211,8 @@ Creates a file in the specified path in asynchronous mode. This API uses a callb
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ----------------------------- | | -------- | ------------------------- | ---- | ----------------------------- |
| filename | string | Yes | Name of the file to create. | | filename | promise<string> | Yes | Name of the file to create. |
| path | string | Yes | URI of the file to create. | | path | promise<string> | Yes | URI of the file to create. |
| options | Object | No| The options are as follows:<br>- &nbsp;**dev**: See [DevInfo](#devinfo). It is **dev = {name: "local"}** by default if not specified. Currently, only 'local' is supported.| | options | Object | No| The options are as follows:<br>- &nbsp;**dev**: See [DevInfo](#devinfo). It is **dev = {name: "local"}** by default if not specified. Currently, only 'local' is supported.|
| callback | AsyncCallback&lt;[FileInfo](#fileinfo)[]&gt; | Yes | Callback invoked to return the file information obtained. | | callback | AsyncCallback&lt;[FileInfo](#fileinfo)[]&gt; | Yes | Callback invoked to return the file information obtained. |
...@@ -246,9 +248,9 @@ Defines the file information returned by **getRoot()** or **listFile()**. ...@@ -246,9 +248,9 @@ Defines the file information returned by **getRoot()** or **listFile()**.
| Name| Type| Readable| Writable| Description| | Name| Type| Readable| Writable| Description|
| --- | -- | -- | -- | -- | | --- | -- | -- | -- | -- |
| name | string | Yes| No| File name.| | name | promise<string>| Yes| No| File name.|
| path | string | Yes| No| URI of the file.| | path | promise<string>| Yes| No| URI of the file.|
| type | string | Yes| No| File type.| | type | promise<string>| Yes| No| File type.|
| size | number | Yes| No| File size.| | size | number | Yes| No| File size.|
| addedTime | number | Yes| No| Time when the file was scanned to the database.| | addedTime | number | Yes| No| Time when the file was scanned to the database.|
| modifiedTime | number | Yes| No| Time when the file was modified.| | modifiedTime | number | Yes| No| Time when the file was modified.|
...@@ -263,4 +265,4 @@ Defines the device type. ...@@ -263,4 +265,4 @@ Defines the device type.
| Name| Type | Readable| Writable| Description | | Name| Type | Readable| Writable| Description |
| ------ | ------ | ---- | ---- | -------- | | ------ | ------ | ---- | ---- | -------- |
| name | string | Yes | Yes | Device name.| | name | promise<string>| Yes | Yes | Device name.|
# RPC # RPC
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br/> > **NOTE**<br>
> 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.
...@@ -26,12 +26,12 @@ Creates a **MessageParcel** object. This method is a static method. ...@@ -26,12 +26,12 @@ Creates a **MessageParcel** object. This method is a static method.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| MessageParcel | **MessageParcel** object created.| | MessageParcel | **MessageParcel** object created.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -47,7 +47,7 @@ Reclaims the **MessageParcel** object that is no longer used. ...@@ -47,7 +47,7 @@ Reclaims the **MessageParcel** object that is no longer used.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Example **Example**
``` ```
let reply = rpc.MessageParcel.create(); let reply = rpc.MessageParcel.create();
...@@ -63,23 +63,37 @@ writeRemoteObject(object: [IRemoteObject](#iremoteobject)): boolean ...@@ -63,23 +63,37 @@ writeRemoteObject(object: [IRemoteObject](#iremoteobject)): boolean
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| object | [IRemoteObject](#iremoteobject) | Yes| Remote object to serialize and write to the **MessageParcel** object.| | object | [IRemoteObject](#iremoteobject) | Yes| Remote object to serialize and write to the **MessageParcel** object.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example **Example**
``` ```
class MyDeathRecipient {
onRemoteDied() {
console.log("server is died");
}
}
class TestRemoteObject extends rpc.RemoteObject { class TestRemoteObject extends rpc.RemoteObject {
constructor(descriptor) { constructor(descriptor) {
super(descriptor); super(descriptor);
} }
addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
return true;
}
removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
return true;
}
isObjectDead(): boolean {
return false;
}
} }
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
let testRemoteObject = new TestRemoteObject("testObject"); let testRemoteObject = new TestRemoteObject("testObject");
...@@ -95,18 +109,32 @@ Reads the remote object from this **MessageParcel** object. You can use this met ...@@ -95,18 +109,32 @@ Reads the remote object from this **MessageParcel** object. You can use this met
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| [IRemoteObject](#iremoteobject) | Remote object obtained.| | [IRemoteObject](#iremoteobject) | Remote object obtained.|
- Example **Example**
``` ```
class MyDeathRecipient {
onRemoteDied() {
console.log("server is died");
}
}
class TestRemoteObject extends rpc.RemoteObject { class TestRemoteObject extends rpc.RemoteObject {
constructor(descriptor) { constructor(descriptor) {
super(descriptor); super(descriptor);
} }
addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
return true;
}
removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
return true;
}
isObjectDead(): boolean {
return false;
}
} }
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
let testRemoteObject = new TestRemoteObject("testObject"); let testRemoteObject = new TestRemoteObject("testObject");
...@@ -123,17 +151,17 @@ Writes an interface token to this **MessageParcel** object. ...@@ -123,17 +151,17 @@ Writes an interface token to this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| token | string | Yes| Interface token to write.| | token | string | Yes| Interface token to write.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -150,12 +178,12 @@ Reads the interface token from this **MessageParcel** object. The interface toke ...@@ -150,12 +178,12 @@ Reads the interface token from this **MessageParcel** object. The interface toke
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| string | Interface token obtained.| | string | Interface token obtained.|
- Example **Example**
``` ```
class Stub extends rpc.RemoteObject { class Stub extends rpc.RemoteObject {
...@@ -176,12 +204,12 @@ Obtains the data size of this **MessageParcel** object. ...@@ -176,12 +204,12 @@ Obtains the data size of this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| number | Size of the **MessageParcel** object obtained, in bytes.| | number | Size of the **MessageParcel** object obtained, in bytes.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -198,12 +226,12 @@ Obtains the capacity of this **MessageParcel** object. ...@@ -198,12 +226,12 @@ Obtains the capacity of this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| number | **MessageParcel** capacity obtained, in bytes.| | number | **MessageParcel** capacity obtained, in bytes.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -220,17 +248,17 @@ Sets the size of data contained in this **MessageParcel** object. ...@@ -220,17 +248,17 @@ Sets the size of data contained in this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| size | number | Yes| Data size to set, in bytes.| | size | number | Yes| Data size to set, in bytes.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -247,17 +275,17 @@ Sets the storage capacity of this **MessageParcel** object. ...@@ -247,17 +275,17 @@ Sets the storage capacity of this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| size | number | Yes| Storage capacity to set, in bytes.| | size | number | Yes| Storage capacity to set, in bytes.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -274,12 +302,12 @@ Obtains the writable capacity of this **MessageParcel** object. ...@@ -274,12 +302,12 @@ Obtains the writable capacity of this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| number | **MessageParcel** writable capacity obtained, in bytes.| | number | **MessageParcel** writable capacity obtained, in bytes.|
- Example **Example**
``` ```
class Stub extends rpc.RemoteObject { class Stub extends rpc.RemoteObject {
...@@ -300,12 +328,12 @@ Obtains the readable capacity of this **MessageParcel** object. ...@@ -300,12 +328,12 @@ Obtains the readable capacity of this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| number | **MessageParcel** object readable capacity, in bytes.| | number | **MessageParcel** object readable capacity, in bytes.|
- Example **Example**
``` ```
class Stub extends rpc.RemoteObject { class Stub extends rpc.RemoteObject {
...@@ -326,12 +354,12 @@ Obtains the read position of this **MessageParcel** object. ...@@ -326,12 +354,12 @@ Obtains the read position of this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| number | Current read position of the **MessageParcel** object.| | number | Current read position of the **MessageParcel** object.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -348,12 +376,12 @@ Obtains the write position of this **MessageParcel** object. ...@@ -348,12 +376,12 @@ Obtains the write position of this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| number | Current write position of the **MessageParcel** object.| | number | Current write position of the **MessageParcel** object.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -371,17 +399,17 @@ Moves the read pointer to the specified position. ...@@ -371,17 +399,17 @@ Moves the read pointer to the specified position.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| pos | number | Yes| Position from which data is to read.| | pos | number | Yes| Position from which data is to read.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the read position changes; returns **false** otherwise.| | boolean | Returns **true** if the read position changes; returns **false** otherwise.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -403,17 +431,17 @@ Moves the write pointer to the specified position. ...@@ -403,17 +431,17 @@ Moves the write pointer to the specified position.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| pos | number | Yes| Position from which data is to write.| | pos | number | Yes| Position from which data is to write.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the write position changes; returns **false** otherwise.| | boolean | Returns **true** if the write position changes; returns **false** otherwise.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -433,17 +461,17 @@ Writes a Byte value to this **MessageParcel** object. ...@@ -433,17 +461,17 @@ Writes a Byte value to this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| val | number | Yes| Byte value to write.| | val | number | Yes| Byte value to write.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -460,12 +488,12 @@ Reads the Byte value from this **MessageParcel** object. ...@@ -460,12 +488,12 @@ Reads the Byte value from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| number | Byte value read.| | number | Byte value read.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -484,17 +512,17 @@ Writes a Short int value to this **MessageParcel** object. ...@@ -484,17 +512,17 @@ Writes a Short int value to this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| val | number | Yes| Short int value to write.| | val | number | Yes| Short int value to write.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -511,12 +539,12 @@ Reads the Short int value from this **MessageParcel** object. ...@@ -511,12 +539,12 @@ Reads the Short int value from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| number | Short int value read.| | number | Short int value read.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -535,17 +563,17 @@ Writes an Int value to this **MessageParcel** object. ...@@ -535,17 +563,17 @@ Writes an Int value to this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| val | number | Yes| Int value to write.| | val | number | Yes| Int value to write.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -562,12 +590,12 @@ Reads the Int value from this **MessageParcel** object. ...@@ -562,12 +590,12 @@ Reads the Int value from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| number | Int value read.| | number | Int value read.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -586,17 +614,17 @@ Writes a Long int value to this **MessageParcel** object. ...@@ -586,17 +614,17 @@ Writes a Long int value to this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| val | number | Yes| Long int value to write.| | val | number | Yes| Long int value to write.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -613,18 +641,18 @@ Reads the Long int value from this **MessageParcel** object. ...@@ -613,18 +641,18 @@ Reads the Long int value from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| number | Long int value read.| | number | Long int value read.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
let result = data.writeLong(10000); let result = data.writeLong(10000);
console.log("RpcClient: writeLong is " + result); console.log("RpcClient: writeLong is " + result);
let ret = data.readlong(); let ret = data.readLong();
console.log("RpcClient: readLong is " + ret); console.log("RpcClient: readLong is " + ret);
``` ```
...@@ -637,17 +665,17 @@ Writes a Float value to this **MessageParcel** object. ...@@ -637,17 +665,17 @@ Writes a Float value to this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| val | number | Yes| Float value to write.| | val | number | Yes| Float value to write.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -664,12 +692,12 @@ Reads the Float value from this **MessageParcel** object. ...@@ -664,12 +692,12 @@ Reads the Float value from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| number | Float value read.| | number | Float value read.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -688,17 +716,17 @@ Writes a Double value to this **MessageParcel** object. ...@@ -688,17 +716,17 @@ Writes a Double value to this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| val | number | Yes| Double value to write.| | val | number | Yes| Double value to write.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -715,12 +743,12 @@ Reads the Double value from this **MessageParcel** object. ...@@ -715,12 +743,12 @@ Reads the Double value from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| number | Double value read.| | number | Double value read.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -739,17 +767,17 @@ Writes a Boolean value to this **MessageParcel** object. ...@@ -739,17 +767,17 @@ Writes a Boolean value to this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| val | boolean | Yes| Boolean value to write.| | val | boolean | Yes| Boolean value to write.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -766,12 +794,12 @@ Reads the Boolean value from this **MessageParcel** object. ...@@ -766,12 +794,12 @@ Reads the Boolean value from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Boolean value read.| | boolean | Boolean value read.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -790,21 +818,21 @@ Writes a Char value to this **MessageParcel** object. ...@@ -790,21 +818,21 @@ Writes a Char value to this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| val | number | Yes| Char value to write.| | val | number | Yes| Char value to write.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
let result = data.writeChar('a'); let result = data.writeChar(97);
console.log("RpcClient: writeChar is " + result); console.log("RpcClient: writeChar is " + result);
``` ```
...@@ -817,16 +845,16 @@ Reads the Char value from this **MessageParcel** object. ...@@ -817,16 +845,16 @@ Reads the Char value from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| number | Char value read.| | number | Char value read.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
let result = data.writeChar('a'); let result = data.writeChar(97);
console.log("RpcClient: writeChar is " + result); console.log("RpcClient: writeChar is " + result);
let ret = data.readChar(); let ret = data.readChar();
console.log("RpcClient: readChar is " + ret); console.log("RpcClient: readChar is " + ret);
...@@ -841,17 +869,17 @@ Writes a String value to this **MessageParcel** object. ...@@ -841,17 +869,17 @@ Writes a String value to this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| val | string | Yes| String value to write.| | val | string | Yes| String value to write.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -868,12 +896,12 @@ Reads the String value from this **MessageParcel** object. ...@@ -868,12 +896,12 @@ Reads the String value from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| string | String value read.| | string | String value read.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -892,23 +920,25 @@ Writes a sequenceable object to this **MessageParcel** object. ...@@ -892,23 +920,25 @@ Writes a sequenceable object to this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| val | [Sequenceable](#sequenceable) | Yes| Sequenceable object to write.| | val | [Sequenceable](#sequenceable) | Yes| Sequenceable object to write.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example **Example**
``` ```
class MySequenceable { class MySequenceable {
constructor(num, string) { num: number;
str: string;
constructor(num, str) {
this.num = num; this.num = num;
this.str = string; this.str = str;
} }
marshalling(messageParcel) { marshalling(messageParcel) {
messageParcel.writeInt(this.num); messageParcel.writeInt(this.num);
...@@ -936,23 +966,25 @@ Reads member variables from this **MessageParcel** object. ...@@ -936,23 +966,25 @@ Reads member variables from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| dataIn | [Sequenceable](#sequenceable) | Yes| Object that reads member variables from the **MessageParcel** object.| | dataIn | [Sequenceable](#sequenceable) | Yes| Object that reads member variables from the **MessageParcel** object.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example **Example**
``` ```
class MySequenceable { class MySequenceable {
constructor(num, string) { num: number;
str: string;
constructor(num, str) {
this.num = num; this.num = num;
this.str = string; this.str = str;
} }
marshalling(messageParcel) { marshalling(messageParcel) {
messageParcel.writeInt(this.num); messageParcel.writeInt(this.num);
...@@ -983,21 +1015,21 @@ Writes a ByteArray to this **MessageParcel** object. ...@@ -983,21 +1015,21 @@ Writes a ByteArray to this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| byteArray | number[] | Yes| ByteArray to write.| | byteArray | number[] | Yes| ByteArray to write.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
let ByteArrayVar = new Int8Array([1, 2, 3, 4, 5]); let ByteArrayVar = [1, 2, 3, 4, 5];
let result = data.writeByteArray(ByteArrayVar); let result = data.writeByteArray(ByteArrayVar);
console.log("RpcClient: writeByteArray is " + result); console.log("RpcClient: writeByteArray is " + result);
``` ```
...@@ -1011,16 +1043,16 @@ Reads the ByteArray from this **MessageParcel** object. ...@@ -1011,16 +1043,16 @@ Reads the ByteArray from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| dataIn | number[] | Yes| ByteArray to read.| | dataIn | number[] | Yes| ByteArray to read.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
let ByteArrayVar = new Int8Array([1, 2, 3, 4, 5]); let ByteArrayVar = [1, 2, 3, 4, 5];
let result = data.writeByteArray(ByteArrayVar); let result = data.writeByteArray(ByteArrayVar);
console.log("RpcClient: writeByteArray is " + result); console.log("RpcClient: writeByteArray is " + result);
let array = new Array(5); let array = new Array(5);
...@@ -1036,16 +1068,16 @@ Reads the ByteArray from this **MessageParcel** object. ...@@ -1036,16 +1068,16 @@ Reads the ByteArray from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| number[] | ByteArray read.| | number[] | ByteArray read.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
let ByteArrayVar = new Int8Array([1, 2, 3, 4, 5]); let ByteArrayVar = [1, 2, 3, 4, 5];
let result = data.writeByteArray(ByteArrayVar); let result = data.writeByteArray(ByteArrayVar);
console.log("RpcClient: writeByteArray is " + result); console.log("RpcClient: writeByteArray is " + result);
let array = data.readByteArray(); let array = data.readByteArray();
...@@ -1061,17 +1093,17 @@ Writes a ShortArray to this **MessageParcel** object. ...@@ -1061,17 +1093,17 @@ Writes a ShortArray to this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| shortArray | number[] | Yes| ShortArray to write.| | shortArray | number[] | Yes| ShortArray to write.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -1088,12 +1120,12 @@ Reads a ShortArray from this **MessageParcel** object. ...@@ -1088,12 +1120,12 @@ Reads a ShortArray from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| dataIn | number[] | Yes| ShortArray to read.| | dataIn | number[] | Yes| ShortArray to read.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -1112,12 +1144,12 @@ Reads the ShortArray from this **MessageParcel** object. ...@@ -1112,12 +1144,12 @@ Reads the ShortArray from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| number[] | ShortArray read.| | number[] | ShortArray read.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -1136,17 +1168,17 @@ Writes an IntArray to this **MessageParcel** object. ...@@ -1136,17 +1168,17 @@ Writes an IntArray to this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| intArray | number[] | Yes| IntArray to write.| | intArray | number[] | Yes| IntArray to write.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -1163,12 +1195,12 @@ Reads an IntArray from this **MessageParcel** object. ...@@ -1163,12 +1195,12 @@ Reads an IntArray from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| dataIn | number[] | Yes| IntArray to read.| | dataIn | number[] | Yes| IntArray to read.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -1187,12 +1219,12 @@ Reads the IntArray from this **MessageParcel** object. ...@@ -1187,12 +1219,12 @@ Reads the IntArray from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| number[] | IntArray read.| | number[] | IntArray read.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -1211,17 +1243,17 @@ Writes a LongArray to this **MessageParcel** object. ...@@ -1211,17 +1243,17 @@ Writes a LongArray to this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| longArray | number[] | Yes| LongArray to write.| | longArray | number[] | Yes| LongArray to write.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -1238,12 +1270,12 @@ Reads a LongArray from this **MessageParcel** object. ...@@ -1238,12 +1270,12 @@ Reads a LongArray from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| dataIn | number[] | Yes| LongArray to read.| | dataIn | number[] | Yes| LongArray to read.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -1262,12 +1294,12 @@ Reads the LongArray from this **MessageParcel** object. ...@@ -1262,12 +1294,12 @@ Reads the LongArray from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| number[] | LongArray read.| | number[] | LongArray read.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -1286,17 +1318,17 @@ Writes a FloatArray to this **MessageParcel** object. ...@@ -1286,17 +1318,17 @@ Writes a FloatArray to this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| floatArray | number[] | Yes| FloatArray to write.| | floatArray | number[] | Yes| FloatArray to write.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -1313,13 +1345,13 @@ Reads a FloatArray from this **MessageParcel** object. ...@@ -1313,13 +1345,13 @@ Reads a FloatArray from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| dataIn | number[] | Yes| FloatArray to read.| | dataIn | number[] | Yes| FloatArray to read.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -1338,12 +1370,12 @@ Reads the FloatArray from this **MessageParcel** object. ...@@ -1338,12 +1370,12 @@ Reads the FloatArray from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| number[] | FloatArray read.| | number[] | FloatArray read.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -1362,17 +1394,17 @@ Writes a DoubleArray to this **MessageParcel** object. ...@@ -1362,17 +1394,17 @@ Writes a DoubleArray to this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| doubleArray | number[] | Yes| DoubleArray to write.| | doubleArray | number[] | Yes| DoubleArray to write.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -1389,12 +1421,12 @@ Reads a DoubleArray from this **MessageParcel** object. ...@@ -1389,12 +1421,12 @@ Reads a DoubleArray from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| dataIn | number[] | Yes| DoubleArray to read.| | dataIn | number[] | Yes| DoubleArray to read.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -1413,12 +1445,12 @@ Reads the DoubleArray from this **MessageParcel** object. ...@@ -1413,12 +1445,12 @@ Reads the DoubleArray from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| number[] | DoubleArray read.| | number[] | DoubleArray read.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -1437,17 +1469,17 @@ Writes a BooleanArray to this **MessageParcel** object. ...@@ -1437,17 +1469,17 @@ Writes a BooleanArray to this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| booleanArray | boolean[] | Yes| BooleanArray to write.| | booleanArray | boolean[] | Yes| BooleanArray to write.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -1464,12 +1496,12 @@ Reads a BooleanArray from this **MessageParcel** object. ...@@ -1464,12 +1496,12 @@ Reads a BooleanArray from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| dataIn | boolean[] | Yes| BooleanArray to read.| | dataIn | boolean[] | Yes| BooleanArray to read.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -1488,7 +1520,7 @@ Reads the BooleanArray from this **MessageParcel** object. ...@@ -1488,7 +1520,7 @@ Reads the BooleanArray from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean[] | BooleanArray read.| | boolean[] | BooleanArray read.|
...@@ -1511,21 +1543,21 @@ Writes a CharArray to this **MessageParcel** object. ...@@ -1511,21 +1543,21 @@ Writes a CharArray to this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| charArray | number[] | Yes| CharArray to write.| | charArray | number[] | Yes| CharArray to write.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
let result = data.writeCharArray(['a', 'b', 'c']); let result = data.writeCharArray([97, 98, 88]);
console.log("RpcClient: writeCharArray is " + result); console.log("RpcClient: writeCharArray is " + result);
``` ```
...@@ -1538,16 +1570,16 @@ Reads a CharArray from this **MessageParcel** object. ...@@ -1538,16 +1570,16 @@ Reads a CharArray from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| dataIn | number[] | Yes| CharArray to read.| | dataIn | number[] | Yes| CharArray to read.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
let result = data.writeCharArray(['a', 'b', 'c']); let result = data.writeCharArray([97, 98, 99]);
console.log("RpcClient: writeCharArray is " + result); console.log("RpcClient: writeCharArray is " + result);
let array = new Array(3); let array = new Array(3);
data.readCharArray(array); data.readCharArray(array);
...@@ -1562,16 +1594,16 @@ Reads the CharArray from this **MessageParcel** object. ...@@ -1562,16 +1594,16 @@ Reads the CharArray from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| number[] | CharArray read.| | number[] | CharArray read.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
let result = data.writeCharArray(['a', 'b', 'c']); let result = data.writeCharArray([97, 98, 99]);
console.log("RpcClient: writeCharArray is " + result); console.log("RpcClient: writeCharArray is " + result);
let array = data.readCharArray(); let array = data.readCharArray();
console.log("RpcClient: readCharArray is " + array); console.log("RpcClient: readCharArray is " + array);
...@@ -1586,17 +1618,17 @@ Writes a StringArray to this **MessageParcel** object. ...@@ -1586,17 +1618,17 @@ Writes a StringArray to this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| stringArray | string[] | Yes| StringArray to write.| | stringArray | string[] | Yes| StringArray to write.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -1613,12 +1645,12 @@ Reads a StringArray from this **MessageParcel** object. ...@@ -1613,12 +1645,12 @@ Reads a StringArray from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| dataIn | string[] | Yes| StringArray to read.| | dataIn | string[] | Yes| StringArray to read.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -1637,12 +1669,12 @@ Reads the StringArray from this **MessageParcel** object. ...@@ -1637,12 +1669,12 @@ Reads the StringArray from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| string[] | StringArray read.| | string[] | StringArray read.|
- Example **Example**
``` ```
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -1661,13 +1693,27 @@ Writes information to this **MessageParcel** object indicating that no exception ...@@ -1661,13 +1693,27 @@ Writes information to this **MessageParcel** object indicating that no exception
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Example **Example**
``` ```
class MyDeathRecipient {
onRemoteDied() {
console.log("server is died");
}
}
class TestRemoteObject extends rpc.RemoteObject { class TestRemoteObject extends rpc.RemoteObject {
constructor(descriptor) { constructor(descriptor) {
super(descriptor); super(descriptor);
} }
addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
return true;
}
removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
return true;
}
isObjectDead(): boolean {
return false;
}
onRemoteRequest(code, data, reply, option) { onRemoteRequest(code, data, reply, option) {
if (code === 1) { if (code === 1) {
console.log("RpcServer: onRemoteRequest called"); console.log("RpcServer: onRemoteRequest called");
...@@ -1690,7 +1736,7 @@ Reads the exception information from this **MessageParcel** object. ...@@ -1690,7 +1736,7 @@ Reads the exception information from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Example **Example**
``` ```
import FA from "@ohos.ability.featureAbility"; import FA from "@ohos.ability.featureAbility";
...@@ -1745,23 +1791,25 @@ Writes a SequenceableArray to this **MessageParcel** object. ...@@ -1745,23 +1791,25 @@ Writes a SequenceableArray to this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| sequenceableArray | Sequenceable[] | Yes| SequenceableArray to write.| | sequenceableArray | Sequenceable[] | Yes| SequenceableArray to write.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example **Example**
``` ```
class MySequenceable { class MySequenceable {
constructor(num, string) { num: number;
str: string;
constructor(num, str) {
this.num = num; this.num = num;
this.str = string; this.str = str;
} }
marshalling(messageParcel) { marshalling(messageParcel) {
messageParcel.writeInt(this.num); messageParcel.writeInt(this.num);
...@@ -1792,18 +1840,20 @@ Reads a SequenceableArray from this **MessageParcel** object. ...@@ -1792,18 +1840,20 @@ Reads a SequenceableArray from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| sequenceableArray | Sequenceable[] | Yes| SequenceableArray to read.| | sequenceableArray | Sequenceable[] | Yes| SequenceableArray to read.|
- Example **Example**
``` ```
class MySequenceable { class MySequenceable {
constructor(num, string) { num: number;
str: string;
constructor(num, str) {
this.num = num; this.num = num;
this.str = string; this.str = str;
} }
marshalling(messageParcel) { marshalling(messageParcel) {
messageParcel.writeInt(this.num); messageParcel.writeInt(this.num);
...@@ -1836,24 +1886,41 @@ Writes an array of **IRemoteObject** objects to this **MessageParcel** object. ...@@ -1836,24 +1886,41 @@ Writes an array of **IRemoteObject** objects to this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| objectArray | IRemoteObject[] | Yes| Array of **IRemoteObject** objects to write.| | objectArray | IRemoteObject[] | Yes| Array of **IRemoteObject** objects to write.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** if the operation fails or if the **IRemoteObject** array is null.| | boolean | Returns **true** if the operation is successful; returns **false** if the operation fails or if the **IRemoteObject** array is null.|
- Example **Example**
``` ```
class MyDeathRecipient {
onRemoteDied() {
console.log("server is died");
}
}
class TestRemoteObject extends rpc.RemoteObject { class TestRemoteObject extends rpc.RemoteObject {
constructor(descriptor) { constructor(descriptor) {
super(descriptor); super(descriptor);
this.attachLocalInterface(this, descriptor); this.attachLocalInterface(this, descriptor);
} }
addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
return true;
}
removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
return true;
}
isObjectDead(): boolean {
return false;
}
asObject(): rpc.IRemoteObject {
return this;
}
} }
let a = [new TestRemoteObject("testObject1"), new TestRemoteObject("testObject2"), new TestRemoteObject("testObject3")]; let a = [new TestRemoteObject("testObject1"), new TestRemoteObject("testObject2"), new TestRemoteObject("testObject3")];
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -1870,19 +1937,36 @@ Reads an **IRemoteObject** array from this **MessageParcel** object. ...@@ -1870,19 +1937,36 @@ Reads an **IRemoteObject** array from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| objects | IRemoteObject[] | Yes| **IRemoteObject** array to read.| | objects | IRemoteObject[] | Yes| **IRemoteObject** array to read.|
- Example **Example**
``` ```
class MyDeathRecipient {
onRemoteDied() {
console.log("server is died");
}
}
class TestRemoteObject extends rpc.RemoteObject { class TestRemoteObject extends rpc.RemoteObject {
constructor(descriptor) { constructor(descriptor) {
super(descriptor); super(descriptor);
this.attachLocalInterface(this, descriptor); this.attachLocalInterface(this, descriptor);
} }
addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
return true;
}
removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
return true;
}
isObjectDead(): boolean {
return false;
}
asObject(): rpc.IRemoteObject {
return this;
}
} }
let a = [new TestRemoteObject("testObject1"), new TestRemoteObject("testObject2"), new TestRemoteObject("testObject3")]; let a = [new TestRemoteObject("testObject1"), new TestRemoteObject("testObject2"), new TestRemoteObject("testObject3")];
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -1900,19 +1984,36 @@ Reads the **IRemoteObject** array from this **MessageParcel** object. ...@@ -1900,19 +1984,36 @@ Reads the **IRemoteObject** array from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| IRemoteObject[] | **IRemoteObject** object array obtained.| | IRemoteObject[] | **IRemoteObject** object array obtained.|
- Example **Example**
``` ```
class MyDeathRecipient {
onRemoteDied() {
console.log("server is died");
}
}
class TestRemoteObject extends rpc.RemoteObject { class TestRemoteObject extends rpc.RemoteObject {
constructor(descriptor) { constructor(descriptor) {
super(descriptor); super(descriptor);
this.attachLocalInterface(this, descriptor); this.attachLocalInterface(this, descriptor);
} }
addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
return true;
}
removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
return true;
}
isObjectDead(): boolean {
return false;
}
asObject(): rpc.IRemoteObject {
return this;
}
} }
let a = [new TestRemoteObject("testObject1"), new TestRemoteObject("testObject2"), new TestRemoteObject("testObject3")]; let a = [new TestRemoteObject("testObject1"), new TestRemoteObject("testObject2"), new TestRemoteObject("testObject3")];
let data = rpc.MessageParcel.create(); let data = rpc.MessageParcel.create();
...@@ -1931,12 +2032,12 @@ Closes a file descriptor. ...@@ -1931,12 +2032,12 @@ Closes a file descriptor.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| fd | number | Yes| File descriptor to close.| | fd | number | Yes| File descriptor to close.|
- Example **Example**
``` ```
import fileio from '@ohos.fileio'; import fileio from '@ohos.fileio';
...@@ -1954,17 +2055,17 @@ Duplicates a file descriptor. ...@@ -1954,17 +2055,17 @@ Duplicates a file descriptor.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| fd | number | Yes| File descriptor to duplicate.| | fd | number | Yes| File descriptor to duplicate.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| number | New file descriptor.| | number | New file descriptor.|
- Example **Example**
``` ```
import fileio from '@ohos.fileio'; import fileio from '@ohos.fileio';
...@@ -1982,12 +2083,12 @@ Checks whether this **MessageParcel** object contains a file descriptor. ...@@ -1982,12 +2083,12 @@ Checks whether this **MessageParcel** object contains a file descriptor.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the **MessageParcel** object contains a file descriptor; returns **false** otherwise.| | boolean | Returns **true** if the **MessageParcel** object contains a file descriptor; returns **false** otherwise.|
- Example **Example**
``` ```
import fileio from '@ohos.fileio'; import fileio from '@ohos.fileio';
...@@ -2010,17 +2111,17 @@ Writes a file descriptor to this **MessageParcel** object. ...@@ -2010,17 +2111,17 @@ Writes a file descriptor to this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| fd | number | Yes| File descriptor to write.| | fd | number | Yes| File descriptor to write.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example **Example**
``` ```
import fileio from '@ohos.fileio'; import fileio from '@ohos.fileio';
...@@ -2040,12 +2141,12 @@ Reads the file descriptor from this **MessageParcel** object. ...@@ -2040,12 +2141,12 @@ Reads the file descriptor from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| number | File descriptor read.| | number | File descriptor read.|
- Example **Example**
``` ```
import fileio from '@ohos.fileio'; import fileio from '@ohos.fileio';
...@@ -2066,17 +2167,17 @@ Writes an anonymous shared object to this **MessageParcel** object. ...@@ -2066,17 +2167,17 @@ Writes an anonymous shared object to this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| ashmem | Ashmem | Yes| Anonymous shared object to write.| | ashmem | Ashmem | Yes| Anonymous shared object to write.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example **Example**
``` ```
let parcel = new rpc.MessageParcel(); let parcel = new rpc.MessageParcel();
...@@ -2094,12 +2195,12 @@ Reads the anonymous shared object from this **MessageParcel** object. ...@@ -2094,12 +2195,12 @@ Reads the anonymous shared object from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Ashmem | Anonymous share object obtained.| | Ashmem | Anonymous share object obtained.|
- Example **Example**
``` ```
let parcel = new rpc.MessageParcel(); let parcel = new rpc.MessageParcel();
...@@ -2119,12 +2220,12 @@ Obtains the maximum amount of raw data that can be held by this **MessageParcel* ...@@ -2119,12 +2220,12 @@ Obtains the maximum amount of raw data that can be held by this **MessageParcel*
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| number | 128 MB, which is the maximum amount of raw data that can be held by this **MessageParcel** object.| | number | 128 MB, which is the maximum amount of raw data that can be held by this **MessageParcel** object.|
- Example **Example**
``` ```
let parcel = new rpc.MessageParcel(); let parcel = new rpc.MessageParcel();
...@@ -2141,22 +2242,22 @@ Writes raw data to this **MessageParcel** object. ...@@ -2141,22 +2242,22 @@ Writes raw data to this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| rawData | number[] | Yes| Raw data to write.| | rawData | number[] | Yes| Raw data to write.|
| size | number | Yes| Size of the raw data, in bytes.| | size | number | Yes| Size of the raw data, in bytes.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example **Example**
``` ```
let parcel = new rpc.MessageParcel(); let parcel = new rpc.MessageParcel();
let arr = new Int8Array([1, 2, 3, 4, 5]); let arr = [1, 2, 3, 4, 5];
let isWriteSuccess = parcel.writeRawData(arr, arr.length); let isWriteSuccess = parcel.writeRawData(arr, arr.length);
console.log("RpcTest: parcel write raw data result is : " + isWriteSuccess); console.log("RpcTest: parcel write raw data result is : " + isWriteSuccess);
``` ```
...@@ -2170,21 +2271,21 @@ Reads raw data from this **MessageParcel** object. ...@@ -2170,21 +2271,21 @@ Reads raw data from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| size | number | Yes| Size of the raw data to read.| | size | number | Yes| Size of the raw data to read.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| number[] | Raw data obtained, in bytes.| | number[] | Raw data obtained, in bytes.|
- Example **Example**
``` ```
let parcel = new rpc.MessageParcel(); let parcel = new rpc.MessageParcel();
let arr = new Int8Array([1, 2, 3, 4, 5]); let arr = [1, 2, 3, 4, 5];
let isWriteSuccess = parcel.writeRawData(arr, arr.length); let isWriteSuccess = parcel.writeRawData(arr, arr.length);
console.log("RpcTest: parcel write raw data result is : " + isWriteSuccess); console.log("RpcTest: parcel write raw data result is : " + isWriteSuccess);
let result = parcel.readRawData(5); let result = parcel.readRawData(5);
...@@ -2204,23 +2305,25 @@ Marshals the sequenceable object into a **MessageParcel** object. ...@@ -2204,23 +2305,25 @@ Marshals the sequenceable object into a **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| dataOut | [MessageParcel](#messageparcel) | Yes| **MessageParcel** object to which the sequenceable object is to be marshaled.| | dataOut | [MessageParcel](#messageparcel) | Yes| **MessageParcel** object to which the sequenceable object is to be marshaled.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example **Example**
``` ```
class MySequenceable { class MySequenceable {
constructor(num, string) { num: number;
str: string;
constructor(num, str) {
this.num = num; this.num = num;
this.str = string; this.str = str;
} }
marshalling(messageParcel) { marshalling(messageParcel) {
messageParcel.writeInt(this.num); messageParcel.writeInt(this.num);
...@@ -2251,23 +2354,25 @@ Unmarshals this sequenceable object from a **MessageParcel** object. ...@@ -2251,23 +2354,25 @@ Unmarshals this sequenceable object from a **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| dataIn | [MessageParcel](#messageparcel) | Yes| **MessageParcel** object in which the sequenceable object is to be unmarshaled.| | dataIn | [MessageParcel](#messageparcel) | Yes| **MessageParcel** object in which the sequenceable object is to be unmarshaled.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example **Example**
``` ```
class MySequenceable { class MySequenceable {
constructor(num, string) { num: number;
str: string;
constructor(num, str) {
this.num = num; this.num = num;
this.str = string; this.str = str;
} }
marshalling(messageParcel) { marshalling(messageParcel) {
messageParcel.writeInt(this.num); messageParcel.writeInt(this.num);
...@@ -2303,12 +2408,12 @@ Obtains a proxy or remote object. This method must be implemented by its derived ...@@ -2303,12 +2408,12 @@ Obtains a proxy or remote object. This method must be implemented by its derived
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| [IRemoteObject](#iremoteobject) | Returns the [RemoteObject](#ashmem8) if it is the caller; returns the [IRemoteObject](#iremoteobject), the holder of this **RemoteProxy** object, if the caller is a [RemoteProxy](#remoteproxy) object.| | [IRemoteObject](#iremoteobject) | Returns the [RemoteObject](#ashmem8) if it is the caller; returns the [IRemoteObject](#iremoteobject), the holder of this **RemoteProxy** object, if the caller is a [RemoteProxy](#remoteproxy) object.|
- Example **Example**
``` ```
class TestAbility extends rpc.RemoteObject { class TestAbility extends rpc.RemoteObject {
...@@ -2318,10 +2423,11 @@ Obtains a proxy or remote object. This method must be implemented by its derived ...@@ -2318,10 +2423,11 @@ Obtains a proxy or remote object. This method must be implemented by its derived
} }
``` ```
- Example **Example**
``` ```
class TestProxy { class TestProxy {
remote: rpc.RemoteObject;
constructor(remote) { constructor(remote) {
this.remote = remote; this.remote = remote;
} }
...@@ -2345,7 +2451,7 @@ Called to perform subsequent operations when a death notification of the remote ...@@ -2345,7 +2451,7 @@ Called to perform subsequent operations when a death notification of the remote
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Example **Example**
``` ```
class MyDeathRecipient { class MyDeathRecipient {
...@@ -2383,28 +2489,29 @@ Obtains the interface. ...@@ -2383,28 +2489,29 @@ Obtains the interface.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| descriptor | string | Yes| Interface descriptor.| | descriptor | string | Yes| Interface descriptor.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| IRemoteBroker | **IRemoteBroker** object bound to the specified interface descriptor.| | IRemoteBroker | **IRemoteBroker** object bound to the specified interface descriptor.|
### sendRequest ### sendRequest<sup>(deprecated)</sup>
sendRequest(code : number, data : MessageParcel, reply : MessageParcel, options : MessageOption): boolean;<sup>7</sup> > **NOTE**<br/>
> This API is deprecated since API Version 8. You are advised to use [sendRequest<sup>8+</sup> ](#sendrequest8).
sendRequest(code : number, data : MessageParcel, reply : MessageParcel, options : MessageOption): Promise&lt;SendRequestResult&gt;<sup>8+</sup> sendRequest(code : number, data : MessageParcel, reply : MessageParcel, options : MessageOption): boolean
Sends a **MessageParcel** message to the remote process in synchronous or asynchronous mode. If **options** is the asynchronous mode, a promise will be fulfilled immediately and the reply message does not contain any content. If **options** is the synchronous mode, a promise will be fulfilled when the response to **sendRequest** is returned, and the reply message contains the returned information. Sends a **MessageParcel** message to the remote process in synchronous or asynchronous mode. If **options** is the asynchronous mode, a promise will be fulfilled immediately and the reply message does not contain any content. If **options** is the synchronous mode, a promise will be fulfilled when the response to **sendRequest** is returned, and the reply message contains the returned information.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| code | number | Yes| Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.| | code | number | Yes| Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.|
...@@ -2412,21 +2519,42 @@ Sends a **MessageParcel** message to the remote process in synchronous or asynch ...@@ -2412,21 +2519,42 @@ Sends a **MessageParcel** message to the remote process in synchronous or asynch
| reply | [MessageParcel](#messageparcel) | Yes| **MessageParcel** object that receives the response.| | reply | [MessageParcel](#messageparcel) | Yes| **MessageParcel** object that receives the response.|
| options | [MessageOption](#messageoption) | Yes| Request sending mode, which can be synchronous (default) or asynchronous.| | options | [MessageOption](#messageoption) | Yes| Request sending mode, which can be synchronous (default) or asynchronous.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;number&gt;<sup>7</sup><br>Promise&lt;SendRequestResult&gt;<sup>8+</sup> | Promise used to return the result. The value **0** will be returned if the request is sent successfully. Otherwise, an error code will be returned.<sup>7</sup><br>Promise used to return the **sendRequestResult** object.<sup>8+</sup> | | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
### sendRequest<sup>8+</sup> ### sendRequest<sup>8+</sup>
sendRequest(code : number, data : MessageParcel, reply : MessageParcel, options : MessageOption): Promise&lt;SendRequestResult&gt;
Sends a **MessageParcel** message to the remote process in synchronous or asynchronous mode. If **options** is the asynchronous mode, a promise will be fulfilled immediately and the reply message does not contain any content. If **options** is the synchronous mode, a promise will be fulfilled when the response to **sendRequest** is returned, and the reply message contains the returned information.
**System capability**: SystemCapability.Communication.IPC.Core
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| code | number | Yes| Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.|
| data | [MessageParcel](#messageparcel) | Yes| **MessageParcel** object holding the data to send.|
| reply | [MessageParcel](#messageparcel) | Yes| **MessageParcel** object that receives the response.|
| options | [MessageOption](#messageoption) | Yes| Request sending mode, which can be synchronous (default) or asynchronous.|
**Return value**
| Type| Description|
| -------- | -------- |
| Promise&lt;SendRequestResult&gt; | Promise used to return the **sendRequestResult** object.|
### sendRequest<sup>8+</sup>
sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption, callback: AsyncCallback&lt;SendRequestResult&gt;): void sendRequest(code: number, data: MessageParcel, reply: MessageParcel, options: MessageOption, callback: AsyncCallback&lt;SendRequestResult&gt;): void
Sends a **MessageParcel** message to the remote process in synchronous or asynchronous mode. If **options** is the asynchronous mode, a callback will be invoked immediately and the reply message does not contain any content. If **options** is the synchronous mode, a callback will be invoked when the response to sendRequest is returned, and the reply message contains the returned information. Sends a **MessageParcel** message to the remote process in synchronous or asynchronous mode. If **options** is the asynchronous mode, a callback will be invoked immediately and the reply message does not contain any content. If **options** is the synchronous mode, a callback will be invoked when the response to sendRequest is returned, and the reply message contains the returned information.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| code | number | Yes| Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.| | code | number | Yes| Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.|
...@@ -2444,13 +2572,13 @@ Adds a callback for receiving death notifications of the remote object. This met ...@@ -2444,13 +2572,13 @@ Adds a callback for receiving death notifications of the remote object. This met
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| recipient | [DeathRecipient](#deathrecipient) | Yes| Callback to add.| | recipient | [DeathRecipient](#deathrecipient) | Yes| Callback to add.|
| flags | number | Yes| Flag of the death notification.| | flags | number | Yes| Flag of the death notification.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the callback is added successfully; returns **false** otherwise.| | boolean | Returns **true** if the callback is added successfully; returns **false** otherwise.|
...@@ -2464,13 +2592,13 @@ Removes the callback used to receive death notifications of the remote object. ...@@ -2464,13 +2592,13 @@ Removes the callback used to receive death notifications of the remote object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| recipient | [DeathRecipient](#deathrecipient) | Yes| Callback to remove.| | recipient | [DeathRecipient](#deathrecipient) | Yes| Callback to remove.|
| flags | number | Yes| Flag of the death notification.| | flags | number | Yes| Flag of the death notification.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the callback is removed successfully; returns **false** otherwise.| | boolean | Returns **true** if the callback is removed successfully; returns **false** otherwise.|
...@@ -2484,7 +2612,7 @@ Obtains the interface descriptor of this object. The interface descriptor is a s ...@@ -2484,7 +2612,7 @@ Obtains the interface descriptor of this object. The interface descriptor is a s
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| string | Interface descriptor obtained.| | string | Interface descriptor obtained.|
...@@ -2498,7 +2626,7 @@ Checks whether this object is dead. ...@@ -2498,7 +2626,7 @@ Checks whether this object is dead.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the object is dead; returns **false** otherwise.| | boolean | Returns **true** if the object is dead; returns **false** otherwise.|
...@@ -2521,18 +2649,18 @@ Provides methods to implement **IRemoteObject**. ...@@ -2521,18 +2649,18 @@ Provides methods to implement **IRemoteObject**.
### sendRequest ### sendRequest<sup>(deprecated)</sup>
sendRequest(code : number, data : MessageParcel, reply : MessageParcel, options : MessageOption): boolean;<sup>7</sup> > **NOTE**<br/>
> This API is deprecated since API Version 8. You are advised to use [sendRequest<sup>8+</sup> ](#sendrequest8-2).
sendRequest(code : number, data : MessageParcel, reply : MessageParcel, options : MessageOption): Promise&lt;SendRequestResult&gt;<sup>8+</sup> sendRequest(code : number, data : MessageParcel, reply : MessageParcel, options : MessageOption): boolean
Sends a **MessageParcel** message to the remote process in synchronous or asynchronous mode. If **options** is the asynchronous mode, a promise will be fulfilled immediately and the reply message does not contain any content. If **options** is the synchronous mode, a promise will be fulfilled when the response to **sendRequest** is returned, and the reply message contains the returned information. Sends a **MessageParcel** message to the remote process in synchronous or asynchronous mode. If **options** is the asynchronous mode, a promise will be fulfilled immediately and the reply message does not contain any content. If **options** is the synchronous mode, a promise will be fulfilled when the response to **sendRequest** is returned, and the reply message contains the returned information.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
**Parameters**
- Parameters
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| code | number | Yes| Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.| | code | number | Yes| Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.|
...@@ -2540,12 +2668,13 @@ Sends a **MessageParcel** message to the remote process in synchronous or asynch ...@@ -2540,12 +2668,13 @@ Sends a **MessageParcel** message to the remote process in synchronous or asynch
| reply | [MessageParcel](#messageparcel) | Yes| **MessageParcel** object that receives the response.| | reply | [MessageParcel](#messageparcel) | Yes| **MessageParcel** object that receives the response.|
| options | [MessageOption](#messageoption) | Yes| Request sending mode, which can be synchronous (default) or asynchronous.| | options | [MessageOption](#messageoption) | Yes| Request sending mode, which can be synchronous (default) or asynchronous.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;number&gt;<sup>7</sup><br>Promise&lt;SendRequestResult&gt;<sup>8+</sup> | Promise used to return the result. The value **0** will be returned if the request is sent successfully. Otherwise, an error code will be returned.<sup>7</sup><br>Promise used to return the **sendRequestResult** object.<sup>8+</sup> | | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example:<sup>7</sup> **Example**
``` ```
import FA from "@ohos.ability.featureAbility"; import FA from "@ohos.ability.featureAbility";
...@@ -2572,25 +2701,41 @@ Sends a **MessageParcel** message to the remote process in synchronous or asynch ...@@ -2572,25 +2701,41 @@ Sends a **MessageParcel** message to the remote process in synchronous or asynch
let reply = rpc.MessageParcel.create(); let reply = rpc.MessageParcel.create();
data.writeInt(1); data.writeInt(1);
data.writeString("hello"); data.writeString("hello");
proxy.sendRequest(1, data, reply, option) let ret: boolean = proxy.sendRequest(1, data, reply, option);
.then(function(errCode) { if (ret) {
if (errCode === 0) {
console.log("sendRequest got result"); console.log("sendRequest got result");
let msg = reply.readString(); let msg = reply.readString();
console.log("RPCTest: reply msg: " + msg); console.log("RPCTest: reply msg: " + msg);
} else { } else {
console.log("RPCTest: sendRequest failed, errCode: " + errCode); console.log("RPCTest: sendRequest failed");
} }
}).catch(function(e) {
console.log("RPCTest: sendRequest got exception: " + e.message);
}).finally (() => {
console.log("RPCTest: sendRequest ends, reclaim parcel"); console.log("RPCTest: sendRequest ends, reclaim parcel");
data.reclaim(); data.reclaim();
reply.reclaim(); reply.reclaim();
});
``` ```
- Example:<sup>8+</sup> ### sendRequest<sup>8+</sup>
sendRequest(code : number, data : MessageParcel, reply : MessageParcel, options : MessageOption): Promise&lt;SendRequestResult&gt;
Sends a **MessageParcel** message to the remote process in synchronous or asynchronous mode. If **options** is the asynchronous mode, a promise will be fulfilled immediately and the reply message does not contain any content. If **options** is the synchronous mode, a promise will be fulfilled when the response to **sendRequest** is returned, and the reply message contains the returned information.
**System capability**: SystemCapability.Communication.IPC.Core
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| code | number | Yes| Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.|
| data | [MessageParcel](#messageparcel) | Yes| **MessageParcel** object holding the data to send.|
| reply | [MessageParcel](#messageparcel) | Yes| **MessageParcel** object that receives the response.|
| options | [MessageOption](#messageoption) | Yes| Request sending mode, which can be synchronous (default) or asynchronous.|
**Return value**
| Type| Description|
| -------- | -------- |
| Promise&lt;SendRequestResult&gt; | Promise used to return the **sendRequestResult** object.|
**Example**
``` ```
import FA from "@ohos.ability.featureAbility"; import FA from "@ohos.ability.featureAbility";
...@@ -2645,7 +2790,7 @@ Sends a **MessageParcel** message to the remote process in synchronous or asynch ...@@ -2645,7 +2790,7 @@ Sends a **MessageParcel** message to the remote process in synchronous or asynch
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| code | number | Yes| Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.| | code | number | Yes| Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.|
...@@ -2654,7 +2799,7 @@ Sends a **MessageParcel** message to the remote process in synchronous or asynch ...@@ -2654,7 +2799,7 @@ Sends a **MessageParcel** message to the remote process in synchronous or asynch
| options | [MessageOption](#messageoption) | Yes| Request sending mode, which can be synchronous (default) or asynchronous.| | options | [MessageOption](#messageoption) | Yes| Request sending mode, which can be synchronous (default) or asynchronous.|
| callback | AsyncCallback&lt;SendRequestResult&gt; | Yes| Callback for receiving the sending result.| | callback | AsyncCallback&lt;SendRequestResult&gt; | Yes| Callback for receiving the sending result.|
- Example **Example**
``` ```
import FA from "@ohos.ability.featureAbility"; import FA from "@ohos.ability.featureAbility";
...@@ -2706,17 +2851,17 @@ Obtains the **LocalInterface** object of an interface descriptor. ...@@ -2706,17 +2851,17 @@ Obtains the **LocalInterface** object of an interface descriptor.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| interface | string | Yes| Interface descriptor.| | interface | string | Yes| Interface descriptor.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| IRemoteBroker | Returns **Null** by default, which indicates a proxy interface.| | IRemoteBroker | Returns **Null** by default, which indicates a proxy interface.|
- Example **Example**
``` ```
import FA from "@ohos.ability.featureAbility"; import FA from "@ohos.ability.featureAbility";
...@@ -2751,18 +2896,18 @@ Adds a callback for receiving the death notifications of the remote object, incl ...@@ -2751,18 +2896,18 @@ Adds a callback for receiving the death notifications of the remote object, incl
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| recipient | [DeathRecipient](#deathrecipient) | Yes| Callback to add.| | recipient | [DeathRecipient](#deathrecipient) | Yes| Callback to add.|
| flags | number | Yes| Flag of the death notification. This parameter is reserved. It is set to **0**.| | flags | number | Yes| Flag of the death notification. This parameter is reserved. It is set to **0**.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the callback is added successfully; returns **false** otherwise.| | boolean | Returns **true** if the callback is added successfully; returns **false** otherwise.|
- Example **Example**
``` ```
import FA from "@ohos.ability.featureAbility"; import FA from "@ohos.ability.featureAbility";
...@@ -2802,18 +2947,18 @@ Removes the callback used to receive death notifications of the remote object. ...@@ -2802,18 +2947,18 @@ Removes the callback used to receive death notifications of the remote object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| recipient | [DeathRecipient](#deathrecipient) | Yes| Callback to remove.| | recipient | [DeathRecipient](#deathrecipient) | Yes| Callback to remove.|
| flags | number | Yes| Flag of the death notification. This parameter is reserved. It is set to **0**.| | flags | number | Yes| Flag of the death notification. This parameter is reserved. It is set to **0**.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the callback is removed successfully; returns **false** otherwise.| | boolean | Returns **true** if the callback is removed successfully; returns **false** otherwise.|
- Example **Example**
``` ```
import FA from "@ohos.ability.featureAbility"; import FA from "@ohos.ability.featureAbility";
...@@ -2854,12 +2999,12 @@ Obtains the interface descriptor of this proxy object. ...@@ -2854,12 +2999,12 @@ Obtains the interface descriptor of this proxy object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| string | Interface descriptor obtained.| | string | Interface descriptor obtained.|
- Example **Example**
``` ```
import FA from "@ohos.ability.featureAbility"; import FA from "@ohos.ability.featureAbility";
...@@ -2894,12 +3039,12 @@ Checks whether the **RemoteObject** is dead. ...@@ -2894,12 +3039,12 @@ Checks whether the **RemoteObject** is dead.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the **RemoteObject** is dead; returns **false** otherwise.| | boolean | Returns **true** if the **RemoteObject** is dead; returns **false** otherwise.|
- Example **Example**
``` ```
import FA from "@ohos.ability.featureAbility"; import FA from "@ohos.ability.featureAbility";
...@@ -2948,7 +3093,7 @@ A constructor used to create a **MessageOption** object. ...@@ -2948,7 +3093,7 @@ A constructor used to create a **MessageOption** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| syncFlags | number | No| Call flag, which can be synchronous or asynchronous. The default value is **synchronous**.| | syncFlags | number | No| Call flag, which can be synchronous or asynchronous. The default value is **synchronous**.|
...@@ -2963,7 +3108,7 @@ Obtains the call flag, which can be synchronous or asynchronous. ...@@ -2963,7 +3108,7 @@ Obtains the call flag, which can be synchronous or asynchronous.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| number | Call mode obtained.| | number | Call mode obtained.|
...@@ -2977,7 +3122,7 @@ Sets the call flag, which can be synchronous or asynchronous. ...@@ -2977,7 +3122,7 @@ Sets the call flag, which can be synchronous or asynchronous.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| flags | number | Yes| Call flag to set.| | flags | number | Yes| Call flag to set.|
...@@ -2991,7 +3136,7 @@ Obtains the maximum wait time for this RPC call. ...@@ -2991,7 +3136,7 @@ Obtains the maximum wait time for this RPC call.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| number | Maximum wait time obtained.| | number | Maximum wait time obtained.|
...@@ -3005,7 +3150,7 @@ Sets the maximum wait time for this RPC call. ...@@ -3005,7 +3150,7 @@ Sets the maximum wait time for this RPC call.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| waitTime | number | Yes| Maximum wait time to set.| | waitTime | number | Yes| Maximum wait time to set.|
...@@ -3024,12 +3169,12 @@ Obtains the system capability manager. ...@@ -3024,12 +3169,12 @@ Obtains the system capability manager.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| [IRemoteObject](#iremoteobject) | System capability manager obtained.| | [IRemoteObject](#iremoteobject) | System capability manager obtained.|
- Example **Example**
``` ```
let samgr = rpc.IPCSkeleton.getContextObject(); let samgr = rpc.IPCSkeleton.getContextObject();
...@@ -3045,12 +3190,12 @@ Obtains the PID of the caller. This method is invoked by the **RemoteObject** ob ...@@ -3045,12 +3190,12 @@ Obtains the PID of the caller. This method is invoked by the **RemoteObject** ob
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| number | PID of the caller.| | number | PID of the caller.|
- Example **Example**
``` ```
class Stub extends rpc.RemoteObject { class Stub extends rpc.RemoteObject {
...@@ -3071,12 +3216,12 @@ Obtains the UID of the caller. This method is invoked by the **RemoteObject** ob ...@@ -3071,12 +3216,12 @@ Obtains the UID of the caller. This method is invoked by the **RemoteObject** ob
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| number | UID of the caller.| | number | UID of the caller.|
- Example **Example**
``` ```
class Stub extends rpc.RemoteObject { class Stub extends rpc.RemoteObject {
...@@ -3088,7 +3233,7 @@ Obtains the UID of the caller. This method is invoked by the **RemoteObject** ob ...@@ -3088,7 +3233,7 @@ Obtains the UID of the caller. This method is invoked by the **RemoteObject** ob
} }
``` ```
### getCallingTokenId ### getCallingTokenId<sup>8+</sup>
static getCallingTokenId(): number; static getCallingTokenId(): number;
...@@ -3096,13 +3241,13 @@ Obtains the caller's token ID, which is used to verify the caller identity. ...@@ -3096,13 +3241,13 @@ Obtains the caller's token ID, which is used to verify the caller identity.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
Return value * Return value
| Type | Description | | Type | Description |
| ------ | --------------------- | | ------ | --------------------- |
| number | Token ID of the caller obtained.| | number | Token ID of the caller obtained.|
Example * Example
``` ```
class Stub extends rpc.RemoteObject { class Stub extends rpc.RemoteObject {
...@@ -3115,7 +3260,7 @@ Example ...@@ -3115,7 +3260,7 @@ Example
``` ```
### getCalligDeviceID ### getCallingDeviceID
static getCallingDeviceID(): string static getCallingDeviceID(): string
...@@ -3123,17 +3268,17 @@ Obtains the ID of the device hosting the caller's process. ...@@ -3123,17 +3268,17 @@ Obtains the ID of the device hosting the caller's process.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| string | Device ID obtained.| | string | Device ID obtained.|
- Example **Example**
``` ```
class Stub extends rpc.RemoteObject { class Stub extends rpc.RemoteObject {
onRemoteRequest(code, data, reply, option) { onRemoteRequest(code, data, reply, option) {
let callerDeviceID = rpc.IPCSkeleton.getCalligDeviceID(); let callerDeviceID = rpc.IPCSkeleton.getCallingDeviceID();
console.log("RpcServer: callerDeviceID is: " + callerDeviceID); console.log("RpcServer: callerDeviceID is: " + callerDeviceID);
return true; return true;
} }
...@@ -3149,12 +3294,12 @@ Obtains the local device ID. ...@@ -3149,12 +3294,12 @@ Obtains the local device ID.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| string | Local device ID obtained.| | string | Local device ID obtained.|
- Example **Example**
``` ```
class Stub extends rpc.RemoteObject { class Stub extends rpc.RemoteObject {
...@@ -3175,12 +3320,12 @@ Checks whether the remote process is a process of the local device. ...@@ -3175,12 +3320,12 @@ Checks whether the remote process is a process of the local device.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the local and remote processes are on the same device; returns **false** otherwise.| | boolean | Returns **true** if the local and remote processes are on the same device; returns **false** otherwise.|
- Example **Example**
``` ```
class Stub extends rpc.RemoteObject { class Stub extends rpc.RemoteObject {
...@@ -3201,21 +3346,40 @@ Flushes all suspended commands from the specified **RemoteProxy** to the corresp ...@@ -3201,21 +3346,40 @@ Flushes all suspended commands from the specified **RemoteProxy** to the corresp
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| object | [IRemoteObject](#iremoteobject) | Yes| **RemoteProxy** specified. | | object | [IRemoteObject](#iremoteobject) | Yes| **RemoteProxy** specified. |
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| number | Returns **0** if the operation is successful; returns an error code if the input object is null or a **RemoteObject**, or if the operation fails.| | number | Returns **0** if the operation is successful; returns an error code if the input object is null or a **RemoteObject**, or if the operation fails.|
- Example **Example**
``` ```
let remoteObject = new rpc.RemoteObject("aaa", 3); class MyDeathRecipient {
onRemoteDied() {
console.log("server is died");
}
}
class TestRemoteObject extends rpc.RemoteObject {
constructor(descriptor) {
super(descriptor);
}
addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
return true;
}
removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
return true;
}
isObjectDead(): boolean {
return false;
}
}
let remoteObject = new TestRemoteObject("aaa");
let ret = rpc.IPCSkeleton.flushCommands(remoteObject); let ret = rpc.IPCSkeleton.flushCommands(remoteObject);
console.log("RpcServer: flushCommands result: " + ret); console.log("RpcServer: flushCommands result: " + ret);
``` ```
...@@ -3229,12 +3393,12 @@ Changes the UID and PID of the remote user to the UID and PID of the local user. ...@@ -3229,12 +3393,12 @@ Changes the UID and PID of the remote user to the UID and PID of the local user.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| string | String containing the UID and PID of the remote user.| | string | String containing the UID and PID of the remote user.|
- Example **Example**
``` ```
class Stub extends rpc.RemoteObject { class Stub extends rpc.RemoteObject {
...@@ -3255,17 +3419,17 @@ Restores the UID and PID of the remote user. It is usually called when the UID a ...@@ -3255,17 +3419,17 @@ Restores the UID and PID of the remote user. It is usually called when the UID a
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| identity | string | Yes| String containing the remote user UID and PID, which are returned by **resetCallingIdentity**.| | identity | string | Yes| String containing the remote user UID and PID, which are returned by **resetCallingIdentity**.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example **Example**
``` ```
class Stub extends rpc.RemoteObject { class Stub extends rpc.RemoteObject {
...@@ -3297,23 +3461,24 @@ A constructor used to create a **RemoteObject** object. ...@@ -3297,23 +3461,24 @@ A constructor used to create a **RemoteObject** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| descriptor | string | Yes| Interface descriptor.| | descriptor | string | Yes| Interface descriptor.|
### sendRequest ### sendRequest<sup>(deprecated)</sup>
sendRequest(code : number, data : MessageParcel, reply : MessageParcel, options : MessageOption): boolean;<sup>7</sup> > **NOTE**<br/>
> This API is deprecated since API Version 8. You are advised to use [sendRequest<sup>8+</sup>](#sendrequest8-4).
sendRequest(code : number, data : MessageParcel, reply : MessageParcel, options : MessageOption): Promise&lt;SendRequestResult&gt;<sup>8+</sup> sendRequest(code : number, data : MessageParcel, reply : MessageParcel, options : MessageOption): boolean
Sends a **MessageParcel** message to the remote process in synchronous or asynchronous mode. If **options** is the asynchronous mode, a promise will be fulfilled immediately and the reply message does not contain any content. If **options** is the synchronous mode, a promise will be fulfilled when the response to **sendRequest** is returned, and the reply message contains the returned information. Sends a **MessageParcel** message to the remote process in synchronous or asynchronous mode. If **options** is the asynchronous mode, a promise will be fulfilled immediately and the reply message does not contain any content. If **options** is the synchronous mode, a promise will be fulfilled when the response to **sendRequest** is returned, and the reply message contains the returned information.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| code | number | Yes| Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.| | code | number | Yes| Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.|
...@@ -3321,19 +3486,33 @@ Sends a **MessageParcel** message to the remote process in synchronous or asynch ...@@ -3321,19 +3486,33 @@ Sends a **MessageParcel** message to the remote process in synchronous or asynch
| reply | [MessageParcel](#messageparcel) | Yes| **MessageParcel** object that receives the response.| | reply | [MessageParcel](#messageparcel) | Yes| **MessageParcel** object that receives the response.|
| options | [MessageOption](#messageoption) | Yes| Request sending mode, which can be synchronous (default) or asynchronous.| | options | [MessageOption](#messageoption) | Yes| Request sending mode, which can be synchronous (default) or asynchronous.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;number&gt;<sup>7</sup><br>Promise&lt;SendRequestResult&gt;<sup>8+</sup> | Promise used to return the result. The value **0** will be returned if the request is sent successfully. Otherwise, an error code will be returned.<sup>7</sup><br>Promise used to return the **sendRequestResult** object.<sup>8+</sup> | | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example<sup>7</sup> **Example**
``` ```
class MyDeathRecipient {
onRemoteDied() {
console.log("server is died");
}
}
class TestRemoteObject extends rpc.RemoteObject { class TestRemoteObject extends rpc.RemoteObject {
constructor(descriptor) { constructor(descriptor) {
super(descriptor); super(descriptor);
} }
addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
return true;
}
removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
return true;
}
isObjectDead(): boolean {
return false;
}
} }
let testRemoteObject = new TestRemoteObject("testObject"); let testRemoteObject = new TestRemoteObject("testObject");
let option = new rpc.MessageOption(); let option = new rpc.MessageOption();
...@@ -3341,32 +3520,63 @@ Sends a **MessageParcel** message to the remote process in synchronous or asynch ...@@ -3341,32 +3520,63 @@ Sends a **MessageParcel** message to the remote process in synchronous or asynch
let reply = rpc.MessageParcel.create(); let reply = rpc.MessageParcel.create();
data.writeInt(1); data.writeInt(1);
data.writeString("hello"); data.writeString("hello");
testRemoteObject.sendRequest(1, data, reply, option) let ret: boolean = testRemoteObject.sendRequest(1, data, reply, option);
.then(function(errCode) { if (ret) {
if (errCode === 0) {
console.log("sendRequest got result"); console.log("sendRequest got result");
let msg = reply.readString(); let msg = reply.readString();
console.log("RPCTest: reply msg: " + msg); console.log("RPCTest: reply msg: " + msg);
} else { } else {
console.log("RPCTest: sendRequest failed, errCode: " + errCode); console.log("RPCTest: sendRequest failed");
} }
}).catch(function(e) {
console.log("RPCTest: sendRequest got exception: " + e.message);
}).finally (() => {
console.log("RPCTest: sendRequest ends, reclaim parcel"); console.log("RPCTest: sendRequest ends, reclaim parcel");
data.reclaim(); data.reclaim();
reply.reclaim(); reply.reclaim();
});
``` ```
- Example<sup>8+</sup> ### sendRequest<sup>8+</sup>
sendRequest(code : number, data : MessageParcel, reply : MessageParcel, options : MessageOption): Promise&lt;SendRequestResult&gt;
Sends a **MessageParcel** message to the remote process in synchronous or asynchronous mode. If **options** is the asynchronous mode, a promise will be fulfilled immediately and the reply message does not contain any content. If **options** is the synchronous mode, a promise will be fulfilled when the response to **sendRequest** is returned, and the reply message contains the returned information.
**System capability**: SystemCapability.Communication.IPC.Core
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| code | number | Yes| Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.|
| data | [MessageParcel](#messageparcel) | Yes| **MessageParcel** object holding the data to send.|
| reply | [MessageParcel](#messageparcel) | Yes| **MessageParcel** object that receives the response.|
| options | [MessageOption](#messageoption) | Yes| Request sending mode, which can be synchronous (default) or asynchronous.|
**Return value**
| Type| Description|
| -------- | -------- |
| Promise&lt;SendRequestResult&gt; | Promise used to return the **sendRequestResult** object.|
**Example**
``` ```
class MyDeathRecipient {
onRemoteDied() {
console.log("server is died");
}
}
class TestRemoteObject extends rpc.RemoteObject { class TestRemoteObject extends rpc.RemoteObject {
constructor(descriptor) { constructor(descriptor) {
super(descriptor); super(descriptor);
} }
addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
return true;
}
removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
return true;
}
isObjectDead(): boolean {
return false;
}
} }
let testRemoteObject = new TestRemoteObject("testObject"); let testRemoteObject = new TestRemoteObject("testObject");
let option = new rpc.MessageOption(); let option = new rpc.MessageOption();
...@@ -3402,7 +3612,7 @@ Sends a **MessageParcel** message to the remote process in synchronous or asynch ...@@ -3402,7 +3612,7 @@ Sends a **MessageParcel** message to the remote process in synchronous or asynch
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| code | number | Yes| Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.| | code | number | Yes| Message code called by the request, which is determined by the client and server. If the method is generated by an IDL tool, the message code is automatically generated by the IDL tool.|
...@@ -3412,13 +3622,27 @@ Sends a **MessageParcel** message to the remote process in synchronous or asynch ...@@ -3412,13 +3622,27 @@ Sends a **MessageParcel** message to the remote process in synchronous or asynch
| AsyncCallback | AsyncCallback&lt;SendRequestResult&gt; | Yes| Callback for receiving the sending result.| | AsyncCallback | AsyncCallback&lt;SendRequestResult&gt; | Yes| Callback for receiving the sending result.|
- Example **Example**
``` ```
class MyDeathRecipient {
onRemoteDied() {
console.log("server is died");
}
}
class TestRemoteObject extends rpc.RemoteObject { class TestRemoteObject extends rpc.RemoteObject {
constructor(descriptor) { constructor(descriptor) {
super(descriptor); super(descriptor);
} }
addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
return true;
}
removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
return true;
}
isObjectDead(): boolean {
return false;
}
} }
function sendRequestCallback(result) { function sendRequestCallback(result) {
if (result.errCode === 0) { if (result.errCode === 0) {
...@@ -3451,7 +3675,7 @@ Provides a response to **sendRequest()**. The server processes the request and r ...@@ -3451,7 +3675,7 @@ Provides a response to **sendRequest()**. The server processes the request and r
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| code | number | Yes| Service request code sent by the remote end.| | code | number | Yes| Service request code sent by the remote end.|
...@@ -3459,19 +3683,33 @@ Provides a response to **sendRequest()**. The server processes the request and r ...@@ -3459,19 +3683,33 @@ Provides a response to **sendRequest()**. The server processes the request and r
| reply | [MessageParcel](#messageparcel) | Yes| **MessageParcel** object carrying the result.| | reply | [MessageParcel](#messageparcel) | Yes| **MessageParcel** object carrying the result.|
| option | [MessageOption](#messageoption) | Yes| Whether the operation is synchronous or asynchronous.| | option | [MessageOption](#messageoption) | Yes| Whether the operation is synchronous or asynchronous.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example **Example**
``` ```
class MyDeathRecipient {
onRemoteDied() {
console.log("server is died");
}
}
class TestRemoteObject extends rpc.RemoteObject { class TestRemoteObject extends rpc.RemoteObject {
constructor(descriptor) { constructor(descriptor) {
super(descriptor); super(descriptor);
} }
addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
return true;
}
removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
return true;
}
isObjectDead(): boolean {
return false;
}
onRemoteRequest(code, data, reply, option) { onRemoteRequest(code, data, reply, option) {
if (code === 1) { if (code === 1) {
...@@ -3494,19 +3732,33 @@ Obtains the UID of the remote process. ...@@ -3494,19 +3732,33 @@ Obtains the UID of the remote process.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| number | UID of the remote process obtained.| | number | UID of the remote process obtained.|
- Example **Example**
``` ```
class MyDeathRecipient {
onRemoteDied() {
console.log("server is died");
}
}
class TestRemoteObject extends rpc.RemoteObject { class TestRemoteObject extends rpc.RemoteObject {
constructor(descriptor) { constructor(descriptor) {
super(descriptor); super(descriptor);
} }
addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
return true;
}
removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
return true;
}
isObjectDead(): boolean {
return false;
}
} }
let testRemoteObject = new TestRemoteObject("testObject"); let testRemoteObject = new TestRemoteObject("testObject");
console.log("RpcServer: getCallingUid: " + testRemoteObject.getCallingUid()); console.log("RpcServer: getCallingUid: " + testRemoteObject.getCallingUid());
...@@ -3521,19 +3773,33 @@ Obtains the PID of the remote process. ...@@ -3521,19 +3773,33 @@ Obtains the PID of the remote process.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| number | PID of the remote process obtained.| | number | PID of the remote process obtained.|
- Example **Example**
``` ```
class MyDeathRecipient {
onRemoteDied() {
console.log("server is died");
}
}
class TestRemoteObject extends rpc.RemoteObject { class TestRemoteObject extends rpc.RemoteObject {
constructor(descriptor) { constructor(descriptor) {
super(descriptor); super(descriptor);
} }
addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
return true;
}
removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
return true;
}
isObjectDead(): boolean {
return false;
}
} }
let testRemoteObject = new TestRemoteObject("testObject"); let testRemoteObject = new TestRemoteObject("testObject");
console.log("RpcServer: getCallingPid: " + testRemoteObject.getCallingPid()); console.log("RpcServer: getCallingPid: " + testRemoteObject.getCallingPid());
...@@ -3548,24 +3814,38 @@ Checks whether the remote object corresponding to the specified interface descri ...@@ -3548,24 +3814,38 @@ Checks whether the remote object corresponding to the specified interface descri
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| descriptor | string | Yes| Interface descriptor.| | descriptor | string | Yes| Interface descriptor.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| IRemoteBroker | Returns the remote object if a match is found; returns **Null** otherwise.| | IRemoteBroker | Returns the remote object if a match is found; returns **Null** otherwise.|
- Example **Example**
``` ```
class MyDeathRecipient {
onRemoteDied() {
console.log("server is died");
}
}
class TestRemoteObject extends rpc.RemoteObject { class TestRemoteObject extends rpc.RemoteObject {
constructor(descriptor) { constructor(descriptor) {
super(descriptor); super(descriptor);
} }
addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
return true;
}
removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
return true;
}
isObjectDead(): boolean {
return false;
}
} }
let testRemoteObject = new TestRemoteObject("testObject"); let testRemoteObject = new TestRemoteObject("testObject");
let broker = testRemoteObject.queryLocalInterface("testObject"); let broker = testRemoteObject.queryLocalInterface("testObject");
...@@ -3580,19 +3860,33 @@ Obtains the interface descriptor. ...@@ -3580,19 +3860,33 @@ Obtains the interface descriptor.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| string | Interface descriptor obtained.| | string | Interface descriptor obtained.|
- Example **Example**
``` ```
class MyDeathRecipient {
onRemoteDied() {
console.log("server is died");
}
}
class TestRemoteObject extends rpc.RemoteObject { class TestRemoteObject extends rpc.RemoteObject {
constructor(descriptor) { constructor(descriptor) {
super(descriptor); super(descriptor);
} }
addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
return true;
}
removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
return true;
}
isObjectDead(): boolean {
return false;
}
} }
let testRemoteObject = new TestRemoteObject("testObject"); let testRemoteObject = new TestRemoteObject("testObject");
let descriptor = testRemoteObject.getInterfaceDescriptor(); let descriptor = testRemoteObject.getInterfaceDescriptor();
...@@ -3608,21 +3902,38 @@ Binds an interface descriptor to an **IRemoteBroker** object. ...@@ -3608,21 +3902,38 @@ Binds an interface descriptor to an **IRemoteBroker** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| localInterface | IRemoteBroker | Yes| **IRemoteBroker** object.| | localInterface | IRemoteBroker | Yes| **IRemoteBroker** object.|
| descriptor | string | Yes| Interface descriptor.| | descriptor | string | Yes| Interface descriptor.|
- Example **Example**
``` ```
class MyDeathRecipient {
onRemoteDied() {
console.log("server is died");
}
}
class TestRemoteObject extends rpc.RemoteObject { class TestRemoteObject extends rpc.RemoteObject {
constructor(descriptor) { constructor(descriptor) {
super(descriptor); super(descriptor);
this.attachLocalInterface(this, descriptor); this.attachLocalInterface(this, descriptor);
} }
addDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
return true;
}
removeDeathRecipient(recipient: MyDeathRecipient, flags: number): boolean {
return true;
}
isObjectDead(): boolean {
return false;
}
asObject(): rpc.IRemoteObject {
return this;
}
} }
let testRemoteObject = new TestRemoteObject("testObject"); let testRemoteObject = new TestRemoteObject("testObject");
``` ```
...@@ -3652,19 +3963,19 @@ Creates an **Ashmem** object with the specified name and size. ...@@ -3652,19 +3963,19 @@ Creates an **Ashmem** object with the specified name and size.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| name | string | Yes| Name of the **Ashmem** object to create.| | name | string | Yes| Name of the **Ashmem** object to create.|
| size | number | Yes| Size (in bytes) of the **Ashmem** object to create.| | size | number | Yes| Size (in bytes) of the **Ashmem** object to create.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Ashmem | Returns the **Ashmem** object if it is created successfully; returns null otherwise.| | Ashmem | Returns the **Ashmem** object if it is created successfully; returns null otherwise.|
- Example **Example**
``` ```
let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024*1024); let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024*1024);
...@@ -3681,18 +3992,18 @@ Creates an **Ashmem** object by copying the file descriptor (FD) of an existing ...@@ -3681,18 +3992,18 @@ Creates an **Ashmem** object by copying the file descriptor (FD) of an existing
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| ashmem | Ashmem | Yes| Existing **Ashmem** object.| | ashmem | Ashmem | Yes| Existing **Ashmem** object.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Ashmem | **Ashmem** object created.| | Ashmem | **Ashmem** object created.|
- Example **Example**
``` ```
let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024*1024); let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024*1024);
...@@ -3710,7 +4021,7 @@ Closes this **Ashmem** object. ...@@ -3710,7 +4021,7 @@ Closes this **Ashmem** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Example **Example**
``` ```
let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024*1024); let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024*1024);
...@@ -3726,7 +4037,7 @@ Deletes the mappings for the specified address range of this **Ashmem** object. ...@@ -3726,7 +4037,7 @@ Deletes the mappings for the specified address range of this **Ashmem** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Example **Example**
``` ```
let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024*1024); let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024*1024);
...@@ -3742,12 +4053,12 @@ Obtains the memory size of this **Ashmem** object. ...@@ -3742,12 +4053,12 @@ Obtains the memory size of this **Ashmem** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| number | **Ashmem** size obtained.| | number | **Ashmem** size obtained.|
- Example **Example**
``` ```
let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024*1024); let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024*1024);
...@@ -3764,21 +4075,21 @@ Creates the shared file mapping on the virtual address space of this process. Th ...@@ -3764,21 +4075,21 @@ Creates the shared file mapping on the virtual address space of this process. Th
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| mapType | number | Yes| Protection level of the memory region to which the shared file is mapped.| | mapType | number | Yes| Protection level of the memory region to which the shared file is mapped.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example **Example**
``` ```
let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024*1024); let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024*1024);
let mapReadAndWrite = ashmem.mapAshmem(rpc.Ashmem.PROT_READ | rpc.Ashmem.PROT_WRITE); let mapReadAndWrite = ashmem.mapAshmem(ashmem.PROT_READ | ashmem.PROT_WRITE);
console.log("RpcTest: map ashmem result is : " + mapReadAndWrite); console.log("RpcTest: map ashmem result is : " + mapReadAndWrite);
``` ```
...@@ -3791,12 +4102,12 @@ Maps the shared file to the readable and writable virtual address space of the p ...@@ -3791,12 +4102,12 @@ Maps the shared file to the readable and writable virtual address space of the p
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example **Example**
``` ```
let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024*1024); let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024*1024);
...@@ -3813,12 +4124,12 @@ Maps the shared file to the read-only virtual address space of the process. ...@@ -3813,12 +4124,12 @@ Maps the shared file to the read-only virtual address space of the process.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example **Example**
``` ```
let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024*1024); let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024*1024);
...@@ -3835,21 +4146,21 @@ Sets the protection level of the memory region to which the shared file is mappe ...@@ -3835,21 +4146,21 @@ Sets the protection level of the memory region to which the shared file is mappe
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| protectionType | number | Yes| Protection type to set.| | protectionType | number | Yes| Protection type to set.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example **Example**
``` ```
let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024*1024); let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024*1024);
let result = ashmem.setProtection(rpc.Ashmem.PROT_READ); let result = ashmem.setProtection(ashmem.PROT_READ);
console.log("RpcTest: Ashmem setProtection result is : " + result); console.log("RpcTest: Ashmem setProtection result is : " + result);
``` ```
...@@ -3862,23 +4173,23 @@ Writes data to the shared file associated with this **Ashmem** object. ...@@ -3862,23 +4173,23 @@ Writes data to the shared file associated with this **Ashmem** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| buf | number[] | Yes| Data to write.| | buf | number[] | Yes| Data to write.|
| size | number | Yes| Size of the data to write.| | size | number | Yes| Size of the data to write.|
| offset | number | Yes| Start position of the data to write in the memory region associated with this **Ashmem** object.| | offset | number | Yes| Start position of the data to write in the memory region associated with this **Ashmem** object.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** is the data is written successfully; returns **false** otherwise.| | boolean | Returns **true** is the data is written successfully; returns **false** otherwise.|
- Example **Example**
``` ```
let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024*1024); let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024*1024);
var ByteArrayVar = new Int8Array([1, 2, 3, 4, 5]); var ByteArrayVar = [1, 2, 3, 4, 5];
let writeResult = ashmem.writeToAshmem(ByteArrayVar, 5, 0); let writeResult = ashmem.writeToAshmem(ByteArrayVar, 5, 0);
console.log("RpcTest: write to Ashmem result is : " + writeResult); console.log("RpcTest: write to Ashmem result is : " + writeResult);
``` ```
...@@ -3892,23 +4203,23 @@ Reads data from the shared file associated with this **Ashmem** object. ...@@ -3892,23 +4203,23 @@ Reads data from the shared file associated with this **Ashmem** object.
**System capability**: SystemCapability.Communication.IPC.Core **System capability**: SystemCapability.Communication.IPC.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| size | number | Yes| Size of the data to read.| | size | number | Yes| Size of the data to read.|
| offset | number | Yes| Start position of the data to read in the memory region associated with this **Ashmem** object.| | offset | number | Yes| Start position of the data to read in the memory region associated with this **Ashmem** object.|
- Return value **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| number[] | Data read.| | number[] | Data read.|
- Example **Example**
``` ```
let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024*1024); let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024*1024);
var ByteArrayVar = new Int8Array([1, 2, 3, 4, 5]); var ByteArrayVar = [1, 2, 3, 4, 5];
let writeResult = ashmem.writeToAshmem(ByteArrayVar, 5, 0); let writeResult = ashmem.writeToAshmem(ByteArrayVar, 5, 0);
console.log("RpcTest: write to Ashmem result is : " + writeResult); console.log("RpcTest: write to Ashmem result is : " + writeResult);
let readResult = ashmem.readFromAshmem(5, 0); let readResult = ashmem.readFromAshmem(5, 0);
......
# statfs # statfs
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br/> > **NOTE**<br>
> 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.
This module provides information related to the file system. It provides JS APIs to obtain the total number of bytes and the number of idle bytes of the file system.
## Modules to Import ## Modules to Import
```js ```js
...@@ -11,11 +13,11 @@ import statfs from '@ohos.statfs'; ...@@ -11,11 +13,11 @@ import statfs from '@ohos.statfs';
## Guidelines ## Guidelines
Before using this module to perform operations on a file or directory, obtain the absolute path of the file or directory. For details, see [getOrCreateLocalDir of the Context module](js-apis-Context.md). Before using the APIs provided by this module to perform operations on a file or directory, obtain the path of the application sandbox. For details, see [getOrCreateLocalDir of the Context module](js-apis-Context.md).
Absolute file or directory path = Application directory + File name or directory name Application sandbox path of a file or directory = Application directory + File name or directory name
For example, if the application directory obtained by using **getOrCreateLocalDir** is **dir** and the file name is **xxx.txt**, the absolute path of the file is as follows: For example, if the application directory obtained by using **getOrCreateLocalDir** is **dir** and the file name is **xxx.txt**, the application sandbox path of the file is as follows:
```js ```js
let path = dir + "xxx.txt"; let path = dir + "xxx.txt";
...@@ -25,7 +27,7 @@ let path = dir + "xxx.txt"; ...@@ -25,7 +27,7 @@ let path = dir + "xxx.txt";
getFreeBytes(path:string):Promise&lt;number&gt; getFreeBytes(path:string):Promise&lt;number&gt;
Obtains the number of free bytes of the specified file system in asynchronous mode. This method uses a promise to return the result. Obtains the number of free bytes of the specified file system in asynchronous mode. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -56,7 +58,7 @@ Obtains the number of free bytes of the specified file system in asynchronous mo ...@@ -56,7 +58,7 @@ Obtains the number of free bytes of the specified file system in asynchronous mo
getFreeBytes(path:string, callback:AsyncCallback&lt;number&gt;): void getFreeBytes(path:string, callback:AsyncCallback&lt;number&gt;): void
Obtains the number of free bytes of the specified file system in asynchronous mode. This method uses a callback to return the result. Obtains the number of free bytes of the specified file system in asynchronous mode. This API uses a callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -79,7 +81,7 @@ Obtains the number of free bytes of the specified file system in asynchronous mo ...@@ -79,7 +81,7 @@ Obtains the number of free bytes of the specified file system in asynchronous mo
getTotalBytes(path: string): Promise&lt;number&gt; getTotalBytes(path: string): Promise&lt;number&gt;
Obtains the total number of bytes of the specified file system in asynchronous mode. This method uses a promise to return the result. Obtains the total number of bytes of the specified file system in asynchronous mode. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -110,7 +112,7 @@ Obtains the total number of bytes of the specified file system in asynchronous m ...@@ -110,7 +112,7 @@ Obtains the total number of bytes of the specified file system in asynchronous m
getTotalBytes(path: string, callback: AsyncCallback&lt;number&gt;): void getTotalBytes(path: string, callback: AsyncCallback&lt;number&gt;): void
Obtains the total number of bytes of the specified file system in asynchronous mode. This method uses a callback to return the result. Obtains the total number of bytes of the specified file system in asynchronous mode. This API uses a callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
......
# App Storage Statistics # App Storage Statistics
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br/> > **NOTE**<br/>
> >
> - 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.
> - API version 9 is a canary release for trial use. The APIs of this version may be unstable. > - API version 9 is a canary version for trial use. The APIs of this version may be unstable.
> - The APIs of this module are system APIs and cannot be called by third-party applications.
This module provides functions to obtain storage statistics, including the space of built-in and plug-in memory cards, statistics of application data by type, and application data.
## Modules to Import ## Modules to Import
...@@ -130,7 +133,7 @@ Asynchronously obtains the available space of the specified volume. This API use ...@@ -130,7 +133,7 @@ Asynchronously obtains the available space of the specified volume. This API use
getBundleStats(packageName: string): Promise&lt;BundleStats&gt; getBundleStats(packageName: string): Promise&lt;BundleStats&gt;
Asynchronously obtains app information. This API uses a promise to return the result. Asynchronously obtains application information. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics **System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
...@@ -138,13 +141,13 @@ Asynchronously obtains app information. This API uses a promise to return the re ...@@ -138,13 +141,13 @@ Asynchronously obtains app information. This API uses a promise to return the re
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ----------- | ------ | ---- | -------- | | ----------- | ------ | ---- | -------- |
| packageName | string | Yes | Bundle name of the app.| | packageName | string | Yes | Bundle name of the application.|
- Return value - Return value
| Type | Description | | Type | Description |
| ------------------------------------------ | -------------------------- | | ------------------------------------------ | -------------------------- |
| Promise&lt;[Bundlestats](#bundlestats)&gt; | Promise used to return the app information.| | Promise&lt;[Bundlestats](#bundlestats)&gt; | Promise used to return the application data obtained.|
- Example - Example
...@@ -161,7 +164,7 @@ Asynchronously obtains app information. This API uses a promise to return the re ...@@ -161,7 +164,7 @@ Asynchronously obtains app information. This API uses a promise to return the re
getBundleStats(packageName: string, callback: AsyncCallback&lt;BundleStats&gt;): void getBundleStats(packageName: string, callback: AsyncCallback&lt;BundleStats&gt;): void
Asynchronously obtains app information. This API uses a callback to return the result. Asynchronously obtains application information. This API uses a callback to return the result.
**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics **System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
...@@ -169,8 +172,8 @@ Asynchronously obtains app information. This API uses a callback to return the r ...@@ -169,8 +172,8 @@ Asynchronously obtains app information. This API uses a callback to return the r
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | --------------------------------------------------------- | ---- | ------------------------------------ | | -------- | --------------------------------------------------------- | ---- | ------------------------------------ |
| packageName | string | Yes | Bundle name of the app.| | packageName | string | Yes | Bundle name of the application.|
| callback | callback:AsyncCallback&lt;[Bundlestats](#bundlestats)&gt; | Yes | Callback invoked to return the app information.| | callback | callback:AsyncCallback&lt;[Bundlestats](#bundlestats)&gt; | Yes | Callback used to return the application information obtained.|
- Example - Example
...@@ -186,10 +189,10 @@ Asynchronously obtains app information. This API uses a callback to return the r ...@@ -186,10 +189,10 @@ Asynchronously obtains app information. This API uses a callback to return the r
**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics **System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
### Attributes ### Attribute
| Name | Type | Description | | Name | Type | Description |
| --------- | ------ | -------------- | | --------- | ------ | -------------- |
| appSize<sup>9+</sup> | number | Size of the app. | | appSize<sup>9+</sup> | number | Size of the application. |
| cacheSize<sup>9+</sup> | number | Cache size of the app. | | cacheSize<sup>9+</sup> | number | Cache size of the application. |
| dataSize<sup>9+</sup> | number | Total data size of the app.| | dataSize<sup>9+</sup> | number | Total data size of the application.|
...@@ -68,7 +68,7 @@ Sets the value in the cache based on the specified key. ...@@ -68,7 +68,7 @@ Sets the value in the cache based on the specified key.
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| key | string | Yes| Key of the data to set.| | key | string | Yes| Key of the data to set.|
| value | string | Yes| New value to set. The maximum length is 128 bytes.| | value | string | Yes| New value to set. The length must be less than 128 bytes.|
| success | Function | No| Called when **storage.set()** is successful.| | success | Function | No| Called when **storage.set()** is successful.|
| fail | Function | No| Called when **storage.set()** fails. In the callback, **data** indicates the error information, and **code** indicates the error code.| | fail | Function | No| Called when **storage.set()** fails. In the callback, **data** indicates the error information, and **code** indicates the error code.|
| complete | Function | No| Called when **storage.set()** is complete.| | complete | Function | No| Called when **storage.set()** is complete.|
......
# Volume Management # Volume Management
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br/> > **NOTE**<br>
> >
> - The initial APIs of this module are supported since API version 9. > - The initial APIs of this module are supported since API version 9.
> - API version 9 is a canary release for trial use. The APIs of this version may be unstable. > - API version 9 is a canary version for trial use. The APIs of this version may be unstable.
> - The APIs of this module are system APIs and cannot be called by third-party applications.
This module provides APIs to implement volume and disk management, including obtaining volume information, mounting and unmounting volumes, partitioning disks, and formatting volumes.
## Modules to Import ## Modules to Import
...@@ -15,7 +18,7 @@ import volumemanager from "@ohos.volumeManager"; ...@@ -15,7 +18,7 @@ import volumemanager from "@ohos.volumeManager";
getAllVolumes(): Promise&lt;Array&lt;Volume&gt;&gt; getAllVolumes(): Promise&lt;Array&lt;Volume&gt;&gt;
Asynchronously obtains information about all available volumes. This method uses a promise to return the result. Asynchronously obtains information about all available volumes. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.StorageService.Volume **System capability**: SystemCapability.FileManagement.StorageService.Volume
...@@ -37,7 +40,7 @@ Asynchronously obtains information about all available volumes. This method uses ...@@ -37,7 +40,7 @@ Asynchronously obtains information about all available volumes. This method uses
getAllVolumes(callback: AsyncCallback&lt;Array&lt;Volume&gt;&gt;): void getAllVolumes(callback: AsyncCallback&lt;Array&lt;Volume&gt;&gt;): void
Asynchronously obtains information about all available volumes. This method uses a callback to return the result. Asynchronously obtains information about all available volumes. This API uses a callback to return the result.
**System capability**: SystemCapability.FileManagement.StorageService.Volume **System capability**: SystemCapability.FileManagement.StorageService.Volume
...@@ -61,7 +64,7 @@ Asynchronously obtains information about all available volumes. This method uses ...@@ -61,7 +64,7 @@ Asynchronously obtains information about all available volumes. This method uses
mount(volumeId: string): Promise&lt;boolean&gt; mount(volumeId: string): Promise&lt;boolean&gt;
Asynchronously mounts a volume. This method uses a promise to return the result. Asynchronously mounts a volume. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.StorageService.Volume **System capability**: SystemCapability.FileManagement.StorageService.Volume
...@@ -90,7 +93,7 @@ Asynchronously mounts a volume. This method uses a promise to return the result. ...@@ -90,7 +93,7 @@ Asynchronously mounts a volume. This method uses a promise to return the result.
mount(volumeId: string, callback:AsyncCallback&lt;boolean&gt;):void mount(volumeId: string, callback:AsyncCallback&lt;boolean&gt;):void
Asynchronously obtains the available space of the specified volume. This method uses a callback to return the result. Asynchronously obtains the available space of the specified volume. This API uses a callback to return the result.
**System capability**: SystemCapability.FileManagement.StorageService.Volume **System capability**: SystemCapability.FileManagement.StorageService.Volume
...@@ -114,7 +117,7 @@ Asynchronously obtains the available space of the specified volume. This method ...@@ -114,7 +117,7 @@ Asynchronously obtains the available space of the specified volume. This method
unmount(volumeId: string): Promise&lt;boolean&gt; unmount(volumeId: string): Promise&lt;boolean&gt;
Asynchronously unmounts a volume. This method uses a promise to return the result. Asynchronously unmounts a volume. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.StorageService.Volume **System capability**: SystemCapability.FileManagement.StorageService.Volume
...@@ -143,7 +146,7 @@ Asynchronously unmounts a volume. This method uses a promise to return the resul ...@@ -143,7 +146,7 @@ Asynchronously unmounts a volume. This method uses a promise to return the resul
unmount(volumeId: string, callback:AsyncCallback&lt;boolean&gt;):void unmount(volumeId: string, callback:AsyncCallback&lt;boolean&gt;):void
Asynchronously unmounts a volume. This method uses a callback to return the result. Asynchronously unmounts a volume. This API uses a callback to return the result.
**System capability**: SystemCapability.FileManagement.StorageService.Volume **System capability**: SystemCapability.FileManagement.StorageService.Volume
......
# Access Control Development # Access Control Development
## Scenario ## When to Use
In this example, the app requires the **ohos.permission.PERMISSION1** and **ohos.permission.PERMISSION2** permissions to implement core functions. In this example, the app requires the **ohos.permission.PERMISSION1** and **ohos.permission.PERMISSION2** permissions to implement core functions.
...@@ -26,7 +26,7 @@ The table below lists only the API used in this guide. For more information, see ...@@ -26,7 +26,7 @@ The table below lists only the API used in this guide. For more information, see
### config.json ### config.json
Declare the permissions required by the app one by one in the **config.json** file. The app cannot obtain a permission if it is not declared in the **config.json** file. Declare the permissions required by the app one by one in the **config.json** file. The app can obtain permissions that have been declared in the **config.json** file.
**Description of config.json** **Description of config.json**
...@@ -107,7 +107,7 @@ In addition to declaring all the permissions in the **config.json** file, you mu ...@@ -107,7 +107,7 @@ In addition to declaring all the permissions in the **config.json** file, you mu
After the permissions are declared, the system grants the system_grant permission during the installation of the app. The user_grant permission must be authorized by the user. After the permissions are declared, the system grants the system_grant permission during the installation of the app. The user_grant permission must be authorized by the user.
Therefore, before invoking the API protected by the **ohos.permission.PERMISSION2 permission**, the app needs to verify whether it has the permission. Therefore, before allowing the app to call the API protected by the **ohos.permission.PERMISSION2** permission, the system needs to verify whether the app has the permission to do so.
If the verification result indicates that the app has the permission, the app can access the target API. Otherwise, the app needs to request user authorization and then proceeds based on the authorization result. For details, see [Access Control Overview](accesstoken-overview.md). If the verification result indicates that the app has the permission, the app can access the target API. Otherwise, the app needs to request user authorization and then proceeds based on the authorization result. For details, see [Access Control Overview](accesstoken-overview.md).
...@@ -119,34 +119,26 @@ If the verification result indicates that the app has the permission, the app ca ...@@ -119,34 +119,26 @@ If the verification result indicates that the app has the permission, the app ca
The procedure is as follows: The procedure is as follows:
1. Obtain the caller's identity tokenId. 1. Obtain the ability context.
2. Determine the permission to be verified. In this example, the permission is **permissionNameUser**. 2. Call **requestPermissionsFromUser** to verify whether the app has required permissions.
3. Call **verifyAccessToken** to verify the permissions of the caller. 3. Proceed based on the permission verification result.
4. Proceed based on the permission verification result.
```js ```js
import {describe, beforeEach, afterEach, it, expect} from 'deccjsunit/index' // OnWindowStageCreate lifecycle of the ability
import abilityAccessCtrl from '@ohos.abilityAccessCtrl' onWindowStageCreate() {
import bundle from '@ohos.bundle' var context = this.context
let array:Array<string> = ["ohos.permission.PERMISSION2"];
async requestPermission() { // requestPermissionsFromUser determines whether to invoke a pop-up window based on the permission authorization status.
var permissionNameUser = "ohos.permission.PERMISSION2"; context.requestPermissionsFromUser(array).then(function(data) {
var bundleFlag = 0; console.log("data type:" + typeof(data));
var tokenID = undefined; console.log("data:" + data);
var userID = 100; console.log("data permissions:" + data.permissions);
var appInfo = await bundle.getApplicationInfo('ohos.acts.security.access_token.normal', bundleFlag, userID); console.log("data result:" + data.authResults);
tokenID = appInfo.accessTokenId; }, (err) => {
console.log("AccessTokenTest accessTokenId:" + appInfo.accessTokenId + ", name:" + appInfo.name console.error('Failed to start ability', err.code);
+ ", bundleName:" + appInfo.bundleName) });
var atManager = abilityAccessCtrl.createAtManager();
var result = await atManager.verifyAccessToken(tokenID, permissionNameUser);
if (result == abilityAccessCtrl.GrantStatus.PERMISSION_GRANTED) {
// Execute the operation.
} else {
// Apply for dynamic user authorization using requestPermissionsFromUser.
}
} }
``` ```
> ![icon-note.gif](../public_sys-resources/icon-note.gif)**NOTE**<br/> > **NOTE**<br>
> For details about how to use **requestPermissionsFromUser**, see [API Reference] (../reference/apis/js-apis-ability-context.md#abilitycontextrequestpermissionsfromuser). > For details about how to use **requestPermissionsFromUser**, see [API Reference](../reference/apis/js-apis-ability-context.md#abilitycontextrequestpermissionsfromuser).
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册