未验证 提交 6f3723de 编写于 作者: O openharmony_ci 提交者: Gitee

!16474 [翻译完成】#I6LM4C (16036+15761+15907+ 16105+15641+15575+15893+15936+15880)

Merge pull request !16474 from Annie_wang/PR15728
......@@ -504,8 +504,8 @@ For details about the error codes, see [Application Access Control Error Codes](
| ID| Error Message|
| -------- | -------- |
| 12100001 | The parameter is invalid. The tokenID in list is all invalid, or the permissionName in list is all invalid. |
| 12100004 | The API is not used together with "on()". |
| 12100001 | The parameter is invalid. The tokenIDs or permissionNames in the list are all invalid. |
| 12100004 | The interface is not used together with "on". |
| 12100007 | Service is abnormal. |
| 12100008 | Out of memory. |
......@@ -532,7 +532,9 @@ verifyAccessToken(tokenID: number, permissionName: Permissions): Promise<Gran
Verifies whether a permission is granted to an application. This API uses a promise to return the result.
> **NOTE**<br>You are advised to use [checkAccessToken](#checkaccesstoken9).
> **NOTE**
>
> You are advised to use [checkAccessToken](#checkaccesstoken9).
**System capability**: SystemCapability.Security.AccessToken
......@@ -619,7 +621,7 @@ Requests permissions from the user in a dialog box. This API uses a promise to
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| context | Context | Yes| Ability context of the application that requests the permissions. |
| permissionList | Array&lt;Permissions&gt; | Yes| Permissions requested. For details about the permissions, see the [Application Permission List](../../security/permission-list.md). |
| permissionList | Array&lt;Permissions&gt; | Yes| Permissions requested. For details about the permissions, see the [Application Permission List](../../security/permission-list.md).|
**Return value**
......@@ -659,7 +661,9 @@ verifyAccessToken(tokenID: number, permissionName: string): Promise&lt;GrantStat
Verifies whether a permission is granted to an application. This API uses a promise to return the result.
> NOTE<br>This API is deprecated since API version 9. You are advised to use [checkAccessToken](#checkaccesstoken9).
> **NOTE**
>
> This API is no longer maintained since API version 9. You are advised to use [checkAccessToken](#checkaccesstoken9).
**System capability**: SystemCapability.Security.AccessToken
......
......@@ -8,7 +8,7 @@ The **relationalStore** module provides the following functions:
- [RdbStore](#rdbstore): provides APIs for managing data in an RDB store.
- [Resultset](#resultset): provides APIs for accessing the result set obtained from the RDB store.
> **NOTE**<br/>
> **NOTE**
>
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
......@@ -30,7 +30,7 @@ Obtains an RDB store. This API uses an asynchronous callback to return the resul
| Name | Type | Mandatory| Description |
| -------- | ---------------------------------------------- | ---- | ------------------------------------------------------------ |
| context | Context | Yes | Application context.<br>For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](js-apis-ability-context.md).|
| context | Context | Yes | Application context.<br>For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](js-apis-inner-application-uiAbilityContext.md).|
| config | [StoreConfig](#storeconfig) | Yes | Configuration of the RDB store. |
| callback | AsyncCallback&lt;[RdbStore](#rdbstore)&gt; | Yes | Callback invoked to return the RDB store obtained. |
......@@ -108,7 +108,7 @@ Obtains an RDB store. This API uses a promise to return the result. You can set
| Name | Type | Mandatory| Description |
| ------- | -------------------------------- | ---- | ------------------------------------------------------------ |
| context | Context | Yes | Application context.<br>For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](js-apis-ability-context.md).|
| context | Context | Yes | Application context.<br>For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](js-apis-inner-application-uiAbilityContext.md).|
| config | [StoreConfig](#storeconfig) | Yes | Configuration of the RDB store. |
**Return value**
......@@ -188,7 +188,7 @@ Deletes an RDB store. This API uses an asynchronous callback to return the resul
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ------------------------------------------------------------ |
| context | Context | Yes | Application context.<br>For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](js-apis-ability-context.md).|
| context | Context | Yes | Application context.<br>For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](js-apis-inner-application-uiAbilityContext.md).|
| name | string | Yes | Name of the RDB store to delete. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. |
......@@ -249,7 +249,7 @@ Deletes an RDB store. This API uses a promise to return the result.
| Name | Type | Mandatory| Description |
| ------- | ------- | ---- | ------------------------------------------------------------ |
| context | Context | Yes | Application context.<br>For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](js-apis-ability-context.md).|
| context | Context | Yes | Application context.<br>For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](js-apis-inner-application-uiAbilityContext.md).|
| name | string | Yes | Name of the RDB store to delete. |
**Return value**
......@@ -2612,9 +2612,9 @@ Synchronizes data between devices. This API uses a promise to return the result.
let predicates = new relationalStore.RdbPredicates('EMPLOYEE');
predicates.inDevices(['12345678abcde']);
let promise = store.sync(relationalStore.SyncMode.SYNC_MODE_PUSH, predicates);
promise.then((resultSet) =>{
promise.then((result) =>{
console.info(`Sync done.`);
for (let i = 0; i < resultSet.length; i++) {
for (let i = 0; i < result.length; i++) {
console.info(`device= ${result[i][0]}, status= ${result[i][1]}`);
}
}).catch((err) => {
......@@ -2693,10 +2693,12 @@ Provides APIs to access the result set obtained by querying the RDB store. A res
Obtain the **resultSet** object first.
```js
let resultSet = null;
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.equalTo("AGE", 18);
let promise = store.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
promise.then((resultSet) => {
promise.then((result) => {
resultSet = result;
console.info(`resultSet columnNames: ${resultSet.columnNames}`);
console.info(`resultSet columnCount: ${resultSet.columnCount}`);
});
......@@ -2867,7 +2869,7 @@ For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode
let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
let promise = store.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
promise.then((resultSet) => {
resultSet.(5);
resultSet.goToRow(5);
resultSet.close();
}).catch((err) => {
console.error(`query failed, err: ${err}`);
......
......@@ -86,8 +86,8 @@ For details about the error codes, see [Enterprise Device Management Error Codes
| ID| Error Message |
| ------- | ---------------------------------------------------------------------------- |
| 9200001 | The application is not an administrator application of the device. |
| 9200002 | The administrator application does not have permission to manage the device.|
| 9200001 | The application is not an administrator application of the device. |
| 9200002 | The administrator application does not have permission to manage the device. |
**Example**
......
......@@ -16,7 +16,7 @@ import fs from '@ohos.file.fs';
## Guidelines
Before using the APIs provided by this module to perform operations on files or directories, obtain the path of the file or directory in the application sandbox as follows:
Before using the APIs provided by this module to perform operations on files or folders, obtain the path of the file or directory in the application sandbox as follows:
**Stage Model**
......@@ -60,14 +60,14 @@ Obtains detailed file information. This API uses a promise to return the result.
**Return value**
| Type | Description |
| ---------------------------- | ---------- |
| Promise&lt;[Stat](#stat)&gt; | Promise used to return the file information obtained.|
| Type | Description |
| ---------------------------- | ---------- |
| Promise&lt;[Stat](#stat)&gt; | Promise used to return the file information obtained.|
**Example**
```js
let filePath = pathDir + "test.txt";
let filePath = pathDir + "/test.txt";
fs.stat(filePath).then((stat) => {
console.info("get file info succeed, the size of file is " + stat.size);
}).catch((err) => {
......@@ -119,9 +119,9 @@ Obtains detailed file information synchronously.
**Return value**
| Type | Description |
| ------------- | ---------- |
| [Stat](#stat) | File information obtained.|
| Type | Description |
| ------------- | ---------- |
| [Stat](#stat) | File information obtained.|
**Example**
......@@ -146,9 +146,9 @@ Checks whether a file exists. This API uses a promise to return the result.
**Return value**
| Type | Description |
| ------------------- | ---------------------------- |
| Promise&lt;boolean&gt; | Promise used to return a Boolean value.|
| Type | Description |
| ------------------- | ---------------------------- |
| Promise&lt;boolean&gt; | Promise used to return a Boolean value.|
**Example**
......@@ -233,15 +233,15 @@ Closes a file. This API uses a promise to return the result.
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ------------ |
| file | [File](#file)\|number | Yes | File object or FD of the file to close.|
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ------------ |
| file | [File](#file)\|number | Yes | File object or FD of the file to close.|
**Return value**
| Type | Description |
| ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
| Type | Description |
| ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
**Example**
......@@ -266,10 +266,10 @@ Closes a file. This API uses an asynchronous callback to return the result.
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | ------------ |
| file | [File](#file)\|number | Yes | File object or FD of the file to close.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file is closed asynchronously.|
| Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | ------------ |
| file | [File](#file)\|number | Yes | File object or FD of the file to close.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file is closed asynchronously.|
**Example**
......@@ -295,9 +295,9 @@ Synchronously closes a file.
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ------------ |
| file | [File](#file)\|number | Yes | File object or FD of the file to close.|
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ------------ |
| file | [File](#file)\|number | Yes | File object or FD of the file to close.|
**Example**
......@@ -317,23 +317,23 @@ Copies a file. This API uses a promise to return the result.
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | -------------------------- | ---- | ---------------------------------------- |
| src | string\|number | Yes | Path or FD of the file to copy. |
| dest | string\|number | Yes | Destination path of the file or FD of the file created. |
| mode | number | No | Whether to overwrite the file of the same name in the destination path. The default value is **0**, which is the only value supported.<br>**0**: overwrite the file of the same name.|
| Name | Type | Mandatory | Description |
| ---- | -------------------------- | ---- | ---------------------------------------- |
| src | string\|number | Yes | Path or FD of the file to copy. |
| dest | string\|number | Yes | Destination path of the file or FD of the file created. |
| mode | number | No | Whether to overwrite the file of the same name in the destination path. The default value is **0**, which is the only value supported.<br>**0**: overwrite the file of the same name.|
**Return value**
| Type | Description |
| ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
| Type | Description |
| ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
**Example**
```js
let srcPath = pathDir + "srcDir/test.txt";
let dstPath = pathDir + "dstDir/test.txt";
let srcPath = pathDir + "/srcDir/test.txt";
let dstPath = pathDir + "/dstDir/test.txt";
fs.copyFile(srcPath, dstPath).then(() => {
console.info("copy file succeed");
}).catch((err) => {
......@@ -351,18 +351,18 @@ Copies a file. This API uses an asynchronous callback to return the result.
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | -------------------------- | ---- | ---------------------------------------- |
| src | string\|number | Yes | Path or FD of the file to copy. |
| dest | string\|number | Yes | Destination path of the file or FD of the file created. |
| mode | number | No | Whether to overwrite the file of the same name in the destination path. The default value is **0**, which is the only value supported.<br>**0**: 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. |
| Name | Type | Mandatory | Description |
| -------- | -------------------------- | ---- | ---------------------------------------- |
| src | string\|number | Yes | Path or FD of the file to copy. |
| dest | string\|number | Yes | Destination path of the file or FD of the file created. |
| mode | number | No | Whether to overwrite the file of the same name in the destination path. The default value is **0**, which is the only value supported.<br>**0**: 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**
```js
let srcPath = pathDir + "srcDir/test.txt";
let dstPath = pathDir + "dstDir/test.txt";
let srcPath = pathDir + "/srcDir/test.txt";
let dstPath = pathDir + "/dstDir/test.txt";
fs.copyFile(srcPath, dstPath, (err) => {
if (err) {
console.info("copy file failed with error message: " + err.message + ", error code: " + err.code);
......@@ -383,17 +383,17 @@ Synchronously copies a file.
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | -------------------------- | ---- | ---------------------------------------- |
| src | string\|number | Yes | Path or FD of the file to copy. |
| dest | string\|number | Yes | Destination path of the file or FD of the file created. |
| mode | number | No | Whether to overwrite the file of the same name in the destination path. The default value is **0**, which is the only value supported.<br>**0**: overwrite the file with the same name and truncate the part that is not overwritten.|
| Name | Type | Mandatory | Description |
| ---- | -------------------------- | ---- | ---------------------------------------- |
| src | string\|number | Yes | Path or FD of the file to copy. |
| dest | string\|number | Yes | Destination path of the file or FD of the file created. |
| mode | number | No | Whether to overwrite the file of the same name in the destination path. The default value is **0**, which is the only value supported.<br>**0**: overwrite the file with the same name and truncate the part that is not overwritten.|
**Example**
```js
let srcPath = pathDir + "srcDir/test.txt";
let dstPath = pathDir + "dstDir/test.txt";
let srcPath = pathDir + "/srcDir/test.txt";
let dstPath = pathDir + "/dstDir/test.txt";
fs.copyFileSync(srcPath, dstPath);
```
......@@ -414,14 +414,14 @@ Creates a directory. This API uses a promise to return the result.
**Return value**
| Type | Description |
| ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
| Type | Description |
| ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
**Example**
```js
let dirPath = pathDir + '/testDir';
let dirPath = pathDir + "/testDir";
fs.mkdir(dirPath).then(() => {
console.info("Directory created");
}).catch((err) => {
......@@ -448,7 +448,7 @@ Creates a directory. This API uses an asynchronous callback to return the result
**Example**
```js
let dirPath = pathDir + '/testDir';
let dirPath = pathDir + "/testDir";
fs.mkdir(dirPath, (err) => {
if (err) {
console.info("mkdir failed with error message: " + err.message + ", error code: " + err.code);
......@@ -476,7 +476,7 @@ Synchronously creates a directory.
**Example**
```js
let dirPath = path + '/testDir';
let dirPath = pathDir + "/testDir";
fs.mkdirSync(dirPath);
```
......@@ -498,9 +498,9 @@ Opens a file. This API uses a promise to return the result. File uniform resourc
**Return value**
| Type | Description |
| --------------------- | ----------- |
| Promise&lt;[File](#file)&gt; | Promise used to return the file object.|
| Type | Description |
| --------------------- | ----------- |
| Promise&lt;[File](#file)&gt; | Promise used to return the file object.|
**Example**
......@@ -559,9 +559,9 @@ Synchronously opens a file. File URIs are supported.
**Return value**
| Type | Description |
| ------ | ----------- |
| [File](#file) | File object opened.|
| Type | Description |
| ------ | ----------- |
| [File](#file) | File object opened.|
**Example**
......@@ -590,9 +590,9 @@ Reads data from a file. This API uses a promise to return the result.
**Return value**
| Type | Description |
| ---------------------------------- | ------ |
| Promise&lt;number&gt; | Promise used to return the data read.|
| Type | Description |
| ---------------------------------- | ------ |
| Promise&lt;number&gt; | Promise used to return the data read.|
**Example**
......@@ -602,7 +602,7 @@ Reads data from a file. This API uses a promise to return the result.
let buf = new ArrayBuffer(4096);
fs.read(file.fd, buf).then((readLen) => {
console.info("Read file data successfully");
console.info(String.fromCharCode.apply(null, new Uint8Array(readLen)));
console.info(String.fromCharCode.apply(null, new Uint8Array(buf.slice(0, readLen))));
fs.closeSync(file);
}).catch((err) => {
console.info("read file data failed with error message: " + err.message + ", error code: " + err.code);
......@@ -619,12 +619,12 @@ Reads data from a file. This API uses an asynchronous callback to return the res
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| fd | number | Yes | FD of the file. |
| buffer | ArrayBuffer | Yes | Buffer used to store the file data read. |
| options | Object | No | The options are as follows:<br>- **offset** (number): position of the data to read in the file. This parameter is optional. By default, data is read from the current position.<br>- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length.|
| callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked when the data is read asynchronously. |
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| fd | number | Yes | FD of the file. |
| buffer | ArrayBuffer | Yes | Buffer used to store the file data read. |
| options | Object | No | The options are as follows:<br>- **offset** (number): position of the data to read in the file. This parameter is optional. By default, data is read from the current position.<br>- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length.|
| callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked when the data is read asynchronously. |
**Example**
......@@ -637,7 +637,7 @@ Reads data from a file. This API uses an asynchronous callback to return the res
console.info("mkdir failed with error message: " + err.message + ", error code: " + err.code);
} else {
console.info("Read file data successfully");
console.info(String.fromCharCode.apply(null, new Uint8Array(readLen)));
console.info(String.fromCharCode.apply(null, new Uint8Array(buf.slice(0, readLen))));
fs.closeSync(file);
}
});
......@@ -654,17 +654,17 @@ Synchronously reads data from a file.
**Parameters**
| Name | Type | Mandatory | Description |
| ------- | ----------- | ---- | ---------------------------------------- |
| fd | number | Yes | FD of the file. |
| buffer | ArrayBuffer | Yes | Buffer used to store the file data read. |
| options | Object | No | The options are as follows:<br>- **offset** (number): position of the data to read in the file. This parameter is optional. By default, data is read from the current position.<br>- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length.|
| Name | Type | Mandatory | Description |
| ------- | ----------- | ---- | ---------------------------------------- |
| fd | number | Yes | FD of the file. |
| buffer | ArrayBuffer | Yes | Buffer used to store the file data read. |
| options | Object | No | The options are as follows:<br>- **offset** (number): position of the data to read in the file. This parameter is optional. By default, data is read from the current position.<br>- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length.|
**Return value**
| Type | Description |
| ------ | -------- |
| number | Length of the data read.|
| Type | Description |
| ------ | -------- |
| number | Length of the data read.|
**Example**
......@@ -693,14 +693,14 @@ Deletes a directory. This API uses a promise to return the result.
**Return value**
| Type | Description |
| ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
| Type | Description |
| ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
**Example**
```js
let dirPath = pathDir + '/testDir';
let dirPath = pathDir + "/testDir";
fs.rmdir(dirPath).then(() => {
console.info("Directory deleted");
}).catch((err) => {
......@@ -727,7 +727,7 @@ Deletes a directory. This API uses an asynchronous callback to return the result
**Example**
```js
let dirPath = pathDir + '/testDir';
let dirPath = pathDir + "/testDir";
fs.rmdir(dirPath, (err) => {
if (err) {
console.info("rmdir failed with error message: " + err.message + ", error code: " + err.code);
......@@ -755,7 +755,7 @@ Synchronously deletes a directory.
**Example**
```js
let dirPath = pathDir + '/testDir';
let dirPath = pathDir + "/testDir";
fs.rmdirSync(dirPath);
```
......@@ -776,9 +776,9 @@ Deletes a file. This API uses a promise to return the result.
**Return value**
| Type | Description |
| ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
| Type | Description |
| ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
**Example**
......@@ -853,17 +853,17 @@ Writes data into a file. This API uses a promise to return the result.
**Parameters**
| Name | Type | Mandatory | Description |
| ------- | ------------------------------- | ---- | ---------------------------------------- |
| fd | number | Yes | FD of the file. |
| buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. |
| options | Object | No | The options are as follows:<br>- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.<br>- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.<br>- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.|
| Name | Type | Mandatory | Description |
| ------- | ------------------------------- | ---- | ---------------------------------------- |
| fd | number | Yes | FD of the file. |
| buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. |
| options | Object | No | The options are as follows:<br>- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.<br>- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.<br>- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.|
**Return value**
| Type | Description |
| --------------------- | -------- |
| Promise&lt;number&gt; | Promise used to return the length of the data written.|
| Type | Description |
| --------------------- | -------- |
| Promise&lt;number&gt; | Promise used to return the length of the data written.|
**Example**
......@@ -889,12 +889,12 @@ Writes data into a file. This API uses an asynchronous callback to return the re
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ------------------------------- | ---- | ---------------------------------------- |
| fd | number | Yes | FD of the file. |
| buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. |
| options | Object | No | The options are as follows:<br>- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.<br>- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.<br>- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.|
| callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked when the data is written asynchronously. |
| Name | Type | Mandatory | Description |
| -------- | ------------------------------- | ---- | ---------------------------------------- |
| fd | number | Yes | FD of the file. |
| buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. |
| options | Object | No | The options are as follows:<br>- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.<br>- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.<br>- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.|
| callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked when the data is written asynchronously. |
**Example**
......@@ -922,17 +922,17 @@ Synchronously writes data into a file.
**Parameters**
| Name | Type | Mandatory | Description |
| ------- | ------------------------------- | ---- | ---------------------------------------- |
| fd | number | Yes | FD of the file. |
| buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. |
| options | Object | No | The options are as follows:<br>- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.<br>- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.<br>- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.|
| Name | Type | Mandatory | Description |
| ------- | ------------------------------- | ---- | ---------------------------------------- |
| fd | number | Yes | FD of the file. |
| buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. |
| options | Object | No | The options are as follows:<br>- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.<br>- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.<br>- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.|
**Return value**
| Type | Description |
| ------ | -------- |
| number | Length of the data written in the file.|
| Type | Description |
| ------ | -------- |
| number | Length of the data written in the file.|
**Example**
......@@ -961,9 +961,9 @@ Truncates a file. This API uses a promise to return the result.
**Return value**
| Type | Description |
| ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
| Type | Description |
| ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
**Example**
......@@ -1050,9 +1050,9 @@ Reads the text content of a file. This API uses a promise to return the result.
**Return value**
| Type | Description |
| --------------------- | ---------- |
| Promise&lt;string&gt; | Promise used to return the content read.|
| Type | Description |
| --------------------- | ---------- |
| Promise&lt;string&gt; | Promise used to return the content read.|
**Example**
......@@ -1113,9 +1113,9 @@ Synchronously reads the text of a file.
**Return value**
| Type | Description |
| ------ | -------------------- |
| string | Promise used to return the content of the file read.|
| Type | Description |
| ------ | -------------------- |
| string | Promise used to return the content of the file read.|
**Example**
......@@ -1141,9 +1141,9 @@ Obtains information about a symbolic link. This API uses a promise to return the
**Return value**
| Type | Description |
| ---------------------------- | ---------- |
| Promise&lt;[Stat](#stat)&gt; | Promise used to return the symbolic link information obtained. For details, see **stat**.|
| Type | Description |
| ---------------------------- | ---------- |
| Promise&lt;[Stat](#stat)&gt; | Promise used to return the symbolic link information obtained. For details, see **stat**.|
**Example**
......@@ -1201,9 +1201,9 @@ Obtains information about a symbolic link synchronously.
**Return value**
| Type | Description |
| ------------- | ---------- |
| [Stat](#stat) | File information obtained.|
| Type | Description |
| ------------- | ---------- |
| [Stat](#stat) | File information obtained.|
**Example**
......@@ -1216,7 +1216,7 @@ Obtains information about a symbolic link synchronously.
rename(oldPath: string, newPath: string): Promise&lt;void&gt;
Renames a file or directory. This API uses a promise to return the result.
Renames a file or folder. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO
......@@ -1229,15 +1229,15 @@ Renames a file or directory. This API uses a promise to return the result.
**Return value**
| Type | Description |
| ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
| Type | Description |
| ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
**Example**
```js
let srcFile = pathDir + "/test.txt";
let dstFile = pathDir + '/new.txt';
let dstFile = pathDir + "/new.txt";
fs.rename(srcFile, dstFile).then(() => {
console.info("File renamed");
}).catch((err) => {
......@@ -1249,7 +1249,7 @@ Renames a file or directory. This API uses a promise to return the result.
rename(oldPath: string, newPath: string, callback: AsyncCallback&lt;void&gt;): void
Renames a file or directory. This API uses an asynchronous callback to return the result.
Renames a file or folder. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO
......@@ -1265,7 +1265,7 @@ Renames a file or directory. This API uses an asynchronous callback to return th
```js
let srcFile = pathDir + "/test.txt";
let dstFile = pathDir + '/new.txt';
let dstFile = pathDir + "/new.txt";
fs.rename(srcFile, dstFile, (err) => {
if (err) {
console.info("rename failed with error message: " + err.message + ", error code: " + err.code);
......@@ -1279,7 +1279,7 @@ Renames a file or directory. This API uses an asynchronous callback to return th
renameSync(oldPath: string, newPath: string): void
Renames a file or directory synchronously.
Renames a file or folder synchronously.
**System capability**: SystemCapability.FileManagement.File.FileIO
......@@ -1294,7 +1294,7 @@ Renames a file or directory synchronously.
```js
let srcFile = pathDir + "/test.txt";
let dstFile = pathDir + '/new.txt';
let dstFile = pathDir + "/new.txt";
fs.renameSync(srcFile, dstFile);
```
......@@ -1309,15 +1309,15 @@ Flushes data of a file to disk. This API uses a promise to return the result.
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ------------ |
| fd | number | Yes | FD of the file.|
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ------------ |
| fd | number | Yes | FD of the file.|
**Return value**
| Type | Description |
| ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
| Type | Description |
| ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
**Example**
......@@ -1342,10 +1342,10 @@ Flushes data of a file to disk. This API uses an asynchronous callback to return
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | --------------- |
| fd | number | Yes | FD of the file. |
| Callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file data is synchronized in asynchronous mode.|
| Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | --------------- |
| fd | number | Yes | FD of the file. |
| Callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file data is synchronized in asynchronous mode.|
**Example**
......@@ -1373,9 +1373,9 @@ Flushes data of a file to disk synchronously.
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ------------ |
| fd | number | Yes | FD of the file.|
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ------------ |
| fd | number | Yes | FD of the file.|
**Example**
......@@ -1397,15 +1397,15 @@ Flushes data of a file to disk. This API uses a promise to return the result. **
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ------------ |
| fd | number | Yes | FD of the file.|
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ------------ |
| fd | number | Yes | FD of the file.|
**Return value**
| Type | Description |
| ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
| Type | Description |
| ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
**Example**
......@@ -1431,10 +1431,10 @@ Flushes data of a file to disk. This API uses an asynchronous callback to return
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ------------------------------- | ---- | ----------------- |
| fd | number | Yes | FD of the file. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file data is synchronized in asynchronous mode.|
| Name | Type | Mandatory | Description |
| -------- | ------------------------------- | ---- | ----------------- |
| fd | number | Yes | FD of the file. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file data is synchronized in asynchronous mode.|
**Example**
......@@ -1461,9 +1461,9 @@ Synchronizes data in a file synchronously.
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ------------ |
| fd | number | Yes | FD of the file.|
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ------------ |
| fd | number | Yes | FD of the file.|
**Example**
......@@ -1492,15 +1492,15 @@ Creates a symbolic link based on a file path. This API uses a promise to return
**Return value**
| Type | Description |
| ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
| Type | Description |
| ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
**Example**
```js
let srcFile = pathDir + "/test.txt";
let dstFile = pathDir + '/test';
let dstFile = pathDir + "/test";
fs.symlink(srcFile, dstFile).then(() => {
console.info("Symbolic link created");
}).catch((err) => {
......@@ -1528,7 +1528,7 @@ Creates a symbolic link based on a file path. This API uses an asynchronous call
```js
let srcFile = pathDir + "/test.txt";
let dstFile = pathDir + '/test';
let dstFile = pathDir + "/test";
fs.symlink(srcFile, dstFile, (err) => {
if (err) {
console.info("symlink failed with error message: " + err.message + ", error code: " + err.code);
......@@ -1557,7 +1557,7 @@ Synchronously creates a symbolic link based on a file path.
```js
let srcFile = pathDir + "/test.txt";
let dstFile = pathDir + '/test';
let dstFile = pathDir + "/test";
fs.symlinkSync(srcFile, dstFile);
```
......@@ -1568,30 +1568,30 @@ listFile(path: string, options?: {
filter?: Filter;
}): Promise<string[]>;
Lists all files in a directory. This API uses a promise to return the result.<br>This API supports recursive listing of all files (including files in subdirectories) and file filtering.
Lists all files in a folder. This API uses a promise to return the result.<br>This API supports recursive listing of all files (including files in subfolders) and file filtering.
**System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- |
| path | string | Yes | Path of the directory in the application sandbox.|
| options | Object | No | File filtering options.|
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- |
| path | string | Yes | Path of the folder in the application sandbox.|
| options | Object | No | File filtering options.|
**options parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- |
| recursion | boolean | No | Whether to list all files in subdirectories recursively. The default value is **false**.|
| listNum | number | No | Number of file names to list. The default value **0** means to list all files.|
| filter | [Filter](#filter) | No | File filtering options. Currently, only the match by file name extension, fuzzy search by file name, and filter by file size or latest modification time are supported.|
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- |
| recursion | boolean | No | Whether to list all files in subfolders recursively. The default value is **false**.|
| listNum | number | No | Number of file names to list. The default value **0** means to list all files.|
| filter | [Filter](#filter) | No | File filtering options. Currently, only the match by file name extension, fuzzy search by file name, and filter by file size or latest modification time are supported.|
**Return value**
| Type | Description |
| --------------------- | ---------- |
| Promise&lt;string[]&gt; | Promise used to return the files names listed.|
| Type | Description |
| --------------------- | ---------- |
| Promise&lt;string[]&gt; | Promise used to return the files names listed.|
**Example**
......@@ -1608,7 +1608,7 @@ Lists all files in a directory. This API uses a promise to return the result.<br
};
fs.listFile(pathDir, options).then((filenames) => {
console.info("listFile succeed");
for (let i = 0; i < filenames.size; i++) {
for (let i = 0; i < filenames.length; i++) {
console.info("fileName: %s", filenames[i]);
}
}).catch((err) => {
......@@ -1623,23 +1623,23 @@ listFile(path: string, options?: {
filter?: Filter;
}, callback: AsyncCallback<string[]>): void;
Lists all files in a directory. This API uses an asynchronous callback to return the result.<br>This API supports recursive listing of all files (including files in subdirectories) and file filtering.
Lists all files in a folder. This API uses an asynchronous callback to return the result.<br>This API supports recursive listing of all files (including files in subfolders) and file filtering.
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- |
| path | string | Yes | Path of the directory in the application sandbox.|
| options | Object | No | File filtering options.|
| callback | AsyncCallback&lt;string[]&gt; | Yes | Callback invoked to return the file names listed. |
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- |
| path | string | Yes | Path of the folder in the application sandbox.|
| options | Object | No | File filtering options.|
| callback | AsyncCallback&lt;string[]&gt; | Yes | Callback invoked to return the file names listed. |
**options parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- |
| recursion | boolean | No | Whether to list all files in subdirectories recursively. The default value is **false**.|
| listNum | number | No | Number of file names to list. The default value **0** means to list all files.|
| filter | [Filter](#filter) | No | File filtering options. Currently, only the match by file name extension, fuzzy search by file name, and filter by file size or latest modification time are supported.|
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- |
| recursion | boolean | No | Whether to list all files in subfolders recursively. The default value is **false**.|
| listNum | number | No | Number of file names to list. The default value **0** means to list all files.|
| filter | [Filter](#filter) | No | File filtering options. Currently, only the match by file name extension, fuzzy search by file name, and filter by file size or latest modification time are supported.|
**Example**
......@@ -1659,7 +1659,7 @@ Lists all files in a directory. This API uses an asynchronous callback to return
console.info("list file failed with error message: " + err.message + ", error code: " + err.code);
} else {
console.info("listFile succeed");
for (let i = 0; i < filenames.size; i++) {
for (let i = 0; i < filenames.length; i++) {
console.info("filename: %s", filenames[i]);
}
}
......@@ -1674,28 +1674,28 @@ listFileSync(path: string, options?: {
filter?: Filter;
}): string[];
Lists all files in a directory synchronously. This API supports recursive listing of all files (including files in subdirectories) and file filtering.
Lists all files in a folder synchronously. This API supports recursive listing of all files (including files in subfolders) and file filtering.
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- |
| path | string | Yes | Path of the directory in the application sandbox.|
| options | Object | No | File filtering options.|
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- |
| path | string | Yes | Path of the folder in the application sandbox.|
| options | Object | No | File filtering options.|
**options parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- |
| recursion | boolean | No | Whether to list all files in subdirectories recursively. The default value is **false**.|
| listNum | number | No | Number of file names to list. The default value **0** means to list all files.|
| filter | [Filter](#filter) | No | File filtering options. Currently, only the match by file name extension, fuzzy search by file name, and filter by file size or latest modification time are supported.|
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- |
| recursion | boolean | No | Whether to list all files in subfolders recursively. The default value is **false**.|
| listNum | number | No | Number of file names to list. The default value **0** means to list all files.|
| filter | [Filter](#filter) | No | File filtering options. Currently, only the match by file name extension, fuzzy search by file name, and filter by file size or latest modification time are supported.|
**Return value**
| Type | Description |
| --------------------- | ---------- |
| string[] | File names listed.|
| Type | Description |
| --------------------- | ---------- |
| string[] | File names listed.|
**Example**
......@@ -1712,13 +1712,13 @@ Lists all files in a directory synchronously. This API supports recursive listin
};
let filenames = fs.listFileSync(pathDir, options);
console.info("listFile succeed");
for (let i = 0; i < filenames.size; i++) {
for (let i = 0; i < filenames.length; i++) {
console.info("filename: %s", filenames[i]);
}
```
## fs.moveFile
moveFile(src: string, dest: string, mode?: number): Promise<void>;
moveFile(src: string, dest: string, mode?: number): Promise\<void>;
Moves a file. This API uses a promise to return the result.
......@@ -1726,15 +1726,17 @@ Moves a file. This API uses a promise to return the result.
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- |
| src | string | Yes | Path of the file to move in the application sandbox.|
| dest | string | Yes | Destination path of the file in the application sandbox.|
| mode | number | No | Whether to overwrite the file of the same name in the destination directory. The value **0** means to overwrite the file of the same name in the destination directory. The value **1** means to throw an exception if a file of the same name exists in the destination directory. The default value is **0**.|
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- |
| src | string | Yes | Path of the file to move in the application sandbox.|
| dest | string | Yes | Destination path of the file in the application sandbox.|
| mode | number | No | Whether to overwrite the file of the same name in the destination directory. The value **0** means to overwrite the file of the same name in the destination directory. The value **1** means to throw an exception if a file of the same name exists in the destination directory. The default value is **0**.|
**Example**
```js
let srcPath = pathDir + "/source.txt";
let destPath = pathDir + "/dest.txt";
fs.moveFile(srcPath, destPath, 0).then(() => {
console.info("move file succeed");
}).catch((err) => {
......@@ -1744,7 +1746,7 @@ Moves a file. This API uses a promise to return the result.
## fs.moveFile
moveFile(src: string, dest: string, mode?: number, callback: AsyncCallback<void>): void;
moveFile(src: string, dest: string, mode?: number, callback: AsyncCallback\<void>): void;
Moves a file. This API uses an asynchronous callback to return the result.
......@@ -1752,16 +1754,18 @@ Moves a file. This API uses an asynchronous callback to return the result.
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- |
| src | string | Yes | Path of the file to move in the application sandbox.|
| dest | string | Yes | Destination path of the file in the application sandbox.|
| mode | number | No | Whether to overwrite the file of the same name in the destination directory. The value **0** means to overwrite the file of the same name in the destination directory. The value **1** means to throw an exception if a file of the same name exists in the destination directory. The default value is **0**.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file is moved. |
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- |
| src | string | Yes | Path of the file to move in the application sandbox.|
| dest | string | Yes | Destination path of the file in the application sandbox.|
| mode | number | No | Whether to overwrite the file of the same name in the destination directory. The value **0** means to overwrite the file of the same name in the destination directory. The value **1** means to throw an exception if a file of the same name exists in the destination directory. The default value is **0**.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file is moved. |
**Example**
```js
let srcPath = pathDir + "/source.txt";
let destPath = pathDir + "/dest.txt";
fs.moveFile(srcPath, destPath, 0, (err) => {
if (err) {
console.info("move file failed with error message: " + err.message + ", error code: " + err.code);
......@@ -1781,15 +1785,17 @@ Moves a file synchronously.
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- |
| src | string | Yes | Path of the file to move in the application sandbox.|
| dest | string | Yes | Destination path of the file in the application sandbox.|
| mode | number | No | Whether to overwrite the file of the same name in the destination directory. The value **0** means to overwrite the file of the same name in the destination directory. The value **1** means to throw an exception if a file of the same name exists in the destination directory. The default value is **0**.|
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- |
| src | string | Yes | Path of the file to move in the application sandbox.|
| dest | string | Yes | Destination path of the file in the application sandbox.|
| mode | number | No | Whether to overwrite the file of the same name in the destination directory. The value **0** means to overwrite the file of the same name in the destination directory. The value **1** means to throw an exception if a file of the same name exists in the destination directory. The default value is **0**.|
**Example**
```js
let srcPath = pathDir + "/source.txt";
let destPath = pathDir + "/dest.txt";
fs.moveFileSync(srcPath, destPath, 0);
console.info("move file succeed");
```
......@@ -1804,15 +1810,15 @@ Creates a temporary directory. This API uses a promise to return the result.
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- |
| prefix | string | Yes | A randomly generated string used to replace "XXXXXX" in a directory.|
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- |
| prefix | string | Yes | A randomly generated string used to replace "XXXXXX" in a directory.|
**Return value**
| Type | Description |
| --------------------- | ---------- |
| Promise&lt;string&gt; | Promise used to return the unique directory generated.|
| Type | Description |
| --------------------- | ---------- |
| Promise&lt;string&gt; | Promise used to return the unique directory generated.|
**Example**
......@@ -1835,10 +1841,10 @@ Creates a temporary directory. This API uses an asynchronous callback to return
**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. |
| 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**
......@@ -1862,21 +1868,21 @@ Synchronously creates a temporary directory.
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- |
| prefix | string | Yes | A randomly generated string used to replace "XXXXXX" in a directory.|
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- |
| prefix | string | Yes | A randomly generated string used to replace "XXXXXX" in a directory.|
**Return value**
| Type | Description |
| ------ | ---------- |
| string | Unique path generated.|
| Type | Description |
| ------ | ---------- |
| string | Unique path generated.|
**Example**
```js
let res = fs.mkdtempSync(pathDir + "/XXXXXX");
```
```
## fs.createStream
......@@ -1895,9 +1901,9 @@ Opens a file stream based on the file path. This API uses a promise to return th
**Return value**
| Type | Description |
| --------------------------------- | --------- |
| Promise&lt;[Stream](#stream)&gt; | Promise used to return the result.|
| Type | Description |
| --------------------------------- | --------- |
| Promise&lt;[Stream](#stream)&gt; | Promise used to return the result.|
**Example**
......@@ -1957,9 +1963,9 @@ Synchronously opens a stream based on the file path.
**Return value**
| Type | Description |
| ------------------ | --------- |
| [Stream](#stream) | Stream opened.|
| Type | Description |
| ------------------ | --------- |
| [Stream](#stream) | Stream opened.|
**Example**
......@@ -1979,16 +1985,16 @@ Opens a file stream based on the file descriptor. This API uses a promise to ret
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ---------------------------------------- |
| fd | number | Yes | FD of the file. |
| mode | string | Yes | - **r**: Open a file for reading. The file must exist.<br>- **r+**: Open a file for both reading and writing. The file must exist.<br>- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **w+**: Open a file for both reading and writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **a**: Open a file in append mode for writing at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).<br>- **a+**: Open a file in append mode for reading or updating at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).|
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ---------------------------------------- |
| fd | number | Yes | FD of the file. |
| mode | string | Yes | - **r**: Open a file for reading. The file must exist.<br>- **r+**: Open a file for both reading and writing. The file must exist.<br>- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **w+**: Open a file for both reading and writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **a**: Open a file in append mode for writing at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).<br>- **a+**: Open a file in append mode for reading or updating at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).|
**Return value**
| Type | Description |
| --------------------------------- | --------- |
| Promise&lt;[Stream](#stream)&gt; | Promise used to return the result.|
| Type | Description |
| --------------------------------- | --------- |
| Promise&lt;[Stream](#stream)&gt; | Promise used to return the result.|
**Example**
......@@ -2014,11 +2020,11 @@ Opens a file stream based on the file descriptor. This API uses an asynchronous
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| fd | number | Yes | FD of the file. |
| mode | string | Yes | - **r**: Open a file for reading. The file must exist.<br>- **r+**: Open a file for both reading and writing. The file must exist.<br>- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **w+**: Open a file for both reading and writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **a**: Open a file in append mode for writing at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).<br>- **a+**: Open a file in append mode for reading or updating at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).|
| callback | AsyncCallback&lt;[Stream](#stream)&gt; | Yes | Callback invoked when the stream is open asynchronously. |
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| fd | number | Yes | FD of the file. |
| mode | string | Yes | - **r**: Open a file for reading. The file must exist.<br>- **r+**: Open a file for both reading and writing. The file must exist.<br>- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **w+**: Open a file for both reading and writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **a**: Open a file in append mode for writing at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).<br>- **a+**: Open a file in append mode for reading or updating at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).|
| callback | AsyncCallback&lt;[Stream](#stream)&gt; | Yes | Callback invoked when the stream is open asynchronously. |
**Example**
......@@ -2045,16 +2051,16 @@ Synchronously opens a stream based on the file descriptor.
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ---------------------------------------- |
| fd | number | Yes | FD of the file. |
| mode | string | Yes | - **r**: Open a file for reading. The file must exist.<br>- **r+**: Open a file for both reading and writing. The file must exist.<br>- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **w+**: Open a file for both reading and writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **a**: Open a file in append mode for writing at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).<br>- **a+**: Open a file in append mode for reading or updating at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).|
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ---------------------------------------- |
| fd | number | Yes | FD of the file. |
| mode | string | Yes | - **r**: Open a file for reading. The file must exist.<br>- **r+**: Open a file for both reading and writing. The file must exist.<br>- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **w+**: Open a file for both reading and writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **a**: Open a file in append mode for writing at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).<br>- **a+**: Open a file in append mode for reading or updating at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).|
**Return value**
| Type | Description |
| ------------------ | --------- |
| [Stream](#stream) | Stream opened.|
| Type | Description |
| ------------------ | --------- |
| [Stream](#stream) | Stream opened.|
**Example**
......@@ -2077,17 +2083,17 @@ Creates a **Watcher** object to observe file or directory changes.
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ---------------------------------------- |
| path | string | Yes | Path of the file or directory to observe in the application sandbox. |
| events | number | Yes | Events to observe. Multiple events can be separated|by a bitwise OR operator (&#124;).<br>- **0x1: IN_ACCESS**: A file is accessed.<br>- **0x2: IN_MODIFY**: The file content is modified.<br>- **0x4: IN_ATTRIB**: Metadata is changed.<br>- **0x8: IN_CLOSE_WRITE**: The file opened for writing is closed.<br>- **0x10: IN_CLOSE_NOWRITE**: The file or directory not opened for writing is closed.<br>- **0x20: IN_OPEN**: A file or directory is opened.<br>- **0x40: IN_MOVED_FROM**: A file in the observed directory is moved.<br>- **0x80: IN_MOVED_TO**: A file is moved to the observed directory.<br>- **0x100: IN_CREATE**: A file or directory is created in the observed directory.<br>- **0x200: IN_DELETE**: A file or directory is deleted form the observed directory.<br>- **0x400: IN_DELETE_SELF**: The observed directory is deleted. After the directory is deleted, the listening stops.<br>- **0x800: IN_MOVE_SELF**: The observed file or directory is moved. After the file or directory is moved, the listening continues.<br>- **0xfff: IN_ALL_EVENTS**: All events.|
| listener | WatchEventListener | Yes | Callback invoked when an observed event occurs. The callback will be invoked each time an observed event occurs. |
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ---------------------------------------- |
| path | string | Yes | Path of the file or directory to observe in the application sandbox. |
| events | number | Yes | Events to observe. Multiple events can be separated by a bitwise OR operator (&#124;).<br>- **0x1: IN_ACCESS**: A file is accessed.<br>- **0x2: IN_MODIFY**: The file content is modified.<br>- **0x4: IN_ATTRIB**: Metadata is changed.<br>- **0x8: IN_CLOSE_WRITE**: The file opened for writing is closed.<br>- **0x10: IN_CLOSE_NOWRITE**: The file or directory not opened for writing is closed.<br>- **0x20: IN_OPEN**: A file or directory is opened.<br>- **0x40: IN_MOVED_FROM**: A file in the observed directory is moved.<br>- **0x80: IN_MOVED_TO**: A file is moved to the observed directory.<br>- **0x100: IN_CREATE**: A file or directory is created in the observed directory.<br>- **0x200: IN_DELETE**: A file or directory is deleted form the observed directory.<br>- **0x400: IN_DELETE_SELF**: The observed directory is deleted. After the directory is deleted, the listening stops.<br>- **0x800: IN_MOVE_SELF**: The observed file or directory is moved. After the file or directory is moved, the listening continues.<br>- **0xfff: IN_ALL_EVENTS**: All events.|
| listener | WatchEventListener | Yes | Callback invoked when an observed event occurs. The callback will be invoked each time an observed event occurs. |
**Return value**
| Type | Description |
| ------------------ | --------- |
| [Watcher](#watcher10) | **Watcher** object created.|
| Type | Description |
| ------------------ | --------- |
| [Watcher](#watcher10) | **Watcher** object created.|
**Example**
......@@ -2119,10 +2125,10 @@ Called when an observed event occurs.
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ---------------------------------------- |
| event | WatchEvent | Yes | Event for the callback to invoke. |
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ---------------------------------------- |
| event | WatchEvent | Yes | Event for the callback to invoke. |
## WatchEvent<sup>10+</sup>
Defines the event to observe.
......@@ -2146,7 +2152,7 @@ Represents detailed file information. Before calling any API of the **Stat()** c
### Attributes
| Name | Type | Readable | Writable | Description |
| ------ | ------ | ---- | ---- | ---------------------------------------- |
| ------ | ------ | ---- | ---- | ---------------------------------------- |
| ino | number | Yes | No | File ID. Different files on the same device have different **ino**s.| |
| mode | number | Yes | No | File permissions. The meaning of each bit is as follows:<br>- **0o400**: The owner has the read permission on a regular file or a directory entry.<br>- **0o200**: The owner has the permission to write a regular file or create and delete a directory entry.<br>- **0o100**: The owner has the permission to execute a regular file or search for the specified path in a directory.<br>- **0o040**: The user group has the read permission on a regular file or a directory entry.<br>- **0o020**: The user group has the permission to write a regular file or create and delete a directory entry.<br>- **0o010**: The user group has the permission to execute a regular file or search for the specified path in a directory.<br>- **0o004**: Other users have the permission to read a regular file or read a directory entry.<br>- **0o002**: Other users have the permission to write a regular file or create and delete a directory entry.<br>- **0o001**: Other users have the permission to execute a regular file or search for the specified path in a directory.|
| uid | number | Yes | No | ID of the file owner.|
......@@ -2167,9 +2173,9 @@ Checks whether this file is a block special file. A block special file supports
**Return value**
| Type | Description |
| ------- | ---------------- |
| boolean | Whether the file is a block special file.|
| Type | Description |
| ------- | ---------------- |
| boolean | Whether the file is a block special file.|
**Example**
......@@ -2188,9 +2194,9 @@ Checks whether this file is a character special file. A character special file s
**Return value**
| Type | Description |
| ------- | ----------------- |
| boolean | Whether the file is a character special file.|
| Type | Description |
| ------- | ----------------- |
| boolean | Whether the file is a character special file.|
**Example**
......@@ -2210,9 +2216,9 @@ Checks whether this file is a directory.
**Return value**
| Type | Description |
| ------- | ------------- |
| boolean | Whether the file is a directory.|
| Type | Description |
| ------- | ------------- |
| boolean | Whether the file is a directory.|
**Example**
......@@ -2232,9 +2238,9 @@ Checks whether this file is a named pipe (or FIFO). Named pipes are used for int
**Return value**
| Type | Description |
| ------- | --------------------- |
| boolean | Whether the file is a FIFO.|
| Type | Description |
| ------- | --------------------- |
| boolean | Whether the file is a FIFO.|
**Example**
......@@ -2254,9 +2260,9 @@ Checks whether this file is a regular file.
**Return value**
| Type | Description |
| ------- | --------------- |
| boolean | Whether the file is a regular file.|
| Type | Description |
| ------- | --------------- |
| boolean | Whether the file is a regular file.|
**Example**
......@@ -2276,9 +2282,9 @@ Checks whether this file is a socket.
**Return value**
| Type | Description |
| ------- | -------------- |
| boolean | Whether the file is a socket.|
| Type | Description |
| ------- | -------------- |
| boolean | Whether the file is a socket.|
**Example**
......@@ -2298,9 +2304,9 @@ Checks whether this file is a symbolic link.
**Return value**
| Type | Description |
| ------- | --------------- |
| boolean | Whether the file is a symbolic link.|
| Type | Description |
| ------- | --------------- |
| boolean | Whether the file is a symbolic link.|
**Example**
......@@ -2324,9 +2330,9 @@ Closes the stream. This API uses a promise to return the result.
**Return value**
| Type | Description |
| ------------------- | ------------- |
| Promise&lt;void&gt; | Promise used to return the stream close result.|
| Type | Description |
| ------------------- | ------------- |
| Promise&lt;void&gt; | Promise used to return the stream close result.|
**Example**
......@@ -2351,9 +2357,9 @@ Closes the stream. This API uses an asynchronous callback to return the result.
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | ------------- |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the stream is closed asynchronously.|
| Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | ------------- |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the stream is closed asynchronously.|
**Example**
......@@ -2395,9 +2401,9 @@ Flushes the stream. This API uses a promise to return the result.
**Return value**
| Type | Description |
| ------------------- | ------------- |
| Promise&lt;void&gt; | Promise used to return the stream flushing result.|
| Type | Description |
| ------------------- | ------------- |
| Promise&lt;void&gt; | Promise used to return the stream flushing result.|
**Example**
......@@ -2422,9 +2428,9 @@ Flushes the stream. This API uses an asynchronous callback to return the result.
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | -------------- |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the stream is asynchronously flushed.|
| Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | -------------- |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the stream is asynchronously flushed.|
**Example**
......@@ -2466,16 +2472,16 @@ Writes data into the stream. This API uses a promise to return the result.
**Parameters**
| Name | Type | Mandatory | Description |
| ------- | ------------------------------- | ---- | ---------------------------------------- |
| buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. |
| options | Object | No | The options are as follows:<br>- **length** (number): length of the data to write. The default value is the buffer length.<br>- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.<br>- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.|
| Name | Type | Mandatory | Description |
| ------- | ------------------------------- | ---- | ---------------------------------------- |
| buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. |
| options | Object | No | The options are as follows:<br>- **length** (number): length of the data to write. The default value is the buffer length.<br>- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.<br>- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.|
**Return value**
| Type | Description |
| --------------------- | -------- |
| Promise&lt;number&gt; | Promise used to return the length of the data written.|
| Type | Description |
| --------------------- | -------- |
| Promise&lt;number&gt; | Promise used to return the length of the data written.|
**Example**
......@@ -2500,11 +2506,11 @@ Writes data into the stream. This API uses an asynchronous callback to return th
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------------- | ---- | ------------------------------------------------------------ |
| buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. |
| options | Object | No | The options are as follows:<br>- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.<br>- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.<br>- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.|
| callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked when the data is written asynchronously. |
| Name | Type | Mandatory| Description |
| -------- | ------------------------------- | ---- | ------------------------------------------------------------ |
| buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. |
| options | Object | No | The options are as follows:<br>- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.<br>- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.<br>- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.|
| callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked when the data is written asynchronously. |
**Example**
......@@ -2532,16 +2538,16 @@ Synchronously writes data into the stream.
**Parameters**
| Name | Type | Mandatory | Description |
| ------- | ------------------------------- | ---- | ---------------------------------------- |
| buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. |
| options | Object | No | The options are as follows:<br>- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.<br>- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.<br>- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.|
| Name | Type | Mandatory | Description |
| ------- | ------------------------------- | ---- | ---------------------------------------- |
| buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. |
| options | Object | No | The options are as follows:<br>- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.<br>- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.<br>- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.|
**Return value**
| Type | Description |
| ------ | -------- |
| number | Length of the data written in the file.|
| Type | Description |
| ------ | -------- |
| number | Length of the data written in the file.|
**Example**
......@@ -2561,16 +2567,16 @@ Reads data from the stream. This API uses a promise to return the result.
**Parameters**
| Name | Type | Mandatory | Description |
| ------- | ----------- | ---- | ---------------------------------------- |
| buffer | ArrayBuffer | Yes | Buffer used to store the file read. |
| options | Object | No | The options are as follows:<br>- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length.<br>- **offset** (number): position of the data to read in the file. By default, data is read from the current position.|
| Name | Type | Mandatory | Description |
| ------- | ----------- | ---- | ---------------------------------------- |
| buffer | ArrayBuffer | Yes | Buffer used to store the file read. |
| options | Object | No | The options are as follows:<br>- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length.<br>- **offset** (number): position of the data to read in the file. By default, data is read from the current position.|
**Return value**
| Type | Description |
| ---------------------------------- | ------ |
| Promise&lt;number&gt; | Promise used to return the data read.|
| Type | Description |
| ---------------------------------- | ------ |
| Promise&lt;number&gt; | Promise used to return the data read.|
**Example**
......@@ -2580,7 +2586,7 @@ Reads data from the stream. This API uses a promise to return the result.
let buf = new ArrayBuffer(4096);
ss.read(buf, {offset: 5, length: 5}).then((readLen) => {
console.info("Read data successfully");
console.log(String.fromCharCode.apply(null, new Uint8Array(buf)));
console.log(String.fromCharCode.apply(null, new Uint8Array(buf.slice(0, readLen))));
}).catch((err) => {
console.info("read data failed with error message: " + err.message + ", error code: " + err.code);
});
......@@ -2597,11 +2603,11 @@ Reads data from the stream. This API uses an asynchronous callback to return the
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| buffer | ArrayBuffer | Yes | Buffer used to store the file read. |
| options | Object | No | The options are as follows:<br>- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length.<br>- **offset** (number): position of the data to read in the file. This parameter is optional. By default, data is read from the current position.|
| callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked when data is read asynchronously from the stream. |
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| buffer | ArrayBuffer | Yes | Buffer used to store the file read. |
| options | Object | No | The options are as follows:<br>- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length.<br>- **offset** (number): position of the data to read in the file. This parameter is optional. By default, data is read from the current position.|
| callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked when data is read asynchronously from the stream. |
**Example**
......@@ -2614,7 +2620,7 @@ Reads data from the stream. This API uses an asynchronous callback to return the
console.info("read stream failed with error message: " + err.message + ", error code: " + err.code);
} else {
console.info("Read data successfully");
console.log(String.fromCharCode.apply(null, new Uint8Array(buf)));
console.log(String.fromCharCode.apply(null, new Uint8Array(buf.slice(0, readLen))));
}
});
```
......@@ -2629,16 +2635,16 @@ Synchronously reads data from the stream.
**Parameters**
| Name | Type | Mandatory | Description |
| ------- | ----------- | ---- | ---------------------------------------- |
| buffer | ArrayBuffer | Yes | Buffer used to store the file read. |
| Name | Type | Mandatory | Description |
| ------- | ----------- | ---- | ---------------------------------------- |
| buffer | ArrayBuffer | Yes | Buffer used to store the file read. |
| options | Object | No | The options are as follows:<br>- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length.<br>- **offset** (number): position of the data to read in the file. This parameter is optional. By default, data is read from the current position.<br> |
**Return value**
| Type | Description |
| ------ | -------- |
| number | Length of the data read.|
| Type | Description |
| ------ | -------- |
| number | Length of the data read.|
**Example**
......@@ -2662,7 +2668,7 @@ Represents a **File** object opened by **open()**.
### lock
lock(exclusive?: boolean): Promise<void>;
lock(exclusive?: boolean): Promise\<void>;
Applies an exclusive lock or a shared lock on this file in blocking mode. This API uses a promise to return the result.
......@@ -2670,15 +2676,15 @@ Applies an exclusive lock or a shared lock on this file in blocking mode. This A
**Parameters**
| Name | Type | Mandatory | Description |
| ------- | ----------- | ---- | ---------------------------------------- |
| exclusive | boolean | No | Lock to apply. The value **true** means an exclusive lock, and the value **false** (default) means a shared lock. |
| Name | Type | Mandatory | Description |
| ------- | ----------- | ---- | ---------------------------------------- |
| exclusive | boolean | No | Lock to apply. The value **true** means an exclusive lock, and the value **false** (default) means a shared lock. |
**Return value**
| Type | Description |
| ---------------------------------- | ------ |
| Promise&lt;void&gt; | Promise that returns no value.|
| Type | Description |
| ---------------------------------- | ------ |
| Promise&lt;void&gt; | Promise that returns no value.|
**Example**
......@@ -2693,7 +2699,7 @@ Applies an exclusive lock or a shared lock on this file in blocking mode. This A
### lock
lock(exclusive?: boolean, callback: AsyncCallback<void>): void;
lock(exclusive?: boolean, callback: AsyncCallback\<void>): void;
Applies an exclusive lock or a shared lock on this file in blocking mode. This API uses a promise to return the result.
......@@ -2701,10 +2707,10 @@ Applies an exclusive lock or a shared lock on this file in blocking mode. This A
**Parameters**
| Name | Type | Mandatory | Description |
| ------- | ----------- | ---- | ---------------------------------------- |
| exclusive | boolean | No | Lock to apply. The value **true** means an exclusive lock, and the value **false** (default) means a shared lock. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file is locked. |
| Name | Type | Mandatory | Description |
| ------- | ----------- | ---- | ---------------------------------------- |
| exclusive | boolean | No | Lock to apply. The value **true** means an exclusive lock, and the value **false** (default) means a shared lock. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file is locked. |
**Example**
......@@ -2729,9 +2735,9 @@ Applies an exclusive lock or a shared lock on this file in non-blocking mode.
**Parameters**
| Name | Type | Mandatory | Description |
| ------- | ----------- | ---- | ---------------------------------------- |
| exclusive | boolean | No | Lock to apply. The value **true** means an exclusive lock, and the value **false** (default) means a shared lock. |
| Name | Type | Mandatory | Description |
| ------- | ----------- | ---- | ---------------------------------------- |
| exclusive | boolean | No | Lock to apply. The value **true** means an exclusive lock, and the value **false** (default) means a shared lock. |
**Example**
......@@ -2760,13 +2766,13 @@ Unlocks this file synchronously.
## Watcher<sup>10+</sup>
Provides APIs for file or directory listening. Before using the APIs of **Watcher** , call **createWatcher()** to create a **Watcher** object.
Provides APIs for observing the changes of files or folders. Before using the APIs of **Watcher** , call **createWatcher()** to create a **Watcher** object.
### start<sup>10+</sup>
start(): void
Starts file or directory listening.
Starts listening.
**System API**: This is a system API.
......@@ -2785,7 +2791,7 @@ Starts file or directory listening.
stop(): void
Stops file or directory listening.
Stops listening.
**System API**: This is a system API.
......
......@@ -326,9 +326,9 @@ Checks whether the specified constraint is enabled for an OS account. This API u
| ID| Error Message |
| -------- | ------------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid localId. |
| 12300003 | Account not found. |
| 12300001 | system service exception. |
| 12300002 | invalid localId or constraint. |
| 12300003 | the account indicated by localId dose not exist. |
**Example**: Check whether OS account 100 is forbidden to use Wi-Fi.
......@@ -376,9 +376,9 @@ Checks whether the specified constraint is enabled for an OS account. This API u
| ID| Error Message |
| -------- | ------------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid localId. |
| 12300003 | Account not found. |
| 12300001 | system service exception. |
| 12300002 | invalid localId or constraint. |
| 12300003 | the account indicated by localId dose not exist. |
**Example**: Check whether OS account 100 is forbidden to use Wi-Fi.
......@@ -475,23 +475,19 @@ checkOsAccountVerified(callback: AsyncCallback&lt;boolean&gt;): void
Checks whether this OS account has been verified. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS or ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
**System capability**: SystemCapability.Account.OsAccount
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ---------------------------- | ---- | ------------------------------------------------------------- |
| callback | AsyncCallback&lt;boolean&gt; | Yes | Callback invoked to return the result. The value **true** means the OS account has been verified; the value **false** means the opposite.|
| callback | AsyncCallback&lt;boolean&gt; | Yes | Callback invoked to return the result. If true is returned, the current account has been verified. If false is returned, the current account has not been verified.|
**Error codes**
| ID| Error Message |
| -------- | ------------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid localId. |
| 12300003 | Account not found. |
| 12300001 | system service exception. |
**Example**
......@@ -531,9 +527,9 @@ Checks whether an OS account has been verified. This API uses an asynchronous ca
| ID| Error Message |
| -------- | ------------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid localId. |
| 12300003 | Account not found. |
| 12300001 | system service exception. |
| 12300002 | invalid localId. |
| 12300003 | the account indicated by localId dose not exist. |
**Example**
......@@ -555,7 +551,7 @@ Checks whether an OS account has been verified. This API uses an asynchronous ca
### checkOsAccountVerified<sup>9+</sup>
checkOsAccountVerified(localId?: number): Promise&lt;boolean&gt;
checkOsAccountVerified(localId: number): Promise&lt;boolean&gt;
Checks whether an OS account has been verified. This API uses a promise to return the result.
......@@ -567,7 +563,7 @@ Checks whether an OS account has been verified. This API uses a promise to retur
| Name | Type | Mandatory| Description |
| ------- | ------ | ---- | --------------------------------------------------------------- |
| localId | number | No | ID of the target OS account. If this parameter is not specified, this API checks whether the current OS account has been verified.|
| localId | number | Yes | ID of the target OS account. If this parameter is not specified, this API checks whether the current OS account has been verified.|
**Return value**
......@@ -579,9 +575,9 @@ Checks whether an OS account has been verified. This API uses a promise to retur
| ID| Error Message |
| -------- | ------------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid localId. |
| 12300003 | Account not found. |
| 12300001 | system service exception. |
| 12300002 | invalid localId. |
| 12300003 | the account indicated by localId dose not exist. |
**Example**
......@@ -991,7 +987,7 @@ Obtains the ID of the OS account to which the current process belongs. This API
| ID| Error Message |
| -------- | ------------------- |
| 12300001 | System service exception. |
| 12300001 | system service exception. |
**Example**
......@@ -1028,7 +1024,7 @@ Obtains the ID of the OS account to which the current process belongs. This API
| ID| Error Message |
| -------- | ------------------- |
| 12300001 | System service exception. |
| 12300001 | system service exception. |
**Example**
......@@ -1064,8 +1060,8 @@ Obtains the OS account ID based on the process UID. This API uses an asynchronou
| ID| Error Message |
| -------- | --------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid uid. |
| 12300001 | system service exception. |
| 12300002 | invalid uid. |
**Example**: Obtain the ID of the OS account whose process UID is **12345678**.
......@@ -1108,8 +1104,8 @@ Obtains the OS account ID based on the process UID. This API uses a promise to r
| ID| Error Message |
| -------- | ------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid uid. |
| 12300001 | system service exception. |
| 12300002 | invalid uid. |
**Example**: Obtain the ID of the OS account whose process UID is **12345678**.
......@@ -1148,8 +1144,8 @@ Obtains the OS account ID based on the domain account information. This API uses
| ID| Error Message |
| -------- | ------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid domainInfo. |
| 12300001 | system service exception. |
| 12300002 | invalid domainInfo. |
**Example**
......@@ -1195,8 +1191,8 @@ Obtains the OS account ID based on the domain account information. This API uses
| ID| Error Message |
| -------- | ------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid domainInfo. |
| 12300001 | system service exception. |
| 12300002 | invalid domainInfo. |
**Example**
......@@ -1474,7 +1470,7 @@ Obtains information about all activated OS accounts. This API uses an asynchrono
| ID| Error Message |
| -------- | ------------- |
| 12300001 | System service exception. |
| 12300001 | system service exception. |
**Example**
......@@ -1511,7 +1507,7 @@ Obtains information about all activated OS accounts. This API uses a promise to
| ID| Error Message |
| -------- | ------------- |
| 12300001 | System service exception. |
| 12300001 | system service exception. |
**Example**
......@@ -2233,9 +2229,9 @@ Obtains the OS account ID based on the serial number (SN). This API uses an asyn
| ID| Error Message |
| -------- | ------------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid serialNumber. |
| 12300003 | Account not found. |
| 12300001 | system service exception. |
| 12300002 | invalid serialNumber. |
| 12300003 | the account indicated by serialNumber dose not exist. |
**Example**: Obtain the ID of the OS account whose SN is 12345.
......@@ -2276,9 +2272,9 @@ Obtains the OS account ID based on the SN. This API uses a promise to return the
| ID| Error Message |
| -------- | ------------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid serialNumber. |
| 12300003 | Account not found. |
| 12300001 | system service exception. |
| 12300002 | invalid serialNumber. |
| 12300003 | the account indicated by serialNumber dose not exist. |
**Example**: Obtain the ID of the OS account whose SN is 12345.
......@@ -2315,9 +2311,9 @@ Obtains the SN of an OS account based on the account ID. This API uses an asynch
| ID| Error Message |
| -------- | ------------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid localId. |
| 12300003 | Account not found. |
| 12300001 | system service exception. |
| 12300002 | invalid localId. |
| 12300003 | the account indicated by localId dose not exist. |
**Example**: Obtain the SN of the OS account 100.
......@@ -2358,9 +2354,9 @@ Obtains the SN of an OS account based on the account ID. This API uses a promise
| ID| Error Message |
| -------- | ------------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid localId. |
| 12300003 | Account not found. |
| 12300001 | system service exception. |
| 12300002 | invalid localId. |
| 12300003 | the account indicated by localId dose not exist. |
**Example**: Obtain the SN of the OS account 100.
......@@ -2483,8 +2479,8 @@ Obtains the bundle ID based on the UID. This API uses an asynchronous callback t
| ID| Error Message |
| -------- | ------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid uid. |
| 12300001 | system service exception. |
| 12300002 | invalid uid. |
**Example**
......@@ -2526,8 +2522,8 @@ Obtains the bundle ID based on the UID. This API uses a promise to return the re
| ID| Error Message |
| -------- | ------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid uid. |
| 12300001 | system service exception. |
| 12300002 | invalid uid. |
**Example**
......@@ -2644,9 +2640,9 @@ Obtains the constraint source information of an OS account. This API uses an asy
| ID| Error Message |
| -------- | ------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid localId or constraint. |
| 12300003 | Account not found. |
| 12300001 | system service exception. |
| 12300002 | invalid name or constraint. |
| 12300003 | the account indicated by localId dose not exist. |
**Example**
......@@ -2691,9 +2687,9 @@ Obtains the constraint source information of an OS account. This API uses a prom
| ID| Error Message |
| -------- | ------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid localId or constraint. |
| 12300003 | Account not found. |
| 12300001 | system service exception. |
| 12300002 | invalid name or constraint. |
| 12300003 | the account indicated by localId dose not exist. |
**Example**
......@@ -4433,15 +4429,26 @@ Authenticates a domain account.
**Example**
```js
let plugin = {
auth: (domainInfo, credential, callback) => {
auth: (domainAccountInfo, credential, callback) => {
// mock authentication
callback.onResult(0, {});
}
// notify authentication result
callback.onResult(0, {
token: new Uint8Array([0]),
remainTimes: 5,
freezingTime: 0
});
},
authWithPopup: (domainAccountInfo, callback) => {},
authWithToken: (domainAccountInfo, callback) => {},
getAccountInfo: (domain, accountName, callback) => {},
getAuthStatusInfo: (domainAccountInfo, callback) => {},
bindAccount: (domainAccountInfo, localId, callback) => {},
unbindAccount: (domainAccountInfo, callback) => {}
}
account_osAccount.DomainAccountManager.registerPlugin(plugin);
let userAuth = new account_osAccount.UserAuth();
let challenge = new Uint8Array([0]);
let authType = account_osAccount.AuthType.PIN;
let authType = account_osAccount.AuthType.DOMAIN;
let authTrustLevel = account_osAccount.AuthTrustLevel.ATL1;
try {
userAuth.auth(challenge, authType, authTrustLevel, {
......@@ -4455,6 +4462,235 @@ Authenticates a domain account.
}
```
### authWithPopup<sup>10+</sup>
authWithPopup(domainAccountInfo: DomainAccountInfo, callback: IUserAuthCallback): void
Authenticates a domain account in a pop-up window.
**System API**: This is a system API.
**System capability**: SystemCapability.Account.OsAccount
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | --------------------------------------- | ---- | --------------- |
| domainAccountInfo | [DomainAccountInfo](#domainaccountinfo8) | Yes | Domain account information.|
| callback | [IUserAuthCallback](#iuserauthcallback8) | Yes | Callback invoked to return the authentication result.|
**Example**
```js
let plugin = {
auth: (domainAccountInfo, credential, callback) => {},
authWithPopup: (domainAccountInfo, callback) => {
// mock authentication
// notify authentication result
callback.onResult(0, {
token: new Uint8Array([0]),
remainTimes: 5,
freezingTime: 0
});
},
authWithToken: (domainAccountInfo, callback) => {},
getAccountInfo: (domain, accountName, callback) => {},
getAuthStatusInfo: (domainAccountInfo, callback) => {},
bindAccount: (domainAccountInfo, localId, callback) => {},
unbindAccount: (domainAccountInfo, callback) => {}
}
account_osAccount.DomainAccountManager.registerPlugin(plugin)
```
### authWithToken<sup>10+</sup>
authWithToken(domainAccountInfo: DomainAccountInfo, token: Uint8Array, callback: IUserAuthCallback): void
Authenticates a domain account by the authorization token.
**System API**: This is a system API.
**System capability**: SystemCapability.Account.OsAccount
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | --------------------------------------- | ---- | --------------- |
| domainAccountInfo | [DomainAccountInfo](#domainaccountinfo8) | Yes | Domain account information.|
| token | Uint8Array | Yes | Authorization token generated when the PIN or biometric authentication is successful.|
| callback | [IUserAuthCallback](#iuserauthcallback8) | Yes | Callback invoked to return the authentication result.|
**Example**
```js
let plugin = {
auth: (domainAccountInfo, credential, callback) => {},
authWithPopup: (domainAccountInfo, callback) => {},
authWithToken: (domainAccountInfo, callback) => {
// mock authentication
// notify authentication result
callback.onResult(0, {
token: new Uint8Array([0]),
remainTimes: 5,
freezingTime: 0
});
},
getAccountInfo: (domain, accountName, callback) => {},
getAuthStatusInfo: (domainAccountInfo, callback) => {},
bindAccount: (domainAccountInfo, localId, callback) => {},
unbindAccount: (domainAccountInfo, callback) => {}
}
account_osAccount.DomainAccountManager.registerPlugin(plugin)
```
### getAccountInfo<sup>10+</sup>
getAccountInfo(domain: string, accountName: string, callback: AsyncCallback&lt;DomainAccountInfo&gt;): void
Obtains information about a domain account.
**System API**: This is a system API.
**System capability**: SystemCapability.Account.OsAccount
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | --------------------------------------- | ---- | --------------- |
| domain | string | Yes | Domain to which the account belongs.|
| accountName | string | Yes | Name of the account.|
| callback | AsyncCallback&lt;[DomainAccountInfo](#domainaccountinfo8)&gt; | Yes | Callback invoked to return the result.|
**Example**
```js
let plugin = {
auth: (domainAccountInfo, credential, callback) => {},
authWithPopup: (domainAccountInfo, callback) => {},
authWithToken: (domainAccountInfo, callback) => {},
getAccountInfo: (domain, accountName, callback) => {
// mock getting account information
// notify result
callback({
code: 0
}, {
domain: domain,
accountName: accountName,
accountId: "xxxx"
})
},
getAuthStatusInfo: (domainAccountInfo, callback) => {},
bindAccount: (domainAccountInfo, localId, callback) => {},
unbindAccount: (domainAccountInfo, callback) => {}
}
account_osAccount.DomainAccountManager.registerPlugin(plugin)
```
### getAuthStatusInfo<sup>10+</sup>
getAuthStatusInfo(domainAccountInfo: DomainAccountInfo, callback: AsyncCallback&lt;AuthStatusInfo&gt;): void
Obtains the authentication status of a domain account.
**System API**: This is a system API.
**System capability**: SystemCapability.Account.OsAccount
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | --------------------------------------- | ---- | --------------- |
| domainAccountInfo | [DomainAccountInfo](#domainaccountinfo8) | Yes | Domain account information.|
| callback | AsyncCallback&lt;[AuthStatusInfo](#authstatusinfo10)&gt; | Yes | Callback invoked to return the result.|
**Example**
```js
let plugin = {
auth: (domainAccountInfo, credential, callback) => {},
authWithPopup: (domainAccountInfo, callback) => {},
authWithToken: (domainAccountInfo, callback) => {},
getAccountInfo: (domain, accountName, callback) => {},
getAuthStatusInfo: (domainAccountInfo, callback) => {
callback({
code: 0
}, {
remainTimes: 5,
freezingTime: 0
})
},
bindAccount: (domainAccountInfo, localId, callback) => {},
unbindAccount: (domainAccountInfo, callback) => {}
}
account_osAccount.DomainAccountManager.registerPlugin(plugin)
```
### bindAccount<sup>10+</sup>
bindAccount(domainAccountInfo: DomainAccountInfo, localId: number, callback: AsyncCallback&lt;void&gt;): void
Binds a domain account.
**System API**: This is a system API.
**System capability**: SystemCapability.Account.OsAccount
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | --------------------------------------- | ---- | --------------- |
| domainAccountInfo | [DomainAccountInfo](#domainaccountinfo8) | Yes | Domain account information.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result.|
**Example**
```js
let plugin = {
auth: (domainAccountInfo, credential, callback) => {},
authWithPopup: (domainAccountInfo, callback) => {},
authWithToken: (domainAccountInfo, callback) => {},
getAccountInfo: (domain, accountName, callback) => {},
getAuthStatusInfo: (domainAccountInfo, callback) => {},
bindAccount: (domainAccountInfo, localId, callback) => {
// mock unbinding operation
// notify binding result
callback({code: 0})
},
unbindAccount: (domainAccountInfo, callback) => {}
}
account_osAccount.DomainAccountManager.registerPlugin(plugin)
```
### unbindAccount<sup>10+</sup>
unbindAccount(domainAccountInfo: DomainAccountInfo, callback: AsyncCallback&lt;void&gt;): void
Unbinds a domain account.
**System API**: This is a system API.
**System capability**: SystemCapability.Account.OsAccount
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | --------------------------------------- | ---- | --------------- |
| domainAccountInfo | [DomainAccountInfo](#domainaccountinfo8) | Yes | Domain account information.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result.|
**Example**
```js
let plugin = {
auth: (domainAccountInfo, credential, callback) => {},
authWithPopup: (domainAccountInfo, callback) => {},
authWithToken: (domainAccountInfo, callback) => {},
getAccountInfo: (domain, accountName, callback) => {},
getAuthStatusInfo: (domainAccountInfo, callback) => {},
bindAccount: (domainAccountInfo, localId, callback) => {},
unbindAccount: (domainAccountInfo, callback) => {
// mock unbinding operation
// notify unbinding result
callback({code: 0})
}
}
account_osAccount.DomainAccountManager.registerPlugin(plugin)
```
## DomainAccountManager <sup>9+</sup>
Provides APIs for domain account management.
......@@ -4480,15 +4716,18 @@ Registers a domain plug-in.
| ID| Error Message |
| -------- | --------------------------- |
| 12300201 | The domain plugin has been registered. |
| 12300201 | the domain plugin has been registered. |
**Example**
```js
let plugin = {
auth: (domainInfo, credential, callback) => {
// mock authentication
callback.onResult(0, {});
}
auth: (domainAccountInfo, credential, callback) => {},
authWithPopup: (domainAccountInfo, callback) => {},
authWithToken: (domainAccountInfo, callback) => {},
getAccountInfo: (domain, accountName, callback) => {},
getAuthStatusInfo: (domainAccountInfo, callback) => {},
bindAccount: (domainAccountInfo, localId, callback) => {},
unbindAccount: (domainAccountInfo, callback) => {}
}
try {
account_osAccount.DomainAccountManager.registerPlugin(plugin);
......@@ -4520,6 +4759,252 @@ Unregisters this domain plug-in.
}
```
### auth<sup>10+</sup>
auth(domainAccountInfo: DomainAccountInfo, credential: Uint8Array, callback: IUserAuthCallback): void
Authenticates a domain account.
**System API**: This is a system API.
**System capability**: SystemCapability.Account.OsAccount
**Required permissions**: ohos.permission.ACCESS_USER_AUTH_INTERNAL
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | --------------------------------------- | ---- | --------------- |
| domainAccountInfo | [DomainAccountInfo](#domainaccountinfo8) | Yes | Domain account information.|
| credential | Uint8Array | Yes | Credentials of the domain account.|
| callback | [IUserAuthCallback](#iuserauthcallback8) | Yes | Callback invoked to return the authentication result.|
**Error codes**
| ID| Error Message |
| -------- | --------------------------- |
| 12300001 | system service exception. |
| 12300002 | invalid domainAccountInfo or credential. |
| 12300003 | domain account does not exist. |
| 12300013 | network exception. |
| 12300101 | authentication failed. |
| 12300109 | authentication is canceled. |
| 12300110 | authentication is locked. |
| 12300111 | authentication timeout. |
| 12300112 | authentication service is busy. |
| 12300113 | authentication service does not exist. |
| 12300114 | authentication service exception. |
**Example**
```js
let domainAccountInfo = {
domain: "CHINA",
accountName: "zhangsan"
}
let credential = new Uint8Array([0])
try {
account_osAccount.DomainAccountManager.auth(domainAccountInfo, credential, {
onResult: (resultCode, authResult) => {
console.log('auth resultCode = ' + resultCode);
console.log('auth authResult = ' + JSON.stringify(authResult));
}
});
} catch (err) {
console.log('auth exception = ' + JSON.stringify(err));
}
```
### authWithPopup<sup>10+</sup>
authWithPopup(callback: IUserAuthCallback): void
Authenticates this domain account in a pop-up window.
**System API**: This is a system API.
**System capability**: SystemCapability.Account.OsAccount
**Required permissions**: ohos.permission.ACCESS_USER_AUTH_INTERNAL
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | --------------------------------------- | ---- | --------------- |
| callback | [IUserAuthCallback](#iuserauthcallback8) | Yes | Callback invoked to return the authentication result.|
**Error codes**
| ID| Error Message |
| -------- | --------------------------- |
| 12300001 | system service exception. |
| 12300003 | no domain account is bound. |
| 12300013 | network exception. |
| 12300101 | authentication failed. |
| 12300109 | authentication is canceled. |
| 12300110 | authentication is locked. |
| 12300111 | authentication timeout. |
| 12300112 | authentication service is busy. |
| 12300113 | authentication service does not exist. |
| 12300114 | authentication service exception. |
**Example**
```js
try {
account_osAccount.DomainAccountManager.authWithPopup({
onResult: (resultCode, authResult) => {
console.log('auth resultCode = ' + resultCode);
console.log('auth authResult = ' + JSON.stringify(authResult));
}
})
} catch (err) {
console.log('auth exception = ' + JSON.stringify(err));
}
```
### authWithPopup<sup>10+</sup>
authWithPopup(localId: number, callback: IUserAuthCallback): void
Authenticates a domain account in a pop-up window.
**System API**: This is a system API.
**System capability**: SystemCapability.Account.OsAccount
**Required permissions**: ohos.permission.ACCESS_USER_AUTH_INTERNAL
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | --------------------------------------- | ---- | --------------- |
| localId | number | Yes | Local ID of the OS account bound to the domain account.|
| callback | [IUserAuthCallback](#iuserauthcallback8) | Yes | Callback invoked to return the authentication result.|
**Error codes**
| ID| Error Message |
| -------- | --------------------------- |
| 12300001 | system service exception. |
| 12300002 | invalid localId. |
| 12300003 | no domain account is bound. |
| 12300013 | network exception. |
| 12300101 | authentication failed. |
| 12300109 | authentication is canceled. |
| 12300110 | authentication is locked. |
| 12300111 | authentication timeout. |
| 12300112 | authentication service is busy. |
| 12300113 | authentication service does not exist. |
| 12300114 | authentication service exception. |
**Example**
```js
try {
account_osAccount.DomainAccountManager.authWithPopup(100, {
onResult: (resultCode, authResult) => {
console.log('authWithPopup resultCode = ' + resultCode);
console.log('authWithPopup authResult = ' + JSON.stringify(authResult));
}
})
} catch (err) {
console.log('authWithPopup exception = ' + JSON.stringify(err));
}
```
### hasAccount<sup>10+</sup>
hasAccount(domainAccountInfo: DomainAccountInfo, callback: AsyncCallback&lt;boolean&gt;): void
Checks whether a domain account exists.
**System API**: This is a system API.
**System capability**: SystemCapability.Account.OsAccount
**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | --------------------------------------- | ---- | --------------- |
| domainAccountInfo | [DomainAccountInfo](#domainaccountinfo8) | Yes | Domain account information.|
| callback | AsyncCallback&lt;boolean&gt; | Yes | Callback invoked to return the result.|
**Error codes**
| ID| Error Message |
| -------- | --------------------------- |
| 12300001 | system service exception. |
| 12300002 | invalid domainAccountInfo. |
| 12300013 | network exception. |
**Example**
```js
let domainAccountInfo = {
domain: "CHINA",
accountName: "zhangsan"
}
try {
account_osAccount.DomainAccountManager.hasAccount(domainAccountInfo, (err, result) => {
if (err) {
console.log("call hasAccount failed, error: " + JSON.stringify(err));
} else {
console.log("hasAccount result: " + result);
}
});
} catch (err) {
console.log('hasAccount exception = ' + JSON.stringify(err));
}
```
### hasAccount<sup>10+</sup>
hasAccount(domainAccountInfo: DomainAccountInfo): Promise&lt;boolean&gt;
Checks whether a domain account exists.
**System API**: This is a system API.
**System capability**: SystemCapability.Account.OsAccount
**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | --------------------------------------- | ---- | --------------- |
| domainAccountInfo | [DomainAccountInfo](#domainaccountinfo8) | Yes | Domain account information.|
**Return value**
| Type | Description |
| :------------------------ | ----------------------- |
| Promise&lt;boolean&gt; | Promise used to return the result.|
**Error codes**
| ID| Error Message |
| -------- | --------------------------- |
| 12300001 | system service exception. |
| 12300002 | invalid domainAccountInfo. |
| 12300013 | network exception. |
**Example**
```js
let domainAccountInfo = {
domain: "CHINA",
accountName: "zhangsan"
}
try {
account_osAccount.DomainAccountManager.hasAccount(domainAccountInfo).then((result) => {
console.log("hasAccount result: " + result);
}).catch((err) => {
console.log("call hasAccount failed, error: " + JSON.stringify(err));
});
} catch (err) {
console.log('hasAccount exception = ' + JSON.stringify(err));
}
```
## UserIdentityManager<sup>8+</sup>
Provides APIs for user identity management (IDM).
......@@ -5254,7 +5739,7 @@ Defines the executor property.
| ------------ | ---------------------------------------- | ----- | ----------------- |
| result | number | Yes | Result. |
| authSubType | [AuthSubType](#authsubtype8) | Yes | Authentication credential subtype.|
| remainTimes | number | No | Remaining time. |
| remainTimes | number | No | Number of remaining authentication times. |
| freezingTime | number | No | Freezing time. |
## AuthResult<sup>8+</sup>
......@@ -5268,7 +5753,7 @@ Defines the authentication result information.
| Name | Type | Mandatory | Description |
| ------------ | ----------- | ----- | ----------------- |
| token | Uint8Array | No | Authentication token. |
| remainTimes | number | No | Remaining time. |
| remainTimes | number | No | Number of remaining authentication times. |
| freezingTime | number | No | Freezing time. |
## CredentialInfo<sup>8+</sup>
......@@ -5351,7 +5836,7 @@ Enumerates the authentication credential types.
| PIN | 1 | PIN authentication.|
| FACE | 2 | Facial authentication.|
| FINGERPRINT<sup>10+</sup> | 4 | Fingerprint authentication.|
| DOMAIN<sup>10+</sup> | 1024 | Domain authentication.|
| DOMAIN<sup>9+</sup> | 1024 | Domain authentication.|
## AuthSubType<sup>8+</sup>
......@@ -5368,7 +5853,7 @@ Enumerates the authentication credential subtypes.
| PIN_MIXED | 10002 | Custom mixed credentials.|
| FACE_2D | 20000 | 2D face credential. |
| FACE_3D | 20001 | 3D face credential. |
| DOMAIN_MIXED<sup>10+</sup> | 10240001 | Mixed domain authentication credentials. |
| DOMAIN_MIXED<sup>9+</sup> | 10240001 | Mixed domain authentication credentials. |
## AuthTrustLevel<sup>8+</sup>
......@@ -5490,6 +5975,7 @@ Defines the domain account information.
| ----------- | ------ | ---- | ---------- |
| domain | string | Yes | Domain name. |
| accountName | string | Yes | Domain account name.|
| accountId<sup>10+</sup> | string | No | Domain account ID.|
## Constraints
......@@ -5586,3 +6072,16 @@ Enumerates the constraint sources.
| CONSTRAINT_TYPE_BASE | 1 | Constraint from system settings. |
| CONSTRAINT_TYPE_DEVICE_OWNER | 2 | Constraint from the device owners' settings. |
| CONSTRAINT_TYPE_PROFILE_OWNER | 3 | Constraint from the profile owners' settings. |
## AuthStatusInfo<sup>10+</sup>
Presents the authentication status information.
**System API**: This is a system API.
**System capability**: SystemCapability.Account.OsAccount
| Name | Type | Mandatory| Description |
| ----------- | ------ | ---- | ---------- |
| remainTimes | number | Yes | Number of remaining authentication times. |
| freezingTime | number | Yes | Freezing time.|
因为 它太大了无法显示 source diff 。你可以改为 查看blob
......@@ -16,7 +16,7 @@ import systemcapability from '@ohos.systemCapability'
## systemcapability.querySystemCapabilities
querySystemCapabilities(callback: AsyncCallback<string>): void;
querySystemCapabilities(callback: AsyncCallback&lt;string&gt;): void;
Queries system capabilities. This API uses an asynchronous callback to return the result.
......@@ -51,7 +51,7 @@ querySystemCapabilities(): Promise&lt;string&gt;
Queries system capabilities. This API uses a promise to return the result.
**System capability**: SystemCapability.Startup.SystemInfo
**System capability**: SystemCapability.Developtools.Syscap
**Return value**
......@@ -76,4 +76,5 @@ try {
> **NOTE**
> - The system capabilities returned by the preceding APIs are in the form of an encoded numeric string.
>
> The system capabilities returned by the preceding APIs are in the form of an encoded numeric string.
......@@ -127,7 +127,7 @@ Obtains the scan result. This API uses a promise to return the result.
| **Type**| **Description**|
| -------- | -------- |
| Promise&lt;&nbsp;Array&lt;[WifiScanInfo](#wifiscaninfo)&gt;&nbsp;&gt; | Promise used to return the detected hotspots.|
| Promise&lt;&nbsp;Array&lt;[WifiScanInfo](#wifiscaninfo)&gt;&nbsp;&gt; | Promise used to return the hotspots detected.|
**Error codes**
......@@ -409,6 +409,8 @@ Represents EAP configuration information.
| caCertAliases | string | Yes| No| CA certificate alias.|
| caPath | string | Yes| No| CA certificate path.|
| clientCertAliases | string | Yes| No| Client certificate alias.|
| certEntry | Uint8Array | Yes| Yes| CA certificate content.|
| certPassword | string | Yes| Yes| CA certificate password.|
| altSubjectMatch | string | Yes| No| A string to match the alternate subject.|
| domainSuffixMatch | string | Yes| No| A string to match the domain suffix.|
| realm | string | Yes| No| Realm for the passpoint credential.|
......
......@@ -2,8 +2,9 @@
This **wifiext** module provides WLAN extension interfaces for non-universal products.
> **NOTE**
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
The APIs described in this document are used only for non-universal products, such as routers.
>
> - The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> - The APIs described in this document are used only for non-universal products, such as routers.
## Modules to Import
......@@ -12,9 +13,9 @@ The APIs described in this document are used only for non-universal products, su
import wifiManagerExt from '@ohos.wifiManagerExt';
```
## wifiext.enableHotspot
## wifiext.enableHotspot<sup>9+</sup>
enableHotspot(): boolean;
enableHotspot(): void;
Enables the WLAN hotspot.
......@@ -27,12 +28,12 @@ Enables the WLAN hotspot.
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**|
| -------- | -------- |
| -------- | -------- |
| 2701000 | Operation failed.|
## wifiext.disableHotspot
## wifiext.disableHotspot<sup>9+</sup>
disableHotspot(): boolean;
disableHotspot(): void;
Disables the WLAN hotspot.
......@@ -45,14 +46,14 @@ Disables the WLAN hotspot.
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**|
| -------- | -------- |
| -------- | -------- |
| 2701000 | Operation failed.|
## wifiext.getSupportedPowerModel
## wifiext.getSupportedPowerMode<sup>9+</sup>
getSupportedPowerModel(): Promise&lt;Array&lt;PowerModel&gt;&gt;
getSupportedPowerMode(): Promise&lt;Array&lt;PowerMode&gt;&gt;
Obtains the supported power models. This API uses a promise to return the result.
Obtains the supported power modes. This API uses a promise to return the result.
**Required permissions**: ohos.permission.GET_WIFI_INFO
......@@ -60,21 +61,21 @@ Obtains the supported power models. This API uses a promise to return the result
**Return value**
| Type| Description|
| -------- | -------- |
| Promise&lt;Array&lt;[PowerModel](#powermodel)&gt;&gt; | Promise used to return the power models obtained.|
| Type| Description|
| -------- | -------- |
| Promise&lt;Array&lt;[PowerMode](#powermode)&gt;&gt; | Promise used to return the power modes obtained.|
**Error codes**
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**|
| -------- | -------- |
| -------- | -------- |
| 2701000 | Operation failed.|
## PowerModel
## PowerMode
Enumerates the power models.
Enumerates the power modes.
**System capability**: SystemCapability.Communication.WiFi.AP.Extension
......@@ -85,11 +86,11 @@ Enumerates the power models.
| THROUGH_WALL | 2 | Through_wall|
## wifiext.getSupportedPowerModel
## wifiext.getSupportedPowerMode<sup>9+</sup>
getSupportedPowerModel(callback: AsyncCallback&lt;Array&lt;PowerModel&gt;&gt;): void
getSupportedPowerMode(callback: AsyncCallback&lt;Array&lt;PowerMode&gt;&gt;): void
Obtains the supported power models. This API uses an asynchronous callback to return the result.
Obtains the supported power modes. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.GET_WIFI_INFO
......@@ -97,23 +98,23 @@ Obtains the supported power models. This API uses an asynchronous callback to re
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;Array&lt;[PowerModel](#powermodel)&gt;&gt; | Yes| Callback invoked to return the result. If the operation is successful, **err** is **0** and **data** is the power models obtained. If **err** is not **0**, an error has occurred.|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;Array&lt;[PowerMode](#powermode)&gt;&gt; | Yes| Callback invoked to return the result. If the operation is successful, **err** is **0** and **data** is the power modes obtained. If **err** is not **0**, an error has occurred.|
**Error codes**
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**|
| -------- | -------- |
| -------- | -------- |
| 2701000 | Operation failed.|
## wifiext.getPowerModel
## wifiext.getPowerMode<sup>9+</sup>
getPowerModel(): Promise&lt;PowerModel&gt;
getPowerMode(): Promise&lt;PowerMode&gt;
Obtains the power model. This API uses a promise to return the result.
Obtains the power mode. This API uses a promise to return the result.
**Required permissions**: ohos.permission.GET_WIFI_INFO
......@@ -121,23 +122,23 @@ Obtains the power model. This API uses a promise to return the result.
**Return value**
| Type| Description|
| -------- | -------- |
| Promise&lt;[PowerModel](#powermodel)&gt; | Promise used to return the power models obtained.|
| Type| Description|
| -------- | -------- |
| Promise&lt;[PowerMode](#powermode)&gt; | Promise used to return the power modes obtained.|
**Error codes**
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**|
| -------- | -------- |
| -------- | -------- |
| 2701000 | Operation failed.|
## wifiext.getPowerModel
## wifiext.getPowerMode<sup>9+</sup>
getPowerModel(callback: AsyncCallback&lt;PowerModel&gt;): void
getPowerMode(callback: AsyncCallback&lt;PowerMode&gt;): void
Obtains the power model. This API uses an asynchronous callback to return the result.
Obtains the power mode. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.GET_WIFI_INFO
......@@ -145,23 +146,23 @@ Obtains the power model. This API uses an asynchronous callback to return the re
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;[PowerModel](#powermodel)&gt; | Yes| Callback invoked to return the result. If the operation is successful, **err** is **0** and **data** is the power model obtained. If **err** is not **0**, an error has occurred.|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;[PowerMode](#powermode)&gt; | Yes| Callback invoked to return the result. If the operation is successful, **err** is **0** and **data** is the power mode obtained. If **err** is not **0**, an error has occurred.|
**Error codes**
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**|
| -------- | -------- |
| -------- | -------- |
| 2701000 | Operation failed.|
## wifiext.setPowerModel
## wifiext.setPowerMode<sup>9+</sup>
setPowerModel(model: PowerModel) : boolean;
setPowerMode(model: PowerMode) : boolean;
Sets the power model.
Sets the power mode.
**Required permissions**: ohos.permission.MANAGE_WIFI_HOTSPOT_EXT
......@@ -169,14 +170,14 @@ setPowerModel(model: PowerModel) : boolean;
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| model | [PowerModel](#powermodel) | Yes| Power model to set.|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| model | [PowerMode](#powermode) | Yes| Power mode to set.|
**Error codes**
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**|
| -------- | -------- |
| -------- | -------- |
| 2701000 | Operation failed.|
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册