> The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
...
...
@@ -15,7 +15,7 @@ import fileio from '@ohos.fileio';
None
## Note
## Guidelines
Before using this module to perform operations on a file or directory, obtain the absolute path of the file or directory. For details, see [getOrCreateLocalDir of the Context module](js-apis-Context.md).
| path | string | Yes| Absolute path of the target file.|
| mode | number | No| Options for accessing the file. You can specify multiple options, separated with a bitwise OR operator (|). The default value is **0**.<br/>The options are as follows:<br/>- **0**: check whether the file exists. <br/>- **1**: check whether the current process has the execute permission on the file. <br/>- **2**: check whether the current process has the write permission on the file. <br/>- **4**: check whether the current process has the read permission on the file.|
| mode | number | No| Options for accessing the file. You can specify multiple options, separated with a bitwise OR operator (|). The default value is **0**.<br>The options are as follows:<br>- **0**: check whether the file exists.<br>- **1**: check whether the current process has the execute permission on the file.<br>- **2**: check whether the current process has the write permission on the file.<br>- **4**: check whether the current process has the read permission on the file.|
- Return value
| Type| Description|
...
...
@@ -207,15 +221,17 @@ Asynchronously checks whether the current process can access a file. This method
| path | string | Yes| Absolute path of the target file.|
| mode | number | No| Options for accessing the file. You can specify multiple options, separated with a bitwise OR operator (|). The default value is **0**.<br/>The options are as follows:<br/>- **0**: check whether the file exists. <br/>- **1**: check whether the current process has the execute permission on the file. <br/>- **2**: check whether the current process has the write permission on the file. <br/>- **4**: check whether the current process has the read permission on the file.|
| mode | number | No| Options for accessing the file. You can specify multiple options, separated with a bitwise OR operator (|). The default value is **0**.<br>The options are as follows:<br>- **0**: check whether the file exists.<br>- **1**: check whether the current process has the execute permission on the file.<br>- **2**: check whether the current process has the write permission on the file.<br>- **4**: check whether the current process has the read permission on the file.|
| callback | AsyncCallback<void> | Yes| Callback invoked when the file is asynchronously checked.|
| path | string | Yes| Absolute path of the target file.|
| mode | number | No| Options for accessing the file. You can specify multiple options, separated with a bitwise OR operator (|). The default value is **0**.<br/>The options are as follows:<br/>- **0**: check whether the file exists. <br/>- **1**: check whether the current process has the execute permission on the file. <br/>- **2**: check whether the current process has the write permission on the file. <br/>- **4**: check whether the current process has the read permission on the file.|
| mode | number | No| Options for accessing the file. You can specify multiple options, separated with a bitwise OR operator (|). The default value is **0**.<br>The options are as follows:<br>- **0**: check whether the file exists.<br>- **1**: check whether the current process has the execute permission on the file.<br>- **2**: check whether the current process has the write permission on the file.<br>- **4**: check whether the current process has the read permission on the file.|
| src | string \| number | Yes| Path or file descriptor of the file to copy.|
| dest | string \| number | Yes| Path or file descriptor of the new file.|
| mode | number | No| Option for overwriting the file of the same name in the destination path. The default value is **0**, which is the only value supported.<br/>**0**: Completely overwrite the file with the same name and truncate the part that is not overwritten.|
| mode | number | No| Option for overwriting the file of the same name in the destination path. The default value is **0**, which is the only value supported.<br>**0**: Completely overwrite the file with the same name and truncate the part that is not overwritten.|
- Return value
| Type| Description|
...
...
@@ -384,16 +413,18 @@ Asynchronously copies a file. This method uses a promise to return the result.
| src | string \| number | Yes| Path or file descriptor of the file to copy.|
| dest | string \| number | Yes| Path or file descriptor of the new file.|
| mode | number | No| Option for overwriting the file of the same name in the destination path. The default value is **0**, which is the only value supported.<br/>**0**: Completely overwrite the file with the same name and truncate the part that is not overwritten.|
| mode | number | No| Option for overwriting the file of the same name in the destination path. The default value is **0**, which is the only value supported.<br>**0**: Completely overwrite the file with the same name and truncate the part that is not overwritten.|
| callback | AsyncCallback<void> | Yes| Callback invoked when the file is copied asynchronously.|
- Example
...
...
@@ -406,16 +437,18 @@ Asynchronously copies a file. This method uses a callback to return the result.
| src | string \| number | Yes| Path or file descriptor of the file to copy.|
| dest | string \| number | Yes| Path or file descriptor of the new file.|
| mode | number | No| Option for overwriting the file of the same name in the destination path. The default value is **0**, which is the only value supported.<br/>**0**: Completely overwrite the file with the same name and truncate the part that is not overwritten.|
| mode | number | No| Option for overwriting the file of the same name in the destination path. The default value is **0**, which is the only value supported.<br>**0**: Completely overwrite the file with the same name and truncate the part that is not overwritten.|
| path | string | Yes| Absolute path of the directory to create.|
| mode | number | No| Permission on the directory to create. You can specify multiple permissions, separated using a bitwise OR operator (|). The default value is **0o775**.<br/>- **0o775**: The owner has the read, write, and execute permissions, and other users have the read and execute permissions. <br/>- **0o700**: The owner has the read, write, and execute permissions. <br/>- **0o400**: The owner has the read permission. <br/>- **0o200**: The owner has the write permission. <br/>- **0o100**: The owner has the execute permission. <br/>- **0o070**: The user group has the read, write, and execute permissions. <br/>- **0o040**: The user group has the read permission. <br/>- **0o020**: The user group has the write permission. <br/>- **0o010**: The user group has the execute permission. <br/>- **0o007**: Other users have the read, write, and execute permissions. <br/>- **0o004**: Other users have the read permission. <br/>- **0o002**: Other users have the write permission. <br/>- **0o001**: Other users have the execute permission.|
| mode | number | No| Permission on the directory to create. You can specify multiple permissions, separated using a bitwise OR operator (|). The default value is **0o775**.<br>- **0o775**: The owner has the read, write, and execute permissions, and other users have the read and execute permissions.<br>- **0o700**: The owner has the read, write, and execute permissions.<br>- **0o400**: The owner has the read permission.<br>- **0o200**: The owner has the write permission.<br>- **0o100**: The owner has the execute permission.<br>- **0o070**: The user group has the read, write, and execute permissions.<br>- **0o040**: The user group has the read permission.<br>- **0o020**: The user group has the write permission.<br>- **0o010**: The user group has the execute permission.<br>- **0o007**: Other users have the read, write, and execute permissions.<br>- **0o004**: Other users have the read permission.<br>- **0o002**: Other users have the write permission.<br>- **0o001**: Other users have the execute permission.|
- Return value
| Type| Description|
...
...
@@ -453,15 +487,17 @@ Asynchronously creates a directory. This method uses a promise to return the res
| path | string | Yes| Absolute path of the directory to create.|
| mode | number | No| Permission on the directory to create. You can specify multiple permissions, separated using a bitwise OR operator (|). The default value is **0o775**.<br/>- **0o775**: The owner has the read, write, and execute permissions, and other users have the read and execute permissions. <br/>- **0o700**: The owner has the read, write, and execute permissions. <br/>- **0o400**: The owner has the read permission. <br/>- **0o200**: The owner has the write permission. <br/>- **0o100**: The owner has the execute permission. <br/>- **0o070**: The user group has the read, write, and execute permissions. <br/>- **0o040**: The user group has the read permission. <br/>- **0o020**: The user group has the write permission. <br/>- **0o010**: The user group has the execute permission. <br/>- **0o007**: Other users have the read, write, and execute permissions. <br/>- **0o004**: Other users have the read permission. <br/>- **0o002**: Other users have the write permission. <br/>- **0o001**: Other users have the execute permission.|
| mode | number | No| Permission on the directory to create. You can specify multiple permissions, separated using a bitwise OR operator (|). The default value is **0o775**.<br>- **0o775**: The owner has the read, write, and execute permissions, and other users have the read and execute permissions.<br>- **0o700**: The owner has the read, write, and execute permissions.<br>- **0o400**: The owner has the read permission.<br>- **0o200**: The owner has the write permission.<br>- **0o100**: The owner has the execute permission.<br>- **0o070**: The user group has the read, write, and execute permissions.<br>- **0o040**: The user group has the read permission.<br>- **0o020**: The user group has the write permission.<br>- **0o010**: The user group has the execute permission.<br>- **0o007**: Other users have the read, write, and execute permissions.<br>- **0o004**: Other users have the read permission.<br>- **0o002**: Other users have the write permission.<br>- **0o001**: Other users have the execute permission.|
| callback | AsyncCallback<void> | Yes| Callback invoked when the directory is created asynchronously.|
- Example
...
...
@@ -476,15 +512,17 @@ Asynchronously creates a directory. This method uses a callback to return the re
| path | string | Yes| Absolute path of the directory to create.|
| mode | number | No| Permission on the directory to create. You can specify multiple permissions, separated using a bitwise OR operator (|). The default value is **0o775**.<br/>- **0o775**: The owner has the read, write, and execute permissions, and other users have the read and execute permissions. <br/>- **0o700**: The owner has the read, write, and execute permissions. <br/>- **0o400**: The owner has the read permission. <br/>- **0o200**: The owner has the write permission. <br/>- **0o100**: The owner has the execute permission. <br/>- **0o070**: The user group has the read, write, and execute permissions. <br/>- **0o040**: The user group has the read permission. <br/>- **0o020**: The user group has the write permission. <br/>- **0o010**: The user group has the execute permission. <br/>- **0o007**: Other users have the read, write, and execute permissions. <br/>- **0o004**: Other users have the read permission. <br/>- **0o002**: Other users have the write permission. <br/>- **0o001**: Other users have the execute permission.|
| mode | number | No| Permission on the directory to create. You can specify multiple permissions, separated using a bitwise OR operator (|). The default value is **0o775**.<br>- **0o775**: The owner has the read, write, and execute permissions, and other users have the read and execute permissions.<br>- **0o700**: The owner has the read, write, and execute permissions.<br>- **0o400**: The owner has the read permission.<br>- **0o200**: The owner has the write permission.<br>- **0o100**: The owner has the execute permission.<br>- **0o070**: The user group has the read, write, and execute permissions.<br>- **0o040**: The user group has the read permission.<br>- **0o020**: The user group has the write permission.<br>- **0o010**: The user group has the execute permission.<br>- **0o007**: Other users have the read, write, and execute permissions.<br>- **0o004**: Other users have the read permission.<br>- **0o002**: Other users have the write permission.<br>- **0o001**: Other users have the execute permission.|
| path | string | Yes| Absolute path of the target file.|
| flags | number | No| Option for opening a file. You must specify one of the following options. By default, the file is opened in read-only mode. <br/>- **0o0**: Open the file in read-only mode. <br/>- **0o1**: Open the file in write-only mode. <br/>- **0o2**: Open the file in read/write mode. <br/>You can also specify the following options, separated using a bitwise OR operator (|). By default, no extra option is specified. <br/>- **0o100**: If the file does not exist, create it. If you use this option, you must also specify **mode**. <br/>- **0o200**: If **0o100** is added and the file already exists, throw an exception. <br/>- **0o1000**: If the file exists and is open in write-only or read/write mode, truncate the file length to 0. <br/>- **0o2000**: Open the file in append mode. New data will be appended to the file (added to the end of the file). <br/>- **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/>- **0o200000**: If **path** points to a directory, throw an exception. <br/>- **0o400000**: If **path** points to a symbolic link, throw an exception. <br/>- **0o4010000**: Open the file in synchronous I/O mode.|
| mode | number | No| Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (|). The default value is **0o666**.<br/>- **0o666**: The owner, user group, and other users have the read and write permissions on the file. <br/>- **0o700**: The owner has the read, write, and execute permissions. <br/>- **0o400**: The owner has the read permission. <br/>- **0o200**: The owner has the write permission. <br/>- **0o100**: The owner has the execute permission. <br/>- **0o070**: The user group has the read, write, and execute permissions. <br/>- **0o040**: The user group has the read permission. <br/>- **0o020**: The user group has the write permission. <br/>- **0o010**: The user group has the execute permission. <br/>- **0o007**: Other users have the read, write, and execute permissions. <br/>- **0o004**: Other users have the read permission. <br/>- **0o002**: Other users have the write permission. <br/>- **0o001**: Other users have the execute permission.|
| flags | number | No| Option for opening the file. You must specify one of the following options. By default, the file is open in read-only mode.<br>- **0o0**: Open the file in read-only mode.<br>- **0o1**: Open the file in write-only mode.<br>- **0o2**: Open the file in read/write mode.<br>In addition, you can specify the following options, separated using a bitwise OR operator (|). By default, no additional option is specified.<br>- **0o100**: If the file does not exist, create it. If you use this option, you must also specify **mode**.<br>- **0o200**: If **0o100** is added and the file already exists, throw an exception.<br>- **0o1000**: If the file exists and is open in write-only or read/write mode, truncate the file length to 0.<br>- **0o2000**: Open the file in append mode. New data will be appended to the file (added to the end of the file).<br>- **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>- **0o200000**: If **path** points to a directory, throw an exception.<br><br/>- **0o400000**: If **path** points to a symbolic link, throw an exception.<br>- **0o4010000**: Open the file in synchronous I/O mode.|
| mode | number | No| Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (|). The default value is **0o666**.<br>- **0o666**: The owner, user group, and other users have the read and write permissions on the file.<br>- **0o700**: The owner has the read, write, and execute permissions.<br>- **0o400**: The owner has the read permission.<br>- **0o200**: The owner has the write permission.<br>- **0o100**: The owner has the execute permission.<br>- **0o070**: The user group has the read, write, and execute permissions.<br>- **0o040**: The user group has the read permission.<br>- **0o020**: The user group has the write permission.<br>- **0o010**: The user group has the execute permission.<br>- **0o007**: Other users have the read, write, and execute permissions.<br>- **0o004**: Other users have the read permission.<br>- **0o002**: Other users have the write permission.<br>- **0o001**: Other users have the execute permission.|
- Return value
| Type| Description|
| -------- | -------- |
| Promise<number> | Promise used to return the file descriptor of the file opened.|
| Promise<number> | File descriptor of the file opened.|
| path | string | Yes| Absolute path of the target file.|
| flags | number | Yes| Option for opening a file. You must specify one of the following options. By default, the file is opened in read-only mode. <br/>- **0o0**: Open the file in read-only mode. <br/>- **0o1**: Open the file in write-only mode. <br/>- **0o2**: Open the file in read/write mode. <br/>You can also specify the following options, separated using a bitwise OR operator (|). By default, no extra option is specified. <br/>- **0o100**: If the file does not exist, create it. If you use this option, you must also specify **mode**. <br/>- **0o200**: If **0o100** is added and the file already exists, throw an exception. <br/>- **0o1000**: If the file exists and is open in write-only or read/write mode, truncate the file length to 0. <br/>- **0o2000**: Open the file in append mode. New data will be appended to the file (added to the end of the file). <br/>- **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/>- **0o200000**: If **path** points to a directory, throw an exception. <br/>- **0o400000**: If **path** points to a symbolic link, throw an exception. <br/>- **0o4010000**: Open the file in synchronous I/O mode.|
| mode | number | Yes| Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (|). The default value is **0o666**.<br/>- **0o666**: The owner, user group, and other users have the read and write permissions on the file. <br/>- **0o700**: The owner has the read, write, and execute permissions. <br/>- **0o400**: The owner has the read permission. <br/>- **0o200**: The owner has the write permission. <br/>- **0o100**: The owner has the execute permission. <br/>- **0o070**: The user group has the read, write, and execute permissions. <br/>- **0o040**: The user group has the read permission. <br/>- **0o020**: The user group has the write permission. <br/>- **0o010**: The user group has the execute permission. <br/>- **0o007**: Other users have the read, write, and execute permissions. <br/>- **0o004**: Other users have the read permission. <br/>- **0o002**: Other users have the write permission. <br/>- **0o001**: Other users have the execute permission.|
| flags | number | Yes| Option for opening the file. You must specify one of the following options. By default, the file is open in read-only mode.<br>- **0o0**: Open the file in read-only mode.<br>- **0o1**: Open the file in write-only mode.<br>- **0o2**: Open the file in read/write mode.<br>In addition, you can specify the following options, separated using a bitwise OR operator (|). By default, no additional option is specified.<br>- **0o100**: If the file does not exist, create it. If you use this option, you must also specify **mode**.<br>- **0o200**: If **0o100** is added and the file already exists, throw an exception.<br>- **0o1000**: If the file exists and is open in write-only or read/write mode, truncate the file length to 0.<br>- **0o2000**: Open the file in append mode. New data will be appended to the file (added to the end of the file).<br>- **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>- **0o200000**: If **path** points to a directory, throw an exception.<br><br/>- **0o400000**: If **path** points to a symbolic link, throw an exception.<br>- **0o4010000**: Open the file in synchronous I/O mode.|
| mode | number | Yes| Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (|). The default value is **0o666**.<br>- **0o666**: The owner, user group, and other users have the read and write permissions on the file.<br>- **0o700**: The owner has the read, write, and execute permissions.<br>- **0o400**: The owner has the read permission.<br>- **0o200**: The owner has the write permission.<br>- **0o100**: The owner has the execute permission.<br>- **0o070**: The user group has the read, write, and execute permissions.<br>- **0o040**: The user group has the read permission.<br>- **0o020**: The user group has the write permission.<br>- **0o010**: The user group has the execute permission.<br>- **0o007**: Other users have the read, write, and execute permissions.<br>- **0o004**: Other users have the read permission.<br>- **0o002**: Other users have the write permission.<br>- **0o001**: Other users have the execute permission.|
| callback | AsyncCallback <void> | Yes| Callback invoked when the file is open asynchronously.|
- Example
...
...
@@ -548,12 +590,14 @@ openSync(path:string, flags?:number, mode?:number): number
| path | string | Yes| Absolute path of the target file.|
| flags | number | No| Option for opening a file. You must specify one of the following options. By default, the file is opened in read-only mode. <br/>- **0o0**: Open the file in read-only mode. <br/>- **0o1**: Open the file in write-only mode. <br/>- **0o2**: Open the file in read/write mode. <br/>You can also specify the following options, separated using a bitwise OR operator (|). By default, no extra option is specified. <br/>- **0o100**: If the file does not exist, create it. If you use this option, you must also specify **mode**. <br/>- **0o200**: If **0o100** is added and the file already exists, throw an exception. <br/>- **0o1000**: If the file exists and is open in write-only or read/write mode, truncate the file length to 0. <br/>- **0o2000**: Open the file in append mode. New data will be appended to the file (added to the end of the file). <br/>- **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/>- **0o200000**: If **path** points to a directory, throw an exception. <br/>- **0o400000**: If **path** points to a symbolic link, throw an exception. <br/>- **0o4010000**: Open the file in synchronous I/O mode.|
| mode | number | No| Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (|). The default value is **0o666**.<br/>- **0o666**: The owner, user group, and other users have the read and write permissions on the file. <br/>- **0o700**: The owner has the read, write, and execute permissions. <br/>- **0o400**: The owner has the read permission. <br/>- **0o200**: The owner has the write permission. <br/>- **0o100**: The owner has the execute permission. <br/>- **0o070**: The user group has the read, write, and execute permissions. <br/>- **0o040**: The user group has the read permission. <br/>- **0o020**: The user group has the write permission. <br/>- **0o010**: The user group has the execute permission. <br/>- **0o007**: Other users have the read, write, and execute permissions. <br/>- **0o004**: Other users have the read permission. <br/>- **0o002**: Other users have the write permission. <br/>- **0o001**: Other users have the execute permission.<br/>The file permissions of newly created files are affected by **umask**, which is set as the process starts. Currently, the modification of **umask** is not open.
| flags | number | No| Option for opening the file. You must specify one of the following options. By default, the file is open in read-only mode.<br>- **0o0**: Open the file in read-only mode.<br>- **0o1**: Open the file in write-only mode.<br>- **0o2**: Open the file in read/write mode.<br>In addition, you can specify the following options, separated using a bitwise OR operator (|). By default, no additional option is specified.<br>- **0o100**: If the file does not exist, create it. If you use this option, you must also specify **mode**.<br>- **0o200**: If **0o100** is added and the file already exists, throw an exception.<br>- **0o1000**: If the file exists and is open in write-only or read/write mode, truncate the file length to 0.<br>- **0o2000**: Open the file in append mode. New data will be appended to the file (added to the end of the file).<br>- **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>- **0o200000**: If **path** points to a directory, throw an exception.<br><br/>- **0o400000**: If **path** points to a symbolic link, throw an exception.<br>- **0o4010000**: Open the file in synchronous I/O mode.|
| mode | number | No| Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (|). The default value is **0o666**.<br>- **0o666**: The owner, user group, and other users have the read and write permissions on the file.<br>- **0o700**: The owner has the read, write, and execute permissions.<br>- **0o400**: The owner has the read permission.<br>- **0o200**: The owner has the write permission.<br>- **0o100**: The owner has the execute permission.<br>- **0o070**: The user group has the read, write, and execute permissions.<br>- **0o040**: The user group has the read permission.<br>- **0o020**: The user group has the write permission.<br>- **0o010**: The user group has the execute permission.<br>- **0o007**: Other users have the read, write, and execute permissions.<br>- **0o004**: Other users have the read permission.<br>- **0o002**: Other users have the write permission.<br>- **0o001**: Other users have the execute permission.<br>The file permissions on newly created files are affected by umask, which is set as the process starts. Currently, the modification of umask is not open.|
| fd | number | Yes| File descriptor of the file to read.|
| buffer | ArrayBuffer | Yes| Buffer used to store the file data read.|
| options | Object | No| The options are as follows:<br/>- **offset** (number): position to store the data read in the buffer in reference to the start address of the buffer. The default value is **0**. <br/>- **length** (number): length of the data to be read. The default value is the buffer length minus the offset. <br/>- **position** (number): position of the data to be read in the file. By default, data is read from the current position.|
| options | Object | No| The options are as follows:<br>- **offset** (number): position to store the data read in the buffer in reference to the start address of the buffer. The default value is **0**.<br>- **length** (number): length of the data to read. The default value is the buffer length minus the offset.<br>- **position** (number): position of the data to read in the file. By default, data is read from the current position.|
- Return value
| Type| Description|
| -------- | -------- |
| Promise<[Readout](#readout)> | Promise used to return the data read.|
| Promise<[ReadOut](#readout)> | Data read.|
- Example
```js
...
...
@@ -598,17 +648,23 @@ Asynchronously reads data from a file. This method uses a promise to return the
| fd | number | Yes| File descriptor of the file to read.|
| buffer | ArrayBuffer | Yes| Buffer used to store the file data read.|
| options | Object | No| The options are as follows:<br/>- **offset** (number): position to store the data read in the buffer in reference to the start address of the buffer. The default value is **0**. <br/>- **length** (number): length of the data to be read. The default value is the buffer length minus the offset. <br/>- **position** (number): position of the data to be read in the file. By default, data is read from the current position.|
| callback | AsyncCallback<[Readout](#readout)> | Yes| Callback invoked when the data is read asynchronously.|
| options | Object | No| The options are as follows:<br>- **offset** (number): position to store the data read in the buffer in reference to the start address of the buffer. The default value is **0**.<br>- **length** (number): length of the data to read. The default value is the buffer length minus the offset.<br>- **position** (number): position of the data to read in the file. By default, data is read from the current position.|
| callback | AsyncCallback<[ReadOut](#readout)> | Yes| Callback invoked when the data is read asynchronously.|
- Example
```js
...
...
@@ -624,16 +680,22 @@ Asynchronously reads data from a file. This method uses a callback to return the
## fileio.readSync
readSync(fd: number, buffer: ArrayBuffer, options?: Object): number
| fd | number | Yes| File descriptor of the file to read.|
| buffer | ArrayBuffer | Yes| Buffer used to store the file data read.|
| options | Object | No| The options are as follows:<br/>- **offset** (number): position to store the data read in the buffer in reference to the start address of the buffer. The default value is **0**. <br/>- **length** (number): length of the data to be read. The default value is the buffer length minus the offset. <br/>- **position** (number): position of the data to be read in the file. By default, data is read from the current position.|
| options | Object | No| The options are as follows:<br>- **offset** (number): position to store the data read in the buffer in reference to the start address of the buffer. The default value is **0**.<br>- **length** (number): length of the data to read. The default value is the buffer length minus the offset.<br>- **position** (number): position of the data to read in the file. By default, data is read from the current position.|
| fd | number | Yes| File descriptor of the file to write.|
| 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): position of the data to write in reference to the start address of the data. The default value is **0**. <br/>- **length** (number): length of the data to write. The default value is the buffer length minus the offset. <br/>- **position** (number): start position to write the data in the file. By default, data is written from the current position. <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 write in reference to the start address of the data. The default value is **0**.<br>- **length** (number): length of the data to write. The default value is the buffer length minus the offset.<br>- **position** (number): start position to write the data in the file. By default, data is written from the current position.<br>- **encoding** (string): format of the string to be encoded. The default value is **utf-8**, which is the only value supported.|
- Return value
| Type| Description|
| -------- | -------- |
| Promise<number> | Promise used to return the length of the data written in the file.|
| Promise<number> | Length of the data written in the file.|
- Example
```js
...
...
@@ -807,16 +888,23 @@ Asynchronously writes data into a file. This method uses a promise to return the
| fd | number | Yes| File descriptor of the file to write.|
| 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): position of the data to write in reference to the start address of the data. The default value is **0**. <br/>- **length** (number): length of the data to write. The default value is the buffer length minus the offset. <br/>- **position** (number): start position to write the data in the file. By default, data is written from the current position. <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 write in reference to the start address of the data. The default value is **0**.<br>- **length** (number): length of the data to write. The default value is the buffer length minus the offset.<br>- **position** (number): start position to write the data in the file. By default, data is written from the current position.<br>- **encoding** (string): format of the string to be encoded. The default value is **utf-8**, which is the only value supported.|
| callback | AsyncCallback<number> | Yes| Callback invoked when the data is written asynchronously.|
- Example
...
...
@@ -832,16 +920,23 @@ Asynchronously writes data into a file. This method uses a callback to return th
## fileio.writeSync
writeSync(fd: number, buffer: ArrayBuffer | string, options?:Object): number
| fd | number | Yes| File descriptor of the file to write.|
| 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): position of the data to write in reference to the start address of the data. The default value is **0**. <br/>- **length** (number): length of the data to write. The default value is the buffer length minus the offset. <br/>- **position** (number): start position to write the data in the file. By default, data is written from the current position. <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 write in reference to the start address of the data. The default value is **0**.<br>- **length** (number): length of the data to write. The default value is the buffer length minus the offset.<br>- **position** (number): start position to write the data in the file. By default, data is written from the current position.<br>- **encoding** (string): format of the string to be encoded. The default value is **utf-8**, which is the only value supported.|
| path | string | Yes| Absolute path of the target file.|
| mode | number | Yes| Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (|).<br/>- **0o700**: The owner has the read, write, and execute permissions. <br/>- **0o400**: The owner has the read permission. <br/>- **0o200**: The owner has the write permission. <br/>- **0o100**: The owner has the execute permission. <br/>- **0o070**: The user group has the read, write, and execute permissions. <br/>- **0o040**: The user group has the read permission. <br/>- **0o020**: The user group has the write permission. <br/>- **0o010**: The user group has the execute permission. <br/>- **0o007**: Other users have the read, write, and execute permissions. <br/>- **0o004**: Other users have the read permission. <br/>- **0o002**: Other users have the write permission. <br/>- **0o001**: Other users have the execute permission.|
| mode | number | Yes| Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (|).<br>- **0o700**: The owner has the read, write, and execute permissions.<br>- **0o400**: The owner has the read permission.<br>- **0o200**: The owner has the write permission.<br>- **0o100**: The owner has the execute permission.<br>- **0o070**: The user group has the read, write, and execute permissions.<br>- **0o040**: The user group has the read permission.<br>- **0o020**: The user group has the write permission.<br>- **0o010**: The user group has the execute permission.<br>- **0o007**: Other users have the read, write, and execute permissions.<br>- **0o004**: Other users have the read permission.<br>- **0o002**: Other users have the write permission.<br>- **0o001**: Other users have the execute permission.|
| path | string | Yes| Absolute path of the target file.|
| mode | number | Yes| Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (|).<br/>- **0o700**: The owner has the read, write, and execute permissions. <br/>- **0o400**: The owner has the read permission. <br/>- **0o200**: The owner has the write permission. <br/>- **0o100**: The owner has the execute permission. <br/>- **0o070**: The user group has the read, write, and execute permissions. <br/>- **0o040**: The user group has the read permission. <br/>- **0o020**: The user group has the write permission. <br/>- **0o010**: The user group has the execute permission. <br/>- **0o007**: Other users have the read, write, and execute permissions. <br/>- **0o004**: Other users have the read permission. <br/>- **0o002**: Other users have the write permission. <br/>- **0o001**: Other users have the execute permission.|
| mode | number | Yes| Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (|).<br>- **0o700**: The owner has the read, write, and execute permissions.<br>- **0o400**: The owner has the read permission.<br>- **0o200**: The owner has the write permission.<br>- **0o100**: The owner has the execute permission.<br>- **0o070**: The user group has the read, write, and execute permissions.<br>- **0o040**: The user group has the read permission.<br>- **0o020**: The user group has the write permission.<br>- **0o010**: The user group has the execute permission.<br>- **0o007**: Other users have the read, write, and execute permissions.<br>- **0o004**: Other users have the read permission.<br>- **0o002**: Other users have the write permission.<br>- **0o001**: Other users have the execute permission.|
| callback | AsyncCallback<void> | Yes| Callback invoked when the file permissions are changed asynchronously.|
| path | string | Yes| Absolute path of the target file.|
| mode | number | Yes| Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (|).<br/>- **0o700**: The owner has the read, write, and execute permissions. <br/>- **0o400**: The owner has the read permission. <br/>- **0o200**: The owner has the write permission. <br/>- **0o100**: The owner has the execute permission. <br/>- **0o070**: The user group has the read, write, and execute permissions. <br/>- **0o040**: The user group has the read permission. <br/>- **0o020**: The user group has the write permission. <br/>- **0o010**: The user group has the execute permission. <br/>- **0o007**: Other users have the read, write, and execute permissions. <br/>- **0o004**: Other users have the read permission. <br/>- **0o002**: Other users have the write permission. <br/>- **0o001**: Other users have the execute permission.|
| mode | number | Yes| Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (|).<br>- **0o700**: The owner has the read, write, and execute permissions.<br>- **0o400**: The owner has the read permission.<br>- **0o200**: The owner has the write permission.<br>- **0o100**: The owner has the execute permission.<br>- **0o070**: The user group has the read, write, and execute permissions.<br>- **0o040**: The user group has the read permission.<br>- **0o020**: The user group has the write permission.<br>- **0o010**: The user group has the execute permission.<br>- **0o007**: Other users have the read, write, and execute permissions.<br>- **0o004**: Other users have the read permission.<br>- **0o002**: Other users have the write permission.<br>- **0o001**: Other users have the execute permission.|
| filePath | string | Yes| Absolute path of the file to read.|
| options | Object | No| The options are as follows:<br/>- **position** (number): position of the data to read in the file. By default, data is read from the current position. <br/>- **length** (number): length of the data to be read. The default value is the buffer length minus the offset. <br/>- **encoding** (string): format of the data (string) to be encoded. The default value is **utf-8**, which is the only value supported.|
| options | Object | No| The options are as follows:<br>- **position** (number): position of the data to read in the file. By default, data is read from the current position.<br>- **length** (number): length of the data to read. The default value is the buffer length minus the offset.<br>- **encoding** (string): format of the data (string) to be encoded. The default value is **utf-8**, which is the only value supported.|
- Return value
| Type| Description|
...
...
@@ -1203,15 +1332,21 @@ Asynchronously reads the text of a file. This method uses a promise to return th
| filePath | string | Yes| Absolute path of the file to read.|
| options | Object | No| The options are as follows:<br/>- **position** (number): position of the data to read in the file. By default, data is read from the current position. <br/>- **length** (number): length of the data to be read. The default value is the buffer length minus the offset. <br/>- **encoding** (string): format of the data (string) to be encoded. The default value is **utf-8**, which is the only value supported.|
| options | Object | No| The options are as follows:<br>- **position** (number): position of the data to read in the file. By default, data is read from the current position.<br>- **length** (number): length of the data to read. The default value is the buffer length minus the offset.<br>- **encoding** (string): format of the data (string) to be encoded. The default value is **utf-8**, which is the only value supported.|
| callback | AsyncCallback<string> | Yes| Callback invoked when the file is read asynchronously.|
- Example
...
...
@@ -1224,20 +1359,26 @@ Asynchronously reads the text of a file. This method uses a callback to return t
| filePath | string | Yes| Absolute path of the file to read.|
| options | Object | No| The options are as follows:<br/>- **position** (number): position of the data to read in the file. By default, data is read from the current position. <br/>- **length** (number): length of the data to be read. The default value is the buffer length minus the offset. <br/>- **encoding** (string): format of the data (string) to be encoded. The default value is **utf-8**, which is the only value supported.|
| options | Object | No| The options are as follows:<br>- **position** (number): position of the data to read in the file. By default, data is read from the current position.<br>- **length** (number): length of the data to read. The default value is the buffer length minus the offset.<br>- **encoding** (string): format of the data (string) to be encoded. The default value is **utf-8**, which is the only value supported.|
| buffer | ArrayBuffer | Yes| Buffer used to store the file data read.|
| options | Object | No| The options are as follows:<br/>- **offset** (number): position to store the data read in the buffer in reference to the start address of the buffer. The default value is **0**. <br/>- **length** (number): length of the data to be read. It is optional. The default value is the buffer length minus the offset.|
| options | Object | No| The options are as follows:<br>- **offset** (number): position to store the data read in the buffer in reference to the start address of the buffer. The default value is **0**.<br>- **length** (number): length of the data to read. The default value is the buffer length minus the offset.|
- Return value
| Type| Description|
| -------- | -------- |
| Promise<[Readout](#readout)> | Promise used to return the data read.|
| Promise<[ReadOut](#readout)> | Data read.|
- Example
```js
...
...
@@ -1342,16 +1495,22 @@ Asynchronously reads data from a file. This method uses a promise to return the
| buffer | ArrayBuffer | Yes| Buffer used to store the file data read.|
| options | Object | No| The options are as follows:<br/>- **offset** (number): position to store the data read in the buffer in reference to the start address of the buffer. The default value is **0**. <br/>- **length** (number): length of the data to be read. It is optional. The default value is the buffer length minus the offset.|
| callback | AsyncCallback<[Readout](#readout)> | Yes| Callback invoked when the data is read asynchronously from the file.|
| options | Object | No| The options are as follows:<br>- **offset** (number): position to store the data read in the buffer in reference to the start address of the buffer. The default value is **0**.<br>- **length** (number): length of the data to read. The default value is the buffer length minus the offset.|
| callback | AsyncCallback<[ReadOut](#readout)> | Yes| Callback invoked when the data is read asynchronously from the file.|
| fd | number | Yes| File descriptor of the target file.|
| mode | number | Yes| Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (|).<br/>- **0o700**: The owner has the read, write, and execute permissions. <br/>- **0o400**: The owner has the read permission. <br/>- **0o200**: The owner has the write permission. <br/>- **0o100**: The owner has the execute permission. <br/>- **0o070**: The user group has the read, write, and execute permissions. <br/>- **0o040**: The user group has the read permission. <br/>- **0o020**: The user group has the write permission. <br/>- **0o010**: The user group has the execute permission. <br/>- **0o007**: Other users have the read, write, and execute permissions. <br/>- **0o004**: Other users have the read permission. <br/>- **0o002**: Other users have the write permission. <br/>- **0o001**: Other users have the execute permission.|
| mode | number | Yes| Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (|).<br>- **0o700**: The owner has the read, write, and execute permissions.<br>- **0o400**: The owner has the read permission.<br>- **0o200**: The owner has the write permission.<br>- **0o100**: The owner has the execute permission.<br>- **0o070**: The user group has the read, write, and execute permissions.<br>- **0o040**: The user group has the read permission.<br>- **0o020**: The user group has the write permission.<br>- **0o010**: The user group has the execute permission.<br>- **0o007**: Other users have the read, write, and execute permissions.<br>- **0o004**: Other users have the read permission.<br>- **0o002**: Other users have the write permission.<br>- **0o001**: Other users have the execute permission.|
| fd | number | Yes| File descriptor of the target file.|
| mode | number | Yes| Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (|).<br/>- **0o700**: The owner has the read, write, and execute permissions. <br/>- **0o400**: The owner has the read permission. <br/>- **0o200**: The owner has the write permission. <br/>- **0o100**: The owner has the execute permission. <br/>- **0o070**: The user group has the read, write, and execute permissions. <br/>- **0o040**: The user group has the read permission. <br/>- **0o020**: The user group has the write permission. <br/>- **0o010**: The user group has the execute permission. <br/>- **0o007**: Other users have the read, write, and execute permissions. <br/>- **0o004**: Other users have the read permission. <br/>- **0o002**: Other users have the write permission. <br/>- **0o001**: Other users have the execute permission.|
| mode | number | Yes| Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (|).<br>- **0o700**: The owner has the read, write, and execute permissions.<br>- **0o400**: The owner has the read permission.<br>- **0o200**: The owner has the write permission.<br>- **0o100**: The owner has the execute permission.<br>- **0o070**: The user group has the read, write, and execute permissions.<br>- **0o040**: The user group has the read permission.<br>- **0o020**: The user group has the write permission.<br>- **0o010**: The user group has the execute permission.<br>- **0o007**: Other users have the read, write, and execute permissions.<br>- **0o004**: Other users have the read permission.<br>- **0o002**: Other users have the write permission.<br>- **0o001**: Other users have the execute permission.|
| callback | AsyncCallback <void> | Yes| Callback invoked when the file permissions are changed asynchronously.|
- Example
...
...
@@ -1811,15 +2010,17 @@ Asynchronously changes the file permissions based on the file descriptor. This m
| fd | number | Yes| File descriptor of the target file.|
| mode | number | Yes| Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (|).<br/>- **0o700**: The owner has the read, write, and execute permissions. <br/>- **0o400**: The owner has the read permission. <br/>- **0o200**: The owner has the write permission. <br/>- **0o100**: The owner has the execute permission. <br/>- **0o070**: The user group has the read, write, and execute permissions. <br/>- **0o040**: The user group has the read permission. <br/>- **0o020**: The user group has the write permission. <br/>- **0o010**: The user group has the execute permission. <br/>- **0o007**: Other users have the read, write, and execute permissions. <br/>- **0o004**: Other users have the read permission. <br/>- **0o002**: Other users have the write permission. <br/>- **0o001**: Other users have the execute permission.|
| mode | number | Yes| Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (|).<br>- **0o700**: The owner has the read, write, and execute permissions.<br>- **0o400**: The owner has the read permission.<br>- **0o200**: The owner has the write permission.<br>- **0o100**: The owner has the execute permission.<br>- **0o070**: The user group has the read, write, and execute permissions.<br>- **0o040**: The user group has the read permission.<br>- **0o020**: The user group has the write permission.<br>- **0o010**: The user group has the execute permission.<br>- **0o007**: Other users have the read, write, and execute permissions.<br>- **0o004**: Other users have the read permission.<br>- **0o002**: Other users have the write permission.<br>- **0o001**: Other users have the execute permission.|
| path | string | Yes| Absolute path of the target 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).|
| path | string | Yes| Absolute path of the target 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<[Stream](#stream7)> | Yes| Callback invoked when the stream is open asynchronously.|
| path | string | Yes| Absolute path of the target 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).|
| fd | number | Yes| File descriptor of the target 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
| Name| Description|
...
...
@@ -1918,7 +2127,7 @@ Asynchronously opens a stream based on the file descriptor. This method uses a p
| fd | number | Yes| File descriptor of the target 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 <[Stream](#stream7)> | Yes| Callback invoked when the stream is open asynchronously.|
| fd | number | Yes| File descriptor of the target 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).|
Asynchronously changes the file owner based on the file path, changes the owner of the symbolic link (not the referenced file), and returns the result in a promise.
Asynchronously changes the file owner based on the file path, changes the owner of the symbolic link (not the referenced file), and returns the result in a callback.
| filename | string | Yes| Absolute path of the target file.|
| events | Number | Yes| - **1**: : The file or directory is renamed. <br/>- **2**: The file or directory is modified. <br/>- **3**: The file or directory is modified and renamed.|
| events | Number | Yes| - **1**: The file or directory is renamed.<br>- **2**: The file or directory is modified.<br>- **3**: The file or directory is modified and renamed.|
| callback | AsyncCallback<number > | Yes| Called each time a change is detected.|
- Return value
...
...
@@ -2143,6 +2370,8 @@ Asynchronously listens for the changes of a file or directory. This method uses
Obtains the file read result. This class applies only to the **read()** method.
| bytesRead | number | Yes| Yes| Length of the data read.|
...
...
@@ -2154,6 +2383,7 @@ Obtains the file read result. This class applies only to the **read()** method.
Provides detailed file information. Before calling a method of the **Stat** class, use the [stat()](#fileiostat) method synchronously or asynchronously to create a **Stat** instance.
| ino | number | Yes| No| File ID. Different files on the same device have different **ino**s.|
| mode | number | Yes| No| File type and permissions. The first four bits indicate the file type, and the last 12 bits indicate the permissions. The bit fields are described as follows:<br/>- **0o170000**: mask used to obtain the file type. <br/>- **0o140000**: The file is a socket. <br/>- **0o120000**: The file is a symbolic link. <br/> - **0o100000**: The file is a regular file. <br/>- **0o060000**: The file is a block device. <br/>- **0o040000**: The file is a directory. <br/>- **0o020000**: The file is a character device. <br/>- **0o010000**: The file is a named pipe (FIFO). <br/>- **0o0700**: mask used to obtain the owner permissions. <br/>- **0o0400**: The owner has the permission to read a regular file or a directory entry. <br/>- **0o0200**: The owner has the permission to write a regular file or create and delete a directory entry. <br/>- **0o0100**: The owner has the permission to execute a regular file or search for the specified path in a directory. <br/>- **0o0070**: mask used to obtain the user group permissions. <br/>- **0o0040**: The user group has the permission to read a regular file or a directory entry. <br/>- **0o0020**: The user group has the permission to write a regular file or create and delete a directory entry. <br/>- **0o0010**: The user group has the permission to execute a regular file or search for the specified path in a directory. <br/>- **0o0007**: mask used to obtain the permissions of other users. <br/>- **0o0004**: Other users have the permission to read a regular file or a directory entry. <br/>- **0o0002**: Other users have the permission to write a regular file or create and delete a directory entry. <br/>- **0o0001**: Other users have the permission to execute a regular file or search for the specified path in a directory.|
| mode | number | Yes| No| File type and permissions. The first four bits indicate the file type, and the last 12 bits indicate the permissions. The bit fields are described as follows:<br>- **0o170000**: mask used to obtain the file type.<br>- **0o140000**: The file is a socket.<br>- **0o120000**: The file is a symbolic link.<br>- **0o100000**: The file is a regular file.<br>- **0o060000**: The file is a block device.<br>- **0o040000**: The file is a directory.<br>- **0o020000**: The file is a character device.<br>- **0o010000**: The file is a named pipe (FIFO).<br>- **0o0700**: mask used to obtain the owner permissions.<br>- **0o0400**: The owner has the permission to read a regular file or a directory entry.<br>- **0o0200**: The owner has the permission to write a regular file or create and delete a directory entry.<br>- **0o0100**: The owner has the permission to execute a regular file or search for the specified path in a directory.<br>- **0o0070**: mask used to obtain the user group permissions.<br>- **0o0040**: The user group has the permission to read a regular file or a directory entry.<br>- **0o0020**: The user group has the permission to write a regular file or create and delete a directory entry.<br>- **0o0010**: The user group has the permission to execute a regular file or search for the specified path in a directory.<br>- **0o0007**: mask used to obtain the permissions of other users.<br>- **0o0004**: Other users have the permission to read a regular file or a directory entry.<br>- **0o0002**: Other users have the permission to write a regular file or create and delete a directory entry.<br>- **0o0001**: Other users have the permission to execute a regular file or search for the specified path in a directory.|
| nlink | number | Yes| No| Number of hard links in the file.|
| uid | number | Yes| No| User ID, that is ID of the file owner.|
| gid | number | Yes| No| Group ID, that is, ID of the user group of the file.|
...
...
@@ -2179,6 +2409,8 @@ isBlockDevice(): boolean
Checks whether the current directory entry is a block special file. A block special file supports access by block only, and it is cached when accessed.
Checks whether the current directory entry is a character special file. A character special file supports random access, and it is not cached when accessed.
@@ -2326,488 +2574,3 @@ Asynchronously stops **watcher**. This method uses a callback to return the resu
// Do something.
});
```
## Stream<sup>7+</sup>
File stream. Before calling a method of the **Stream** class, use the **createStream()** method synchronously or asynchronously to create a **Stream** instance.
### close<sup>7+</sup>
close(): Promise<void>
Asynchronously closes the stream. This method uses a promise to return the result.
- Return value
| Type| Description|
| -------- | -------- |
| Promise<void> | Promise used to return the stream close result.|
- Example
```js
letss=fileio.createStreamSync(path);
ss.close().then(function(){
console.info("close fileStream successfully");
}).catch(function(err){
console.info("close fileStream failed with error:"+err);
});
```
### close<sup>7+</sup>
close(callback: AsyncCallback<void>): void
Asynchronously closes the stream. This method uses a callback to return the result.
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback<void> | Yes| Callback invoked when the stream is closed asynchronously.|
- Example
```js
letss=fileio.createStreamSync(path);
ss.close(function(err){
// do something
});
```
### closeSync<sup>7+</sup>
closeSync(): void
Synchronously closes the stream.
- Example
```js
letss=fileio.createStreamSync(path);
ss.closeSync();
```
### flush<sup>7+</sup>
flush(): Promise<void>
Asynchronously flushes the stream. This method uses a promise to return the result.
- Return value
| Type| Description|
| -------- | -------- |
| Promise<void> | Promise used to return the stream flushing result.|
- Example
```js
letss=fileio.createStreamSync(path);
ss.flush().then(function(){
console.info("flush successfully");
}).catch(function(err){
console.info("flush failed with error:"+err);
});
```
### flush<sup>7+</sup>
flush(callback: AsyncCallback<void>): void
Asynchronously flushes the stream. This method uses a callback to return the result.
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback<void> | Yes| Callback invoked when the stream is asynchronously flushed.|
Asynchronously writes data into the stream. This method uses a promise to return the result.
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| buffer | ArrayBuffer \| string | Yes| Data to write. It can be a string or data from a buffer.|
| options | Object | No| The options are as follows: <br/>- **offset** (number): position of the data to write in reference to the start address of the data. The default value is **0**. <br/>- **length** (number): length of the data to write. The default value is the buffer length minus the offset. <br/>- **position** (number): start position to write the data in the file. By default, data is written from the current position. <br/>- **encoding** (string): format of the string to be encoded. The default value is **utf-8**, which is the only value supported.|
- Return value
| Type| Description|
| -------- | -------- |
| Promise<number> | Promise used to return the length of the data written in the file.|
Asynchronously writes data into the stream. This method uses a callback to return the result.
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| buffer | ArrayBuffer \| string | Yes| Data to write. It can be a string or data from a buffer.|
| options | Object | No| The options are as follows: <br/>- **offset** (number): position of the data to write in reference to the start address of the data. The default value is **0**. <br/>- **length** (number): length of the data to write. The default value is the buffer length minus the offset. <br/>- **position** (number): start position to write the data in the file. By default, data is written from the current position. <br/>- **encoding** (string): format of the string to be encoded. The default value is **utf-8**, which is the only value supported.|
| callback | AsyncCallback<number> | Yes| Callback invoked when the data is written asynchronously.|
writeSync(buffer: ArrayBuffer | string, options?:Object): number
Synchronously writes data into the stream.
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| buffer | ArrayBuffer \| string | Yes| Data to write. It can be a string or data from a buffer.|
| options | Object | No| The options are as follows: <br/>- **offset** (number): position of the data to write in reference to the start address of the data. The default value is **0**. <br/>- **length** (number): length of the data to write. The default value is the buffer length minus the offset. <br/>- **position** (number): start position to write the data in the file. By default, data is written from the current position. <br/>- **encoding** (string): format of the string to be encoded. The default value is **utf-8**, which is the only value supported.|
- Return value
| Type| Description|
| -------- | -------- |
| number | Length of the data written in the file.|
Asynchronously reads data from the stream. This method uses a promise to return the result.
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| buffer | ArrayBuffer | Yes| Buffer used to store the file read.|
| options | Object | No| The options are as follows: <br/>- **offset** (number): position to store the data read in the buffer in reference to the start address of the buffer. The default value is **0**. <br/>- **length** (number): length of the data to read. The default value is the buffer length minus the offset. <br/>- **position** (number): position of the data to be read in the file. By default, data is read from the current position.|
- Return value
| Type| Description|
| -------- | -------- |
| Promise<[Readout](#readout)> | Promise used to return the data read.|
Asynchronously reads data from the stream. This method uses a callback to return the result.
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| buffer | ArrayBuffer | Yes| Buffer used to store the file read.|
| options | Object | No| The options are as follows: <br/>- **offset** (number): position to store the data read in the buffer in reference to the start address of the buffer. The default value is **0**. <br/>- **length** (number): length of the data to read. The default value is the buffer length minus the offset. <br/>- **position** (number): position of the data to be read in the file. By default, data is read from the current position.|
| callback | AsyncCallback<[Readout](#readout)> | Yes| Callback invoked when data is read asynchronously from the stream.|
readSync(buffer: ArrayBuffer, options?: Object): number
Synchronously reads data from the stream.
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| buffer | ArrayBuffer | Yes| Buffer used to store the file read.|
| options | Object | No| The options are as follows: <br/>- **offset** (number): position to store the data read in the buffer in reference to the start address of the buffer. The default value is **0**. <br/>- **length** (number): length of the data to read. The default value is the buffer length minus the offset. <br/>- **position** (number): position of the data to be read in the file. By default, data is read from the current position.|
Manages directories. Before calling a method of the **Dir** class, use the [opendir()](#fileioopendir) method synchronously or asynchronously to create a **Dir** instance.
### read
read(): Promise<Dirent>
Asynchronously reads the next directory entry. This method uses a promise to return the result.
- Return value
| Type| Description|
| -------- | -------- |
| Promise<[Dirent](#dirent)> | Directory entry that is read asynchronously.|
- Example
```js
letdir=fileio.opendirSync(dpath);
dir.read().then(function(dirent){
console.info("read successfully:"+dirent.name);
}).catch(function(err){
console.info("read failed with error:"+err);
});
```
### read
read(callback: AsyncCallback<Dirent>): void
Asynchronously reads the next directory entry. This method uses a callback to return the result.
- Parameters
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback<[Dirent](#dirent)> | Yes| Callback invoked when the next directory entry is asynchronously read.|
- Example
```js
letdir=fileio.opendirSync(dpath);
dir.read(function(err,dirent){
if(!err){
// do something
console.log(dirent.name)
}
});
```
### readSync
readSync(): Dirent
Synchronously reads the next directory entry.
- Return value
| Type| Description|
| -------- | -------- |
| [Dirent](#dirent) | Directory entry read.|
- Example
```js
letdir=fileio.opendirSync(dpath);
letdirent=dir.readSync();
```
### closeSync
closeSync(): void
Closes a directory. After a directory is closed, the file descriptor in Dir will be released and no directory entry can be read from Dir.
- Example
```js
letdir=fileio.opendirSync(dpath);
dir.closeSync();
```
## Dirent
Provides information about files and directories. Before calling a method of the **Dirent** class, use the [dir.read()](#read) method synchronously or asynchronously to create a **Dirent** instance.
Checks whether the current directory entry is a block special file. A block special file supports access by block only, and it is cached when accessed.
- Return value
| Type| Description|
| -------- | -------- |
| boolean | Whether the directory entry is a block special file.|
- Example
```js
letdir=fileio.opendirSync(dpath);
letisBLockDevice=dir.readSync().isBlockDevice();
```
### isCharacterDevice
isCharacterDevice(): boolean
Checks whether a directory entry is a character special file. A character special file supports random access, and it is not cached when accessed.
- Return value
| Type| Description|
| -------- | -------- |
| boolean | Whether the directory entry is a character special file.|
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
...
...
@@ -9,7 +9,7 @@
importstatfsfrom'@ohos.statfs';
```
## Note
## Guidelines
Before using this module to perform operations on a file or directory, obtain the absolute path of the file or directory. For details, see [getOrCreateLocalDir of the Context module](js-apis-Context.md).
...
...
@@ -21,27 +21,25 @@ For example, if the application directory obtained by using **getOrCreateLocalDi
letpath=dir+"xxx.txt";
```
## System Capabilities
SystemCapability.FileManagement.File.FileIO
## statfs.getFreeBytes
getFreeBytes(path:string):Promise<number>
Obtains the number of free bytes of the specified file system in asynchronous mode. This method uses a promise to return the result.
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> - The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> - This is a system API and cannot be called by third-party applications.