未验证 提交 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.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| 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**
| Type| Description|
......@@ -1390,7 +1390,7 @@ promise.then((resultSet) => {
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
......@@ -1555,9 +1555,9 @@ rdbStore.setDistributedTables(["EMPLOYEE"], function (err) {
console.info('setDistributedTables failed, err: ' + err)
return
}
console.info('setDistributedTables successful.')
console.info('setDistributedTables successfully.')
})
```
```
### setDistributedTables<sup>8+</sup>
......@@ -1582,7 +1582,7 @@ Sets a list of distributed tables. This API uses a promise to return the result.
```js
let promise = rdbStore.setDistributedTables(["EMPLOYEE"])
promise.then(() => {
console.info("setDistributedTables successful.")
console.info("setDistributedTables successfully.")
}).catch((err) => {
console.info("setDistributedTables failed, err: " + err)
})
......@@ -1610,7 +1610,7 @@ rdbStore.obtainDistributedTableName(deviceId, "EMPLOYEE", function (err, tableNa
console.info('obtainDistributedTableName failed, err: ' + err)
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
```js
let promise = rdbStore.obtainDistributedTableName(deviceId, "EMPLOYEE")
promise.then((tableName) => {
console.info('obtainDistributedTableName successful, tableName=' + tableName)
console.info('obtainDistributedTableName successfully, tableName=' + tableName)
}).catch((err) => {
console.info('obtainDistributedTableName failed, err: ' + err)
})
......
......@@ -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.
>
>
## Modules to Import
......@@ -22,15 +22,15 @@ import dataStorage from '@ohos.data.storage';
| Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| MAX_KEY_LENGTH | string | Yes| No| Maximum length of a key. It is 80 bytes.|
| MAX_VALUE_LENGTH | string | Yes| No| Maximum length of a value. It is 8192 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 must be less than 8192 bytes.|
## dataStorage.getStorageSync
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
......
......@@ -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.
>**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.
......@@ -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_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_QUERY_LENGTH | 512000 | Maximum query length. |
| MAX_BATCH_SIZE | 128 | Maximum size of a batch operation. |
| MAX_QUERY_LENGTH | 512000 | Maximum query length, in bytes.|
| MAX_BATCH_SIZE | 128 | Maximum number of batch operations.|
## 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
......@@ -731,15 +732,15 @@ let kvStore;
try {
let resultSet;
kvStore.getResultSet('batch_test_string_key').then((result) => {
console.log('getResultSet success');
console.log('getResultSet succeed.');
resultSet = result;
}).catch((err) => {
console.log('getResultSet fail ' + err);
console.log('getResultSet failed:' + err);
});
const count = resultSet.getCount();
console.log("GetCount " + count);
console.log("getCount succeed:" + count);
} catch (e) {
console.log("GetCount fail " + e);
console.log("getCount failed: " + e);
}
```
......@@ -764,15 +765,15 @@ let kvStore;
try {
let resultSet;
kvStore.getResultSet('batch_test_string_key').then((result) => {
console.log('getResultSet success');
console.log('getResultSet succeeed.');
resultSet = result;
}).catch((err) => {
console.log('getResultSet fail ' + err);
console.log('getResultSet failed:' + err);
});
const position = resultSet.getPosition();
console.log("getPosition " + position);
console.log("getPosition succeed:" + position);
} catch (e) {
console.log("GetPosition fail " + e);
console.log("getPosition failed: " + e);
}
```
......@@ -798,15 +799,15 @@ let kvStore;
try {
let resultSet;
kvStore.getResultSet('batch_test_string_key').then((result) => {
console.log('getResultSet success');
console.log('getResultSet succeed.');
resultSet = result;
}).catch((err) => {
console.log('getResultSet fail ' + err);
console.log('getResultSet failed: ' + err);
});
const moved = resultSet.moveToFirst();
console.log("moveToFirst " + moved);
const moved1 = resultSet.moveToFirst();
console.log("moveToFirst succeed: " + moved1);
} catch (e) {
console.log("MoveToFirst fail " + e);
console.log("moveToFirst failed " + e);
}
```
......@@ -832,15 +833,15 @@ let kvStore;
try {
let resultSet;
kvStore.getResultSet('batch_test_string_key').then((result) => {
console.log('getResultSet success');
console.log('getResultSet succeed.');
resultSet = result;
}).catch((err) => {
console.log('getResultSet fail ' + err);
console.log('getResultSet failed: ' + err);
});
const moved = resultSet.moveToLast();
console.log("moveToLast " + moved);
const moved2 = resultSet.moveToLast();
console.log("moveToLast succeed:" + moved2);
} catch (e) {
console.log("moveToLast fail " + e);
console.log("moveToLast failed: " + e);
}
```
......@@ -866,15 +867,15 @@ let kvStore;
try {
let resultSet;
kvStore.getResultSet('batch_test_string_key').then((result) => {
console.log('getResultSet success');
console.log('getResultSet succeed.');
resultSet = result;
}).catch((err) => {
console.log('getResultSet fail ' + err);
console.log('getResultSet failed: ' + err);
});
const moved = resultSet.moveToNext();
console.log("moveToNext " + moved);
const moved3 = resultSet.moveToNext();
console.log("moveToNext succeed: " + moved3);
} catch (e) {
console.log("moveToNext fail " + e);
console.log("moveToNext failed: " + e);
}
```
......@@ -900,15 +901,15 @@ let kvStore;
try {
let resultSet;
kvStore.getResultSet('batch_test_string_key').then((result) => {
console.log('getResultSet success');
console.log('getResultSet succeed.');
resultSet = result;
}).catch((err) => {
console.log('getResultSet fail ' + err);
console.log('getResultSet failed: ' + err);
});
const moved = resultSet.moveToPrevious();
console.log("moveToPrevious " + moved);
const moved4 = resultSet.moveToPrevious();
console.log("moveToPrevious succeed:" + moved4);
} catch (e) {
console.log("moveToPrevious fail " + e);
console.log("moveToPrevious failed: " + e);
}
```
......@@ -940,15 +941,15 @@ let kvStore;
try {
let resultSet;
kvStore.getResultSet('batch_test_string_key').then((result) => {
console.log('getResultSet success');
console.log('getResultSet succeed.');
resultSet = result;
}).catch((err) => {
console.log('getResultSet fail ' + err);
console.log('getResultSet failed: ' + err);
});
const moved = resultSet.move();
console.log("move " + moved);
const moved5 = resultSet.move();
console.log("move succeed:" + moved5);
} catch (e) {
console.log("move fail " + e);
console.log("move failed: " + e);
}
```
......@@ -980,15 +981,15 @@ let kvStore;
try {
let resultSet;
kvStore.getResultSet('batch_test_string_key').then((result) => {
console.log('getResultSet success');
console.log('getResultSet succeed.');
resultSet = result;
}).catch((err) => {
console.log('getResultSet fail ' + err);
console.log('getResultSet failed: ' + err);
});
const moved = resultSet.moveToPosition();
console.log("moveToPosition " + moved);
const moved6 = resultSet.moveToPosition();
console.log("moveToPosition succeed: " + moved6);
} catch (e) {
console.log("moveToPosition fail " + e);
console.log("moveToPosition failed: " + e);
}
```
......@@ -1014,15 +1015,15 @@ let kvStore;
try {
let resultSet;
kvStore.getResultSet('batch_test_string_key').then((result) => {
console.log('getResultSet success');
console.log('getResultSet succeed.');
resultSet = result;
}).catch((err) => {
console.log('getResultSet fail ' + err);
console.log('getResultSet failed: ' + err);
});
const moved = resultSet.isFirst();
console.log("isFirst " + moved);
const isfirst = resultSet.isFirst();
console.log("Check isFirst succeed:" + isfirst);
} catch (e) {
console.log("isFirst fail " + e);
console.log("Check isFirst failed: " + e);
}
```
......@@ -1048,15 +1049,15 @@ let kvStore;
try {
let resultSet;
kvStore.getResultSet('batch_test_string_key').then((result) => {
console.log('getResultSet success');
console.log('getResultSet succeed.');
resultSet = result;
}).catch((err) => {
console.log('getResultSet fail ' + err);
console.log('getResultSet failed: ' + err);
});
const moved = resultSet.isLast();
console.log("isLast " + moved);
const islast = resultSet.isLast();
console.log("Check isLast succeed: " + islast);
} catch (e) {
console.log("isLast fail " + e);
console.log("Check isLast failed: " + e);
}
```
......@@ -1081,15 +1082,15 @@ let kvStore;
try {
let resultSet;
kvStore.getResultSet('batch_test_string_key').then((result) => {
console.log('getResultSet success');
console.log('getResultSet succeed.');
resultSet = result;
}).catch((err) => {
console.log('getResultSet fail ' + err);
console.log('getResultSet failed: ' + err);
});
const moved = resultSet.isBeforeFirst();
console.log("isBeforeFirst " + moved);
const isbeforefirst = resultSet.isBeforeFirst();
console.log("Check isBeforeFirst succeed: " + isbeforefirst);
} catch (e) {
console.log("isBeforeFirst fail " + e);
console.log("Check isBeforeFirst failed: " + e);
}
```
......@@ -1115,15 +1116,15 @@ let kvStore;
try {
let resultSet;
kvStore.getResultSet('batch_test_string_key').then((result) => {
console.log('getResultSet success');
console.log('getResultSet succeed.');
resultSet = result;
}).catch((err) => {
console.log('getResultSet fail ' + err);
console.log('getResultSet failed: ' + err);
});
const moved = resultSet.isAfterLast();
console.log("isAfterLast " + moved);
const isafterlast = resultSet.isAfterLast();
console.log("Check isAfterLast succeed:" + isafterlast);
} catch (e) {
console.log("isAfterLast fail " + e);
console.log("Check isAfterLast failed: " + e);
}
```
......@@ -1149,16 +1150,15 @@ let kvStore;
try {
let resultSet;
kvStore.getResultSet('batch_test_string_key').then((result) => {
console.log('getResultSet success');
console.log('getResultSet succeed.');
resultSet = result;
}).catch((err) => {
console.log('getResultSet fail ' + err);
console.log('getResultSet failed: ' + err);
});
const moved = resultSet.moveToNext();
const entry = resultSet.getEntry();
console.log("getEntry " + JSON.stringify(entry));
console.log("getEntry succeed:" + JSON.stringify(entry));
} 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
| 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.|
**Return value**
......@@ -1256,7 +1256,7 @@ Creates a **Query** object to match the specified field whose value is not equal
| 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.|
**Return value**
......@@ -1291,7 +1291,7 @@ Creates a **Query** object to match the specified field whose value is greater t
| 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.|
**Return value**
......@@ -1326,7 +1326,7 @@ Creates a **Query** object to match the specified field whose value is less than
| 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.|
**Return value**
......@@ -1361,7 +1361,7 @@ Creates a **Query** object to match the specified field whose value is greater t
| 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.|
**Return value**
......@@ -1396,7 +1396,7 @@ Creates a **Query** object to match the specified field whose value is less than
| 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.|
**Return value**
......@@ -1432,7 +1432,7 @@ Creates a **Query** object to match the specified field whose value is **null**.
| 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**
......@@ -1467,7 +1467,7 @@ Creates a **Query** object to match the specified field whose value is within th
| 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.|
**Return value**
......@@ -1502,7 +1502,7 @@ Creates a **Query** object to match the specified field whose value is within th
| 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.|
**Return value**
......@@ -1537,7 +1537,7 @@ Creates a **Query** object to match the specified field whose value is not withi
| 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.|
**Return value**
......@@ -1572,7 +1572,7 @@ Creates a **Query** object to match the specified field whose value is not withi
| 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.|
**Return value**
......@@ -1607,8 +1607,8 @@ Creates a **Query** object to match the specified field whose value is similar t
| Name | Type| Mandatory | Description |
| ----- | ------ | ---- | ----------------------- |
| fieId | string | Yes |Field to match. It must start with $ and cannot contain ^. |
| valueList | string | Yes | String specified.|
| fieId | string | Yes Field to match. It cannot contain '^'. |
| value | string | Yes | String specified.|
**Return value**
......@@ -1642,8 +1642,8 @@ Creates a **Query** object to match the specified field whose value is not simil
| Name | Type| Mandatory | Description |
| ----- | ------ | ---- | ----------------------- |
| fieId | string | Yes |Field to match. It must start with $ and cannot contain ^. |
| valueList | string | Yes | String specified.|
| fieId | string | Yes |Field to match. It cannot contain '^'. |
| value | string | Yes | String specified.|
**Return value**
......@@ -1737,7 +1737,7 @@ Creates a **Query** object to sort the query results in ascending order.
| 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**
......@@ -1772,7 +1772,7 @@ Creates a **Query** object to sort the query results in descending order.
| 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**
......@@ -2041,7 +2041,7 @@ Obtains the query statement of this **Query** object.
| Type | Description |
| ------ | ------- |
| [Query](#query8) |**Query** object Created.|
| string |Query statement obtained.|
**Example**
......@@ -2058,9 +2058,7 @@ try {
## 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.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
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.
### put
......@@ -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.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
### get
get(key: string, callback: AsyncCallback&lt;Uint8Array | string | boolean | number&gt;): void
......@@ -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
......@@ -3258,7 +3254,7 @@ try {
kvStore.putBatch(entries, async function (err, data) {
console.log('GetResultSet putBatch success');
await kvStore.getResultSet('batch_test_string_key', async function (err, result) {
console.log('GetResultSet getResultSet success');
console.log('GetResultSet getResultSet succeed.');
resultSet = result;
kvStore.closeResultSet(resultSet, function (err, data) {
console.log('GetResultSet closeResultSet success');
......@@ -3315,10 +3311,10 @@ try {
console.log('PutBatch putBatch fail ' + JSON.stringify(err));
});
kvStore.getResultSet('batch_test_string_key').then((result) => {
console.log('GetResult getResultSet success');
console.log('GetResult getResultSet succeed.');
resultSet = result;
}).catch((err) => {
console.log('getResultSet fail ' + JSON.stringify(err));
console.log('getResultSet failed: ' + JSON.stringify(err));
});
kvStore.closeResultSet(resultSet).then((err) => {
console.log('GetResult closeResultSet success');
......@@ -3369,7 +3365,7 @@ try {
const query = new distributedData.Query();
query.prefixKey("batch_test");
await kvStore.getResultSet(query, async function (err, result) {
console.log('getResultSet success');
console.log('getResultSet succeed.');
resultSet = result;
});
});
......@@ -3425,10 +3421,10 @@ try {
const query = new distributedData.Query();
query.prefixKey("batch_test");
kvStore.getResultSet(query).then((result) => {
console.log(' getResultSet success');
console.log(' getResultSet succeed.');
resultSet = result;
}).catch((err) => {
console.log('getResultSet fail ' + JSON.stringify(err));
console.log('getResultSet failed: ' + JSON.stringify(err));
});
}catch(e) {
console.log('GetResultSet e ' + e);
......@@ -3439,7 +3435,7 @@ try {
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
......@@ -3473,7 +3469,7 @@ try {
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
......@@ -3543,7 +3539,7 @@ try {
const query = new distributedData.Query();
query.prefixKey("batch_test");
await kvStore.getResultSize(query, async function (err, resultSize) {
console.log('getResultSet success');
console.log('getResultSet succeed.');
});
});
} catch(e) {
......@@ -3597,9 +3593,9 @@ try {
const query = new distributedData.Query();
query.prefixKey("batch_test");
kvStore.getResultSize(query).then((resultSize) => {
console.log('getResultSet success');
console.log('getResultSet succeed.');
}).catch((err) => {
console.log('getResultSet fail ' + JSON.stringify(err));
console.log('getResultSet failed: ' + JSON.stringify(err));
});
}catch(e) {
console.log('GetResultSize e ' + e);
......@@ -3769,7 +3765,7 @@ try {
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
......@@ -3794,7 +3790,7 @@ kvStore.sync('deviceIds', distributedData.SyncMode.PULL_ONLY, 1000);
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
......@@ -3824,7 +3820,7 @@ try {
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
......@@ -3898,7 +3894,7 @@ Obtains the security level of this KV store. This API uses a promise to return t
| 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**
......@@ -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.
**System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
### get<sup>8+</sup> ###
get(deviceId: string, key: string, callback: AsyncCallback&lt;boolean|string|number|Uint8Array&gt;): void
......@@ -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
......@@ -4356,7 +4350,7 @@ let kvStore;
try {
let resultSet;
kvStore.getResultSet('localDeviceId', 'batch_test_string_key', async function (err, result) {
console.log('getResultSet success');
console.log('getResultSet succeed.');
resultSet = result;
await kvStore.closeResultSet(resultSet, function (err, data) {
console.log('closeResultSet success');
......@@ -4396,10 +4390,10 @@ let kvStore;
try {
let resultSet;
kvStore.getResultSet('localDeviceId', 'batch_test_string_key').then((result) => {
console.log('getResultSet success');
console.log('getResultSet succeed.');
resultSet = result;
}).catch((err) => {
console.log('getResultSet fail ' + JSON.stringify(err));
console.log('getResultSet failed: ' + JSON.stringify(err));
});
kvStore.closeResultSet(resultSet).then((err) => {
console.log('closeResultSet success');
......@@ -4451,7 +4445,7 @@ try {
query.prefixKey("batch_test");
query.deviceId('localDeviceId');
await kvStore.getResultSet(query, async function (err, result) {
console.log('getResultSet success');
console.log('getResultSet succeed.');
resultSet = result;
await kvStore.closeResultSet(resultSet, function (err, data) {
console.log('closeResultSet success');
......@@ -4512,10 +4506,10 @@ try {
query.prefixKey("batch_test");
console.log("GetResultSet " + query.getSqlLike());
kvStore.getResultSet(query).then((result) => {
console.log('getResultSet success');
console.log('getResultSet succeed.');
resultSet = result;
}).catch((err) => {
console.log('getResultSet fail ' + JSON.stringify(err));
console.log('getResultSet failed: ' + JSON.stringify(err));
});
kvStore.closeResultSet(resultSet).then((err) => {
console.log('closeResultSet success');
......@@ -4567,7 +4561,7 @@ try {
const query = new distributedData.Query();
query.prefixKey("batch_test");
await kvStore.getResultSet('localDeviceId', query, async function (err, result) {
console.log('getResultSet success');
console.log('getResultSet succeed.');
resultSet = result;
await kvStore.closeResultSet(resultSet, function (err, data) {
console.log('closeResultSet success');
......@@ -4627,10 +4621,10 @@ try {
const query = new distributedData.Query();
query.prefixKey("batch_test");
kvStore.getResultSet('localDeviceId', query).then((result) => {
console.log('GetResultSet getResultSet success');
console.log('GetResultSet getResultSet succeed.');
resultSet = result;
}).catch((err) => {
console.log('GetResultSet getResultSet fail ' + JSON.stringify(err));
console.log('GetResultSet getResultSet failed: ' + JSON.stringify(err));
});
query.deviceId('localDeviceId');
console.log("GetResultSet " + query.getSqlLike());
......@@ -4650,7 +4644,7 @@ try {
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
......@@ -4685,7 +4679,7 @@ try {
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
......@@ -4757,7 +4751,7 @@ try {
query.prefixKey("batch_test");
query.deviceId('localDeviceId');
await kvStore.getResultSize(query, async function (err, resultSize) {
console.log('getResultSet success');
console.log('getResultSet succeed.');
});
});
} catch(e) {
......@@ -4812,9 +4806,9 @@ try {
query.prefixKey("batch_test");
query.deviceId('localDeviceId');
kvStore.getResultSize(query).then((resultSize) => {
console.log('getResultSet success');
console.log('getResultSet succeed.');
}).catch((err) => {
console.log('getResultSet fail ' + JSON.stringify(err));
console.log('getResultSet failed: ' + JSON.stringify(err));
});
}catch(e) {
console.log('GetResultSize e ' + e);
......@@ -4860,7 +4854,7 @@ try {
const query = new distributedData.Query();
query.prefixKey("batch_test");
await kvStore.getResultSize('localDeviceId', query, async function (err, resultSize) {
console.log('getResultSet success');
console.log('getResultSet succeed.');
});
});
} catch(e) {
......@@ -4915,9 +4909,9 @@ try {
var query = new distributedData.Query();
query.prefixKey("batch_test");
kvStore.getResultSize('localDeviceId', query).then((resultSize) => {
console.log('getResultSet success');
console.log('getResultSet succeed.');
}).catch((err) => {
console.log('getResultSet fail ' + JSON.stringify(err));
console.log('getResultSet failed: ' + JSON.stringify(err));
});
}catch(e) {
console.log('GetResultSize e ' + e);
......@@ -5020,7 +5014,7 @@ try {
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
......@@ -5031,7 +5025,7 @@ Manually triggers KV store synchronization synchronously.
| Name | Type| Mandatory | Description |
| ----- | ------ | ---- | ----------------------- |
| 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. |
**Example**
......@@ -5123,7 +5117,7 @@ try {
## SyncMode
Defines the synchronization mode.
Enumerates the synchronization modes.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
......
# 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.
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
```js
......@@ -10,18 +12,13 @@ import fileio from '@ohos.fileio';
```
## Required Permissions
None
## 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
let path = dir + "/xxx.txt";
......@@ -40,21 +37,23 @@ let fd = fileio.openSync(path);
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
- Parameters
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ----------- |
| path | string | Yes | Absolute path of the target file.|
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | -------------------------- |
| path | string | Yes | Application sandbox path of the target file.|
**Return value**
- Return value
| Type | Description |
| ---------------------------- | ---------- |
| Promise&lt;[Stat](#stat)&gt; | Promise used to return the file information obtained.|
- Example
**Example**
```js
fileio.stat(path).then(function(stat){
console.info("getFileInfo successfully:"+ JSON.stringify(stat));
......@@ -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
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
- Parameters
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------- | ---- | --------------- |
| path | string | Yes | Absolute path of the target file. |
| callback | AsyncCallback&lt;[Stat](#stat)&gt; | Yes | Callback invoked to return the file information obtained.|
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ---------------------------------- | ---- | ------------------------------ |
| 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.|
- Example
**Example**
```js
fileio.stat(path, function (err, stat) {
// Example code in Stat
......@@ -94,18 +93,18 @@ Synchronously obtains file information.
**System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ----------- |
| path | string | Yes | Absolute path of the target file.|
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | -------------------------- |
| path | string | Yes | Application sandbox path of the target file.|
- Return value
**Return value**
| Type | Description |
| ------------- | ---------- |
| [Stat](#stat) | File information obtained.|
- Example
**Example**
```js
let stat = fileio.statSync(path);
// Example code in Stat
......@@ -116,21 +115,21 @@ Synchronously obtains file information.
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
- Parameters
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ------------- |
| path | string | Yes | Absolute path of the directory to open.|
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------------ |
| path | string | Yes | Application sandbox path of the directory to open.|
- Return value
**Return value**
| Type | Description |
| -------------------------- | -------- |
| Promise&lt;[Dir](#dir)&gt; | A **Dir** instance corresponding to the directory.|
- Example
**Example**
```js
fileio.opendir(path).then(function(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
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
- 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.|
**Parameters**
- 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
fileio.opendir(path, function (err, dir) {
// Example code in Dir struct
......@@ -172,17 +172,18 @@ Synchronously opens a directory.
**System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ------------- |
| path | string | Yes | Absolute path of the directory to open.|
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------------ |
| path | string | Yes | Application sandbox path of the directory to open.|
- Return value
**Return value**
| Type | Description |
| ----------- | -------- |
| [Dir](#dir) | A **Dir** instance corresponding to the directory.|
- Example
**Example**
```js
let dir = fileio.opendirSync(path);
// Example code in Dir struct
......@@ -194,22 +195,23 @@ Synchronously opens a directory.
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
- 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.|
**Parameters**
- 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 |
| ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise used to return the result. An empty value is returned.|
- Example
**Example**
```js
fileio.access(path).then(function() {
console.info("access successfully");
......@@ -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
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
- 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.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file is asynchronously checked. |
**Parameters**
| 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.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file is asynchronously checked. |
- Example
**Example**
```js
fileio.access(path, function (err) {
// Do something.
......@@ -250,13 +252,13 @@ Synchronously checks whether the current process can access the specified file.
**System capability**: SystemCapability.FileManagement.File.FileIO
- 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.|
**Parameters**
| 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.|
- Example
**Example**
```js
try {
fileio.accessSync(path);
......@@ -270,21 +272,21 @@ Synchronously checks whether the current process can access the specified file.
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
- Parameters
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ------------ |
| fd | number | Yes | File descriptor of the file to close.|
- Return value
**Return value**
| Type | Description |
| ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise used to return the result. An empty value is returned.|
- Example
**Example**
```js
let fd = fileio.openSync(path);
fileio.close(fd).then(function(){
......@@ -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
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
- Parameters
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | ------------ |
| fd | number | Yes | File descriptor of the file to close.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file is closed asynchronously.|
- Example
**Example**
```js
let fd = fileio.openSync(path);
fileio.close(fd, function (err) {
......@@ -326,12 +328,12 @@ Synchronously closes a file.
**System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ------------ |
| fd | number | Yes | File descriptor of the file to close.|
- Example
**Example**
```js
fileio.closeSync(fd);
```
......@@ -341,16 +343,16 @@ Synchronously closes a file.
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
- Return value
**Return value**
| Type | Description |
| ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise used to return the result. An empty value is returned.|
- Example
**Example**
```js
fileio.close().then(function(){
console.info("close file stream successfully");
......@@ -364,16 +366,16 @@ Asynchronously closes the stream. This method uses a promise to return the resul
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
- Parameters
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | ------------- |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the stream is closed asynchronously.|
- Example
**Example**
```js
fileio.close(function(err){
// Do something.
......@@ -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;
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
- Parameters
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | -------------------------- | ---- | ---------------------------------------- |
| 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. |
| 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 |
| ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise used to return the result. An empty value is returned.|
- Example
**Example**
```js
fileio.copyFile(src, dest).then(function(){
console.info("copyFile successfully");
......@@ -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
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
- Parameters
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | -------------------------- | ---- | ---------------------------------------- |
| 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.
| 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. |
- Example
**Example**
```js
fileio.copyFile(src, dest, function (err) {
// Do something.
......@@ -443,14 +445,14 @@ Synchronously copies a file.
**System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | -------------------------- | ---- | ---------------------------------------- |
| 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. |
| 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
fileio.copyFileSync(src, dest);
```
......@@ -460,22 +462,22 @@ Synchronously copies a file.
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
- Parameters
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ---------------------------------------- |
| path | string | Yes | Absolute 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.|
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------------------------------------------ |
| 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.|
- Return value
**Return value**
| Type | Description |
| ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise used to return the result. An empty value is returned.|
- Example
**Example**
```js
fileio.mkdir(path).then(function() {
console.info("mkdir successfully");
......@@ -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
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
- Parameters
| Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | ---------------------------------------- |
| path | string | Yes | Absolute 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.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the directory is created asynchronously. |
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ------------------------------------------------------------ |
| 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.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the directory is created asynchronously. |
- Example
**Example**
```js
fileio.mkdir(path, function(err) {
console.info("mkdir successfully");
......@@ -516,13 +518,13 @@ Synchronously creates a directory.
**System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ---------------------------------------- |
| path | string | Yes | Absolute 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.|
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------------------------------------------ |
| 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.|
- Example
**Example**
```js
fileio.mkdirSync(path);
```
......@@ -532,23 +534,23 @@ Synchronously creates a directory.
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
- Parameters
| Name | Type | Mandatory | Description |
| ----- | ------ | ---- | ---------------------------------------- |
| path | string | Yes | Absolute 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.|
| 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.|
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------------------------------------------ |
| 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.|
| 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 |
| --------------------- | ----------- |
| Promise&lt;number&gt; | File descriptor of the file opened.|
- Example
**Example**
```js
fileio.open(path, 0o1, 0o0200).then(function(number){
console.info("open file successfully");
......@@ -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
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
- Parameters
| Name | Type | Mandatory | Description |
| -------- | ------------------------------- | ---- | ---------------------------------------- |
| path | string | Yes | Absolute 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.|
| 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. |
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------------- | ---- | ------------------------------------------------------------ |
| 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.|
| 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. |
- Example
**Example**
```js
fileio.open(path, 0, function(err, fd) {
// Do something.
......@@ -590,19 +592,19 @@ Synchronously opens a file.
**System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters
| Name | Type | Mandatory | Description |
| ----- | ------ | ---- | ---------------------------------------- |
| path | string | Yes | Absolute 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.|
| 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.|
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------------------------------------------ |
| 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.|
| 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 |
| ------ | ----------- |
| number | File descriptor of the file opened.|
- Example
**Example**
```js
let fd = fileio.openSync(path);
```
......@@ -616,23 +618,24 @@ read(fd: number, buffer: ArrayBuffer, options?: {
position?: number;
}): 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
- Parameters
| Name | Type | Mandatory | Description |
| ------- | ----------- | ---- | ---------------------------------------- |
| fd | number | Yes | File descriptor of the file to 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. |
**Parameters**
| Name | Type | Mandatory| Description |
| ------- | ----------- | ---- | ------------------------------------------------------------ |
| fd | number | Yes | File descriptor of the file to 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>Constraints: offset + length <= Buffer size|
**Return value**
- Return value
| Type | Description |
| ---------------------------------- | ------ |
| Promise&lt;[ReadOut](#readout)&gt; | Data read.|
- Example
**Example**
```js
let fd = fileio.openSync(path, 0o2);
let buf = new ArrayBuffer(4096);
......@@ -653,19 +656,19 @@ read(fd: number, buffer: ArrayBuffer, options: {
position?: number;
}, 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
- Parameters
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| fd | number | Yes | File descriptor of the file to 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. |
- Example
**Example**
```js
let fd = fileio.openSync(path, 0o2);
let buf = new ArrayBuffer(4096);
......@@ -690,19 +693,19 @@ Synchronously reads data from a file.
**System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters
**Parameters**
| Name | Type | Mandatory | Description |
| ------- | ----------- | ---- | ---------------------------------------- |
| fd | number | Yes | File descriptor of the file to 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 |
| ------ | -------- |
| number | Length of the data read.|
- Example
**Example**
```js
let fd = fileio.openSync(path, 0o2);
let buf = new ArrayBuffer(4096);
......@@ -714,21 +717,21 @@ Synchronously reads data from a file.
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
- Parameters
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ----------- |
| path | string | Yes | Absolute path of the directory to delete.|
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | -------------------------- |
| path | string | Yes | Application sandbox path of the directory to delete.|
- Return value
**Return value**
| Type | Description |
| ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise used to return the result. An empty value is returned.|
- Example
**Example**
```js
fileio.rmdir(path).then(function() {
console.info("rmdir successfully");
......@@ -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
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
- Parameters
| Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | ------------ |
| path | string | Yes | Absolute path of the directory to delete. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the directory is deleted asynchronously.|
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | -------------------------- |
| 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. |
- Example
**Example**
```js
fileio.rmdir(path, function(err){
// Do something.
......@@ -769,12 +772,12 @@ Synchronously deletes a directory.
**System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ----------- |
| path | string | Yes | Absolute path of the directory to delete.|
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | -------------------------- |
| path | string | Yes | Application sandbox path of the directory to delete.|
- Example
**Example**
```js
fileio.rmdirSync(path);
```
......@@ -784,21 +787,21 @@ Synchronously deletes a directory.
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
- Parameters
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ----------- |
| path | string | Yes | Absolute path of the file to delete.|
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | -------------------------- |
| path | string | Yes | Application sandbox path of the file to delete.|
- Return value
**Return value**
| Type | Description |
| ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise used to return the result. An empty value is returned.|
- Example
**Example**
```js
fileio.unlink(path).then(function(){
console.info("remove file successfully");
......@@ -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
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
- Parameters
| Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | ------------ |
| path | string | Yes | Absolute path of the file to delete. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file is deleted asynchronously.|
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | -------------------------- |
| 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. |
- Example
**Example**
```js
fileio.unlink(path, function(err) {
console.info("remove file successfully");
......@@ -838,12 +841,12 @@ Synchronously deletes a file.
**System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ----------- |
| path | string | Yes | Absolute path of the file to delete.|
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | -------------------------- |
| path | string | Yes | Application sandbox path of the file to delete.|
- Example
**Example**
```js
fileio.unlinkSync(path);
```
......@@ -858,23 +861,23 @@ write(fd: number, buffer: ArrayBuffer | string, options?: {
encoding?: string;
}): 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
- Parameters
**Parameters**
| Name | Type | Mandatory | Description |
| ------- | ------------------------------- | ---- | ---------------------------------------- |
| 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. |
| 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 |
| --------------------- | -------- |
| Promise&lt;number&gt; | Length of the data written in the file.|
- Example
**Example**
```js
let fd = fileio.openSync(fpath, 0o100 | 0o2, 0o666);
fileio.write(fd, "hello, world").then(function(number){
......@@ -894,19 +897,19 @@ write(fd: number, buffer: ArrayBuffer | string, options: {
encoding?: string;
}, 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
- Parameters
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ------------------------------- | ---- | ---------------------------------------- |
| 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. |
| 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. |
- Example
**Example**
```js
let fd = fileio.openSync(path, 0o100 | 0o2, 0o666);
fileio.write(fd, "hello, world", function (err, bytesWritten) {
......@@ -930,19 +933,19 @@ Synchronously writes data into a file.
**System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters
**Parameters**
| Name | Type | Mandatory | Description |
| ------- | ------------------------------- | ---- | ---------------------------------------- |
| 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. |
| 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 |
| ------ | -------- |
| number | Length of the data written in the file.|
- Example
**Example**
```js
let fd = fileio.openSync(path, 0o100 | 0o2, 0o666);
let num = fileio.writeSync(fd, "hello, world");
......@@ -953,22 +956,22 @@ Synchronously writes data into a file.
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
- Parameters
| Name | Type | Mandatory | Description |
| --------- | ------ | ---- | ---------------------------------------- |
| path | string | Yes | Absolute 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.|
**Parameters**
| Name | Type | Mandatory| Description |
| --------- | ------ | ---- | ------------------------------------------------------------ |
| 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**. **sha256** is recommended for security purposes.|
- Return value
**Return value**
| 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.|
- Example
**Example**
```js
fileio.hash(path, "sha256").then(function(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
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
- Parameters
| Name | Type | Mandatory | Description |
| --------- | --------------------------- | ---- | ---------------------------------------- |
| path | string | Yes | Absolute 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.|
| 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.|
**Parameters**
| Name | Type | Mandatory| Description |
| --------- | --------------------------- | ---- | ------------------------------------------------------------ |
| 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**. **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.|
- Example
**Example**
```js
fileio.hash(fpath, "sha256", function(err, hashStr) {
if (hashStr) {
......@@ -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;
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
- Parameters
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ---------------------------------------- |
| path | string | Yes | Absolute 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.|
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------------------------------------------ |
| 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.|
- Return value
**Return value**
| Type | Description |
| ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise used to return the result. An empty value is returned.|
- Example
**Example**
```js
fileio.chmod(path, mode).then(function() {
console.info("chmod successfully");
......@@ -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
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
- Parameters
| Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | ---------------------------------------- |
| path | string | Yes | Absolute 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.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file permissions are changed asynchronously. |
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ------------------------------------------------------------ |
| 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.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file permissions are changed asynchronously. |
- Example
**Example**
```js
fileio.chmod(path, mode, function (err) {
// Do something.
......@@ -1063,13 +1066,13 @@ Synchronously changes the file permissions based on its path.
**System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ---------------------------------------- |
| path | string | Yes | Absolute 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.|
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------------------------------------------ |
| 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.|
- Example
**Example**
```js
fileio.chmodSync(fpath, mode);
```
......@@ -1079,21 +1082,21 @@ Synchronously changes the file permissions based on its path.
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
- Parameters
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ------------ |
| fd | number | Yes | File descriptor of the target file.|
- Return value
**Return value**
| 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
fileio.fstat(fd).then(function(stat){
console.info("fstat successfully:"+ JSON.stringify(stat));
......@@ -1107,17 +1110,17 @@ Asynchronously obtains file status information based on the file descriptor. Thi
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
- Parameters
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------- | ---- | ---------------- |
| 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
let fd = fileio.openSync(path);
fileio.fstat(fd, function (err) {
......@@ -1130,21 +1133,21 @@ Asynchronously obtains file status information based on the file descriptor. Thi
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
- Parameters
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ------------ |
| fd | number | Yes | File descriptor of the target file.|
- Return value
**Return value**
| Type | Description |
| ------------- | ---------- |
| [Stat](#stat) | File status information obtained.|
| [Stat](#stat) | File information obtained.|
- Example
**Example**
```js
let fd = fileio.openSync(path);
let stat = fileio.fstatSync(fd);
......@@ -1155,22 +1158,22 @@ Synchronously obtains file status information based on the file descriptor.
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
- Parameters
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ---------------- |
| fd | number | Yes | File descriptor of the file to truncate. |
| len | number | Yes | File length, in bytes, after truncation.|
- Return value
**Return value**
| Type | Description |
| ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise used to return the result. An empty value is returned.|
- Example
**Example**
```js
let fd = fileio.openSync(path);
fileio.ftruncate(fd, 5).then(function(err) {
......@@ -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
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
- Parameters
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | ---------------- |
| fd | number | Yes | File descriptor of the file to truncate. |
| len | number | Yes | File length, in bytes, after truncation.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file is truncated asynchronously. |
- Example
**Example**
```js
fileio.ftruncate(fd, len, function(err){
// Do something.
......@@ -1212,13 +1215,13 @@ Synchronously truncates a file based on the file descriptor.
**System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ---------------- |
| fd | number | Yes | File descriptor of the file to truncate. |
| len | number | No | File length, in bytes, after truncation.|
- Example
**Example**
```js
fileio.ftruncateSync(fd, len);
```
......@@ -1228,22 +1231,22 @@ Synchronously truncates a file based on the file descriptor.
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
- Parameters
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ---------------- |
| path | string | Yes | Absolute path of the file to truncate. |
| len | number | Yes | File length, in bytes, after truncation.|
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | -------------------------------- |
| path | string | Yes | Application sandbox path of the file to truncate. |
| len | number | Yes | File length, in bytes, after truncation.|
- Return value
**Return value**
| Type | Description |
| ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise used to return the result. An empty value is returned.|
- Example
**Example**
```js
fileio.truncate(path, len).then(function(){
console.info("File truncated successfully.");
......@@ -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
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
- Parameters
| Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | ---------------- |
| path | string | Yes | Absolute path of the file to truncate. |
| len | number | Yes | File length, in bytes, after truncation.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file is truncated asynchronously. |
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | -------------------------------- |
| path | string | Yes | Application sandbox path of the file to truncate. |
| len | number | Yes | File length, in bytes, after truncation.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file is truncated asynchronously. |
- Example
**Example**
```js
fileio.truncate(path, len, function(err){
// Do something.
......@@ -1284,13 +1287,13 @@ Synchronously truncates a file based on the file path.
**System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ---------------- |
| path | string | Yes | Absolute path of the file to truncate. |
| len | number | No | File length, in bytes, after truncation.|
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | -------------------------------- |
| path | string | Yes | Application sandbox path of the file to be truncate. |
| len | number | No | File length, in bytes, after truncation.|
- Example
**Example**
```js
fileio.truncateSync(path, len);
```
......@@ -1304,22 +1307,22 @@ readText(filePath: string, options?: {
encoding?: string;
}): 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
- Parameters
| Name | Type | Mandatory | Description |
| -------- | ------ | ---- | ---------------------------------------- |
| filePath | string | Yes | Absolute 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.|
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------ | ---- | ------------------------------------------------------------ |
| 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.|
- Return value
**Return value**
| Type | Description |
| --------------------- | ---------- |
| Promise&lt;string&gt; | Promise used to return the content of the file read.|
- Example
**Example**
```js
fileio.readText(path).then(function(str) {
console.info("readText successfully:"+ str);
......@@ -1337,18 +1340,18 @@ readText(filePath: string, options: {
encoding?: string;
}, 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
- Parameters
| Name | Type | Mandatory | Description |
| -------- | --------------------------- | ---- | ---------------------------------------- |
| filePath | string | Yes | Absolute 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.|
| callback | AsyncCallback&lt;string&gt; | Yes | Callback invoked when the file is read asynchronously. |
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------------- | ---- | ------------------------------------------------------------ |
| 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.|
| callback | AsyncCallback&lt;string&gt; | Yes | Callback invoked when the file is read asynchronously. |
- Example
**Example**
```js
fileio.readText(path, function(err, str){
// Do something.
......@@ -1368,18 +1371,18 @@ Synchronously reads the text of a file.
**System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters
| Name | Type | Mandatory | Description |
| -------- | ------ | ---- | ---------------------------------------- |
| filePath | string | Yes | Absolute 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.|
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------ | ---- | ------------------------------------------------------------ |
| 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.|
- Return value
**Return value**
| Type | Description |
| ------ | -------------------- |
| string | Content of the file read.|
| string | Promise used to return the content of the file read.|
- Example
**Example**
```js
let str = fileio.readTextSync(path, {position: 1, length: 3});
```
......@@ -1389,21 +1392,21 @@ Synchronously reads the text of a file.
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
- Parameters
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ----------------- |
| path | string | Yes | Absolute path of the target file, pointing to the link status.|
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | -------------------------------------- |
| path | string | Yes | Application sandbox path of the target file, pointing to the link.|
- Return value
**Return value**
| 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
fileio.lstat(path).then(function(stat){
console.info("Link status obtained:"+ number);
......@@ -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
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
- Parameters
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------- | ---- | ----------------- |
| path | string | Yes | Absolute path of the target file, pointing to the link status.|
| callback | AsyncCallback&lt;[Stat](#stat)&gt; | Yes | Callback invoked when the link status information is obtained asynchronously. |
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ---------------------------------- | ---- | -------------------------------------- |
| path | string | Yes | Application sandbox path of the target file, pointing to the link.|
| callback | AsyncCallback&lt;[Stat](#stat)&gt; | Yes | Callback invoked to return the link information obtained. |
- Example
**Example**
```js
fileio.lstat(path, function (err, stat) {
// Do something.
......@@ -1439,21 +1442,21 @@ Asynchronously obtains link status information. This method uses a callback to r
lstatSync(path:string): Stat
Synchronously obtains link status information.
Synchronously obtains the link information.
**System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ----------------- |
| path | string | Yes | Absolute path of the target file, pointing to the link status.|
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | -------------------------------------- |
| path | string | Yes | Application sandbox path of the target file, pointing to the link.|
- Return value
**Return value**
| Type | Description |
| ------------- | ---------- |
| [Stat](#stat) | Link status obtained.|
| [Stat](#stat) | Link information obtained.|
- Example
**Example**
```js
let stat = fileio.lstatSync(path);
```
......@@ -1467,22 +1470,22 @@ read(buffer: ArrayBuffer, options?: {
length?: number;
}): 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
- Parameters
**Parameters**
| Name | Type | Mandatory| Description |
| ------- | ----------- | ---- | ------------------------------------------------------------ |
| 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 |
| ---------------------------------- | ------ |
| Promise&lt;[ReadOut](#readout)&gt; | Data read.|
- Example
**Example**
```js
fileio.read(new ArrayBuffer(4096)).then(function(readout){
console.info("read file data successfully");
......@@ -1501,18 +1504,18 @@ read(buffer: ArrayBuffer, options: {
length?: number;
}, 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
- Parameters
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| 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. |
- Example
**Example**
```js
let buf = new ArrayBuffer(4096);
fileio.read(buf, function (err, readOut) {
......@@ -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;
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
- Parameters
| Name | Type | Mandatory| Description |
| ------- | ------ | ---- | ------------------------ |
| oldPath | string | Yes | Absolute path of the file to rename.|
| newPath | String | Yes | Absolute path of the file renamed. |
**Parameters**
| Name | Type | Mandatory| Description |
| ------- | ------ | ---- | ---------------------------- |
| oldPath | string | Yes | Application sandbox path of the file to rename.|
| newPath | String | Yes | Application sandbox path of the file renamed. |
- Return value
**Return value**
| Type | Description |
| ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise used to return the result. An empty value is returned.|
- Example
**Example**
```js
fileio.rename(oldPath, newPath).then(function() {
console.info("rename successfully");
......@@ -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
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
- Parameters
| Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | ------------- |
| oldPath | string | Yes | Absolute path of the file to rename. |
| newPath | String | Yes | Absolute path of the file renamed. |
| Callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file is asynchronously renamed.|
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ---------------------------- |
| oldPath | string | Yes | Application sandbox path of the file to rename.|
| newPath | String | Yes | Application sandbox path of the file renamed. |
| Callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file is asynchronously renamed. |
- Example
**Example**
```js
fileio.rename(oldPath, newPath, function(err){
});
......@@ -1583,13 +1586,13 @@ Synchronously renames a file.
**System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters
| Name | Type | Mandatory | Description |
| ------- | ------ | ---- | ------------ |
| oldPath | string | Yes | Absolute path of the file to rename.|
| newPath | String | Yes | Absolute path of the file renamed. |
**Parameters**
| Name | Type | Mandatory| Description |
| ------- | ------ | ---- | ---------------------------- |
| oldPath | string | Yes | Application sandbox path of the file to rename.|
| newPath | String | Yes | Application sandbox path of the file renamed. |
- Example
**Example**
```js
fileio.renameSync(oldPath, newPath);
```
......@@ -1599,21 +1602,21 @@ Synchronously renames a file.
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
- Parameters
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ------------ |
| fd | number | Yes | File descriptor of the file to synchronize.|
- Return value
**Return value**
| Type | Description |
| ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise used to return the result. An empty value is returned.|
- Example
**Example**
```js
fileio.fsync(fd).then(function(){
console.info("sync data successfully");
......@@ -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
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
- Parameters
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | --------------- |
| 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.|
- Example
**Example**
```js
fileio.fsync(fd, function(err){
// Do something.
......@@ -1653,12 +1656,12 @@ Synchronizes a file in synchronous mode.
**System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ------------ |
| fd | number | Yes | File descriptor of the file to synchronize.|
- Example
**Example**
```js
fileio.fyncsSync(fd);
```
......@@ -1668,21 +1671,21 @@ Synchronizes a file in synchronous mode.
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
- Parameters
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ------------ |
| fd | number | Yes | File descriptor of the file to synchronize.|
- Return value
**Return value**
| Type | Description |
| ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise used to return the result asynchronously. An empty value is returned.|
- Example
**Example**
```js
fileio.fdatasync(fd).then(function(err) {
console.info("sync data successfully");
......@@ -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
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
- Parameters
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ------------------------------- | ---- | ----------------- |
| 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.|
- Example
**Example**
```js
fileio.fdatasync (fd, function (err) {
// Do something.
......@@ -1722,12 +1725,12 @@ Synchronizes data in a file in synchronous mode.
**System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ------------ |
| fd | number | Yes | File descriptor of the file to synchronize.|
- Example
**Example**
```js
let stat = fileio.fdatasyncSync(fd);
```
......@@ -1737,22 +1740,22 @@ Synchronizes data in a file in synchronous mode.
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
- Parameters
| Name | Type | Mandatory | Description |
| ------- | ------ | ---- | ------------ |
| target | string | Yes | Absolute path of the symbolic link. |
| srcPath | string | Yes | Absolute path of the referenced file or directory contained in the symbolic link.|
**Parameters**
| Name | Type | Mandatory| Description |
| ------- | ------ | ---- | ---------------------------- |
| target | string | Yes | Application sandbox path of 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 |
| ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise used to return the result asynchronously. An empty value is returned.|
- Example
**Example**
```js
fileio.symlink(target, srcPath).then(function() {
console.info("symlink successfully");
......@@ -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
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
- Parameters
| Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | ---------------- |
| target | string | Yes | Absolute path of the symbolic link. |
| srcPath | string | Yes | Absolute 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.|
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | -------------------------------- |
| target | string | Yes | Application sandbox path of 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.|
- Example
**Example**
```js
fileio.symlink(target, srcPath, function (err) {
// Do something.
......@@ -1793,13 +1796,13 @@ Synchronously creates a symbolic link based on a specified path.
**System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters
| Name | Type | Mandatory | Description |
| ------- | ------ | ---- | ------------ |
| target | string | Yes | Absolute path of the symbolic link. |
| srcPath | string | Yes | Absolute path of the referenced file or directory contained in the symbolic link.|
**Parameters**
| Name | Type | Mandatory| Description |
| ------- | ------ | ---- | ---------------------------- |
| target | string | Yes | Application sandbox path of the symbolic link. |
| srcPath | string | Yes | Application sandbox path the referenced file or directory contained in the symbolic link.|
- Example
**Example**
```js
fileio.symlinkSync(target, srcPath);
```
......@@ -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;
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
- Parameters
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | --------------- |
| path | string | Yes | Absolute path of the target file. |
| uid | number | Yes | New user ID (UID). |
| gid | number | Yes | New group ID (GID).|
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | -------------------------- |
| path | string | Yes | Application sandbox path of the target file.|
| uid | number | Yes | New user ID (UID). |
| gid | number | Yes | New group ID (GID). |
- Return value
**Return value**
| Type | Description |
| ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise used to return the result asynchronously. An empty value is returned.|
- Example
**Example**
```js
let stat = fileio.statSync(path);
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
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
- Parameters
| Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | --------------- |
| path | string | Yes | Absolute path of the target file. |
| uid | number | Yes | New UID. |
| gid | number | Yes | New GID. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file owner is changed asynchronously.|
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ------------------------------ |
| path | string | Yes | Application sandbox path of the target file. |
| uid | number | Yes | New UID. |
| gid | number | Yes | New GID. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file owner is changed asynchronously.|
- Example
**Example**
```js
let stat = fileio.statSync(fpath)
fileio.chown(path, stat.uid, stat.gid, function (err){
......@@ -1869,14 +1872,14 @@ Synchronously changes the file owner based on its path.
**System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ----------- |
| path | string | Yes | Absolute path of the target file.|
| uid | number | Yes | New UID. |
| gid | number | Yes | New GID. |
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | -------------------------- |
| path | string | Yes | Application sandbox path of the target file.|
| uid | number | Yes | New UID. |
| gid | number | Yes | New GID. |
- Example
**Example**
```js
let stat = fileio.statSync(fpath)
fileio.chownSync(path, stat.uid, stat.gid);
......@@ -1887,21 +1890,21 @@ Synchronously changes the file owner based on its path.
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
- Parameters
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- |
| prefix | string | Yes | A randomly generated string used to replace "XXXXXX" in a directory.|
- Return value
**Return value**
| Name | Description |
| --------------------- | ---------- |
| Promise&lt;string&gt; | Unique path generated.|
- Example
**Example**
```js
fileio.mkdtemp(path + "XXXX").then(function(path){
console.info("mkdtemp successfully:"+ path);
......@@ -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
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
- Parameters
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | --------------------------- | ---- | --------------------------- |
| 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. |
- Example
**Example**
```js
fileio.mkdtemp(path + "XXXX", function (err, res) {
// Do something.
......@@ -1941,17 +1944,17 @@ Synchronously creates a temporary directory.
**System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- |
| prefix | string | Yes | A randomly generated string used to replace "XXXXXX" in a directory.|
- Return value
**Return value**
| Name | Description |
| ------ | ---------- |
| string | Unique path generated.|
- Example
**Example**
```js
let res = fileio.mkdtempSync(path + "XXXX");
```
......@@ -1961,22 +1964,22 @@ Synchronously creates a temporary directory.
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
- Parameters
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ---------------------------------------- |
| 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.|
- Return value
**Return value**
| Name | Description |
| ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise used to return the result asynchronously. An empty value is returned.|
- Example
**Example**
```js
fileio.fchmod(fd, mode).then(function() {
console.info("chmod successfully");
......@@ -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
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
- Parameters
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ------------------------------- | ---- | ---------------------------------------- |
| 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.|
| callback | AsyncCallback&nbsp;&lt;void&gt; | Yes | Callback invoked when the file permissions are changed asynchronously. |
- Example
**Example**
```js
fileio.fchmod(fd, mode, function (err) {
// Do something.
......@@ -2017,13 +2020,13 @@ Synchronously changes the file permissions based on the file descriptor.
**System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ---------------------------------------- |
| 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.|
- Example
**Example**
```js
fileio.fchmodSync(fd, mode);
```
......@@ -2033,22 +2036,22 @@ Synchronously changes the file permissions based on the file descriptor.
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
- Parameters
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ---------------------------------------- |
| path | string | Yes | Absolute 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).|
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------------------------------------------ |
| 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).|
- Return value
**Return value**
| Type | Description |
| --------------------------------- | --------- |
| Promise&lt;[Stream](#stream7)&gt; | Promise used to return the result.|
- Example
**Example**
```js
fileio.createStream(path, "r+").then(function(stream){
console.info("createStream successfully");
......@@ -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
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
- Parameters
| Name | Type | Mandatory | Description |
| -------- | --------------------------------------- | ---- | ---------------------------------------- |
| path | string | Yes | Absolute 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).|
| callback | AsyncCallback&lt;[Stream](#stream7)&gt; | Yes | Callback invoked when the stream is open asynchronously. |
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ------------------------------------------------------------ |
| 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).|
| callback | AsyncCallback&lt;[Stream](#stream7)&gt; | Yes | Callback invoked when the stream is open asynchronously. |
- Example
**Example**
```js
fileio.createStream(path, mode, function(err, stream){
// Do something.
......@@ -2089,18 +2092,18 @@ Synchronously opens a stream based on the file path.
**System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ---------------------------------------- |
| path | string | Yes | Absolute 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).|
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------------------------------------------ |
| 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).|
- Return value
**Return value**
| Name | Description |
| ------------------ | --------- |
| [Stream](#stream7) | Stream opened.|
- Example
**Example**
```js
let ss = fileio.createStreamSync(path, "r+");
```
......@@ -2110,22 +2113,22 @@ Synchronously opens a stream based on the file path.
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
- Parameters
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ---------------------------------------- |
| 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).|
- Return value
**Return value**
| Name | Description |
| --------------------------------- | --------- |
| Promise&lt;[Stream](#stream7)&gt; | Promise used to return the result.|
- Example
**Example**
```js
fileio.fdopenStream(fd, mode).then(function(stream){
console.info("openStream successfully");
......@@ -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
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
- Parameters
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| 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).|
| callback | AsyncCallback&nbsp;&lt;[Stream](#stream7)&gt; | Yes | Callback invoked when the stream is open asynchronously. |
- Example
**Example**
```js
fileio.fdopenStream(fd, mode, function (err, stream) {
// Do something.
......@@ -2166,18 +2169,18 @@ Synchronously opens a stream based on the file descriptor.
**System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ---------------------------------------- |
| 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).|
- Return value
| Name | Description |
**Return value**
| Type | Description |
| ------------------ | --------- |
| [Stream](#stream7) | Stream opened.|
- Example
**Example**
```js
let ss = fileio.fdopenStreamSync(fd, "r+");
```
......@@ -2187,23 +2190,23 @@ Synchronously opens a stream based on the file descriptor.
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
- Parameters
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ------------ |
| fd | number | Yes | File descriptor of the target file.|
| uid | number | Yes | New UID. |
| gid | number | Yes | New GID. |
- Return value
**Return value**
| Type | Description |
| ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise used to return the result. An empty value is returned.|
- Example
**Example**
```js
let stat = fileio.statSync(path);
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
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
- Parameters
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | --------------- |
| 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
| gid | number | Yes | New GID. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file owner is changed asynchronously.|
- Example
**Example**
```js
let stat = fileio.statSync(fpath);
fileio.fchown(fd, stat.uid, stat.gid, function (err){
......@@ -2247,14 +2250,14 @@ Synchronously changes the file owner based on the file descriptor.
**System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ------------ |
| fd | number | Yes | File descriptor of the target file.|
| uid | number | Yes | New UID. |
| gid | number | Yes | New GID. |
- Example
**Example**
```js
let stat = fileio.statSync(fpath);
fileio.fchownSync(fd, stat.uid, stat.gid);
......@@ -2269,19 +2272,19 @@ Asynchronously changes the file owner based on the file path, changes the owner
**System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ----------- |
| path | string | Yes | Absolute path of the target file.|
| uid | number | Yes | New UID. |
| gid | number | Yes | New GID. |
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | -------------------------- |
| path | string | Yes | Application sandbox path of the target file.|
| uid | number | Yes | New UID. |
| gid | number | Yes | New GID. |
- Return value
**Return value**
| Type | Description |
| ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise used to return the result. An empty value is returned.|
- Example
**Example**
```js
let stat = fileio.statSync(path);
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
**System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters
| Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | --------------- |
| path | string | Yes | Absolute path of the target file. |
| uid | number | Yes | New UID. |
| gid | number | Yes | New GID. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file owner is changed asynchronously.|
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ------------------------------ |
| path | string | Yes | Application sandbox path of the target file. |
| uid | number | Yes | New UID. |
| gid | number | Yes | New GID. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file owner is changed asynchronously.|
- Example
**Example**
```js
let stat = fileio.statSync(path);
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
**System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ----------- |
| path | string | Yes | Absolute path of the target file.|
| uid | number | Yes | New UID. |
| gid | number | Yes | New GID. |
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | -------------------------- |
| path | string | Yes | Application sandbox path of the target file.|
| uid | number | Yes | New UID. |
| gid | number | Yes | New GID. |
- Example
**Example**
```js
let stat = fileio.statSync(path);
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
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
- Parameters
| Name | Type | Mandatory | Description |
| -------- | --------------------------------- | ---- | ---------------------------------------- |
| filename | string | Yes | Absolute 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.|
| callback | AsyncCallback&lt;number&nbsp;&gt; | Yes | Called each time a change is detected. |
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------------------- | ---- | ------------------------------------------------------------ |
| 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.|
| callback | AsyncCallback&lt;number&nbsp;&gt; | Yes | Called each time a change is detected. |
- Return value
**Return value**
| Name | Description |
| -------------------- | ---------- |
| [Watcher](#watcher7) | Instance for listening for a file change event.|
- Example
**Example**
```js
fileio.createWatcher(filename, events, function(watcher){
// Do something.
......@@ -2412,12 +2415,12 @@ Checks whether this file is a block special file. A block special file supports
**System capability**: SystemCapability.FileManagement.File.FileIO
- Return value
**Return value**
| Type | Description |
| ------- | ---------------- |
| boolean | Whether the file is a block special file.|
- Example
**Example**
```js
let isBLockDevice = fileio.statSync(path).isBlockDevice();
```
......@@ -2431,12 +2434,12 @@ Checks whether this file is a character special file. A character special file s
**System capability**: SystemCapability.FileManagement.File.FileIO
- Return value
**Return value**
| Type | Description |
| ------- | ----------------- |
| boolean | Whether the file is a character special file.|
- Example
**Example**
```js
let isCharacterDevice = fileio.statSync(path).isCharacterDevice();
```
......@@ -2450,12 +2453,12 @@ Checks whether this file is a directory.
**System capability**: SystemCapability.FileManagement.File.FileIO
- Return value
**Return value**
| Type | Description |
| ------- | ------------- |
| boolean | Whether the file is a directory.|
- Example
**Example**
```js
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
**System capability**: SystemCapability.FileManagement.File.FileIO
- Return value
**Return value**
| Type | Description |
| ------- | --------------------- |
| boolean | Whether the file is an FIFO.|
- Example
**Example**
```js
let isFIFO = fileio.statSync(path).isFIFO();
```
......@@ -2488,12 +2491,12 @@ Checks whether this file is a regular file.
**System capability**: SystemCapability.FileManagement.File.FileIO
- Return value
**Return value**
| Type | Description |
| ------- | --------------- |
| boolean | Whether the file is a regular file.|
- Example
**Example**
```js
let isFile = fileio.statSync(fpath).isFile();
```
......@@ -2507,12 +2510,12 @@ Checks whether this file is a socket.
**System capability**: SystemCapability.FileManagement.File.FileIO
- Return value
**Return value**
| Type | Description |
| ------- | -------------- |
| boolean | Whether the file is a socket.|
- Example
**Example**
```js
let isSocket = fileio.statSync(path).isSocket();
```
......@@ -2526,12 +2529,12 @@ Checks whether this file is a symbolic link.
**System capability**: SystemCapability.FileManagement.File.FileIO
- Return value
**Return value**
| Type | Description |
| ------- | --------------- |
| boolean | Whether the file is a symbolic link.|
- Example
**Example**
```js
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
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
- Example
**Example**
```js
fileio.stop();
```
......@@ -2560,16 +2563,16 @@ Asynchronously stops **watcher**. This method uses a promise to return the resul
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
- Parameters
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | ---------------------- |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when **watcher** is stopped asynchronously.|
- Example
**Example**
```js
fileio.stop(function(err){
// Do something.
......@@ -2587,16 +2590,16 @@ File stream. Before calling a method of the **Stream** class, use the **createSt
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
- Return value
**Return value**
| Type | Description |
| ------------------- | ------------- |
| Promise&lt;void&gt; | Promise used to return the stream close result.|
- Example
**Example**
```js
let ss= fileio.createStreamSync(path);
ss.close().then(function(){
......@@ -2611,16 +2614,16 @@ Asynchronously closes the stream. This method uses a promise to return the resul
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
- Parameters
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | ------------- |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the stream is closed asynchronously.|
- Example
**Example**
```js
let ss= fileio.createStreamSync(path);
ss.close(function (err) {
......@@ -2637,7 +2640,7 @@ Synchronously closes the stream.
**System capability**: SystemCapability.FileManagement.File.FileIO
- Example
**Example**
```js
let ss= fileio.createStreamSync(path);
ss.closeSync();
......@@ -2648,16 +2651,16 @@ Synchronously closes the stream.
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
- Return value
**Return value**
| Type | Description |
| ------------------- | ------------- |
| Promise&lt;void&gt; | Promise used to return the stream flushing result.|
- Example
**Example**
```js
let ss= fileio.createStreamSync(path);
ss.flush().then(function (){
......@@ -2672,16 +2675,16 @@ Asynchronously flushes the stream. This method uses a promise to return the resu
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
- Parameters
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | -------------- |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the stream is asynchronously flushed.|
- Example
**Example**
```js
let ss= fileio.createStreamSync(path);
ss.flush(function (err) {
......@@ -2698,7 +2701,7 @@ Synchronously flushes the stream.
**System capability**: SystemCapability.FileManagement.File.FileIO
- Example
**Example**
```js
let ss= fileio.createStreamSync(path);
ss.flushSync();
......@@ -2714,22 +2717,22 @@ write(buffer: ArrayBuffer | string, options?: {
encoding?: string;
}): 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
- Parameters
**Parameters**
| Name | Type | Mandatory | Description |
| ------- | ------------------------------- | ---- | ---------------------------------------- |
| 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 |
| --------------------- | -------- |
| Promise&lt;number&gt; | Length of the data written in the file.|
- Example
**Example**
```js
let ss= fileio.createStreamSync(fpath, "r+");
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: {
encoding?: string;
}, 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
- Parameters
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------------- | ---- | ------------------------------------------------------------ |
| 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. |
- Example
**Example**
```js
let ss= fileio.createStreamSync(fpath, "r+");
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.
**System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters
**Parameters**
| Name | Type | Mandatory | Description |
| ------- | ------------------------------- | ---- | ---------------------------------------- |
| 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 |
| ------ | -------- |
| number | Length of the data written in the file.|
- Example
**Example**
```js
let ss= fileio.createStreamSync(fpath,"r+");
let num = ss.writeSync("hello, world", {offset: 1, length: 5, position: 5, encoding :'utf-8'});
......@@ -2811,22 +2814,22 @@ read(buffer: ArrayBuffer, options?: {
length?: number;
}): 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
- Parameters
**Parameters**
| Name | Type | Mandatory | Description |
| ------- | ----------- | ---- | ---------------------------------------- |
| 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 |
| ---------------------------------- | ------ |
| Promise&lt;[ReadOut](#readout)&gt; | Data read.|
- Example
**Example**
```js
let ss = fileio.createStreamSync(fpath, "r+");
ss.read(new ArrayBuffer(4096), {offset: 1, length: 5, position: 5}).then(function (readout){
......@@ -2846,18 +2849,18 @@ read(buffer: ArrayBuffer, options: {
length?: number;
}, 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
- Parameters
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| 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. |
- Example
**Example**
```js
let ss = fileio.createStreamSync(fpath, "r+");
ss.read(new ArrayBuffer(4096),{offset: 1, length: 5, position: 5},function (err, readOut) {
......@@ -2881,18 +2884,20 @@ Synchronously reads data from the stream.
**System capability**: SystemCapability.FileManagement.File.FileIO
- Parameters
**Parameters**
| Name | Type | Mandatory | Description |
| ------- | ----------- | ---- | ---------------------------------------- |
| 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 |
| ------ | -------- |
| number | Length of the data read.|
- Example
**Example**
```js
let ss = fileio.createStreamSync(fpath, "r+");
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
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
- Return value
**Return value**
| Type | Description |
| -------------------------------- | ------------- |
| Promise&lt;[Dirent](#dirent)&gt; | Directory entry that is read asynchronously.|
- Example
**Example**
```js
let dir = fileio.opendirSync(path);
dir.read().then(function (dirent){
......@@ -2932,16 +2937,16 @@ Asynchronously reads the next directory entry. This method uses a promise to ret
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
- Parameters
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | -------------------------------------- | ---- | ---------------- |
| callback | AsyncCallback&lt;[Dirent](#dirent)&gt; | Yes | Callback invoked when the next directory entry is asynchronously read.|
- Example
**Example**
```js
let dir = fileio.opendirSync(path);
dir.read(function (err, dirent) {
......@@ -2961,12 +2966,12 @@ Synchronously reads the next directory entry.
**System capability**: SystemCapability.FileManagement.File.FileIO
- Return value
**Return value**
| Type | Description |
| ----------------- | -------- |
| [Dirent](#dirent) | Directory entry read.|
- Example
**Example**
```js
let dir = fileio.opendirSync(path);
let dirent = dir.readSync();
......@@ -2981,7 +2986,7 @@ Closes a directory. After a directory is closed, the file descriptor in Dir will
**System capability**: SystemCapability.FileManagement.File.FileIO
- Example
**Example**
```js
let dir = fileio.opendirSync(path);
dir.closeSync();
......@@ -3009,12 +3014,12 @@ Checks whether the current directory entry is a block special file. A block spec
**System capability**: SystemCapability.FileManagement.File.FileIO
- Return value
**Return value**
| Type | Description |
| ------- | ---------------- |
| boolean | Whether the directory entry is a block special file.|
- Example
**Example**
```js
let dir = fileio.opendirSync(path);
let isBLockDevice = dir.readSync().isBlockDevice();
......@@ -3029,12 +3034,12 @@ Checks whether a directory entry is a character special file. A character specia
**System capability**: SystemCapability.FileManagement.File.FileIO
- Return value
**Return value**
| Type | Description |
| ------- | ----------------- |
| boolean | Whether the directory entry is a character special file.|
- Example
**Example**
```js
let dir = fileio.opendirSync(path);
let isCharacterDevice = dir.readSync().isCharacterDevice();
......@@ -3049,12 +3054,12 @@ Checks whether a directory entry is a directory.
**System capability**: SystemCapability.FileManagement.File.FileIO
- Return value
**Return value**
| Type | Description |
| ------- | ------------- |
| boolean | Whether the directory entry is a directory.|
- Example
**Example**
```js
let dir = fileio.opendirSync(path);
let isDirectory = dir.readSync().isDirectory();
......@@ -3069,12 +3074,12 @@ Checks whether the current directory entry is a named pipe (or FIFO). Named pipe
**System capability**: SystemCapability.FileManagement.File.FileIO
- Return value
**Return value**
| Type | Description |
| ------- | --------------- |
| boolean | Whether the directory entry is a FIFO.|
- Example
**Example**
```js
let dir = fileio.opendirSync(path);
let isFIFO = dir.readSync().isFIFO();
......@@ -3089,12 +3094,12 @@ Checks whether a directory entry is a regular file.
**System capability**: SystemCapability.FileManagement.File.FileIO
- Return value
**Return value**
| Type | Description |
| ------- | --------------- |
| boolean | Whether the directory entry is a regular file.|
- Example
**Example**
```js
let dir = fileio.opendirSync(path);
let isFile = dir.readSync().isFile();
......@@ -3109,12 +3114,12 @@ Checks whether a directory entry is a socket.
**System capability**: SystemCapability.FileManagement.File.FileIO
- Return value
**Return value**
| Type | Description |
| ------- | -------------- |
| boolean | Whether the directory entry is a socket.|
- Example
**Example**
```js
let dir = fileio.opendirSync(dpath);
let isSocket = dir.readSync().isSocket();
......@@ -3129,12 +3134,12 @@ Checks whether a directory entry is a symbolic link.
**System capability**: SystemCapability.FileManagement.File.FileIO
- Return value
**Return value**
| Type | Description |
| ------- | --------------- |
| boolean | Whether the directory entry is a symbolic link.|
- Example
**Example**
```js
let dir = fileio.opendirSync(path);
let isSymbolicLink = dir.readSync().isSymbolicLink();
......
# 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**.
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
```js
......@@ -81,8 +83,8 @@ Obtains information about the second-level album or files in asynchronous mode.
- Parameters
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| path | 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**.|
| path | promise<string>| Yes| URI of the directory to query.|
| 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.|
- Return value
......@@ -128,8 +130,8 @@ Obtains information about the second-level album or files in asynchronous mode.
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ------------------------------------------------------------ |
| path | 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**.|
| path | promise<string> | Yes | URI of the directory to query. |
| 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.|
| callback | AsyncCallback&lt;[FileInfo](#fileinfo)[]&gt; | Yes | Callback invoked to return the file information obtained. |
- Error
......@@ -156,7 +158,7 @@ Obtains information about the second-level album or files in asynchronous mode.
## 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.
......@@ -165,8 +167,8 @@ Creates a file in the specified path in asynchronous mode. This API uses a promi
- Parameters
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| filename | string | Yes| Name of the file to create.|
| path | string | Yes| URI of the file to create.|
| filename | promise<string>| Yes| Name 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.|
- Return value
......@@ -209,8 +211,8 @@ Creates a file in the specified path in asynchronous mode. This API uses a callb
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ----------------------------- |
| filename | string | Yes | Name of the file to create. |
| path | string | Yes | URI of the file to create. |
| filename | promise<string> | Yes | Name 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.|
| 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()**.
| Name| Type| Readable| Writable| Description|
| --- | -- | -- | -- | -- |
| name | string | Yes| No| File name.|
| path | string | Yes| No| URI of the file.|
| type | string | Yes| No| File type.|
| name | promise<string>| Yes| No| File name.|
| path | promise<string>| Yes| No| URI of the file.|
| type | promise<string>| Yes| No| File type.|
| size | number | Yes| No| File size.|
| addedTime | number | Yes| No| Time when the file was scanned to the database.|
| modifiedTime | number | Yes| No| Time when the file was modified.|
......@@ -263,4 +265,4 @@ Defines the device type.
| Name| Type | Readable| Writable| Description |
| ------ | ------ | ---- | ---- | -------- |
| name | string | Yes | Yes | Device name.|
| name | promise<string>| Yes | Yes | Device name.|
# 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.
......@@ -26,12 +26,12 @@ Creates a **MessageParcel** object. This method is a static method.
**System capability**: SystemCapability.Communication.IPC.Core
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| MessageParcel | **MessageParcel** object created.|
- Example
**Example**
```
let data = rpc.MessageParcel.create();
......@@ -47,7 +47,7 @@ Reclaims the **MessageParcel** object that is no longer used.
**System capability**: SystemCapability.Communication.IPC.Core
- Example
**Example**
```
let reply = rpc.MessageParcel.create();
......@@ -63,23 +63,37 @@ writeRemoteObject(object: [IRemoteObject](#iremoteobject)): boolean
**System capability**: SystemCapability.Communication.IPC.Core
- Parameters
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| object | [IRemoteObject](#iremoteobject) | Yes| Remote object to serialize and write to the **MessageParcel** object.|
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| 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 {
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 data = rpc.MessageParcel.create();
let testRemoteObject = new TestRemoteObject("testObject");
......@@ -95,18 +109,32 @@ Reads the remote object from this **MessageParcel** object. You can use this met
**System capability**: SystemCapability.Communication.IPC.Core
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| [IRemoteObject](#iremoteobject) | Remote object obtained.|
- Example
**Example**
```
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 data = rpc.MessageParcel.create();
let testRemoteObject = new TestRemoteObject("testObject");
......@@ -123,17 +151,17 @@ Writes an interface token to this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core
- Parameters
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| token | string | Yes| Interface token to write.|
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example
**Example**
```
let data = rpc.MessageParcel.create();
......@@ -150,12 +178,12 @@ Reads the interface token from this **MessageParcel** object. The interface toke
**System capability**: SystemCapability.Communication.IPC.Core
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| string | Interface token obtained.|
- Example
**Example**
```
class Stub extends rpc.RemoteObject {
......@@ -176,12 +204,12 @@ Obtains the data size of this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| number | Size of the **MessageParcel** object obtained, in bytes.|
- Example
**Example**
```
let data = rpc.MessageParcel.create();
......@@ -198,12 +226,12 @@ Obtains the capacity of this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| number | **MessageParcel** capacity obtained, in bytes.|
- Example
**Example**
```
let data = rpc.MessageParcel.create();
......@@ -220,17 +248,17 @@ Sets the size of data contained in this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core
- Parameters
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| size | number | Yes| Data size to set, in bytes.|
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example
**Example**
```
let data = rpc.MessageParcel.create();
......@@ -247,17 +275,17 @@ Sets the storage capacity of this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core
- Parameters
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| size | number | Yes| Storage capacity to set, in bytes.|
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example
**Example**
```
let data = rpc.MessageParcel.create();
......@@ -274,12 +302,12 @@ Obtains the writable capacity of this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| number | **MessageParcel** writable capacity obtained, in bytes.|
- Example
**Example**
```
class Stub extends rpc.RemoteObject {
......@@ -300,12 +328,12 @@ Obtains the readable capacity of this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| number | **MessageParcel** object readable capacity, in bytes.|
- Example
**Example**
```
class Stub extends rpc.RemoteObject {
......@@ -326,12 +354,12 @@ Obtains the read position of this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| number | Current read position of the **MessageParcel** object.|
- Example
**Example**
```
let data = rpc.MessageParcel.create();
......@@ -348,12 +376,12 @@ Obtains the write position of this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| number | Current write position of the **MessageParcel** object.|
- Example
**Example**
```
let data = rpc.MessageParcel.create();
......@@ -371,17 +399,17 @@ Moves the read pointer to the specified position.
**System capability**: SystemCapability.Communication.IPC.Core
- Parameters
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| pos | number | Yes| Position from which data is to read.|
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the read position changes; returns **false** otherwise.|
- Example
**Example**
```
let data = rpc.MessageParcel.create();
......@@ -403,17 +431,17 @@ Moves the write pointer to the specified position.
**System capability**: SystemCapability.Communication.IPC.Core
- Parameters
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| pos | number | Yes| Position from which data is to write.|
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the write position changes; returns **false** otherwise.|
- Example
**Example**
```
let data = rpc.MessageParcel.create();
......@@ -433,17 +461,17 @@ Writes a Byte value to this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core
- Parameters
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| val | number | Yes| Byte value to write.|
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example
**Example**
```
let data = rpc.MessageParcel.create();
......@@ -460,12 +488,12 @@ Reads the Byte value from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| number | Byte value read.|
- Example
**Example**
```
let data = rpc.MessageParcel.create();
......@@ -484,17 +512,17 @@ Writes a Short int value to this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core
- Parameters
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| val | number | Yes| Short int value to write.|
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example
**Example**
```
let data = rpc.MessageParcel.create();
......@@ -511,12 +539,12 @@ Reads the Short int value from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| number | Short int value read.|
- Example
**Example**
```
let data = rpc.MessageParcel.create();
......@@ -535,17 +563,17 @@ Writes an Int value to this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core
- Parameters
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| val | number | Yes| Int value to write.|
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example
**Example**
```
let data = rpc.MessageParcel.create();
......@@ -562,12 +590,12 @@ Reads the Int value from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| number | Int value read.|
- Example
**Example**
```
let data = rpc.MessageParcel.create();
......@@ -586,17 +614,17 @@ Writes a Long int value to this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core
- Parameters
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| val | number | Yes| Long int value to write.|
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example
**Example**
```
let data = rpc.MessageParcel.create();
......@@ -613,18 +641,18 @@ Reads the Long int value from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| number | Long int value read.|
- Example
**Example**
```
let data = rpc.MessageParcel.create();
let result = data.writeLong(10000);
console.log("RpcClient: writeLong is " + result);
let ret = data.readlong();
let ret = data.readLong();
console.log("RpcClient: readLong is " + ret);
```
......@@ -637,17 +665,17 @@ Writes a Float value to this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core
- Parameters
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| val | number | Yes| Float value to write.|
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example
**Example**
```
let data = rpc.MessageParcel.create();
......@@ -664,12 +692,12 @@ Reads the Float value from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| number | Float value read.|
- Example
**Example**
```
let data = rpc.MessageParcel.create();
......@@ -688,17 +716,17 @@ Writes a Double value to this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core
- Parameters
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| val | number | Yes| Double value to write.|
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example
**Example**
```
let data = rpc.MessageParcel.create();
......@@ -715,12 +743,12 @@ Reads the Double value from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| number | Double value read.|
- Example
**Example**
```
let data = rpc.MessageParcel.create();
......@@ -739,17 +767,17 @@ Writes a Boolean value to this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core
- Parameters
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| val | boolean | Yes| Boolean value to write.|
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example
**Example**
```
let data = rpc.MessageParcel.create();
......@@ -766,12 +794,12 @@ Reads the Boolean value from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Boolean value read.|
- Example
**Example**
```
let data = rpc.MessageParcel.create();
......@@ -790,21 +818,21 @@ Writes a Char value to this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core
- Parameters
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| val | number | Yes| Char value to write.|
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example
**Example**
```
let data = rpc.MessageParcel.create();
let result = data.writeChar('a');
let result = data.writeChar(97);
console.log("RpcClient: writeChar is " + result);
```
......@@ -817,16 +845,16 @@ Reads the Char value from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| number | Char value read.|
- Example
**Example**
```
let data = rpc.MessageParcel.create();
let result = data.writeChar('a');
let result = data.writeChar(97);
console.log("RpcClient: writeChar is " + result);
let ret = data.readChar();
console.log("RpcClient: readChar is " + ret);
......@@ -841,17 +869,17 @@ Writes a String value to this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core
- Parameters
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| val | string | Yes| String value to write.|
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example
**Example**
```
let data = rpc.MessageParcel.create();
......@@ -868,12 +896,12 @@ Reads the String value from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| string | String value read.|
- Example
**Example**
```
let data = rpc.MessageParcel.create();
......@@ -892,23 +920,25 @@ Writes a sequenceable object to this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core
- Parameters
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| val | [Sequenceable](#sequenceable) | Yes| Sequenceable object to write.|
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example
**Example**
```
class MySequenceable {
constructor(num, string) {
num: number;
str: string;
constructor(num, str) {
this.num = num;
this.str = string;
this.str = str;
}
marshalling(messageParcel) {
messageParcel.writeInt(this.num);
......@@ -936,23 +966,25 @@ Reads member variables from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core
- Parameters
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| dataIn | [Sequenceable](#sequenceable) | Yes| Object that reads member variables from the **MessageParcel** object.|
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example
**Example**
```
class MySequenceable {
constructor(num, string) {
num: number;
str: string;
constructor(num, str) {
this.num = num;
this.str = string;
this.str = str;
}
marshalling(messageParcel) {
messageParcel.writeInt(this.num);
......@@ -983,21 +1015,21 @@ Writes a ByteArray to this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core
- Parameters
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| byteArray | number[] | Yes| ByteArray to write.|
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example
**Example**
```
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);
console.log("RpcClient: writeByteArray is " + result);
```
......@@ -1011,16 +1043,16 @@ Reads the ByteArray from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core
- Parameters
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| dataIn | number[] | Yes| ByteArray to read.|
- Example
**Example**
```
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);
console.log("RpcClient: writeByteArray is " + result);
let array = new Array(5);
......@@ -1036,16 +1068,16 @@ Reads the ByteArray from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| number[] | ByteArray read.|
- Example
**Example**
```
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);
console.log("RpcClient: writeByteArray is " + result);
let array = data.readByteArray();
......@@ -1061,17 +1093,17 @@ Writes a ShortArray to this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core
- Parameters
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| shortArray | number[] | Yes| ShortArray to write.|
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example
**Example**
```
let data = rpc.MessageParcel.create();
......@@ -1088,12 +1120,12 @@ Reads a ShortArray from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core
- Parameters
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| dataIn | number[] | Yes| ShortArray to read.|
- Example
**Example**
```
let data = rpc.MessageParcel.create();
......@@ -1112,12 +1144,12 @@ Reads the ShortArray from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| number[] | ShortArray read.|
- Example
**Example**
```
let data = rpc.MessageParcel.create();
......@@ -1136,17 +1168,17 @@ Writes an IntArray to this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core
- Parameters
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| intArray | number[] | Yes| IntArray to write.|
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example
**Example**
```
let data = rpc.MessageParcel.create();
......@@ -1163,12 +1195,12 @@ Reads an IntArray from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core
- Parameters
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| dataIn | number[] | Yes| IntArray to read.|
- Example
**Example**
```
let data = rpc.MessageParcel.create();
......@@ -1187,12 +1219,12 @@ Reads the IntArray from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| number[] | IntArray read.|
- Example
**Example**
```
let data = rpc.MessageParcel.create();
......@@ -1211,17 +1243,17 @@ Writes a LongArray to this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core
- Parameters
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| longArray | number[] | Yes| LongArray to write.|
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example
**Example**
```
let data = rpc.MessageParcel.create();
......@@ -1238,12 +1270,12 @@ Reads a LongArray from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core
- Parameters
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| dataIn | number[] | Yes| LongArray to read.|
- Example
**Example**
```
let data = rpc.MessageParcel.create();
......@@ -1262,12 +1294,12 @@ Reads the LongArray from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| number[] | LongArray read.|
- Example
**Example**
```
let data = rpc.MessageParcel.create();
......@@ -1286,17 +1318,17 @@ Writes a FloatArray to this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core
- Parameters
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| floatArray | number[] | Yes| FloatArray to write.|
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example
**Example**
```
let data = rpc.MessageParcel.create();
......@@ -1313,13 +1345,13 @@ Reads a FloatArray from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core
- Parameters
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| dataIn | number[] | Yes| FloatArray to read.|
- Example
**Example**
```
let data = rpc.MessageParcel.create();
......@@ -1338,12 +1370,12 @@ Reads the FloatArray from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| number[] | FloatArray read.|
- Example
**Example**
```
let data = rpc.MessageParcel.create();
......@@ -1362,17 +1394,17 @@ Writes a DoubleArray to this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core
- Parameters
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| doubleArray | number[] | Yes| DoubleArray to write.|
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example
**Example**
```
let data = rpc.MessageParcel.create();
......@@ -1389,12 +1421,12 @@ Reads a DoubleArray from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core
- Parameters
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| dataIn | number[] | Yes| DoubleArray to read.|
- Example
**Example**
```
let data = rpc.MessageParcel.create();
......@@ -1413,12 +1445,12 @@ Reads the DoubleArray from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| number[] | DoubleArray read.|
- Example
**Example**
```
let data = rpc.MessageParcel.create();
......@@ -1437,17 +1469,17 @@ Writes a BooleanArray to this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core
- Parameters
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| booleanArray | boolean[] | Yes| BooleanArray to write.|
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example
**Example**
```
let data = rpc.MessageParcel.create();
......@@ -1464,12 +1496,12 @@ Reads a BooleanArray from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core
- Parameters
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| dataIn | boolean[] | Yes| BooleanArray to read.|
- Example
**Example**
```
let data = rpc.MessageParcel.create();
......@@ -1488,7 +1520,7 @@ Reads the BooleanArray from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| boolean[] | BooleanArray read.|
......@@ -1511,21 +1543,21 @@ Writes a CharArray to this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core
- Parameters
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| charArray | number[] | Yes| CharArray to write.|
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example
**Example**
```
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);
```
......@@ -1538,16 +1570,16 @@ Reads a CharArray from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core
- Parameters
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| dataIn | number[] | Yes| CharArray to read.|
- Example
**Example**
```
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);
let array = new Array(3);
data.readCharArray(array);
......@@ -1562,16 +1594,16 @@ Reads the CharArray from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| number[] | CharArray read.|
- Example
**Example**
```
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);
let array = data.readCharArray();
console.log("RpcClient: readCharArray is " + array);
......@@ -1586,17 +1618,17 @@ Writes a StringArray to this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core
- Parameters
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| stringArray | string[] | Yes| StringArray to write.|
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example
**Example**
```
let data = rpc.MessageParcel.create();
......@@ -1613,12 +1645,12 @@ Reads a StringArray from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core
- Parameters
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| dataIn | string[] | Yes| StringArray to read.|
- Example
**Example**
```
let data = rpc.MessageParcel.create();
......@@ -1637,12 +1669,12 @@ Reads the StringArray from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| string[] | StringArray read.|
- Example
**Example**
```
let data = rpc.MessageParcel.create();
......@@ -1661,13 +1693,27 @@ Writes information to this **MessageParcel** object indicating that no exception
**System capability**: SystemCapability.Communication.IPC.Core
- Example
**Example**
```
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;
}
onRemoteRequest(code, data, reply, option) {
if (code === 1) {
console.log("RpcServer: onRemoteRequest called");
......@@ -1690,7 +1736,7 @@ Reads the exception information from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core
- Example
**Example**
```
import FA from "@ohos.ability.featureAbility";
......@@ -1745,23 +1791,25 @@ Writes a SequenceableArray to this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core
- Parameters
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| sequenceableArray | Sequenceable[] | Yes| SequenceableArray to write.|
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example
**Example**
```
class MySequenceable {
constructor(num, string) {
num: number;
str: string;
constructor(num, str) {
this.num = num;
this.str = string;
this.str = str;
}
marshalling(messageParcel) {
messageParcel.writeInt(this.num);
......@@ -1792,18 +1840,20 @@ Reads a SequenceableArray from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core
- Parameters
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| sequenceableArray | Sequenceable[] | Yes| SequenceableArray to read.|
- Example
**Example**
```
class MySequenceable {
constructor(num, string) {
num: number;
str: string;
constructor(num, str) {
this.num = num;
this.str = string;
this.str = str;
}
marshalling(messageParcel) {
messageParcel.writeInt(this.num);
......@@ -1836,24 +1886,41 @@ Writes an array of **IRemoteObject** objects to this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core
- Parameters
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| objectArray | IRemoteObject[] | Yes| Array of **IRemoteObject** objects to write.|
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| 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 {
constructor(descriptor) {
super(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 data = rpc.MessageParcel.create();
......@@ -1870,19 +1937,36 @@ Reads an **IRemoteObject** array from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core
- Parameters
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| objects | IRemoteObject[] | Yes| **IRemoteObject** array to read.|
- Example
**Example**
```
class MyDeathRecipient {
onRemoteDied() {
console.log("server is died");
}
}
class TestRemoteObject extends rpc.RemoteObject {
constructor(descriptor) {
super(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 data = rpc.MessageParcel.create();
......@@ -1900,19 +1984,36 @@ Reads the **IRemoteObject** array from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| IRemoteObject[] | **IRemoteObject** object array obtained.|
- Example
**Example**
```
class MyDeathRecipient {
onRemoteDied() {
console.log("server is died");
}
}
class TestRemoteObject extends rpc.RemoteObject {
constructor(descriptor) {
super(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 data = rpc.MessageParcel.create();
......@@ -1931,12 +2032,12 @@ Closes a file descriptor.
**System capability**: SystemCapability.Communication.IPC.Core
- Parameters
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| fd | number | Yes| File descriptor to close.|
- Example
**Example**
```
import fileio from '@ohos.fileio';
......@@ -1954,17 +2055,17 @@ Duplicates a file descriptor.
**System capability**: SystemCapability.Communication.IPC.Core
- Parameters
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| fd | number | Yes| File descriptor to duplicate.|
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| number | New file descriptor.|
- Example
**Example**
```
import fileio from '@ohos.fileio';
......@@ -1982,12 +2083,12 @@ Checks whether this **MessageParcel** object contains a file descriptor.
**System capability**: SystemCapability.Communication.IPC.Core
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the **MessageParcel** object contains a file descriptor; returns **false** otherwise.|
- Example
**Example**
```
import fileio from '@ohos.fileio';
......@@ -2010,17 +2111,17 @@ Writes a file descriptor to this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core
- Parameters
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| fd | number | Yes| File descriptor to write.|
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example
**Example**
```
import fileio from '@ohos.fileio';
......@@ -2040,12 +2141,12 @@ Reads the file descriptor from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| number | File descriptor read.|
- Example
**Example**
```
import fileio from '@ohos.fileio';
......@@ -2066,17 +2167,17 @@ Writes an anonymous shared object to this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core
- Parameters
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| ashmem | Ashmem | Yes| Anonymous shared object to write.|
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example
**Example**
```
let parcel = new rpc.MessageParcel();
......@@ -2094,12 +2195,12 @@ Reads the anonymous shared object from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| Ashmem | Anonymous share object obtained.|
- Example
**Example**
```
let parcel = new rpc.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
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| 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();
......@@ -2141,22 +2242,22 @@ Writes raw data to this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core
- Parameters
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| rawData | number[] | Yes| Raw data to write.|
| size | number | Yes| Size of the raw data, in bytes.|
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example
**Example**
```
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);
console.log("RpcTest: parcel write raw data result is : " + isWriteSuccess);
```
......@@ -2170,21 +2271,21 @@ Reads raw data from this **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core
- Parameters
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| size | number | Yes| Size of the raw data to read.|
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| number[] | Raw data obtained, in bytes.|
- Example
**Example**
```
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);
console.log("RpcTest: parcel write raw data result is : " + isWriteSuccess);
let result = parcel.readRawData(5);
......@@ -2204,23 +2305,25 @@ Marshals the sequenceable object into a **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core
- Parameters
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| dataOut | [MessageParcel](#messageparcel) | Yes| **MessageParcel** object to which the sequenceable object is to be marshaled.|
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example
**Example**
```
class MySequenceable {
constructor(num, string) {
num: number;
str: string;
constructor(num, str) {
this.num = num;
this.str = string;
this.str = str;
}
marshalling(messageParcel) {
messageParcel.writeInt(this.num);
......@@ -2251,23 +2354,25 @@ Unmarshals this sequenceable object from a **MessageParcel** object.
**System capability**: SystemCapability.Communication.IPC.Core
- Parameters
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| dataIn | [MessageParcel](#messageparcel) | Yes| **MessageParcel** object in which the sequenceable object is to be unmarshaled.|
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example
**Example**
```
class MySequenceable {
constructor(num, string) {
num: number;
str: string;
constructor(num, str) {
this.num = num;
this.str = string;
this.str = str;
}
marshalling(messageParcel) {
messageParcel.writeInt(this.num);
......@@ -2303,12 +2408,12 @@ Obtains a proxy or remote object. This method must be implemented by its derived
**System capability**: SystemCapability.Communication.IPC.Core
- Return value
**Return value**
| 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.|
- Example
**Example**
```
class TestAbility extends rpc.RemoteObject {
......@@ -2318,10 +2423,11 @@ Obtains a proxy or remote object. This method must be implemented by its derived
}
```
- Example
**Example**
```
class TestProxy {
remote: rpc.RemoteObject;
constructor(remote) {
this.remote = remote;
}
......@@ -2345,7 +2451,7 @@ Called to perform subsequent operations when a death notification of the remote
**System capability**: SystemCapability.Communication.IPC.Core
- Example
**Example**
```
class MyDeathRecipient {
......@@ -2383,28 +2489,29 @@ Obtains the interface.
**System capability**: SystemCapability.Communication.IPC.Core
- Parameters
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| descriptor | string | Yes| Interface descriptor.|
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| 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.
**System capability**: SystemCapability.Communication.IPC.Core
- Parameters
**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.|
......@@ -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.|
| options | [MessageOption](#messageoption) | Yes| Request sending mode, which can be synchronous (default) or asynchronous.|
- Return value
**Return value**
| 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(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
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
- Parameters
**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.|
......@@ -2444,13 +2572,13 @@ Adds a callback for receiving death notifications of the remote object. This met
**System capability**: SystemCapability.Communication.IPC.Core
- Parameters
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| recipient | [DeathRecipient](#deathrecipient) | Yes| Callback to add.|
| flags | number | Yes| Flag of the death notification.|
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| 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.
**System capability**: SystemCapability.Communication.IPC.Core
- Parameters
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| recipient | [DeathRecipient](#deathrecipient) | Yes| Callback to remove.|
| flags | number | Yes| Flag of the death notification.|
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| 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
**System capability**: SystemCapability.Communication.IPC.Core
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| string | Interface descriptor obtained.|
......@@ -2498,7 +2626,7 @@ Checks whether this object is dead.
**System capability**: SystemCapability.Communication.IPC.Core
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the object is dead; returns **false** otherwise.|
......@@ -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.
**System capability**: SystemCapability.Communication.IPC.Core
- Parameters
**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.|
......@@ -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.|
| options | [MessageOption](#messageoption) | Yes| Request sending mode, which can be synchronous (default) or asynchronous.|
- Return value
**Return value**
| 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";
......@@ -2572,25 +2701,41 @@ Sends a **MessageParcel** message to the remote process in synchronous or asynch
let reply = rpc.MessageParcel.create();
data.writeInt(1);
data.writeString("hello");
proxy.sendRequest(1, data, reply, option)
.then(function(errCode) {
if (errCode === 0) {
console.log("sendRequest got result");
let msg = reply.readString();
console.log("RPCTest: reply msg: " + msg);
} else {
console.log("RPCTest: sendRequest failed, errCode: " + errCode);
}
}).catch(function(e) {
console.log("RPCTest: sendRequest got exception: " + e.message);
}).finally (() => {
console.log("RPCTest: sendRequest ends, reclaim parcel");
data.reclaim();
reply.reclaim();
});
let ret: boolean = proxy.sendRequest(1, data, reply, option);
if (ret) {
console.log("sendRequest got result");
let msg = reply.readString();
console.log("RPCTest: reply msg: " + msg);
} else {
console.log("RPCTest: sendRequest failed");
}
console.log("RPCTest: sendRequest ends, reclaim parcel");
data.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";
......@@ -2645,7 +2790,7 @@ Sends a **MessageParcel** message to the remote process in synchronous or asynch
**System capability**: SystemCapability.Communication.IPC.Core
- Parameters
**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.|
......@@ -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.|
| callback | AsyncCallback&lt;SendRequestResult&gt; | Yes| Callback for receiving the sending result.|
- Example
**Example**
```
import FA from "@ohos.ability.featureAbility";
......@@ -2706,17 +2851,17 @@ Obtains the **LocalInterface** object of an interface descriptor.
**System capability**: SystemCapability.Communication.IPC.Core
- Parameters
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| interface | string | Yes| Interface descriptor.|
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| IRemoteBroker | Returns **Null** by default, which indicates a proxy interface.|
- Example
**Example**
```
import FA from "@ohos.ability.featureAbility";
......@@ -2751,18 +2896,18 @@ Adds a callback for receiving the death notifications of the remote object, incl
**System capability**: SystemCapability.Communication.IPC.Core
- Parameters
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| recipient | [DeathRecipient](#deathrecipient) | Yes| Callback to add.|
| flags | number | Yes| Flag of the death notification. This parameter is reserved. It is set to **0**.|
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the callback is added successfully; returns **false** otherwise.|
- Example
**Example**
```
import FA from "@ohos.ability.featureAbility";
......@@ -2802,18 +2947,18 @@ Removes the callback used to receive death notifications of the remote object.
**System capability**: SystemCapability.Communication.IPC.Core
- Parameters
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| recipient | [DeathRecipient](#deathrecipient) | Yes| Callback to remove.|
| flags | number | Yes| Flag of the death notification. This parameter is reserved. It is set to **0**.|
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the callback is removed successfully; returns **false** otherwise.|
- Example
**Example**
```
import FA from "@ohos.ability.featureAbility";
......@@ -2854,12 +2999,12 @@ Obtains the interface descriptor of this proxy object.
**System capability**: SystemCapability.Communication.IPC.Core
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| string | Interface descriptor obtained.|
- Example
**Example**
```
import FA from "@ohos.ability.featureAbility";
......@@ -2894,12 +3039,12 @@ Checks whether the **RemoteObject** is dead.
**System capability**: SystemCapability.Communication.IPC.Core
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the **RemoteObject** is dead; returns **false** otherwise.|
- Example
**Example**
```
import FA from "@ohos.ability.featureAbility";
......@@ -2948,7 +3093,7 @@ A constructor used to create a **MessageOption** object.
**System capability**: SystemCapability.Communication.IPC.Core
- Parameters
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| 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.
**System capability**: SystemCapability.Communication.IPC.Core
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| number | Call mode obtained.|
......@@ -2977,7 +3122,7 @@ Sets the call flag, which can be synchronous or asynchronous.
**System capability**: SystemCapability.Communication.IPC.Core
- Parameters
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| flags | number | Yes| Call flag to set.|
......@@ -2991,7 +3136,7 @@ Obtains the maximum wait time for this RPC call.
**System capability**: SystemCapability.Communication.IPC.Core
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| number | Maximum wait time obtained.|
......@@ -3005,7 +3150,7 @@ Sets the maximum wait time for this RPC call.
**System capability**: SystemCapability.Communication.IPC.Core
- Parameters
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| waitTime | number | Yes| Maximum wait time to set.|
......@@ -3024,12 +3169,12 @@ Obtains the system capability manager.
**System capability**: SystemCapability.Communication.IPC.Core
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| [IRemoteObject](#iremoteobject) | System capability manager obtained.|
- Example
**Example**
```
let samgr = rpc.IPCSkeleton.getContextObject();
......@@ -3045,12 +3190,12 @@ Obtains the PID of the caller. This method is invoked by the **RemoteObject** ob
**System capability**: SystemCapability.Communication.IPC.Core
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| number | PID of the caller.|
- Example
**Example**
```
class Stub extends rpc.RemoteObject {
......@@ -3071,12 +3216,12 @@ Obtains the UID of the caller. This method is invoked by the **RemoteObject** ob
**System capability**: SystemCapability.Communication.IPC.Core
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| number | UID of the caller.|
- Example
**Example**
```
class Stub extends rpc.RemoteObject {
......@@ -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;
......@@ -3096,13 +3241,13 @@ Obtains the caller's token ID, which is used to verify the caller identity.
**System capability**: SystemCapability.Communication.IPC.Core
Return value
* Return value
| Type | Description |
| ------ | --------------------- |
| number | Token ID of the caller obtained.|
Example
* Example
```
class Stub extends rpc.RemoteObject {
......@@ -3115,7 +3260,7 @@ Example
```
### getCalligDeviceID
### getCallingDeviceID
static getCallingDeviceID(): string
......@@ -3123,17 +3268,17 @@ Obtains the ID of the device hosting the caller's process.
**System capability**: SystemCapability.Communication.IPC.Core
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| string | Device ID obtained.|
- Example
**Example**
```
class Stub extends rpc.RemoteObject {
onRemoteRequest(code, data, reply, option) {
let callerDeviceID = rpc.IPCSkeleton.getCalligDeviceID();
let callerDeviceID = rpc.IPCSkeleton.getCallingDeviceID();
console.log("RpcServer: callerDeviceID is: " + callerDeviceID);
return true;
}
......@@ -3149,12 +3294,12 @@ Obtains the local device ID.
**System capability**: SystemCapability.Communication.IPC.Core
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| string | Local device ID obtained.|
- Example
**Example**
```
class Stub extends rpc.RemoteObject {
......@@ -3175,12 +3320,12 @@ Checks whether the remote process is a process of the local device.
**System capability**: SystemCapability.Communication.IPC.Core
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the local and remote processes are on the same device; returns **false** otherwise.|
- Example
**Example**
```
class Stub extends rpc.RemoteObject {
......@@ -3201,21 +3346,40 @@ Flushes all suspended commands from the specified **RemoteProxy** to the corresp
**System capability**: SystemCapability.Communication.IPC.Core
- Parameters
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| object | [IRemoteObject](#iremoteobject) | Yes| **RemoteProxy** specified. |
- Return value
**Return value**
| 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.|
- 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);
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.
**System capability**: SystemCapability.Communication.IPC.Core
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| string | String containing the UID and PID of the remote user.|
- Example
**Example**
```
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
**System capability**: SystemCapability.Communication.IPC.Core
- Parameters
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| identity | string | Yes| String containing the remote user UID and PID, which are returned by **resetCallingIdentity**.|
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example
**Example**
```
class Stub extends rpc.RemoteObject {
......@@ -3297,23 +3461,24 @@ A constructor used to create a **RemoteObject** object.
**System capability**: SystemCapability.Communication.IPC.Core
- Parameters
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| 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.
**System capability**: SystemCapability.Communication.IPC.Core
- Parameters
**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.|
......@@ -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.|
| options | [MessageOption](#messageoption) | Yes| Request sending mode, which can be synchronous (default) or asynchronous.|
- Return value
**Return value**
| 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 {
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 testRemoteObject = new TestRemoteObject("testObject");
let option = new rpc.MessageOption();
......@@ -3341,32 +3520,63 @@ Sends a **MessageParcel** message to the remote process in synchronous or asynch
let reply = rpc.MessageParcel.create();
data.writeInt(1);
data.writeString("hello");
testRemoteObject.sendRequest(1, data, reply, option)
.then(function(errCode) {
if (errCode === 0) {
console.log("sendRequest got result");
let msg = reply.readString();
console.log("RPCTest: reply msg: " + msg);
} else {
console.log("RPCTest: sendRequest failed, errCode: " + errCode);
}
}).catch(function(e) {
console.log("RPCTest: sendRequest got exception: " + e.message);
}).finally (() => {
console.log("RPCTest: sendRequest ends, reclaim parcel");
data.reclaim();
reply.reclaim();
});
let ret: boolean = testRemoteObject.sendRequest(1, data, reply, option);
if (ret) {
console.log("sendRequest got result");
let msg = reply.readString();
console.log("RPCTest: reply msg: " + msg);
} else {
console.log("RPCTest: sendRequest failed");
}
console.log("RPCTest: sendRequest ends, reclaim parcel");
data.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 {
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 testRemoteObject = new TestRemoteObject("testObject");
let option = new rpc.MessageOption();
......@@ -3402,7 +3612,7 @@ Sends a **MessageParcel** message to the remote process in synchronous or asynch
**System capability**: SystemCapability.Communication.IPC.Core
- Parameters
**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.|
......@@ -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.|
- Example
**Example**
```
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;
}
}
function sendRequestCallback(result) {
if (result.errCode === 0) {
......@@ -3451,7 +3675,7 @@ Provides a response to **sendRequest()**. The server processes the request and r
**System capability**: SystemCapability.Communication.IPC.Core
- Parameters
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| 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
| reply | [MessageParcel](#messageparcel) | Yes| **MessageParcel** object carrying the result.|
| option | [MessageOption](#messageoption) | Yes| Whether the operation is synchronous or asynchronous.|
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| 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 {
constructor(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) {
if (code === 1) {
......@@ -3494,19 +3732,33 @@ Obtains the UID of the remote process.
**System capability**: SystemCapability.Communication.IPC.Core
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| number | UID of the remote process obtained.|
- Example
**Example**
```
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 testRemoteObject = new TestRemoteObject("testObject");
console.log("RpcServer: getCallingUid: " + testRemoteObject.getCallingUid());
......@@ -3521,19 +3773,33 @@ Obtains the PID of the remote process.
**System capability**: SystemCapability.Communication.IPC.Core
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| number | PID of the remote process obtained.|
- Example
**Example**
```
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 testRemoteObject = new TestRemoteObject("testObject");
console.log("RpcServer: getCallingPid: " + testRemoteObject.getCallingPid());
......@@ -3548,24 +3814,38 @@ Checks whether the remote object corresponding to the specified interface descri
**System capability**: SystemCapability.Communication.IPC.Core
- Parameters
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| descriptor | string | Yes| Interface descriptor.|
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| 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 {
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 testRemoteObject = new TestRemoteObject("testObject");
let broker = testRemoteObject.queryLocalInterface("testObject");
......@@ -3580,19 +3860,33 @@ Obtains the interface descriptor.
**System capability**: SystemCapability.Communication.IPC.Core
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| string | Interface descriptor obtained.|
- Example
**Example**
```
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 testRemoteObject = new TestRemoteObject("testObject");
let descriptor = testRemoteObject.getInterfaceDescriptor();
......@@ -3608,21 +3902,38 @@ Binds an interface descriptor to an **IRemoteBroker** object.
**System capability**: SystemCapability.Communication.IPC.Core
- Parameters
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| localInterface | IRemoteBroker | Yes| **IRemoteBroker** object.|
| descriptor | string | Yes| Interface descriptor.|
- Example
**Example**
```
class MyDeathRecipient {
onRemoteDied() {
console.log("server is died");
}
}
class TestRemoteObject extends rpc.RemoteObject {
constructor(descriptor) {
super(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");
```
......@@ -3652,19 +3963,19 @@ Creates an **Ashmem** object with the specified name and size.
**System capability**: SystemCapability.Communication.IPC.Core
- Parameters
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| name | string | Yes| Name of the **Ashmem** object to create.|
| size | number | Yes| Size (in bytes) of the **Ashmem** object to create.|
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| Ashmem | Returns the **Ashmem** object if it is created successfully; returns null otherwise.|
- Example
**Example**
```
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
**System capability**: SystemCapability.Communication.IPC.Core
- Parameters
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| ashmem | Ashmem | Yes| Existing **Ashmem** object.|
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| Ashmem | **Ashmem** object created.|
- Example
**Example**
```
let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024*1024);
......@@ -3710,7 +4021,7 @@ Closes this **Ashmem** object.
**System capability**: SystemCapability.Communication.IPC.Core
- Example
**Example**
```
let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024*1024);
......@@ -3726,7 +4037,7 @@ Deletes the mappings for the specified address range of this **Ashmem** object.
**System capability**: SystemCapability.Communication.IPC.Core
- Example
**Example**
```
let ashmem = rpc.Ashmem.createAshmem("ashmem", 1024*1024);
......@@ -3742,12 +4053,12 @@ Obtains the memory size of this **Ashmem** object.
**System capability**: SystemCapability.Communication.IPC.Core
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| number | **Ashmem** size obtained.|
- Example
**Example**
```
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
**System capability**: SystemCapability.Communication.IPC.Core
- Parameters
| Name| Type| Mandatory| Description|
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| mapType | number | Yes| Protection level of the memory region to which the shared file is mapped.|
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example
**Example**
```
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);
```
......@@ -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
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example
**Example**
```
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.
**System capability**: SystemCapability.Communication.IPC.Core
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example
**Example**
```
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
**System capability**: SystemCapability.Communication.IPC.Core
- Parameters
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| protectionType | number | Yes| Protection type to set.|
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
- Example
**Example**
```
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);
```
......@@ -3862,23 +4173,23 @@ Writes data to the shared file associated with this **Ashmem** object.
**System capability**: SystemCapability.Communication.IPC.Core
- Parameters
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| buf | number[] | Yes| 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.|
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** is the data is written successfully; returns **false** otherwise.|
- Example
**Example**
```
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);
console.log("RpcTest: write to Ashmem result is : " + writeResult);
```
......@@ -3892,23 +4203,23 @@ Reads data from the shared file associated with this **Ashmem** object.
**System capability**: SystemCapability.Communication.IPC.Core
- Parameters
| Name| Type| Mandatory| Description|
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| 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.|
- Return value
**Return value**
| Type| Description|
| -------- | -------- |
| number[] | Data read.|
- Example
**Example**
```
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);
console.log("RpcTest: write to Ashmem result is : " + writeResult);
let readResult = ashmem.readFromAshmem(5, 0);
......
# 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.
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
```js
......@@ -11,11 +13,11 @@ import statfs from '@ohos.statfs';
## 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
let path = dir + "xxx.txt";
......@@ -25,7 +27,7 @@ let path = dir + "xxx.txt";
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
......@@ -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
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
......@@ -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;
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
......@@ -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
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
......
# 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.
> - 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
......@@ -130,7 +133,7 @@ Asynchronously obtains the available space of the specified volume. This API use
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
......@@ -138,13 +141,13 @@ Asynchronously obtains app information. This API uses a promise to return the re
| Name | Type | Mandatory| Description |
| ----------- | ------ | ---- | -------- |
| packageName | string | Yes | Bundle name of the app.|
| packageName | string | Yes | Bundle name of the application.|
- Return value
| 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
......@@ -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
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
......@@ -169,8 +172,8 @@ Asynchronously obtains app information. This API uses a callback to return the r
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------------------------- | ---- | ------------------------------------ |
| packageName | string | Yes | Bundle name of the app.|
| callback | callback:AsyncCallback&lt;[Bundlestats](#bundlestats)&gt; | Yes | Callback invoked to return the app information.|
| packageName | string | Yes | Bundle name of the application.|
| callback | callback:AsyncCallback&lt;[Bundlestats](#bundlestats)&gt; | Yes | Callback used to return the application information obtained.|
- Example
......@@ -186,10 +189,10 @@ Asynchronously obtains app information. This API uses a callback to return the r
**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
### Attributes
### Attribute
| Name | Type | Description |
| --------- | ------ | -------------- |
| appSize<sup>9+</sup> | number | Size of the app. |
| cacheSize<sup>9+</sup> | number | Cache size of the app. |
| dataSize<sup>9+</sup> | number | Total data size of the app.|
| appSize<sup>9+</sup> | number | Size of the application. |
| cacheSize<sup>9+</sup> | number | Cache size of the application. |
| 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.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| 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.|
| 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.|
......
# 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.
> - 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
......@@ -15,7 +18,7 @@ import volumemanager from "@ohos.volumeManager";
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
......@@ -37,7 +40,7 @@ Asynchronously obtains information about all available volumes. This method uses
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
......@@ -61,7 +64,7 @@ Asynchronously obtains information about all available volumes. This method uses
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
......@@ -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
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
......@@ -114,7 +117,7 @@ Asynchronously obtains the available space of the specified volume. This method
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
......@@ -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
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
......
# 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.
......@@ -26,7 +26,7 @@ The table below lists only the API used in this guide. For more information, see
### 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**
......@@ -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.
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).
......@@ -119,34 +119,26 @@ If the verification result indicates that the app has the permission, the app ca
The procedure is as follows:
1. Obtain the caller's identity tokenId.
2. Determine the permission to be verified. In this example, the permission is **permissionNameUser**.
3. Call **verifyAccessToken** to verify the permissions of the caller.
4. Proceed based on the permission verification result.
1. Obtain the ability context.
2. Call **requestPermissionsFromUser** to verify whether the app has required permissions.
3. Proceed based on the permission verification result.
```js
import {describe, beforeEach, afterEach, it, expect} from 'deccjsunit/index'
import abilityAccessCtrl from '@ohos.abilityAccessCtrl'
import bundle from '@ohos.bundle'
async requestPermission() {
var permissionNameUser = "ohos.permission.PERMISSION2";
var bundleFlag = 0;
var tokenID = undefined;
var userID = 100;
var appInfo = await bundle.getApplicationInfo('ohos.acts.security.access_token.normal', bundleFlag, userID);
tokenID = appInfo.accessTokenId;
console.log("AccessTokenTest accessTokenId:" + appInfo.accessTokenId + ", name:" + appInfo.name
+ ", 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.
}
// OnWindowStageCreate lifecycle of the ability
onWindowStageCreate() {
var context = this.context
let array:Array<string> = ["ohos.permission.PERMISSION2"];
// requestPermissionsFromUser determines whether to invoke a pop-up window based on the permission authorization status.
context.requestPermissionsFromUser(array).then(function(data) {
console.log("data type:" + typeof(data));
console.log("data:" + data);
console.log("data permissions:" + data.permissions);
console.log("data result:" + data.authResults);
}, (err) => {
console.error('Failed to start ability', err.code);
});
}
```
> ![icon-note.gif](../public_sys-resources/icon-note.gif)**NOTE**<br/>
> For details about how to use **requestPermissionsFromUser**, see [API Reference] (../reference/apis/js-apis-ability-context.md#abilitycontextrequestpermissionsfromuser).
> **NOTE**<br>
> 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.
先完成此消息的编辑!
想要评论请 注册