提交 de42efee 编写于 作者: A Annie_wang

update docs

Signed-off-by: NAnnie_wang <annie.wangli@huawei.com>
上级 0228ed86
...@@ -2,7 +2,8 @@ ...@@ -2,7 +2,8 @@
The **fs** module provides APIs for file operations, including basic file management, directory management, file information statistics, and data read and write using a stream. The **fs** module provides APIs for file operations, including basic file management, directory management, file information statistics, and data read and write using a stream.
> **NOTE**<br> > **NOTE**
>
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import ## Modules to Import
...@@ -11,10 +12,6 @@ The **fs** module provides APIs for file operations, including basic file manage ...@@ -11,10 +12,6 @@ The **fs** module provides APIs for file operations, including basic file manage
import fs from '@ohos.file.fs'; import fs from '@ohos.file.fs';
``` ```
## Error Code Description
The APIs of this module supports processing of error codes. For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
## Guidelines ## Guidelines
Before using the APIs provided by this module to perform operations on a file or folder, obtain the application sandbox path of the file or folder as follows: Before using the APIs provided by this module to perform operations on a file or folder, obtain the application sandbox path of the file or folder as follows:
...@@ -61,9 +58,13 @@ Obtains detailed file information. This API uses a promise to return the result. ...@@ -61,9 +58,13 @@ Obtains detailed file information. This API uses a promise to return the result.
**Return value** **Return value**
| Type | Description | | Type | Description |
| ---------------------------- | ---------- | | ---------------------------- | ---------- |
| Promise&lt;[Stat](#stat)&gt; | Promise used to return the file information obtained.| | Promise&lt;[Stat](#stat)&gt; | Promise used to return the file information obtained.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
...@@ -91,6 +92,10 @@ Obtains detailed file information. This API uses an asynchronous callback to ret ...@@ -91,6 +92,10 @@ Obtains detailed file information. This API uses an asynchronous callback to ret
| file | string\|number | Yes | Application sandbox path or FD of the file. | | file | string\|number | Yes | Application sandbox path or FD of the file. |
| callback | AsyncCallback&lt;[Stat](#stat)&gt; | Yes | Callback invoked to return the file information obtained.| | callback | AsyncCallback&lt;[Stat](#stat)&gt; | Yes | Callback invoked to return the file information obtained.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
```js ```js
...@@ -117,12 +122,15 @@ Obtains detailed file information synchronously. ...@@ -117,12 +122,15 @@ Obtains detailed file information synchronously.
| ------ | ------ | ---- | -------------------------- | | ------ | ------ | ---- | -------------------------- |
| file | string\|number | Yes | Application sandbox path or FD of the file.| | file | string\|number | Yes | Application sandbox path or FD of the file.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------- | ---------- | | ------------- | ---------- |
| [Stat](#stat) | File information obtained.| | [Stat](#stat) | File information obtained.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
...@@ -147,9 +155,13 @@ Checks whether a file exists. This API uses a promise to return the result. ...@@ -147,9 +155,13 @@ Checks whether a file exists. This API uses a promise to return the result.
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;boolean&gt; | Promise used to return the result. The value **true** means the file exists; the value **false** means the opposite.| | Promise&lt;boolean&gt; | Promise used to return the result. The value **true** means the file exists; the value false means the opposite.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
...@@ -164,7 +176,6 @@ Checks whether a file exists. This API uses a promise to return the result. ...@@ -164,7 +176,6 @@ Checks whether a file exists. This API uses a promise to return the result.
}); });
``` ```
## fs.access ## fs.access
access(path: string, callback: AsyncCallback&lt;boolean&gt;): void access(path: string, callback: AsyncCallback&lt;boolean&gt;): void
...@@ -178,7 +189,11 @@ Checks whether a file exists. This API uses an asynchronous callback to return t ...@@ -178,7 +189,11 @@ Checks whether a file exists. This API uses an asynchronous callback to return t
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ------------------------------------------------------------ | | -------- | ------------------------- | ---- | ------------------------------------------------------------ |
| path | string | Yes | Application sandbox path of the file. | | path | string | Yes | Application sandbox path of the file. |
| callback | AsyncCallback&lt;boolean&gt; | Yes | Callback invoked to return the result. | | callback | AsyncCallback&lt;boolean&gt; | Yes | Callback invoked to return the result. The value **true** means the file exists; the value **false** means the opposite.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
...@@ -211,9 +226,13 @@ Synchronously checks whether a file exists. ...@@ -211,9 +226,13 @@ Synchronously checks whether a file exists.
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| boolean | Returns **true** if the file exists; returns **false** otherwise.| | boolean | Returns **true** if the file exists; returns **false** otherwise.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
...@@ -240,15 +259,19 @@ Closes a file. This API uses a promise to return the result. ...@@ -240,15 +259,19 @@ Closes a file. This API uses a promise to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ------------ | | ---- | ------ | ---- | ------------ |
| file | [File](#file)\|number | Yes | File object or FD of the file to close.| | file | [File](#file)\|number | Yes | File object or FD of the file to close.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.| | Promise&lt;void&gt; | Promise that returns no value.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
...@@ -273,10 +296,14 @@ Closes a file. This API uses an asynchronous callback to return the result. ...@@ -273,10 +296,14 @@ Closes a file. This API uses an asynchronous callback to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | ------------ | | -------- | ------------------------- | ---- | ------------ |
| file | [File](#file)\|number | Yes | File object or FD of the file to close.| | 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.| | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file is closed asynchronously.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
...@@ -302,9 +329,13 @@ Synchronously closes a file. ...@@ -302,9 +329,13 @@ Synchronously closes a file.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ------------ | | ---- | ------ | ---- | ------------ |
| file | [File](#file)\|number | Yes | File object or FD of the file to close.| | file | [File](#file)\|number | Yes | File object or FD of the file to close.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
...@@ -324,17 +355,21 @@ Copies a file. This API uses a promise to return the result. ...@@ -324,17 +355,21 @@ Copies a file. This API uses a promise to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | -------------------------- | ---- | ---------------------------------------- | | ---- | -------------------------- | ---- | ---------------------------------------- |
| src | string\|number | Yes | Path or FD of the file to copy. | | src | string\|number | Yes | Path or FD of the file to copy. |
| dest | string\|number | Yes | Destination path of the file or FD of the file created. | | dest | string\|number | Yes | Destination path of the file or FD of the file created. |
| mode | number | No | Whether to overwrite the file of the same name in the destination path. The default value is **0**, which is the only value supported.<br>**0**: overwrite the file of the same name.| | mode | number | No | Whether to overwrite the file of the same name in the destination path. The default value is **0**, which is the only value supported.<br>**0**: overwrite the file of the same name.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.| | Promise&lt;void&gt; | Promise that returns no value.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
...@@ -358,12 +393,16 @@ Copies a file. This API uses an asynchronous callback to return the result. ...@@ -358,12 +393,16 @@ Copies a file. This API uses an asynchronous callback to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | -------------------------- | ---- | ---------------------------------------- | | -------- | -------------------------- | ---- | ---------------------------------------- |
| src | string\|number | Yes | Path or FD of the file to copy. | | src | string\|number | Yes | Path or FD of the file to copy. |
| dest | string\|number | Yes | Destination path of the file or FD of the file created. | | dest | string\|number | Yes | Destination path of the file or FD of the file created. |
| mode | number | No | Whether to overwrite the file of the same name in the destination path. The default value is **0**, which is the only value supported.<br>**0**: overwrite the file with the same name and truncate the part that is not overwritten.| | mode | number | No | Whether to overwrite the file of the same name in the destination path. The default value is **0**, which is the only value supported.<br>**0**: overwrite the file with the same name and truncate the part that is not overwritten.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file is copied asynchronously. | | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file is copied asynchronously. |
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
...@@ -390,11 +429,15 @@ Synchronously copies a file. ...@@ -390,11 +429,15 @@ Synchronously copies a file.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | -------------------------- | ---- | ---------------------------------------- | | ---- | -------------------------- | ---- | ---------------------------------------- |
| src | string\|number | Yes | Path or FD of the file to copy. | | src | string\|number | Yes | Path or FD of the file to copy. |
| dest | string\|number | Yes | Destination path of the file or FD of the file created. | | dest | string\|number | Yes | Destination path of the file or FD of the file created. |
| mode | number | No | Whether to overwrite the file of the same name in the destination path. The default value is **0**, which is the only value supported.<br>**0**: overwrite the file with the same name and truncate the part that is not overwritten.| | mode | number | No | Whether to overwrite the file of the same name in the destination path. The default value is **0**, which is the only value supported.<br>**0**: overwrite the file with the same name and truncate the part that is not overwritten.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
...@@ -404,7 +447,6 @@ Synchronously copies a file. ...@@ -404,7 +447,6 @@ Synchronously copies a file.
fs.copyFileSync(srcPath, dstPath); fs.copyFileSync(srcPath, dstPath);
``` ```
## fs.mkdir ## fs.mkdir
mkdir(path: string): Promise&lt;void&gt; mkdir(path: string): Promise&lt;void&gt;
...@@ -421,9 +463,13 @@ Creates a directory. This API uses a promise to return the result. ...@@ -421,9 +463,13 @@ Creates a directory. This API uses a promise to return the result.
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.| | Promise&lt;void&gt; | Promise that returns no value.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
...@@ -436,7 +482,6 @@ Creates a directory. This API uses a promise to return the result. ...@@ -436,7 +482,6 @@ Creates a directory. This API uses a promise to return the result.
}); });
``` ```
## fs.mkdir ## fs.mkdir
mkdir(path: string, callback: AsyncCallback&lt;void&gt;): void mkdir(path: string, callback: AsyncCallback&lt;void&gt;): void
...@@ -452,6 +497,10 @@ Creates a directory. This API uses an asynchronous callback to return the result ...@@ -452,6 +497,10 @@ Creates a directory. This API uses an asynchronous callback to return the result
| path | string | Yes | Application sandbox path of the directory. | | path | string | Yes | Application sandbox path of the directory. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the directory is created asynchronously. | | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the directory is created asynchronously. |
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
```js ```js
...@@ -465,7 +514,6 @@ Creates a directory. This API uses an asynchronous callback to return the result ...@@ -465,7 +514,6 @@ Creates a directory. This API uses an asynchronous callback to return the result
}); });
``` ```
## fs.mkdirSync ## fs.mkdirSync
mkdirSync(path: string): void mkdirSync(path: string): void
...@@ -480,6 +528,10 @@ Synchronously creates a directory. ...@@ -480,6 +528,10 @@ Synchronously creates a directory.
| ------ | ------ | ---- | ------------------------------------------------------------ | | ------ | ------ | ---- | ------------------------------------------------------------ |
| path | string | Yes | Application sandbox path of the directory. | | path | string | Yes | Application sandbox path of the directory. |
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
```js ```js
...@@ -487,7 +539,6 @@ Synchronously creates a directory. ...@@ -487,7 +539,6 @@ Synchronously creates a directory.
fs.mkdirSync(dirPath); fs.mkdirSync(dirPath);
``` ```
## fs.open ## fs.open
open(path: string, mode?: number): Promise&lt;File&gt; open(path: string, mode?: number): Promise&lt;File&gt;
...@@ -505,9 +556,13 @@ Opens a file. This API uses a promise to return the result. File uniform resourc ...@@ -505,9 +556,13 @@ Opens a file. This API uses a promise to return the result. File uniform resourc
**Return value** **Return value**
| Type | Description | | Type | Description |
| --------------------- | ----------- | | --------------------- | ----------- |
| Promise&lt;[File](#file)&gt; | Promise used to return the file object.| | Promise&lt;[File](#file)&gt; | Promise used to return the file object.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
...@@ -536,6 +591,10 @@ Opens a file. This API uses an asynchronous callback to return the result. File ...@@ -536,6 +591,10 @@ Opens a file. This API uses an asynchronous callback to return the result. File
| path | string | Yes | Application sandbox path or URI of the file. | | path | string | Yes | Application sandbox path or URI of the file. |
| mode | number | No | [Mode](#openmode) for opening the file. You must specify one of the following options. By default, the file is open in read-only mode.<br>- **OpenMode.READ_ONLY(0o0)**: Open the file in read-only mode.<br>- **OpenMode.WRITE_ONLY(0o1)**: Open the file in write-only mode.<br>- **OpenMode.READ_WRITE(0o2)**: Open the file in read/write mode.<br>You can also specify the following options, separated by a bitwise OR operator (&#124;). By default, no additional options are given.<br>- **OpenMode.CREATE(0o100)**: If the file does not exist, create it.<br>- **OpenMode.TRUNC(0o1000)**: If the file exists and is open in write-only or read/write mode, truncate the file length to 0.<br>- **OpenMode.APPEND(0o2000)**: Open the file in append mode. New data will be added to the end of the file.<br>- **OpenMode.NONBLOCK(0o4000)**: If **path** points to a named pipe (also known as a FIFO), block special file, or character special file, perform non-blocking operations on the open file and in subsequent I/Os.<br>- **OpenMode.DIR(0o200000)**: If **path** does not point to a directory, throw an exception.<br>- **OpenMode.NOFOLLOW(0o400000)**: If **path** points to a symbolic link, throw an exception.<br>- **OpenMode.SYNC(0o4010000)**: Open the file in synchronous I/O mode.| | mode | number | No | [Mode](#openmode) for opening the file. You must specify one of the following options. By default, the file is open in read-only mode.<br>- **OpenMode.READ_ONLY(0o0)**: Open the file in read-only mode.<br>- **OpenMode.WRITE_ONLY(0o1)**: Open the file in write-only mode.<br>- **OpenMode.READ_WRITE(0o2)**: Open the file in read/write mode.<br>You can also specify the following options, separated by a bitwise OR operator (&#124;). By default, no additional options are given.<br>- **OpenMode.CREATE(0o100)**: If the file does not exist, create it.<br>- **OpenMode.TRUNC(0o1000)**: If the file exists and is open in write-only or read/write mode, truncate the file length to 0.<br>- **OpenMode.APPEND(0o2000)**: Open the file in append mode. New data will be added to the end of the file.<br>- **OpenMode.NONBLOCK(0o4000)**: If **path** points to a named pipe (also known as a FIFO), block special file, or character special file, perform non-blocking operations on the open file and in subsequent I/Os.<br>- **OpenMode.DIR(0o200000)**: If **path** does not point to a directory, throw an exception.<br>- **OpenMode.NOFOLLOW(0o400000)**: If **path** points to a symbolic link, throw an exception.<br>- **OpenMode.SYNC(0o4010000)**: Open the file in synchronous I/O mode.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
```js ```js
...@@ -566,9 +625,13 @@ Synchronously opens a file. File URIs are supported. ...@@ -566,9 +625,13 @@ Synchronously opens a file. File URIs are supported.
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------ | ----------- | | ------ | ----------- |
| [File](#file) | File object opened.| | [File](#file) | File object opened.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
...@@ -597,9 +660,13 @@ Reads data from a file. This API uses a promise to return the result. ...@@ -597,9 +660,13 @@ Reads data from a file. This API uses a promise to return the result.
**Return value** **Return value**
| Type | Description | | Type | Description |
| ---------------------------------- | ------ | | ---------------------------------- | ------ |
| Promise&lt;number&gt; | Promise used to return the data read.| | Promise&lt;number&gt; | Promise used to return the data read.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
...@@ -626,12 +693,16 @@ Reads data from a file. This API uses an asynchronous callback to return the res ...@@ -626,12 +693,16 @@ Reads data from a file. This API uses an asynchronous callback to return the res
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- | | -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| fd | number | Yes | FD of the file. | | fd | number | Yes | FD of the file. |
| buffer | ArrayBuffer | Yes | Buffer used to store the file data read. | | buffer | ArrayBuffer | Yes | Buffer used to store the file data read. |
| options | Object | No | The options are as follows:<br>- **offset** (number): position of the data to read in the file. This parameter is optional. By default, data is read from the current position.<br>- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length.| | options | Object | No | The options are as follows:<br>- **offset** (number): position of the data to read in the file. This parameter is optional. By default, data is read from the current position.<br>- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length.|
| callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked when the data is read asynchronously. | | callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked when the data is read asynchronously. |
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
...@@ -650,7 +721,6 @@ Reads data from a file. This API uses an asynchronous callback to return the res ...@@ -650,7 +721,6 @@ Reads data from a file. This API uses an asynchronous callback to return the res
}); });
``` ```
## fs.readSync ## fs.readSync
readSync(fd: number, buffer: ArrayBuffer, options?: { offset?: number; length?: number; }): number readSync(fd: number, buffer: ArrayBuffer, options?: { offset?: number; length?: number; }): number
...@@ -661,17 +731,21 @@ Synchronously reads data from a file. ...@@ -661,17 +731,21 @@ Synchronously reads data from a file.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------- | ----------- | ---- | ---------------------------------------- | | ------- | ----------- | ---- | ---------------------------------------- |
| fd | number | Yes | FD of the file. | | fd | number | Yes | FD of the file. |
| buffer | ArrayBuffer | Yes | Buffer used to store the file data read. | | buffer | ArrayBuffer | Yes | Buffer used to store the file data read. |
| options | Object | No | The options are as follows:<br>- **offset** (number): position of the data to read in the file. This parameter is optional. By default, data is read from the current position.<br>- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length.| | options | Object | No | The options are as follows:<br>- **offset** (number): position of the data to read in the file. This parameter is optional. By default, data is read from the current position.<br>- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------ | -------- | | ------ | -------- |
| number | Length of the data read.| | number | Length of the data read.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
...@@ -683,7 +757,6 @@ Synchronously reads data from a file. ...@@ -683,7 +757,6 @@ Synchronously reads data from a file.
fs.closeSync(file); fs.closeSync(file);
``` ```
## fs.rmdir ## fs.rmdir
rmdir(path: string): Promise&lt;void&gt; rmdir(path: string): Promise&lt;void&gt;
...@@ -700,9 +773,13 @@ Deletes a directory. This API uses a promise to return the result. ...@@ -700,9 +773,13 @@ Deletes a directory. This API uses a promise to return the result.
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.| | Promise&lt;void&gt; | Promise that returns no value.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
...@@ -715,7 +792,6 @@ Deletes a directory. This API uses a promise to return the result. ...@@ -715,7 +792,6 @@ Deletes a directory. This API uses a promise to return the result.
}); });
``` ```
## fs.rmdir ## fs.rmdir
rmdir(path: string, callback: AsyncCallback&lt;void&gt;): void rmdir(path: string, callback: AsyncCallback&lt;void&gt;): void
...@@ -731,6 +807,10 @@ Deletes a directory. This API uses an asynchronous callback to return the result ...@@ -731,6 +807,10 @@ Deletes a directory. This API uses an asynchronous callback to return the result
| path | string | Yes | Application sandbox path of the directory.| | path | string | Yes | Application sandbox path of the directory.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the directory is deleted asynchronously. | | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the directory is deleted asynchronously. |
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
```js ```js
...@@ -744,7 +824,6 @@ Deletes a directory. This API uses an asynchronous callback to return the result ...@@ -744,7 +824,6 @@ Deletes a directory. This API uses an asynchronous callback to return the result
}); });
``` ```
## fs.rmdirSync ## fs.rmdirSync
rmdirSync(path: string): void rmdirSync(path: string): void
...@@ -759,6 +838,10 @@ Synchronously deletes a directory. ...@@ -759,6 +838,10 @@ Synchronously deletes a directory.
| ------ | ------ | ---- | -------------------------- | | ------ | ------ | ---- | -------------------------- |
| path | string | Yes | Application sandbox path of the directory.| | path | string | Yes | Application sandbox path of the directory.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
```js ```js
...@@ -766,7 +849,6 @@ Synchronously deletes a directory. ...@@ -766,7 +849,6 @@ Synchronously deletes a directory.
fs.rmdirSync(dirPath); fs.rmdirSync(dirPath);
``` ```
## fs.unlink ## fs.unlink
unlink(path: string): Promise&lt;void&gt; unlink(path: string): Promise&lt;void&gt;
...@@ -783,9 +865,13 @@ Deletes a file. This API uses a promise to return the result. ...@@ -783,9 +865,13 @@ Deletes a file. This API uses a promise to return the result.
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.| | Promise&lt;void&gt; | Promise that returns no value.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
...@@ -798,7 +884,6 @@ Deletes a file. This API uses a promise to return the result. ...@@ -798,7 +884,6 @@ Deletes a file. This API uses a promise to return the result.
}); });
``` ```
## fs.unlink ## fs.unlink
unlink(path: string, callback: AsyncCallback&lt;void&gt;): void unlink(path: string, callback: AsyncCallback&lt;void&gt;): void
...@@ -814,6 +899,10 @@ Deletes a file. This API uses an asynchronous callback to return the result. ...@@ -814,6 +899,10 @@ Deletes a file. This API uses an asynchronous callback to return the result.
| path | string | Yes | Application sandbox path of the file.| | path | string | Yes | Application sandbox path of the file.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file is deleted asynchronously. | | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file is deleted asynchronously. |
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
```js ```js
...@@ -827,7 +916,6 @@ Deletes a file. This API uses an asynchronous callback to return the result. ...@@ -827,7 +916,6 @@ Deletes a file. This API uses an asynchronous callback to return the result.
}); });
``` ```
## fs.unlinkSync ## fs.unlinkSync
unlinkSync(path: string): void unlinkSync(path: string): void
...@@ -842,6 +930,10 @@ Synchronously deletes a file. ...@@ -842,6 +930,10 @@ Synchronously deletes a file.
| ------ | ------ | ---- | -------------------------- | | ------ | ------ | ---- | -------------------------- |
| path | string | Yes | Application sandbox path of the file.| | path | string | Yes | Application sandbox path of the file.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
```js ```js
...@@ -860,17 +952,21 @@ Writes data into a file. This API uses a promise to return the result. ...@@ -860,17 +952,21 @@ Writes data into a file. This API uses a promise to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------- | ------------------------------- | ---- | ---------------------------------------- | | ------- | ------------------------------- | ---- | ---------------------------------------- |
| fd | number | Yes | FD of the file. | | fd | number | Yes | FD of the file. |
| buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. | | buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. |
| options | Object | No | The options are as follows:<br>- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.<br>- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.<br>- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.| | options | Object | No | The options are as follows:<br>- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.<br>- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.<br>- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| --------------------- | -------- | | --------------------- | -------- |
| Promise&lt;number&gt; | Promise used to return the length of the data written.| | Promise&lt;number&gt; | Promise used to return the length of the data written.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
...@@ -885,7 +981,6 @@ Writes data into a file. This API uses a promise to return the result. ...@@ -885,7 +981,6 @@ Writes data into a file. This API uses a promise to return the result.
}); });
``` ```
## fs.write ## fs.write
write(fd: number, buffer: ArrayBuffer|string, options?: { offset?: number; length?: number; encoding?: string; }, callback: AsyncCallback&lt;number&gt;): void write(fd: number, buffer: ArrayBuffer|string, options?: { offset?: number; length?: number; encoding?: string; }, callback: AsyncCallback&lt;number&gt;): void
...@@ -896,12 +991,16 @@ Writes data into a file. This API uses an asynchronous callback to return the re ...@@ -896,12 +991,16 @@ Writes data into a file. This API uses an asynchronous callback to return the re
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ------------------------------- | ---- | ---------------------------------------- | | -------- | ------------------------------- | ---- | ---------------------------------------- |
| fd | number | Yes | FD of the file. | | fd | number | Yes | FD of the file. |
| buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. | | buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. |
| options | Object | No | The options are as follows:<br>- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.<br>- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.<br>- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.| | options | Object | No | The options are as follows:<br>- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.<br>- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.<br>- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.|
| callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked when the data is written asynchronously. | | callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked when the data is written asynchronously. |
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
...@@ -918,7 +1017,6 @@ Writes data into a file. This API uses an asynchronous callback to return the re ...@@ -918,7 +1017,6 @@ Writes data into a file. This API uses an asynchronous callback to return the re
}); });
``` ```
## fs.writeSync ## fs.writeSync
writeSync(fd: number, buffer: ArrayBuffer|string, options?: { offset?: number; length?: number; encoding?: string; }): number writeSync(fd: number, buffer: ArrayBuffer|string, options?: { offset?: number; length?: number; encoding?: string; }): number
...@@ -929,17 +1027,21 @@ Synchronously writes data into a file. ...@@ -929,17 +1027,21 @@ Synchronously writes data into a file.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------- | ------------------------------- | ---- | ---------------------------------------- | | ------- | ------------------------------- | ---- | ---------------------------------------- |
| fd | number | Yes | FD of the file. | | fd | number | Yes | FD of the file. |
| buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. | | buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. |
| options | Object | No | The options are as follows:<br>- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.<br>- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.<br>- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.| | options | Object | No | The options are as follows:<br>- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.<br>- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.<br>- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------ | -------- | | ------ | -------- |
| number | Length of the data written in the file.| | number | Length of the data written in the file.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
...@@ -968,9 +1070,13 @@ Truncates a file. This API uses a promise to return the result. ...@@ -968,9 +1070,13 @@ Truncates a file. This API uses a promise to return the result.
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.| | Promise&lt;void&gt; | Promise that returns no value.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
...@@ -984,7 +1090,6 @@ Truncates a file. This API uses a promise to return the result. ...@@ -984,7 +1090,6 @@ Truncates a file. This API uses a promise to return the result.
}); });
``` ```
## fs.truncate ## fs.truncate
truncate(file: string|number, len?: number, callback: AsyncCallback&lt;void&gt;): void truncate(file: string|number, len?: number, callback: AsyncCallback&lt;void&gt;): void
...@@ -1001,6 +1106,10 @@ Truncates a file. This API uses an asynchronous callback to return the result. ...@@ -1001,6 +1106,10 @@ Truncates a file. This API uses an asynchronous callback to return the result.
| len | number | No | File length, in bytes, after truncation. The default value is **0**.| | len | number | No | File length, in bytes, after truncation. The default value is **0**.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback that returns no value. | | callback | AsyncCallback&lt;void&gt; | Yes | Callback that returns no value. |
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
```js ```js
...@@ -1015,7 +1124,6 @@ Truncates a file. This API uses an asynchronous callback to return the result. ...@@ -1015,7 +1124,6 @@ Truncates a file. This API uses an asynchronous callback to return the result.
}); });
``` ```
## fs.truncateSync ## fs.truncateSync
truncateSync(file: string|number, len?: number): void truncateSync(file: string|number, len?: number): void
...@@ -1031,6 +1139,10 @@ Synchronously truncates a file. ...@@ -1031,6 +1139,10 @@ Synchronously truncates a file.
| file | string\|number | Yes | Application sandbox path or FD of the file. | | file | string\|number | Yes | Application sandbox path or FD of the file. |
| len | number | No | File length, in bytes, after truncation. The default value is **0**.| | len | number | No | File length, in bytes, after truncation. The default value is **0**.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
```js ```js
...@@ -1039,7 +1151,6 @@ Synchronously truncates a file. ...@@ -1039,7 +1151,6 @@ Synchronously truncates a file.
fs.truncateSync(filePath, len); fs.truncateSync(filePath, len);
``` ```
## fs.readText ## fs.readText
readText(filePath: string, options?: { offset?: number; length?: number; encoding?: string; }): Promise&lt;string&gt; readText(filePath: string, options?: { offset?: number; length?: number; encoding?: string; }): Promise&lt;string&gt;
...@@ -1057,9 +1168,13 @@ Reads the text content of a file. This API uses a promise to return the result. ...@@ -1057,9 +1168,13 @@ Reads the text content of a file. This API uses a promise to return the result.
**Return value** **Return value**
| Type | Description | | Type | Description |
| --------------------- | ---------- | | --------------------- | ---------- |
| Promise&lt;string&gt; | Promise used to return the content read.| | Promise&lt;string&gt; | Promise used to return the content read.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
...@@ -1072,7 +1187,6 @@ Reads the text content of a file. This API uses a promise to return the result. ...@@ -1072,7 +1187,6 @@ Reads the text content of a file. This API uses a promise to return the result.
}); });
``` ```
## fs.readText ## fs.readText
readText(filePath: string, options?: { offset?: number; length?: number; encoding?: string; }, callback: AsyncCallback&lt;string&gt;): void readText(filePath: string, options?: { offset?: number; length?: number; encoding?: string; }, callback: AsyncCallback&lt;string&gt;): void
...@@ -1089,6 +1203,10 @@ Reads the text content of a file. This API uses an asynchronous callback to retu ...@@ -1089,6 +1203,10 @@ Reads the text content of a file. This API uses an asynchronous callback to retu
| 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 file length.<br>- **encoding** (string): format of the string to be encoded. The default value is **'utf-8'**, which is the only value supported.| | options | Object | No | The options are as follows:<br>- **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 file length.<br>- **encoding** (string): format of the string to be encoded. The default value is **'utf-8'**, which is the only value supported.|
| callback | AsyncCallback&lt;string&gt; | Yes | Callback invoked to return the content read. | | callback | AsyncCallback&lt;string&gt; | Yes | Callback invoked to return the content read. |
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
```js ```js
...@@ -1102,7 +1220,6 @@ Reads the text content of a file. This API uses an asynchronous callback to retu ...@@ -1102,7 +1220,6 @@ Reads the text content of a file. This API uses an asynchronous callback to retu
}); });
``` ```
## fs.readTextSync ## fs.readTextSync
readTextSync(filePath: string, options?: { offset?: number; length?: number; encoding?: string; }): string readTextSync(filePath: string, options?: { offset?: number; length?: number; encoding?: string; }): string
...@@ -1120,9 +1237,13 @@ Synchronously reads the text of a file. ...@@ -1120,9 +1237,13 @@ Synchronously reads the text of a file.
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------ | -------------------- | | ------ | -------------------- |
| string | Promise used to return the content of the file read.| | string | Promise used to return the content of the file read.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
...@@ -1148,9 +1269,13 @@ Obtains information about a symbolic link. This API uses a promise to return the ...@@ -1148,9 +1269,13 @@ Obtains information about a symbolic link. This API uses a promise to return the
**Return value** **Return value**
| Type | Description | | Type | Description |
| ---------------------------- | ---------- | | ---------------------------- | ---------- |
| Promise&lt;[Stat](#stat)&gt; | Promise used to return the symbolic link information obtained. For details, see **stat**.| | Promise&lt;[Stat](#stat)&gt; | Promise used to return the symbolic link information obtained. For details, see **stat**.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
...@@ -1163,7 +1288,6 @@ Obtains information about a symbolic link. This API uses a promise to return the ...@@ -1163,7 +1288,6 @@ Obtains information about a symbolic link. This API uses a promise to return the
}); });
``` ```
## fs.lstat ## fs.lstat
lstat(path: string, callback: AsyncCallback&lt;Stat&gt;): void lstat(path: string, callback: AsyncCallback&lt;Stat&gt;): void
...@@ -1179,6 +1303,10 @@ Obtains information about a symbolic link. This API uses an asynchronous callbac ...@@ -1179,6 +1303,10 @@ Obtains information about a symbolic link. This API uses an asynchronous callbac
| path | string | Yes | Application sandbox path of the file.| | path | string | Yes | Application sandbox path of the file.|
| callback | AsyncCallback&lt;[Stat](#stat)&gt; | Yes | Callback invoked to return the symbolic link information obtained. | | callback | AsyncCallback&lt;[Stat](#stat)&gt; | Yes | Callback invoked to return the symbolic link information obtained. |
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
```js ```js
...@@ -1208,9 +1336,13 @@ Obtains information about a symbolic link synchronously. ...@@ -1208,9 +1336,13 @@ Obtains information about a symbolic link synchronously.
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------- | ---------- | | ------------- | ---------- |
| [Stat](#stat) | File information obtained.| | [Stat](#stat) | File information obtained.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
...@@ -1236,9 +1368,13 @@ Renames a file or folder. This API uses a promise to return the result. ...@@ -1236,9 +1368,13 @@ Renames a file or folder. This API uses a promise to return the result.
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.| | Promise&lt;void&gt; | Promise that returns no value.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
...@@ -1268,6 +1404,10 @@ Renames a file or folder. This API uses an asynchronous callback to return the r ...@@ -1268,6 +1404,10 @@ Renames a file or folder. This API uses an asynchronous callback to return the r
| newPath | string | Yes | Application sandbox path of the renamed file or folder. | | newPath | string | Yes | Application sandbox path of the renamed file or folder. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file or folder is asynchronously renamed. | | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file or folder is asynchronously renamed. |
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
```js ```js
...@@ -1297,6 +1437,10 @@ Renames a file or folder synchronously. ...@@ -1297,6 +1437,10 @@ Renames a file or folder synchronously.
| oldPath | string | Yes | Application sandbox path of the file or folder to rename.| | oldPath | string | Yes | Application sandbox path of the file or folder to rename.|
| newPath | string | Yes | Application sandbox path of the renamed file or folder. | | newPath | string | Yes | Application sandbox path of the renamed file or folder. |
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
```js ```js
...@@ -1305,7 +1449,6 @@ Renames a file or folder synchronously. ...@@ -1305,7 +1449,6 @@ Renames a file or folder synchronously.
fs.renameSync(srcFile, dstFile); fs.renameSync(srcFile, dstFile);
``` ```
## fs.fsync ## fs.fsync
fsync(fd: number): Promise&lt;void&gt; fsync(fd: number): Promise&lt;void&gt;
...@@ -1316,15 +1459,19 @@ Flushes data of a file to disk. This API uses a promise to return the result. ...@@ -1316,15 +1459,19 @@ Flushes data of a file to disk. This API uses a promise to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ------------ | | ---- | ------ | ---- | ------------ |
| fd | number | Yes | FD of the file.| | fd | number | Yes | FD of the file.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.| | Promise&lt;void&gt; | Promise that returns no value.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
...@@ -1338,7 +1485,6 @@ Flushes data of a file to disk. This API uses a promise to return the result. ...@@ -1338,7 +1485,6 @@ Flushes data of a file to disk. This API uses a promise to return the result.
}); });
``` ```
## fs.fsync ## fs.fsync
fsync(fd: number, callback: AsyncCallback&lt;void&gt;): void fsync(fd: number, callback: AsyncCallback&lt;void&gt;): void
...@@ -1349,10 +1495,14 @@ Flushes data of a file to disk. This API uses an asynchronous callback to return ...@@ -1349,10 +1495,14 @@ Flushes data of a file to disk. This API uses an asynchronous callback to return
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | --------------- | | -------- | ------------------------- | ---- | --------------- |
| fd | number | Yes | FD of the file. | | fd | number | Yes | FD of the file. |
| Callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file data is synchronized in asynchronous mode.| | Callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file data is synchronized in asynchronous mode.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
...@@ -1380,9 +1530,13 @@ Flushes data of a file to disk synchronously. ...@@ -1380,9 +1530,13 @@ Flushes data of a file to disk synchronously.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ------------ | | ---- | ------ | ---- | ------------ |
| fd | number | Yes | FD of the file.| | fd | number | Yes | FD of the file.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
...@@ -1393,7 +1547,6 @@ Flushes data of a file to disk synchronously. ...@@ -1393,7 +1547,6 @@ Flushes data of a file to disk synchronously.
fs.closeSync(file); fs.closeSync(file);
``` ```
## fs.fdatasync ## fs.fdatasync
fdatasync(fd: number): Promise&lt;void&gt; fdatasync(fd: number): Promise&lt;void&gt;
...@@ -1404,15 +1557,19 @@ Flushes data of a file to disk. This API uses a promise to return the result. ** ...@@ -1404,15 +1557,19 @@ Flushes data of a file to disk. This API uses a promise to return the result. **
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ------------ | | ---- | ------ | ---- | ------------ |
| fd | number | Yes | FD of the file.| | fd | number | Yes | FD of the file.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.| | Promise&lt;void&gt; | Promise that returns no value.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
...@@ -1427,7 +1584,6 @@ Flushes data of a file to disk. This API uses a promise to return the result. ** ...@@ -1427,7 +1584,6 @@ Flushes data of a file to disk. This API uses a promise to return the result. **
}); });
``` ```
## fs.fdatasync ## fs.fdatasync
fdatasync(fd: number, callback: AsyncCallback&lt;void&gt;): void fdatasync(fd: number, callback: AsyncCallback&lt;void&gt;): void
...@@ -1438,10 +1594,14 @@ Flushes data of a file to disk. This API uses an asynchronous callback to return ...@@ -1438,10 +1594,14 @@ Flushes data of a file to disk. This API uses an asynchronous callback to return
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ------------------------------- | ---- | ----------------- | | -------- | ------------------------------- | ---- | ----------------- |
| fd | number | Yes | FD of the file. | | fd | number | Yes | FD of the file. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file data is synchronized in asynchronous mode.| | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file data is synchronized in asynchronous mode.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
...@@ -1468,9 +1628,13 @@ Synchronizes data in a file synchronously. ...@@ -1468,9 +1628,13 @@ Synchronizes data in a file synchronously.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ------------ | | ---- | ------ | ---- | ------------ |
| fd | number | Yes | FD of the file.| | fd | number | Yes | FD of the file.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
...@@ -1481,7 +1645,6 @@ Synchronizes data in a file synchronously. ...@@ -1481,7 +1645,6 @@ Synchronizes data in a file synchronously.
fs.closeSync(file); fs.closeSync(file);
``` ```
## fs.symlink ## fs.symlink
symlink(target: string, srcPath: string): Promise&lt;void&gt; symlink(target: string, srcPath: string): Promise&lt;void&gt;
...@@ -1499,9 +1662,13 @@ Creates a symbolic link based on a file path. This API uses a promise to return ...@@ -1499,9 +1662,13 @@ Creates a symbolic link based on a file path. This API uses a promise to return
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.| | Promise&lt;void&gt; | Promise that returns no value.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
...@@ -1531,6 +1698,10 @@ Creates a symbolic link based on a file path. This API uses an asynchronous call ...@@ -1531,6 +1698,10 @@ Creates a symbolic link based on a file path. This API uses an asynchronous call
| srcPath | string | Yes | Application sandbox path of the symbolic link. | | srcPath | string | Yes | Application sandbox path of the symbolic link. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the symbolic link is created asynchronously.| | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the symbolic link is created asynchronously.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
```js ```js
...@@ -1560,6 +1731,10 @@ Synchronously creates a symbolic link based on a file path. ...@@ -1560,6 +1731,10 @@ Synchronously creates a symbolic link based on a file path.
| target | string | Yes | Application sandbox path of the source file. | | target | string | Yes | Application sandbox path of the source file. |
| srcPath | string | Yes | Application sandbox path of the symbolic link.| | srcPath | string | Yes | Application sandbox path of the symbolic link.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
```js ```js
...@@ -1573,7 +1748,7 @@ listFile(path: string, options?: { ...@@ -1573,7 +1748,7 @@ listFile(path: string, options?: {
recursion?: boolean; recursion?: boolean;
listNum?: number; listNum?: number;
filter?: Filter; filter?: Filter;
}): Promise<string[]>; }): 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 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.
...@@ -1581,24 +1756,28 @@ Lists all files in a directory. This API uses a promise to return the result.<br ...@@ -1581,24 +1756,28 @@ Lists all files in a directory. This API uses a promise to return the result.<br
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- | | ------ | ------ | ---- | --------------------------- |
| path | string | Yes | Application sandbox path of the folder.| | path | string | Yes | Application sandbox path of the folder.|
| options | Object | No | File filtering options. The files are not filtered by default.| | options | Object | No | File filtering options. The files are not filtered by default.|
**options parameters** **options parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- | | ------ | ------ | ---- | --------------------------- |
| recursion | boolean | No | Whether to list all files in subdirectories recursively. The default value is **false**.| | recursion | boolean | No | Whether to list all files in subdirectories recursively. The default value is **false**.|
| listNum | number | No | Number of file names to list. The default value **0** means to list all files.| | listNum | number | No | Number of file names to list. The default value **0** means to list all files.|
| filter | [Filter](#filter) | No | File filtering options. Currently, only the match by file name extension, fuzzy search by file name, and filter by file size or latest modification time are supported.| | filter | [Filter](#filter) | No | File filtering options. Currently, only the match by file name extension, fuzzy search by file name, and filter by file size or latest modification time are supported.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| --------------------- | ---------- | | --------------------- | ---------- |
| Promise&lt;string[]&gt; | Promise used to return the files names listed.| | Promise&lt;string[]&gt; | Promise used to return the files names listed.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
...@@ -1628,25 +1807,29 @@ listFile(path: string, options?: { ...@@ -1628,25 +1807,29 @@ listFile(path: string, options?: {
recursion?: boolean; recursion?: boolean;
listNum?: number; listNum?: number;
filter?: Filter; filter?: Filter;
}, callback: AsyncCallback<string[]>): void; }, 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 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.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- | | ------ | ------ | ---- | --------------------------- |
| path | string | Yes | Application sandbox path of the folder.| | path | string | Yes | Application sandbox path of the folder.|
| options | Object | No | File filtering options. The files are not filtered by default.| | options | Object | No | File filtering options. The files are not filtered by default.|
| callback | AsyncCallback&lt;string[]&gt; | Yes | Callback invoked to return the file names listed. | | callback | AsyncCallback&lt;string[]&gt; | Yes | Callback invoked to return the file names listed. |
**options parameters** **options parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- | | ------ | ------ | ---- | --------------------------- |
| recursion | boolean | No | Whether to list all files in subdirectories recursively. The default value is **false**.| | recursion | boolean | No | Whether to list all files in subdirectories recursively. The default value is **false**.|
| listNum | number | No | Number of file names to list. The default value **0** means to list all files.| | listNum | number | No | Number of file names to list. The default value **0** means to list all files.|
| filter | [Filter](#filter) | No | File filtering options. Currently, only the match by file name extension, fuzzy search by file name, and filter by file size or latest modification time are supported.| | filter | [Filter](#filter) | No | File filtering options. Currently, only the match by file name extension, fuzzy search by file name, and filter by file size or latest modification time are supported.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
...@@ -1679,30 +1862,34 @@ listFileSync(path: string, options?: { ...@@ -1679,30 +1862,34 @@ listFileSync(path: string, options?: {
recursion?: boolean; recursion?: boolean;
listNum?: number; listNum?: number;
filter?: Filter; filter?: Filter;
}): string[]; }): 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 directory synchronously. This API supports recursive listing of all files (including files in subdirectories) and file filtering.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- | | ------ | ------ | ---- | --------------------------- |
| path | string | Yes | Application sandbox path of the folder.| | path | string | Yes | Application sandbox path of the folder.|
| options | Object | No | File filtering options. The files are not filtered by default.| | options | Object | No | File filtering options. The files are not filtered by default.|
**options parameters** **options parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- | | ------ | ------ | ---- | --------------------------- |
| recursion | boolean | No | Whether to list all files in subdirectories recursively. The default value is **false**.| | recursion | boolean | No | Whether to list all files in subdirectories recursively. The default value is **false**.|
| listNum | number | No | Number of file names to list. The default value **0** means to list all files.| | listNum | number | No | Number of file names to list. The default value **0** means to list all files.|
| filter | [Filter](#filter) | No | File filtering options. Currently, only the match by file name extension, fuzzy search by file name, and filter by file size or latest modification time are supported.| | filter | [Filter](#filter) | No | File filtering options. Currently, only the match by file name extension, fuzzy search by file name, and filter by file size or latest modification time are supported.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| --------------------- | ---------- | | --------------------- | ---------- |
| string[] | File names listed.| | string[] | File names listed.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
...@@ -1723,9 +1910,10 @@ Lists all files in a directory synchronously. This API supports recursive listin ...@@ -1723,9 +1910,10 @@ Lists all files in a directory synchronously. This API supports recursive listin
console.info("filename: %s", filenames[i]); console.info("filename: %s", filenames[i]);
} }
``` ```
## fs.moveFile ## 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. Moves a file. This API uses a promise to return the result.
...@@ -1733,11 +1921,21 @@ Moves a file. This API uses a promise to return the result. ...@@ -1733,11 +1921,21 @@ Moves a file. This API uses a promise to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- | | ------ | ------ | ---- | --------------------------- |
| src | string | Yes | Application sandbox path of the source file.| | src | string | Yes | Application sandbox path of the source file.|
| dest | string | Yes | Application sandbox path of the destination file.| | dest | string | Yes | Application sandbox path of the destination file.|
| mode | number | No | Whether to overwrite the file of the same name in the destination directory. The value **0** means to overwrite the file of the same name in the destination directory. The value **1** means to throw an exception if a file of the same name exists in the destination directory. The default value is **0**.| | mode | number | No | Whether to overwrite the file of the same name in the destination directory. The value **0** means to overwrite the file of the same name in the destination directory. The value **1** means to throw an exception if a file of the same name exists in the destination directory. The default value is **0**.|
**Return value**
| Type | Description |
| ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
...@@ -1753,7 +1951,7 @@ Moves a file. This API uses a promise to return the result. ...@@ -1753,7 +1951,7 @@ Moves a file. This API uses a promise to return the result.
## fs.moveFile ## 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. Moves a file. This API uses an asynchronous callback to return the result.
...@@ -1761,12 +1959,16 @@ Moves a file. This API uses an asynchronous callback to return the result. ...@@ -1761,12 +1959,16 @@ Moves a file. This API uses an asynchronous callback to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- | | ------ | ------ | ---- | --------------------------- |
| src | string | Yes | Application sandbox path of the source file.| | src | string | Yes | Application sandbox path of the source file.|
| dest | string | Yes | Application sandbox path of the destination file.| | dest | string | Yes | Application sandbox path of the destination file.|
| mode | number | No | Whether to overwrite the file of the same name in the destination directory. The value **0** means to overwrite the file of the same name in the destination directory. The value **1** means to throw an exception if a file of the same name exists in the destination directory. The default value is **0**.| | mode | number | No | Whether to overwrite the file of the same name in the destination directory. The value **0** means to overwrite the file of the same name in the destination directory. The value **1** means to throw an exception if a file of the same name exists in the destination directory. The default value is **0**.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file is moved. | | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file is moved. |
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
...@@ -1784,7 +1986,7 @@ Moves a file. This API uses an asynchronous callback to return the result. ...@@ -1784,7 +1986,7 @@ Moves a file. This API uses an asynchronous callback to return the result.
## fs.moveFileSync ## fs.moveFileSync
moveFile(src: string, dest: string, mode?: number): void; moveFile(src: string, dest: string, mode?: number): void
Moves a file synchronously. Moves a file synchronously.
...@@ -1792,11 +1994,15 @@ Moves a file synchronously. ...@@ -1792,11 +1994,15 @@ Moves a file synchronously.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- | | ------ | ------ | ---- | --------------------------- |
| src | string | Yes | Application sandbox path of the source file.| | src | string | Yes | Application sandbox path of the source file.|
| dest | string | Yes | Application sandbox path of the destination file.| | dest | string | Yes | Application sandbox path of the destination file.|
| mode | number | No | Whether to overwrite the file of the same name in the destination directory. The value **0** means to overwrite the file of the same name in the destination directory. The value **1** means to throw an exception if a file of the same name exists in the destination directory. The default value is **0**.| | mode | number | No | Whether to overwrite the file of the same name in the destination directory. The value **0** means to overwrite the file of the same name in the destination directory. The value **1** means to throw an exception if a file of the same name exists in the destination directory. The default value is **0**.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
...@@ -1817,15 +2023,19 @@ Creates a temporary directory. This API uses a promise to return the result. ...@@ -1817,15 +2023,19 @@ Creates a temporary directory. This API uses a promise to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- | | ------ | ------ | ---- | --------------------------- |
| prefix | string | Yes | A randomly generated string used to replace "XXXXXX" in a directory.| | prefix | string | Yes | A randomly generated string used to replace "XXXXXX" in a directory.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| --------------------- | ---------- | | --------------------- | ---------- |
| Promise&lt;string&gt; | Promise used to return the unique directory generated.| | Promise&lt;string&gt; | Promise used to return the unique directory generated.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
...@@ -1837,7 +2047,6 @@ Creates a temporary directory. This API uses a promise to return the result. ...@@ -1837,7 +2047,6 @@ Creates a temporary directory. This API uses a promise to return the result.
}); });
``` ```
## fs.mkdtemp ## fs.mkdtemp
mkdtemp(prefix: string, callback: AsyncCallback&lt;string&gt;): void mkdtemp(prefix: string, callback: AsyncCallback&lt;string&gt;): void
...@@ -1848,10 +2057,14 @@ Creates a temporary directory. This API uses an asynchronous callback to return ...@@ -1848,10 +2057,14 @@ Creates a temporary directory. This API uses an asynchronous callback to return
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | --------------------------- | ---- | --------------------------- | | -------- | --------------------------- | ---- | --------------------------- |
| prefix | string | Yes | A randomly generated string used to replace "XXXXXX" in a directory.| | prefix | string | Yes | A randomly generated string used to replace "XXXXXX" in a directory.|
| callback | AsyncCallback&lt;string&gt; | Yes | Callback invoked when a temporary directory is created asynchronously. | | callback | AsyncCallback&lt;string&gt; | Yes | Callback invoked when a temporary directory is created asynchronously. |
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
...@@ -1875,15 +2088,19 @@ Synchronously creates a temporary directory. ...@@ -1875,15 +2088,19 @@ Synchronously creates a temporary directory.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- | | ------ | ------ | ---- | --------------------------- |
| prefix | string | Yes | A randomly generated string used to replace "XXXXXX" in a directory.| | prefix | string | Yes | A randomly generated string used to replace "XXXXXX" in a directory.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------ | ---------- | | ------ | ---------- |
| string | Unique path generated.| | string | Unique path generated.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
...@@ -1908,9 +2125,13 @@ Creates a stream based on the file path. This API uses a promise to return the r ...@@ -1908,9 +2125,13 @@ Creates a stream based on the file path. This API uses a promise to return the r
**Return value** **Return value**
| Type | Description | | Type | Description |
| --------------------------------- | --------- | | --------------------------------- | --------- |
| Promise&lt;[Stream](#stream)&gt; | Promise used to return the result.| | Promise&lt;[Stream](#stream)&gt; | Promise used to return the result.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
...@@ -1940,6 +2161,10 @@ Creates a stream based on the file path. This API uses an asynchronous callback ...@@ -1940,6 +2161,10 @@ Creates a stream based on the file path. This API uses an asynchronous callback
| mode | string | Yes | - **r**: Open a file for reading. The file must exist.<br>- **r+**: Open a file for both reading and writing. The file must exist.<br>- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **w+**: Open a file for both reading and writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **a**: Open a file in append mode for writing at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).<br>- **a+**: Open a file in append mode for reading or updating at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).| | mode | string | Yes | - **r**: Open a file for reading. The file must exist.<br>- **r+**: Open a file for both reading and writing. The file must exist.<br>- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **w+**: Open a file for both reading and writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **a**: Open a file in append mode for writing at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).<br>- **a+**: Open a file in append mode for reading or updating at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).|
| callback | AsyncCallback&lt;[Stream](#stream)&gt; | Yes | Callback invoked when the stream is created asynchronously. | | callback | AsyncCallback&lt;[Stream](#stream)&gt; | Yes | Callback invoked when the stream is created asynchronously. |
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
```js ```js
...@@ -1970,9 +2195,13 @@ Synchronously creates a stream based on the file path. ...@@ -1970,9 +2195,13 @@ Synchronously creates a stream based on the file path.
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------ | --------- | | ------------------ | --------- |
| [Stream](#stream) | Stream opened.| | [Stream](#stream) | Stream opened.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
...@@ -1992,16 +2221,20 @@ Opens a stream based on the file descriptor. This API uses a promise to return t ...@@ -1992,16 +2221,20 @@ Opens a stream based on the file descriptor. This API uses a promise to return t
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ---------------------------------------- | | ---- | ------ | ---- | ---------------------------------------- |
| fd | number | Yes | FD of the file. | | 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).| | mode | string | Yes | - **r**: Open a file for reading. The file must exist.<br>- **r+**: Open a file for both reading and writing. The file must exist.<br>- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **w+**: Open a file for both reading and writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **a**: Open a file in append mode for writing at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).<br>- **a+**: Open a file in append mode for reading or updating at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).|
**Return value** **Return value**
| Type | Description | | Type | Description |
| --------------------------------- | --------- | | --------------------------------- | --------- |
| Promise&lt;[Stream](#stream)&gt; | Promise used to return the result.| | Promise&lt;[Stream](#stream)&gt; | Promise used to return the result.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
...@@ -2016,7 +2249,6 @@ Opens a stream based on the file descriptor. This API uses a promise to return t ...@@ -2016,7 +2249,6 @@ Opens a stream based on the file descriptor. This API uses a promise to return t
}); });
``` ```
## fs.fdopenStream ## fs.fdopenStream
fdopenStream(fd: number, mode: string, callback: AsyncCallback&lt;Stream&gt;): void fdopenStream(fd: number, mode: string, callback: AsyncCallback&lt;Stream&gt;): void
...@@ -2027,11 +2259,15 @@ Opens a stream based on the file descriptor. This API uses an asynchronous callb ...@@ -2027,11 +2259,15 @@ Opens a stream based on the file descriptor. This API uses an asynchronous callb
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- | | -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| fd | number | Yes | FD of the file. | | 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).| | 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. | | callback | AsyncCallback&lt;[Stream](#stream)&gt; | Yes | Callback invoked when the stream is open asynchronously. |
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
...@@ -2058,16 +2294,20 @@ Synchronously opens a stream based on the file descriptor. ...@@ -2058,16 +2294,20 @@ Synchronously opens a stream based on the file descriptor.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ---------------------------------------- | | ---- | ------ | ---- | ---------------------------------------- |
| fd | number | Yes | FD of the file. | | 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).| | mode | string | Yes | - **r**: Open a file for reading. The file must exist.<br>- **r+**: Open a file for both reading and writing. The file must exist.<br>- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **w+**: Open a file for both reading and writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **a**: Open a file in append mode for writing at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).<br>- **a+**: Open a file in append mode for reading or updating at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------ | --------- | | ------------------ | --------- |
| [Stream](#stream) | Stream opened.| | [Stream](#stream) | Stream opened.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
...@@ -2097,7 +2337,6 @@ Represents detailed file information. Before calling any API of the **Stat()** c ...@@ -2097,7 +2337,6 @@ Represents detailed file information. Before calling any API of the **Stat()** c
| mtime | number | Yes | No | Time of the last modification to the file. The value is the number of seconds elapsed since 00:00:00 on January 1, 1970. | | mtime | number | Yes | No | Time of the last modification to the file. The value is the number of seconds elapsed since 00:00:00 on January 1, 1970. |
| ctime | number | Yes | No | Time of the last status change of the file. The value is the number of seconds elapsed since 00:00:00 on January 1, 1970. | | ctime | number | Yes | No | Time of the last status change of the file. The value is the number of seconds elapsed since 00:00:00 on January 1, 1970. |
### isBlockDevice ### isBlockDevice
isBlockDevice(): boolean isBlockDevice(): boolean
...@@ -2108,9 +2347,13 @@ Checks whether this file is a block special file. A block special file supports ...@@ -2108,9 +2347,13 @@ Checks whether this file is a block special file. A block special file supports
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------- | ---------------- | | ------- | ---------------- |
| boolean | Whether the file is a block special file.| | boolean | Whether the file is a block special file.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
...@@ -2129,9 +2372,13 @@ Checks whether this file is a character special file. A character special file s ...@@ -2129,9 +2372,13 @@ Checks whether this file is a character special file. A character special file s
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------- | ----------------- | | ------- | ----------------- |
| boolean | Whether the file is a character special file.| | boolean | Whether the file is a character special file.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
...@@ -2140,7 +2387,6 @@ Checks whether this file is a character special file. A character special file s ...@@ -2140,7 +2387,6 @@ Checks whether this file is a character special file. A character special file s
let isCharacterDevice = fs.statSync(filePath).isCharacterDevice(); let isCharacterDevice = fs.statSync(filePath).isCharacterDevice();
``` ```
### isDirectory ### isDirectory
isDirectory(): boolean isDirectory(): boolean
...@@ -2151,9 +2397,13 @@ Checks whether this file is a directory. ...@@ -2151,9 +2397,13 @@ Checks whether this file is a directory.
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------- | ------------- | | ------- | ------------- |
| boolean | Whether the file is a directory.| | boolean | Whether the file is a directory.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
...@@ -2162,7 +2412,6 @@ Checks whether this file is a directory. ...@@ -2162,7 +2412,6 @@ Checks whether this file is a directory.
let isDirectory = fs.statSync(dirPath).isDirectory(); let isDirectory = fs.statSync(dirPath).isDirectory();
``` ```
### isFIFO ### isFIFO
isFIFO(): boolean isFIFO(): boolean
...@@ -2173,9 +2422,13 @@ Checks whether this file is a named pipe (or FIFO). Named pipes are used for int ...@@ -2173,9 +2422,13 @@ Checks whether this file is a named pipe (or FIFO). Named pipes are used for int
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------- | --------------------- | | ------- | --------------------- |
| boolean | Whether the file is a FIFO.| | boolean | Whether the file is a FIFO.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
...@@ -2184,7 +2437,6 @@ Checks whether this file is a named pipe (or FIFO). Named pipes are used for int ...@@ -2184,7 +2437,6 @@ Checks whether this file is a named pipe (or FIFO). Named pipes are used for int
let isFIFO = fs.statSync(filePath).isFIFO(); let isFIFO = fs.statSync(filePath).isFIFO();
``` ```
### isFile ### isFile
isFile(): boolean isFile(): boolean
...@@ -2195,9 +2447,13 @@ Checks whether this file is a regular file. ...@@ -2195,9 +2447,13 @@ Checks whether this file is a regular file.
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------- | --------------- | | ------- | --------------- |
| boolean | Whether the file is a regular file.| | boolean | Whether the file is a regular file.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
...@@ -2206,7 +2462,6 @@ Checks whether this file is a regular file. ...@@ -2206,7 +2462,6 @@ Checks whether this file is a regular file.
let isFile = fs.statSync(filePath).isFile(); let isFile = fs.statSync(filePath).isFile();
``` ```
### isSocket ### isSocket
isSocket(): boolean isSocket(): boolean
...@@ -2217,9 +2472,13 @@ Checks whether this file is a socket. ...@@ -2217,9 +2472,13 @@ Checks whether this file is a socket.
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------- | -------------- | | ------- | -------------- |
| boolean | Whether the file is a socket.| | boolean | Whether the file is a socket.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
...@@ -2228,7 +2487,6 @@ Checks whether this file is a socket. ...@@ -2228,7 +2487,6 @@ Checks whether this file is a socket.
let isSocket = fs.statSync(filePath).isSocket(); let isSocket = fs.statSync(filePath).isSocket();
``` ```
### isSymbolicLink ### isSymbolicLink
isSymbolicLink(): boolean isSymbolicLink(): boolean
...@@ -2239,9 +2497,13 @@ Checks whether this file is a symbolic link. ...@@ -2239,9 +2497,13 @@ Checks whether this file is a symbolic link.
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------- | --------------- | | ------- | --------------- |
| boolean | Whether the file is a symbolic link.| | boolean | Whether the file is a symbolic link.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
...@@ -2254,7 +2516,6 @@ Checks whether this file is a symbolic link. ...@@ -2254,7 +2516,6 @@ Checks whether this file is a symbolic link.
Provides a stream for file operations. Before calling any API of the **Stream** class, use **createStream()** to create a **Stream** instance synchronously or asynchronously. Provides a stream for file operations. Before calling any API of the **Stream** class, use **createStream()** to create a **Stream** instance synchronously or asynchronously.
### close ### close
close(): Promise&lt;void&gt; close(): Promise&lt;void&gt;
...@@ -2265,9 +2526,13 @@ Closes the stream. This API uses a promise to return the result. ...@@ -2265,9 +2526,13 @@ Closes the stream. This API uses a promise to return the result.
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ------------- | | ------------------- | ------------- |
| Promise&lt;void&gt; | Promise used to return the stream close result.| | Promise&lt;void&gt; | Promise used to return the stream close result.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
...@@ -2281,7 +2546,6 @@ Closes the stream. This API uses a promise to return the result. ...@@ -2281,7 +2546,6 @@ Closes the stream. This API uses a promise to return the result.
}); });
``` ```
### close ### close
close(callback: AsyncCallback&lt;void&gt;): void close(callback: AsyncCallback&lt;void&gt;): void
...@@ -2292,9 +2556,13 @@ Closes the stream. This API uses an asynchronous callback to return the result. ...@@ -2292,9 +2556,13 @@ Closes the stream. This API uses an asynchronous callback to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | ------------- | | -------- | ------------------------- | ---- | ------------- |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the stream is closed asynchronously.| | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the stream is closed asynchronously.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
...@@ -2318,6 +2586,10 @@ Synchronously closes the stream. ...@@ -2318,6 +2586,10 @@ Synchronously closes the stream.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
```js ```js
...@@ -2336,9 +2608,13 @@ Flushes the stream. This API uses a promise to return the result. ...@@ -2336,9 +2608,13 @@ Flushes the stream. This API uses a promise to return the result.
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ------------- | | ------------------- | ------------- |
| Promise&lt;void&gt; | Promise used to return the stream flushing result.| | Promise&lt;void&gt; | Promise used to return the stream flushing result.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
...@@ -2352,7 +2628,6 @@ Flushes the stream. This API uses a promise to return the result. ...@@ -2352,7 +2628,6 @@ Flushes the stream. This API uses a promise to return the result.
}); });
``` ```
### flush ### flush
flush(callback: AsyncCallback&lt;void&gt;): void flush(callback: AsyncCallback&lt;void&gt;): void
...@@ -2363,9 +2638,13 @@ Flushes the stream. This API uses an asynchronous callback to return the result. ...@@ -2363,9 +2638,13 @@ Flushes the stream. This API uses an asynchronous callback to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | -------------- | | -------- | ------------------------- | ---- | -------------- |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the stream is asynchronously flushed.| | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the stream is asynchronously flushed.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
...@@ -2389,6 +2668,10 @@ Synchronously flushes the stream. ...@@ -2389,6 +2668,10 @@ Synchronously flushes the stream.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
```js ```js
...@@ -2407,16 +2690,20 @@ Writes data into the stream. This API uses a promise to return the result. ...@@ -2407,16 +2690,20 @@ Writes data into the stream. This API uses a promise to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------- | ------------------------------- | ---- | ---------------------------------------- | | ------- | ------------------------------- | ---- | ---------------------------------------- |
| buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. | | buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. |
| options | Object | No | The options are as follows:<br>- **length** (number): length of the data to write. The default value is the buffer length.<br>- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.<br>- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.| | options | Object | No | The options are as follows:<br>- **length** (number): length of the data to write. The default value is the buffer length.<br>- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.<br>- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| --------------------- | -------- | | --------------------- | -------- |
| Promise&lt;number&gt; | Promise used to return the length of the data written.| | Promise&lt;number&gt; | Promise used to return the length of the data written.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
...@@ -2430,7 +2717,6 @@ Writes data into the stream. This API uses a promise to return the result. ...@@ -2430,7 +2717,6 @@ Writes data into the stream. This API uses a promise to return the result.
}); });
``` ```
### write ### write
write(buffer: ArrayBuffer|string, options?: { offset?: number; length?: number; encoding?: string; }, callback: AsyncCallback&lt;number&gt;): void write(buffer: ArrayBuffer|string, options?: { offset?: number; length?: number; encoding?: string; }, callback: AsyncCallback&lt;number&gt;): void
...@@ -2441,11 +2727,15 @@ Writes data into the stream. This API uses an asynchronous callback to return th ...@@ -2441,11 +2727,15 @@ Writes data into the stream. This API uses an asynchronous callback to return th
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------------- | ---- | ------------------------------------------------------------ | | -------- | ------------------------------- | ---- | ------------------------------------------------------------ |
| buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. | | buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. |
| options | Object | No | The options are as follows:<br>- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.<br>- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.<br>- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.| | options | Object | No | The options are as follows:<br>- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.<br>- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.<br>- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.|
| callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked when the data is written asynchronously. | | callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked when the data is written asynchronously. |
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
...@@ -2473,16 +2763,20 @@ Synchronously writes data into the stream. ...@@ -2473,16 +2763,20 @@ Synchronously writes data into the stream.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------- | ------------------------------- | ---- | ---------------------------------------- | | ------- | ------------------------------- | ---- | ---------------------------------------- |
| buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. | | buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. |
| options | Object | No | The options are as follows:<br>- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.<br>- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.<br>- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.| | options | Object | No | The options are as follows:<br>- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.<br>- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.<br>- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------ | -------- | | ------ | -------- |
| number | Length of the data written in the file.| | number | Length of the data written in the file.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
...@@ -2502,16 +2796,20 @@ Reads data from the stream. This API uses a promise to return the result. ...@@ -2502,16 +2796,20 @@ Reads data from the stream. This API uses a promise to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------- | ----------- | ---- | ---------------------------------------- | | ------- | ----------- | ---- | ---------------------------------------- |
| buffer | ArrayBuffer | Yes | Buffer used to store the file read. | | buffer | ArrayBuffer | Yes | Buffer used to store the file read. |
| options | Object | No | The options are as follows:<br>- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length.<br>- **offset** (number): position of the data to read in the file. By default, data is read from the current position.| | options | Object | No | The options are as follows:<br>- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length.<br>- **offset** (number): position of the data to read in the file. By default, data is read from the current position.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ---------------------------------- | ------ | | ---------------------------------- | ------ |
| Promise&lt;number&gt; | Promise used to return the data read.| | Promise&lt;number&gt; | Promise used to return the data read.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
...@@ -2527,7 +2825,6 @@ Reads data from the stream. This API uses a promise to return the result. ...@@ -2527,7 +2825,6 @@ Reads data from the stream. This API uses a promise to return the result.
}); });
``` ```
### read ### read
read(buffer: ArrayBuffer, options?: { position?: number; offset?: number; length?: number; }, callback: AsyncCallback&lt;number&gt;): void read(buffer: ArrayBuffer, options?: { position?: number; offset?: number; length?: number; }, callback: AsyncCallback&lt;number&gt;): void
...@@ -2538,11 +2835,15 @@ Reads data from the stream. This API uses an asynchronous callback to return the ...@@ -2538,11 +2835,15 @@ Reads data from the stream. This API uses an asynchronous callback to return the
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- | | -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| buffer | ArrayBuffer | Yes | Buffer used to store the file read. | | buffer | ArrayBuffer | Yes | Buffer used to store the file read. |
| options | Object | No | The options are as follows:<br>- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length.<br>- **offset** (number): position of the data to read in the file. This parameter is optional. By default, data is read from the current position.| | options | Object | No | The options are as follows:<br>- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length.<br>- **offset** (number): position of the data to read in the file. This parameter is optional. By default, data is read from the current position.|
| callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked when data is read asynchronously from the stream. | | callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked when data is read asynchronously from the stream. |
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
...@@ -2570,16 +2871,20 @@ Synchronously reads data from the stream. ...@@ -2570,16 +2871,20 @@ Synchronously reads data from the stream.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------- | ----------- | ---- | ---------------------------------------- | | ------- | ----------- | ---- | ---------------------------------------- |
| buffer | ArrayBuffer | Yes | Buffer used to store the file read. | | buffer | ArrayBuffer | Yes | Buffer used to store the file read. |
| options | Object | No | The options are as follows:<br>- **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.<br> | | options | Object | No | The options are as follows:<br>- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length.<br>- **offset** (number): position of the data to read in the file. By default, data is read from the current position.<br> |
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------ | -------- | | ------ | -------- |
| number | Length of the data read.| | number | Length of the data read.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
...@@ -2603,7 +2908,7 @@ Represents a **File** object opened by **open()**. ...@@ -2603,7 +2908,7 @@ Represents a **File** object opened by **open()**.
### lock ### 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. Applies an exclusive lock or a shared lock on this file in blocking mode. This API uses a promise to return the result.
...@@ -2611,15 +2916,19 @@ Applies an exclusive lock or a shared lock on this file in blocking mode. This A ...@@ -2611,15 +2916,19 @@ Applies an exclusive lock or a shared lock on this file in blocking mode. This A
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | 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. | | exclusive | boolean | No | Lock to apply. The value **true** means an exclusive lock, and the value **false** (default) means a shared lock. |
**Return value** **Return value**
| Type | Description | | Type | Description |
| ---------------------------------- | ------ | | ---------------------------------- | ------ |
| Promise&lt;void&gt; | Promise that returns no value.| | Promise&lt;void&gt; | Promise that returns no value.|
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
...@@ -2634,7 +2943,7 @@ Applies an exclusive lock or a shared lock on this file in blocking mode. This A ...@@ -2634,7 +2943,7 @@ Applies an exclusive lock or a shared lock on this file in blocking mode. This A
### lock ### 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. Applies an exclusive lock or a shared lock on this file in blocking mode. This API uses a promise to return the result.
...@@ -2642,10 +2951,14 @@ Applies an exclusive lock or a shared lock on this file in blocking mode. This A ...@@ -2642,10 +2951,14 @@ Applies an exclusive lock or a shared lock on this file in blocking mode. This A
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | 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. | | 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. | | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file is locked. |
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
...@@ -2662,7 +2975,7 @@ Applies an exclusive lock or a shared lock on this file in blocking mode. This A ...@@ -2662,7 +2975,7 @@ Applies an exclusive lock or a shared lock on this file in blocking mode. This A
### tryLock ### tryLock
tryLock(exclusive?: boolean): void; tryLock(exclusive?: boolean): void
Applies an exclusive lock or a shared lock on this file in non-blocking mode. Applies an exclusive lock or a shared lock on this file in non-blocking mode.
...@@ -2670,9 +2983,13 @@ Applies an exclusive lock or a shared lock on this file in non-blocking mode. ...@@ -2670,9 +2983,13 @@ Applies an exclusive lock or a shared lock on this file in non-blocking mode.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | 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. | | exclusive | boolean | No | Lock to apply. The value **true** means an exclusive lock, and the value **false** (default) means a shared lock. |
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
...@@ -2684,12 +3001,16 @@ Applies an exclusive lock or a shared lock on this file in non-blocking mode. ...@@ -2684,12 +3001,16 @@ Applies an exclusive lock or a shared lock on this file in non-blocking mode.
### unlock ### unlock
unlock(): void; unlock(): void
Unlocks this file synchronously. Unlocks this file synchronously.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Error codes**
For details about error codes, see "Basic File I/O Error Codes" in [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
**Example** **Example**
```js ```js
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册