From f6fef3c7ec34a09c937d4189f54ab5dc53d88573 Mon Sep 17 00:00:00 2001 From: Annie_wang Date: Mon, 6 Jun 2022 09:04:39 +0800 Subject: [PATCH] update docs Signed-off-by: Annie_wang --- .../reference/apis/js-apis-fileio.md | 1231 +++++++++-------- 1 file changed, 618 insertions(+), 613 deletions(-) diff --git a/en/application-dev/reference/apis/js-apis-fileio.md b/en/application-dev/reference/apis/js-apis-fileio.md index 09f43ce1da..204144be86 100644 --- a/en/application-dev/reference/apis/js-apis-fileio.md +++ b/en/application-dev/reference/apis/js-apis-fileio.md @@ -1,8 +1,10 @@ # File Management -> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
+> **NOTE**
> The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version. +This module provides file storage functions. It provides JS I/O APIs, including basic file management APIs, basic directory management APIs, statistical APIs for obtaining file information, and streaming APIs for reading and writing files. + ## Modules to Import ```js @@ -10,18 +12,13 @@ import fileio from '@ohos.fileio'; ``` -## Required Permissions - -None - - ## Guidelines -Before using this module to perform operations on a file or directory, obtain the absolute path of the file or directory. For details, see [getOrCreateLocalDir of the Context module](js-apis-Context.md). +Before using the APIs provided by this module to perform operations on a file or directory, obtain the path of the application sandbox. For details, see [getOrCreateLocalDir of the Context module](js-apis-Context.md). -Absolute file or directory path = Application directory + File name or directory name +Application sandbox path of a file or directory = Application directory + File name or directory name -For example, if the application directory obtained by using **getOrCreateLocalDir** is **dir** and the file name is **xxx.txt**, the absolute path of the file is as follows: +For example, if the application directory obtained by using **getOrCreateLocalDir** is **dir** and the file name is **xxx.txt**, the application sandbox path of the file is as follows: ```js let path = dir + "/xxx.txt"; @@ -40,21 +37,23 @@ let fd = fileio.openSync(path); stat(path: string): Promise<Stat> -Asynchronously obtains file information. This method uses a promise to return the result. +Asynchronously obtains file information. This API uses a promise to return the result. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters - | Name | Type | Mandatory | Description | - | ---- | ------ | ---- | ----------- | - | path | string | Yes | Absolute path of the target file.| +**Parameters** + +| Name| Type | Mandatory| Description | +| ------ | ------ | ---- | -------------------------- | +| path | string | Yes | Application sandbox path of the target file.| + +**Return value** -- Return value | Type | Description | | ---------------------------- | ---------- | | Promise<[Stat](#stat)> | Promise used to return the file information obtained.| -- Example +**Example** ```js fileio.stat(path).then(function(stat){ console.info("getFileInfo successfully:"+ JSON.stringify(stat)); @@ -68,17 +67,17 @@ Asynchronously obtains file information. This method uses a promise to return th stat(path:string, callback:AsyncCallback<Stat>): void -Asynchronously obtains file information. This method uses a callback to return the result. +Asynchronously obtains file information. This API uses a callback to return the result. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters - | Name | Type | Mandatory | Description | - | -------- | ---------------------------------- | ---- | --------------- | - | path | string | Yes | Absolute path of the target file. | - | callback | AsyncCallback<[Stat](#stat)> | Yes | Callback invoked to return the file information obtained.| +**Parameters** +| Name | Type | Mandatory| Description | +| -------- | ---------------------------------- | ---- | ------------------------------ | +| path | string | Yes | Application sandbox path of the target file. | +| callback | AsyncCallback<[Stat](#stat)> | Yes | Callback invoked to return the file information obtained.| -- Example +**Example** ```js fileio.stat(path, function (err, stat) { // Example code in Stat @@ -94,18 +93,18 @@ Synchronously obtains file information. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters - | Name | Type | Mandatory | Description | - | ---- | ------ | ---- | ----------- | - | path | string | Yes | Absolute path of the target file.| +**Parameters** +| Name| Type | Mandatory| Description | +| ------ | ------ | ---- | -------------------------- | +| path | string | Yes | Application sandbox path of the target file.| -- Return value +**Return value** | Type | Description | | ------------- | ---------- | | [Stat](#stat) | File information obtained.| -- Example +**Example** ```js let stat = fileio.statSync(path); // Example code in Stat @@ -116,21 +115,21 @@ Synchronously obtains file information. opendir(path: string): Promise<Dir> -Asynchronously opens a directory. This method uses a promise to return the result. +Asynchronously opens a directory. This API uses a promise to return the result. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters - | Name | Type | Mandatory | Description | - | ---- | ------ | ---- | ------------- | - | path | string | Yes | Absolute path of the directory to open.| +**Parameters** +| Name| Type | Mandatory| Description | +| ------ | ------ | ---- | ------------------------------ | +| path | string | Yes | Application sandbox path of the directory to open.| -- Return value +**Return value** | Type | Description | | -------------------------- | -------- | | Promise<[Dir](#dir)> | A **Dir** instance corresponding to the directory.| -- Example +**Example** ```js fileio.opendir(path).then(function(dir){ console.info("opendir successfully:"+ JSON.stringify(dir)); @@ -144,17 +143,18 @@ Asynchronously opens a directory. This method uses a promise to return the resul opendir(path: string, callback: AsyncCallback<Dir>): void -Asynchronously opens a directory. This method uses a callback to return the result. +Asynchronously opens a directory. This API uses a callback to return the result. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters - | Name | Type | Mandatory | Description | - | -------- | -------------------------------- | ---- | -------------- | - | path | string | Yes | Absolute path of the directory to open. | - | callback | AsyncCallback<[Dir](#dir)> | Yes | Callback invoked when the directory is open asynchronously.| +**Parameters** -- Example +| Name | Type | Mandatory| Description | +| -------- | -------------------------------- | ---- | ------------------------------ | +| path | string | Yes | Application sandbox path of the directory to open.| +| callback | AsyncCallback<[Dir](#dir)> | Yes | Callback invoked when the directory is open asynchronously. | + +**Example** ```js fileio.opendir(path, function (err, dir) { // Example code in Dir struct @@ -172,17 +172,18 @@ Synchronously opens a directory. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters - | Name | Type | Mandatory | Description | - | ---- | ------ | ---- | ------------- | - | path | string | Yes | Absolute path of the directory to open.| +**Parameters** + +| Name| Type | Mandatory| Description | +| ------ | ------ | ---- | ------------------------------ | +| path | string | Yes | Application sandbox path of the directory to open.| -- Return value +**Return value** | Type | Description | | ----------- | -------- | | [Dir](#dir) | A **Dir** instance corresponding to the directory.| -- Example +**Example** ```js let dir = fileio.opendirSync(path); // Example code in Dir struct @@ -194,22 +195,23 @@ Synchronously opens a directory. access(path: string, mode?: number): Promise<void> -Asynchronously checks whether the current process can access a file. This method uses a promise to return the result. +Asynchronously checks whether the current process can access a file. This API uses a promise to return the result. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters - | Name | Type | Mandatory | Description | - | ---- | ------ | ---- | ---------------------------------------- | - | path | string | Yes | Absolute path of the target file. | - | mode | number | No | Options for accessing the file. You can specify multiple options, separated with a bitwise OR operator (|). The default value is **0**.
The options are as follows:
- **0**: check whether the file exists.
- **1**: check whether the current process has the execute permission on the file.
- **2**: check whether the current process has the write permission on the file.
- **4**: check whether the current process has the read permission on the file.| +**Parameters** -- Return value +| Name| Type | Mandatory| Description | +| ------ | ------ | ---- | ------------------------------------------------------------ | +| path | string | Yes | Application sandbox path of the target file. | +| mode | number | No | Options for accessing the file. You can specify multiple options, separated with a bitwise OR operator (|). The default value is **0**.
The options are as follows:
- **0**: check whether the file exists.
- **1**: check whether the current process has the execute permission on the file.
- **2**: check whether the current process has the write permission on the file.
- **4**: check whether the current process has the read permission on the file.| + +**Return value** | Type | Description | | ------------------- | ---------------------------- | | Promise<void> | Promise used to return the result. An empty value is returned.| -- Example +**Example** ```js fileio.access(path).then(function() { console.info("access successfully"); @@ -223,18 +225,18 @@ Asynchronously checks whether the current process can access a file. This method access(path: string, mode: number, callback: AsyncCallback<void>): void -Asynchronously checks whether the current process can access a file. This method uses a callback to return the result. +Asynchronously checks whether the current process can access a file. This API uses a callback to return the result. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters - | Name | Type | Mandatory | Description | - | -------- | ------------------------- | ---- | ---------------------------------------- | - | path | string | Yes | Absolute path of the target file. | - | mode | number | No | Options for accessing the file. You can specify multiple options, separated with a bitwise OR operator (|). The default value is **0**.
The options are as follows:
- **0**: check whether the file exists.
- **1**: check whether the current process has the execute permission on the file.
- **2**: check whether the current process has the write permission on the file.
- **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. | +**Parameters** +| Name | Type | Mandatory| Description | +| -------- | ------------------------- | ---- | ------------------------------------------------------------ | +| path | string | Yes | Application sandbox path of the target file. | +| mode | number | No | Options for accessing the file. You can specify multiple options, separated with a bitwise OR operator (|). The default value is **0**.
The options are as follows:
- **0**: check whether the file exists.
- **1**: check whether the current process has the execute permission on the file.
- **2**: check whether the current process has the write permission on the file.
- **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. | -- Example +**Example** ```js fileio.access(path, function (err) { // Do something. @@ -250,13 +252,13 @@ Synchronously checks whether the current process can access the specified file. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters - | Name | Type | Mandatory | Description | - | ---- | ------ | ---- | ---------------------------------------- | - | path | string | Yes | Absolute path of the target file. | - | mode | number | No | Options for accessing the file. You can specify multiple options, separated with a bitwise OR operator (|). The default value is **0**.
The options are as follows:
- **0**: check whether the file exists.
- **1**: check whether the current process has the execute permission on the file.
- **2**: check whether the current process has the write permission on the file.
- **4**: check whether the current process has the read permission on the file.| +**Parameters** +| Name| Type | Mandatory| Description | +| ------ | ------ | ---- | ------------------------------------------------------------ | +| path | string | Yes | Application sandbox path of the target file. | +| mode | number | No | Options for accessing the file. You can specify multiple options, separated with a bitwise OR operator (|). The default value is **0**.
The options are as follows:
- **0**: check whether the file exists.
- **1**: check whether the current process has the execute permission on the file.
- **2**: check whether the current process has the write permission on the file.
- **4**: check whether the current process has the read permission on the file.| -- Example +**Example** ```js try { fileio.accessSync(path); @@ -270,21 +272,21 @@ Synchronously checks whether the current process can access the specified file. close(fd: number):Promise<void> -Asynchronously closes a file. This method uses a promise to return the result. +Asynchronously closes a file. This API uses a promise to return the result. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters +**Parameters** | Name | Type | Mandatory | Description | | ---- | ------ | ---- | ------------ | | fd | number | Yes | File descriptor of the file to close.| -- Return value +**Return value** | Type | Description | | ------------------- | ---------------------------- | | Promise<void> | Promise used to return the result. An empty value is returned.| -- Example +**Example** ```js let fd = fileio.openSync(path); fileio.close(fd).then(function(){ @@ -299,17 +301,17 @@ Asynchronously closes a file. This method uses a promise to return the result. close(fd: number, callback:AsyncCallback<void>): void -Asynchronously closes a file. This method uses a callback to return the result. +Asynchronously closes a file. This API uses a callback to return the result. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters +**Parameters** | Name | Type | Mandatory | Description | | -------- | ------------------------- | ---- | ------------ | | fd | number | Yes | File descriptor of the file to close.| | callback | AsyncCallback<void> | Yes | Callback invoked when the file is closed asynchronously.| -- Example +**Example** ```js let fd = fileio.openSync(path); fileio.close(fd, function (err) { @@ -326,12 +328,12 @@ Synchronously closes a file. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters +**Parameters** | Name | Type | Mandatory | Description | | ---- | ------ | ---- | ------------ | | fd | number | Yes | File descriptor of the file to close.| -- Example +**Example** ```js fileio.closeSync(fd); ``` @@ -341,16 +343,16 @@ Synchronously closes a file. close(): Promise<void> -Asynchronously closes the stream. This method uses a promise to return the result. +Asynchronously closes the stream. This API uses a promise to return the result. **System capability**: SystemCapability.FileManagement.File.FileIO -- Return value +**Return value** | Type | Description | | ------------------- | ---------------------------- | | Promise<void> | Promise used to return the result. An empty value is returned.| -- Example +**Example** ```js fileio.close().then(function(){ console.info("close file stream successfully"); @@ -364,16 +366,16 @@ Asynchronously closes the stream. This method uses a promise to return the resul close(callback: AsyncCallback<void>): void -Asynchronously closes the stream. This method uses a callback to return the result. +Asynchronously closes the stream. This API uses a callback to return the result. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters +**Parameters** | Name | Type | Mandatory | Description | | -------- | ------------------------- | ---- | ------------- | | callback | AsyncCallback<void> | Yes | Callback invoked when the stream is closed asynchronously.| -- Example +**Example** ```js fileio.close(function(err){ // Do something. @@ -385,23 +387,23 @@ Asynchronously closes the stream. This method uses a callback to return the resu copyFile(src:string | number, dest:string | number, mode?:number):Promise<void> -Asynchronously copies a file. This method uses a promise to return the result. +Asynchronously copies a file. This API uses a promise to return the result. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters +**Parameters** | Name | Type | Mandatory | Description | | ---- | -------------------------- | ---- | ---------------------------------------- | | src | string \| 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.
**0**: Completely overwrite the file with the same name and truncate the part that is not overwritten.| -- Return value +**Return value** | Type | Description | | ------------------- | ---------------------------- | | Promise<void> | Promise used to return the result. An empty value is returned.| -- Example +**Example** ```js fileio.copyFile(src, dest).then(function(){ console.info("copyFile successfully"); @@ -415,11 +417,11 @@ Asynchronously copies a file. This method uses a promise to return the result. copyFile(src: string | number, dest: string | number, mode: number, callback: AsyncCallback<void>): void -Asynchronously copies a file. This method uses a callback to return the result. +Asynchronously copies a file. This API uses a callback to return the result. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters +**Parameters** | Name | Type | Mandatory | Description | | -------- | -------------------------- | ---- | ---------------------------------------- | | src | string \| number | Yes | Path or file descriptor of the file to copy. | @@ -427,7 +429,7 @@ Asynchronously copies a file. This method uses a callback to return the result. | mode | number | No | Option for overwriting the file of the same name in the destination path. The default value is **0**, which is the only value supported.
**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 +**Example** ```js fileio.copyFile(src, dest, function (err) { // Do something. @@ -443,14 +445,14 @@ Synchronously copies a file. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters +**Parameters** | Name | Type | Mandatory | Description | | ---- | -------------------------- | ---- | ---------------------------------------- | | src | string \| 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.
**0**: Completely overwrite the file with the same name and truncate the part that is not overwritten.| -- Example +**Example** ```js fileio.copyFileSync(src, dest); ``` @@ -460,22 +462,22 @@ Synchronously copies a file. mkdir(path:string, mode?: number): Promise<void> -Asynchronously creates a directory. This method uses a promise to return the result. +Asynchronously creates a directory. This API uses a promise to return the result. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters - | Name | Type | Mandatory | Description | - | ---- | ------ | ---- | ---------------------------------------- | - | path | string | Yes | Absolute path of the directory to create. | - | mode | number | No | Permission on the directory to create. You can specify multiple permissions, separated using a bitwise OR operator (|). The default value is **0o775**.
- **0o775**: The owner has the read, write, and execute permissions, and other users have the read and execute permissions.
- **0o700**: The owner has the read, write, and execute permissions.
-  **0o400**: The owner has the read permission.
- **0o200**: The owner has the write permission.
- **0o100**: The owner has the execute permission.
- **0o070**: The user group has the read, write, and execute permissions.
- **0o040**: The user group has the read permission.
- **0o020**: The user group has the write permission.
- **0o010**: The user group has the execute permission.
- **0o007**: Other users have the read, write, and execute permissions.
- **0o004**: Other users have the read permission.
- **0o002**: Other users have the write permission.
- **0o001**: Other users have the execute permission.| +**Parameters** +| Name| Type | Mandatory| Description | +| ------ | ------ | ---- | ------------------------------------------------------------ | +| path | string | Yes | Application sandbox path of the directory to create. | +| mode | number | No | Permission on the directory to create. You can specify multiple permissions, separated using a bitwise OR operator (|). The default value is **0o775**.
- **0o775**: The owner has the read, write, and execute permissions, and other users have the read and execute permissions.
- **0o700**: The owner has the read, write, and execute permissions.
-  **0o400**: The owner has the read permission.
- **0o200**: The owner has the write permission.
- **0o100**: The owner has the execute permission.
- **0o070**: The user group has the read, write, and execute permissions.
- **0o040**: The user group has the read permission.
- **0o020**: The user group has the write permission.
- **0o010**: The user group has the execute permission.
- **0o007**: Other users have the read, write, and execute permissions.
- **0o004**: Other users have the read permission.
- **0o002**: Other users have the write permission.
- **0o001**: Other users have the execute permission.| -- Return value +**Return value** | Type | Description | | ------------------- | ---------------------------- | | Promise<void> | Promise used to return the result. An empty value is returned.| -- Example +**Example** ```js fileio.mkdir(path).then(function() { console.info("mkdir successfully"); @@ -489,18 +491,18 @@ Asynchronously creates a directory. This method uses a promise to return the res mkdir(path: string, mode: number, callback: AsyncCallback<void>): void -Asynchronously creates a directory. This method uses a callback to return the result. +Asynchronously creates a directory. This API uses a callback to return the result. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters - | Name | Type | Mandatory | Description | - | -------- | ------------------------- | ---- | ---------------------------------------- | - | path | string | Yes | Absolute path of the directory to create. | - | mode | number | No | Permission on the directory to create. You can specify multiple permissions, separated using a bitwise OR operator (|). The default value is **0o775**.
- **0o775**: The owner has the read, write, and execute permissions, and other users have the read and execute permissions.
- **0o700**: The owner has the read, write, and execute permissions.
-  **0o400**: The owner has the read permission.
- **0o200**: The owner has the write permission.
- **0o100**: The owner has the execute permission.
- **0o070**: The user group has the read, write, and execute permissions.
- **0o040**: The user group has the read permission.
- **0o020**: The user group has the write permission.
- **0o010**: The user group has the execute permission.
- **0o007**: Other users have the read, write, and execute permissions.
- **0o004**: Other users have the read permission.
- **0o002**: Other users have the write permission.
- **0o001**: Other users have the execute permission.| - | callback | AsyncCallback<void> | Yes | Callback invoked when the directory is created asynchronously. | +**Parameters** +| Name | Type | Mandatory| Description | +| -------- | ------------------------- | ---- | ------------------------------------------------------------ | +| path | string | Yes | Application sandbox path of the directory to create. | +| mode | number | No | Permission on the directory to create. You can specify multiple permissions, separated using a bitwise OR operator (|). The default value is **0o775**.
- **0o775**: The owner has the read, write, and execute permissions, and other users have the read and execute permissions.
- **0o700**: The owner has the read, write, and execute permissions.
-  **0o400**: The owner has the read permission.
- **0o200**: The owner has the write permission.
- **0o100**: The owner has the execute permission.
- **0o070**: The user group has the read, write, and execute permissions.
- **0o040**: The user group has the read permission.
- **0o020**: The user group has the write permission.
- **0o010**: The user group has the execute permission.
- **0o007**: Other users have the read, write, and execute permissions.
- **0o004**: Other users have the read permission.
- **0o002**: Other users have the write permission.
- **0o001**: Other users have the execute permission.| +| callback | AsyncCallback<void> | Yes | Callback invoked when the directory is created asynchronously. | -- Example +**Example** ```js fileio.mkdir(path, function(err) { console.info("mkdir successfully"); @@ -516,13 +518,13 @@ Synchronously creates a directory. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters - | Name | Type | Mandatory | Description | - | ---- | ------ | ---- | ---------------------------------------- | - | path | string | Yes | Absolute path of the directory to create. | - | mode | number | No | Permission on the directory to create. You can specify multiple permissions, separated using a bitwise OR operator (|). The default value is **0o775**.
- **0o775**: The owner has the read, write, and execute permissions, and other users have the read and execute permissions.
- **0o700**: The owner has the read, write, and execute permissions.
-  **0o400**: The owner has the read permission.
- **0o200**: The owner has the write permission.
- **0o100**: The owner has the execute permission.
- **0o070**: The user group has the read, write, and execute permissions.
- **0o040**: The user group has the read permission.
- **0o020**: The user group has the write permission.
- **0o010**: The user group has the execute permission.
- **0o007**: Other users have the read, write, and execute permissions.
- **0o004**: Other users have the read permission.
- **0o002**: Other users have the write permission.
- **0o001**: Other users have the execute permission.| +**Parameters** +| Name| Type | Mandatory| Description | +| ------ | ------ | ---- | ------------------------------------------------------------ | +| path | string | Yes | Application sandbox path of the directory to create. | +| mode | number | No | Permission on the directory to create. You can specify multiple permissions, separated using a bitwise OR operator (|). The default value is **0o775**.
- **0o775**: The owner has the read, write, and execute permissions, and other users have the read and execute permissions.
- **0o700**: The owner has the read, write, and execute permissions.
-  **0o400**: The owner has the read permission.
- **0o200**: The owner has the write permission.
- **0o100**: The owner has the execute permission.
- **0o070**: The user group has the read, write, and execute permissions.
- **0o040**: The user group has the read permission.
- **0o020**: The user group has the write permission.
- **0o010**: The user group has the execute permission.
- **0o007**: Other users have the read, write, and execute permissions.
- **0o004**: Other users have the read permission.
- **0o002**: Other users have the write permission.
- **0o001**: Other users have the execute permission.| -- Example +**Example** ```js fileio.mkdirSync(path); ``` @@ -532,23 +534,23 @@ Synchronously creates a directory. open(path: string, flags?: number, mode?: number): Promise<number> -Asynchronously opens a file. This method uses a promise to return the result. +Asynchronously opens a file. This API uses a promise to return the result. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters - | Name | Type | Mandatory | Description | - | ----- | ------ | ---- | ---------------------------------------- | - | path | string | Yes | Absolute path of the target file. | - | flags | number | No | Option for opening the file. You must specify one of the following options. By default, the file is open in read-only mode.
- **0o0**: Open the file in read-only mode.
- **0o1**: Open the file in write-only mode.
- **0o2**: Open the file in read/write mode.
In addition, you can specify the following options, separated using a bitwise OR operator (|). By default, no additional option is specified.
- **0o100**: If the file does not exist, create it. If you use this option, you must also specify **mode**.
- **0o200**: If **0o100** is added and the file already exists, throw an exception.
- **0o1000**: If the file exists and is open in write-only or read/write mode, truncate the file length to 0.
- **0o2000**: Open the file in append mode. New data will be appended to the file (added to the end of the file).
- **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.
- **0o200000**: If **path** points to a directory, throw an exception.

- **0o400000**: If **path** points to a symbolic link, throw an exception.
- **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**.
- **0o666**: The owner, user group, and other users have the read and write permissions on the file.
- **0o700**: The owner has the read, write, and execute permissions.
-  **0o400**: The owner has the read permission.
- **0o200**: The owner has the write permission.
- **0o100**: The owner has the execute permission.
- **0o070**: The user group has the read, write, and execute permissions.
- **0o040**: The user group has the read permission.
- **0o020**: The user group has the write permission.
- **0o010**: The user group has the execute permission.
- **0o007**: Other users have the read, write, and execute permissions.
- **0o004**: Other users have the read permission.
- **0o002**: Other users have the write permission.
- **0o001**: Other users have the execute permission.| +**Parameters** +| Name| Type | Mandatory| Description | +| ------ | ------ | ---- | ------------------------------------------------------------ | +| path | string | Yes | Application sandbox path of the target file. | +| flags | number | No | Option for opening the file. You must specify one of the following options. By default, the file is open in read-only mode.
- **0o0**: Open the file in read-only mode.
- **0o1**: Open the file in write-only mode.
- **0o2**: Open the file in read/write mode.
In addition, you can specify the following options, separated using a bitwise OR operator (|). By default, no additional option is specified.
- **0o100**: If the file does not exist, create it. If you use this option, you must also specify **mode**.
- **0o200**: If **0o100** is added and the file already exists, throw an exception.
- **0o1000**: If the file exists and is open in write-only or read/write mode, truncate the file length to 0.
- **0o2000**: Open the file in append mode. New data will be appended to the file (added to the end of the file).
- **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.
- **0o200000**: If **path** points to a directory, throw an exception.

- **0o400000**: If **path** points to a symbolic link, throw an exception.
- **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**.
- **0o666**: The owner, user group, and other users have the read and write permissions on the file.
- **0o700**: The owner has the read, write, and execute permissions.
-  **0o400**: The owner has the read permission.
- **0o200**: The owner has the write permission.
- **0o100**: The owner has the execute permission.
- **0o070**: The user group has the read, write, and execute permissions.
- **0o040**: The user group has the read permission.
- **0o020**: The user group has the write permission.
- **0o010**: The user group has the execute permission.
- **0o007**: Other users have the read, write, and execute permissions.
- **0o004**: Other users have the read permission.
- **0o002**: Other users have the write permission.
- **0o001**: Other users have the execute permission.| -- Return value +**Return value** | Type | Description | | --------------------- | ----------- | | Promise<number> | File descriptor of the file opened.| -- Example +**Example** ```js fileio.open(path, 0o1, 0o0200).then(function(number){ console.info("open file successfully"); @@ -562,19 +564,19 @@ Asynchronously opens a file. This method uses a promise to return the result. open(path: string, flags: number, mode: number, callback: AsyncCallback<number>): void -Asynchronously opens a file. This method uses a callback to return the result. +Asynchronously opens a file. This API uses a callback to return the result. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters - | Name | Type | Mandatory | Description | - | -------- | ------------------------------- | ---- | ---------------------------------------- | - | path | string | Yes | Absolute path of the target file. | - | flags | number | Yes | Option for opening the file. You must specify one of the following options. By default, the file is open in read-only mode.
- **0o0**: Open the file in read-only mode.
- **0o1**: Open the file in write-only mode.
- **0o2**: Open the file in read/write mode.
In addition, you can specify the following options, separated using a bitwise OR operator (|). By default, no additional option is specified.
- **0o100**: If the file does not exist, create it. If you use this option, you must also specify **mode**.
- **0o200**: If **0o100** is added and the file already exists, throw an exception.
- **0o1000**: If the file exists and is open in write-only or read/write mode, truncate the file length to 0.
- **0o2000**: Open the file in append mode. New data will be appended to the file (added to the end of the file).
- **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.
- **0o200000**: If **path** points to a directory, throw an exception.

- **0o400000**: If **path** points to a symbolic link, throw an exception.
- **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**.
- **0o666**: The owner, user group, and other users have the read and write permissions on the file.
- **0o700**: The owner has the read, write, and execute permissions.
-  **0o400**: The owner has the read permission.
- **0o200**: The owner has the write permission.
- **0o100**: The owner has the execute permission.
- **0o070**: The user group has the read, write, and execute permissions.
- **0o040**: The user group has the read permission.
- **0o020**: The user group has the write permission.
- **0o010**: The user group has the execute permission.
- **0o007**: Other users have the read, write, and execute permissions.
- **0o004**: Other users have the read permission.
- **0o002**: Other users have the write permission.
- **0o001**: Other users have the execute permission.| - | callback | AsyncCallback <void> | Yes | Callback invoked when the file is open asynchronously. | +**Parameters** +| Name | Type | Mandatory| Description | +| -------- | ------------------------------- | ---- | ------------------------------------------------------------ | +| path | string | Yes | Application sandbox path of the target file. | +| flags | number | Yes | Option for opening the file. You must specify one of the following options. By default, the file is open in read-only mode.
- **0o0**: Open the file in read-only mode.
- **0o1**: Open the file in write-only mode.
- **0o2**: Open the file in read/write mode.
In addition, you can specify the following options, separated using a bitwise OR operator (|). By default, no additional option is specified.
- **0o100**: If the file does not exist, create it. If you use this option, you must also specify **mode**.
- **0o200**: If **0o100** is added and the file already exists, throw an exception.
- **0o1000**: If the file exists and is open in write-only or read/write mode, truncate the file length to 0.
- **0o2000**: Open the file in append mode. New data will be appended to the file (added to the end of the file).
- **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.
- **0o200000**: If **path** points to a directory, throw an exception.

- **0o400000**: If **path** points to a symbolic link, throw an exception.
- **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**.
- **0o666**: The owner, user group, and other users have the read and write permissions on the file.
- **0o700**: The owner has the read, write, and execute permissions.
-  **0o400**: The owner has the read permission.
- **0o200**: The owner has the write permission.
- **0o100**: The owner has the execute permission.
- **0o070**: The user group has the read, write, and execute permissions.
- **0o040**: The user group has the read permission.
- **0o020**: The user group has the write permission.
- **0o010**: The user group has the execute permission.
- **0o007**: Other users have the read, write, and execute permissions.
- **0o004**: Other users have the read permission.
- **0o002**: Other users have the write permission.
- **0o001**: Other users have the execute permission.| +| callback | AsyncCallback <void> | Yes | Callback invoked when the file is open asynchronously. | -- Example +**Example** ```js fileio.open(path, 0, function(err, fd) { // Do something. @@ -590,19 +592,19 @@ Synchronously opens a file. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters - | Name | Type | Mandatory | Description | - | ----- | ------ | ---- | ---------------------------------------- | - | path | string | Yes | Absolute path of the target file. | - | flags | number | No | Option for opening the file. You must specify one of the following options. By default, the file is open in read-only mode.
- **0o0**: Open the file in read-only mode.
- **0o1**: Open the file in write-only mode.
- **0o2**: Open the file in read/write mode.
In addition, you can specify the following options, separated using a bitwise OR operator (|). By default, no additional option is specified.
- **0o100**: If the file does not exist, create it. If you use this option, you must also specify **mode**.
- **0o200**: If **0o100** is added and the file already exists, throw an exception.
- **0o1000**: If the file exists and is open in write-only or read/write mode, truncate the file length to 0.
- **0o2000**: Open the file in append mode. New data will be appended to the file (added to the end of the file).
- **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.
- **0o200000**: If **path** points to a directory, throw an exception.

- **0o400000**: If **path** points to a symbolic link, throw an exception.
- **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**.
- **0o666**: The owner, user group, and other users have the read and write permissions on the file.
- **0o700**: The owner has the read, write, and execute permissions.
-  **0o400**: The owner has the read permission.
- **0o200**: The owner has the write permission.
- **0o100**: The owner has the execute permission.
- **0o070**: The user group has the read, write, and execute permissions.
- **0o040**: The user group has the read permission.
- **0o020**: The user group has the write permission.
- **0o010**: The user group has the execute permission.
- **0o007**: Other users have the read, write, and execute permissions.
- **0o004**: Other users have the read permission.
- **0o002**: Other users have the write permission.
- **0o001**: Other users have the execute permission.
The file permissions on newly created files are affected by umask, which is set as the process starts. Currently, the modification of umask is not open.| +**Parameters** +| Name| Type | Mandatory| Description | +| ------ | ------ | ---- | ------------------------------------------------------------ | +| path | string | Yes | Application sandbox path of the target file. | +| flags | number | No | Option for opening the file. You must specify one of the following options. By default, the file is open in read-only mode.
- **0o0**: Open the file in read-only mode.
- **0o1**: Open the file in write-only mode.
- **0o2**: Open the file in read/write mode.
In addition, you can specify the following options, separated using a bitwise OR operator (|). By default, no additional option is specified.
- **0o100**: If the file does not exist, create it. If you use this option, you must also specify **mode**.
- **0o200**: If **0o100** is added and the file already exists, throw an exception.
- **0o1000**: If the file exists and is open in write-only or read/write mode, truncate the file length to 0.
- **0o2000**: Open the file in append mode. New data will be appended to the file (added to the end of the file).
- **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.
- **0o200000**: If **path** points to a directory, throw an exception.

- **0o400000**: If **path** points to a symbolic link, throw an exception.
- **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**.
- **0o666**: The owner, user group, and other users have the read and write permissions on the file.
- **0o700**: The owner has the read, write, and execute permissions.
-  **0o400**: The owner has the read permission.
- **0o200**: The owner has the write permission.
- **0o100**: The owner has the execute permission.
- **0o070**: The user group has the read, write, and execute permissions.
- **0o040**: The user group has the read permission.
- **0o020**: The user group has the write permission.
- **0o010**: The user group has the execute permission.
- **0o007**: Other users have the read, write, and execute permissions.
- **0o004**: Other users have the read permission.
- **0o002**: Other users have the write permission.
- **0o001**: Other users have the execute permission.
The file permissions on newly created files are affected by umask, which is set as the process starts. Currently, the modification of umask is not open.| -- Return value +**Return value** | Type | Description | | ------ | ----------- | | number | File descriptor of the file opened.| -- Example +**Example** ```js let fd = fileio.openSync(path); ``` @@ -616,23 +618,24 @@ read(fd: number, buffer: ArrayBuffer, options?: { position?: number; }): Promise<ReadOut> -Asynchronously reads data from a file. This method uses a promise to return the result. +Asynchronously reads data from a file. This API uses a promise to return the result. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters - | Name | Type | Mandatory | Description | - | ------- | ----------- | ---- | ---------------------------------------- | - | fd | number | Yes | File descriptor of the file to read. | - | buffer | ArrayBuffer | Yes | Buffer used to store the file data read. | - | options | Object | No | The options are as follows:
- **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**.
- **length** (number): length of the data to read. The default value is the buffer length minus the offset.
- **position** (number): position of the data to read in the file. By default, data is read from the current position.
-  The sum of **offset** and **length** must be less than or equal to the buffer size. | +**Parameters** +| Name | Type | Mandatory| Description | +| ------- | ----------- | ---- | ------------------------------------------------------------ | +| fd | number | Yes | File descriptor of the file to read. | +| buffer | ArrayBuffer | Yes | Buffer used to store the file data read. | +| options | Object | No | The options are as follows:
- **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**.
- **length** (number): length of the data to read. The default value is the buffer length minus the offset.
- **position** (number): position of the data to read in the file. By default, data is read from the current position.
Constraints: offset + length <= Buffer size| + +**Return value** -- Return value | Type | Description | | ---------------------------------- | ------ | | Promise<[ReadOut](#readout)> | Data read.| -- Example +**Example** ```js let fd = fileio.openSync(path, 0o2); let buf = new ArrayBuffer(4096); @@ -653,19 +656,19 @@ read(fd: number, buffer: ArrayBuffer, options: { position?: number; }, callback: AsyncCallback<ReadOut>): void -Asynchronously reads data from a file. This method uses a callback to return the result. +Asynchronously reads data from a file. This API uses a callback to return the result. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters +**Parameters** | Name | Type | Mandatory | Description | | -------- | ---------------------------------------- | ---- | ---------------------------------------- | | fd | number | Yes | File descriptor of the file to read. | | buffer | ArrayBuffer | Yes | Buffer used to store the file data read. | - | options | Object | No | The options are as follows:
- **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**.
- **length** (number): length of the data to read. The default value is the buffer length minus the offset.
- **position** (number): position of the data to read in the file. By default, data is read from the current position.
-  The sum of **offset** and **length** must be less than or equal to the buffer size. | + | options | Object | No | The options are as follows:
- **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**.
- **length** (number): length of the data to read. The default value is the buffer length minus the offset.
- **position** (number): position of the data to read in the file. By default, data is read from the current position.
Constraints: offset + length <= Buffer size | | callback | AsyncCallback<[ReadOut](#readout)> | Yes | Callback invoked when the data is read asynchronously. | -- Example +**Example** ```js let fd = fileio.openSync(path, 0o2); let buf = new ArrayBuffer(4096); @@ -690,19 +693,19 @@ Synchronously reads data from a file. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters +**Parameters** | Name | Type | Mandatory | Description | | ------- | ----------- | ---- | ---------------------------------------- | | fd | number | Yes | File descriptor of the file to read. | | buffer | ArrayBuffer | Yes | Buffer used to store the file data read. | - | options | Object | No | The options are as follows:
- **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**.
- **length** (number): length of the data to read. The default value is the buffer length minus the offset.
- **position** (number): position of the data to read in the file. By default, data is read from the current position.
-  The sum of **offset** and **length** must be less than or equal to the buffer size. | + | options | Object | No | The options are as follows:
- **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**.
- **length** (number): length of the data to read. The default value is the buffer length minus the offset.
- **position** (number): position of the data to read in the file. By default, data is read from the current position.
Constraints: offset + length <= Buffer size | -- Return value +**Return value** | Type | Description | | ------ | -------- | | number | Length of the data read.| -- Example +**Example** ```js let fd = fileio.openSync(path, 0o2); let buf = new ArrayBuffer(4096); @@ -714,21 +717,21 @@ Synchronously reads data from a file. rmdir(path: string): Promise<void> -Asynchronously deletes a directory. This method uses a promise to return the result. +Asynchronously deletes a directory. This API uses a promise to return the result. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters - | Name | Type | Mandatory | Description | - | ---- | ------ | ---- | ----------- | - | path | string | Yes | Absolute path of the directory to delete.| +**Parameters** +| Name| Type | Mandatory| Description | +| ------ | ------ | ---- | -------------------------- | +| path | string | Yes | Application sandbox path of the directory to delete.| -- Return value +**Return value** | Type | Description | | ------------------- | ---------------------------- | | Promise<void> | Promise used to return the result. An empty value is returned.| -- Example +**Example** ```js fileio.rmdir(path).then(function() { console.info("rmdir successfully"); @@ -742,17 +745,17 @@ Asynchronously deletes a directory. This method uses a promise to return the res rmdir(path: string, callback:AsyncCallback<void>): void -Asynchronously deletes a directory. This method uses a callback to return the result. +Asynchronously deletes a directory. This API uses a callback to return the result. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters - | Name | Type | Mandatory | Description | - | -------- | ------------------------- | ---- | ------------ | - | path | string | Yes | Absolute path of the directory to delete. | - | callback | AsyncCallback<void> | Yes | Callback invoked when the directory is deleted asynchronously.| +**Parameters** +| Name | Type | Mandatory| Description | +| -------- | ------------------------- | ---- | -------------------------- | +| path | string | Yes | Application sandbox path of the directory to delete.| +| callback | AsyncCallback<void> | Yes | Callback invoked when the directory is deleted asynchronously. | -- Example +**Example** ```js fileio.rmdir(path, function(err){ // Do something. @@ -769,12 +772,12 @@ Synchronously deletes a directory. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters - | Name | Type | Mandatory | Description | - | ---- | ------ | ---- | ----------- | - | path | string | Yes | Absolute path of the directory to delete.| +**Parameters** +| Name| Type | Mandatory| Description | +| ------ | ------ | ---- | -------------------------- | +| path | string | Yes | Application sandbox path of the directory to delete.| -- Example +**Example** ```js fileio.rmdirSync(path); ``` @@ -784,21 +787,21 @@ Synchronously deletes a directory. unlink(path:string): Promise<void> -Asynchronously deletes a file. This method uses a promise to return the result. +Asynchronously deletes a file. This API uses a promise to return the result. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters - | Name | Type | Mandatory | Description | - | ---- | ------ | ---- | ----------- | - | path | string | Yes | Absolute path of the file to delete.| +**Parameters** +| Name| Type | Mandatory| Description | +| ------ | ------ | ---- | -------------------------- | +| path | string | Yes | Application sandbox path of the file to delete.| -- Return value +**Return value** | Type | Description | | ------------------- | ---------------------------- | | Promise<void> | Promise used to return the result. An empty value is returned.| -- Example +**Example** ```js fileio.unlink(path).then(function(){ console.info("remove file successfully"); @@ -812,17 +815,17 @@ Asynchronously deletes a file. This method uses a promise to return the result. unlink(path:string, callback:AsyncCallback<void>): void -Asynchronously deletes a file. This method uses a callback to return the result. +Asynchronously deletes a file. This API uses a callback to return the result. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters - | Name | Type | Mandatory | Description | - | -------- | ------------------------- | ---- | ------------ | - | path | string | Yes | Absolute path of the file to delete. | - | callback | AsyncCallback<void> | Yes | Callback invoked when the file is deleted asynchronously.| +**Parameters** +| Name | Type | Mandatory| Description | +| -------- | ------------------------- | ---- | -------------------------- | +| path | string | Yes | Application sandbox path of the file to delete.| +| callback | AsyncCallback<void> | Yes | Callback invoked when the file is deleted asynchronously. | -- Example +**Example** ```js fileio.unlink(path, function(err) { console.info("remove file successfully"); @@ -838,12 +841,12 @@ Synchronously deletes a file. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters - | Name | Type | Mandatory | Description | - | ---- | ------ | ---- | ----------- | - | path | string | Yes | Absolute path of the file to delete.| +**Parameters** +| Name| Type | Mandatory| Description | +| ------ | ------ | ---- | -------------------------- | +| path | string | Yes | Application sandbox path of the file to delete.| -- Example +**Example** ```js fileio.unlinkSync(path); ``` @@ -858,23 +861,23 @@ write(fd: number, buffer: ArrayBuffer | string, options?: { encoding?: string; }): Promise<number> -Asynchronously writes data into a file. This method uses a promise to return the result. +Asynchronously writes data into a file. This API uses a promise to return the result. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters +**Parameters** | Name | Type | Mandatory | Description | | ------- | ------------------------------- | ---- | ---------------------------------------- | | fd | number | Yes | File descriptor of the file to write. | | buffer | ArrayBuffer \| string | Yes | Data to write. It can be a string or data from a buffer. | - | options | Object | No | The options are as follows:
- **offset** (number): position of the data to write in reference to the start address of the data. The default value is **0**.
- **length** (number): length of the data to write. The default value is the buffer length minus the offset.
- **position** (number): start position to write the data in the file. By default, data is written from the current position.
- **encoding** (string): format of the string to be encoded. The default value is **utf-8**, which is the only value supported.
-  The sum of **offset** and **length** must be less than or equal to the buffer size.| + | options | Object | No | The options are as follows:
- **offset** (number): position of the data to write in reference to the start address of the data. The default value is **0**.
- **length** (number): length of the data to write. The default value is the buffer length minus the offset.
- **position** (number): start position to write the data in the file. By default, data is written from the current position.
- **encoding** (string): format of the string to be encoded. The default value is **utf-8**, which is the only value supported.
Constraints: offset + length <= Buffer size| -- Return value +**Return value** | Type | Description | | --------------------- | -------- | | Promise<number> | Length of the data written in the file.| -- Example +**Example** ```js let fd = fileio.openSync(fpath, 0o100 | 0o2, 0o666); fileio.write(fd, "hello, world").then(function(number){ @@ -894,19 +897,19 @@ write(fd: number, buffer: ArrayBuffer | string, options: { encoding?: string; }, callback: AsyncCallback<number>): void -Asynchronously writes data into a file. This method uses a callback to return the result. +Asynchronously writes data into a file. This API uses a callback to return the result. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters +**Parameters** | Name | Type | Mandatory | Description | | -------- | ------------------------------- | ---- | ---------------------------------------- | | fd | number | Yes | File descriptor of the file to write. | | buffer | ArrayBuffer \| string | Yes | Data to write. It can be a string or data from a buffer. | - | options | Object | No | The options are as follows:
- **offset** (number): position of the data to write in reference to the start address of the data. The default value is **0**.
- **length** (number): length of the data to write. The default value is the buffer length minus the offset.
- **position** (number): start position to write the data in the file. By default, data is written from the current position.
- **encoding** (string): format of the string to be encoded. The default value is **utf-8**, which is the only value supported.
-  The sum of **offset** and **length** must be less than or equal to the buffer size.| + | options | Object | No | The options are as follows:
- **offset** (number): position of the data to write in reference to the start address of the data. The default value is **0**.
- **length** (number): length of the data to write. The default value is the buffer length minus the offset.
- **position** (number): start position to write the data in the file. By default, data is written from the current position.
- **encoding** (string): format of the string to be encoded. The default value is **utf-8**, which is the only value supported.
Constraints: offset + length <= Buffer size| | callback | AsyncCallback<number> | Yes | Callback invoked when the data is written asynchronously. | -- Example +**Example** ```js let fd = fileio.openSync(path, 0o100 | 0o2, 0o666); fileio.write(fd, "hello, world", function (err, bytesWritten) { @@ -930,19 +933,19 @@ Synchronously writes data into a file. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters +**Parameters** | Name | Type | Mandatory | Description | | ------- | ------------------------------- | ---- | ---------------------------------------- | | fd | number | Yes | File descriptor of the file to write. | | buffer | ArrayBuffer \| string | Yes | Data to write. It can be a string or data from a buffer. | - | options | Object | No | The options are as follows:
- **offset** (number): position of the data to write in reference to the start address of the data. The default value is **0**.
- **length** (number): length of the data to write. The default value is the buffer length minus the offset.
- **position** (number): start position to write the data in the file. By default, data is written from the current position.
- **encoding** (string): format of the string to be encoded. The default value is **utf-8**, which is the only value supported.
-  The sum of **offset** and **length** must be less than or equal to the buffer size.| + | options | Object | No | The options are as follows:
- **offset** (number): position of the data to write in reference to the start address of the data. The default value is **0**.
- **length** (number): length of the data to write. The default value is the buffer length minus the offset.
- **position** (number): start position to write the data in the file. By default, data is written from the current position.
- **encoding** (string): format of the string to be encoded. The default value is **utf-8**, which is the only value supported.
Constraints: offset + length <= Buffer size| -- Return value +**Return value** | Type | Description | | ------ | -------- | | number | Length of the data written in the file.| -- Example +**Example** ```js let fd = fileio.openSync(path, 0o100 | 0o2, 0o666); let num = fileio.writeSync(fd, "hello, world"); @@ -953,22 +956,22 @@ Synchronously writes data into a file. hash(path: string, algorithm: string): Promise<string> -Asynchronously calculates the hash value of a file. This method uses a promise to return the result. +Asynchronously calculates the hash value of a file. This API uses a promise to return the result. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters - | Name | Type | Mandatory | Description | - | --------- | ------ | ---- | ---------------------------------------- | - | path | string | Yes | Absolute path of the target file. | - | algorithm | string | Yes | Algorithm used to calculate the hash value. The value can be **md5**, **sha1**, or **sha256**.
**sha256** is recommended for security purposes.| +**Parameters** +| Name | Type | Mandatory| Description | +| --------- | ------ | ---- | ------------------------------------------------------------ | +| path | string | Yes | Application sandbox path of the target file. | +| algorithm | string | Yes | Algorithm used to calculate the hash value. The value can be **md5**, **sha1**, or **sha256**. **sha256** is recommended for security purposes.| -- Return value +**Return value** | Type | Description | | --------------------- | -------------------------- | | Promise<string> | Promise used to return the hash value of the file. The hash value is a hexadecimal string consisting of digits and uppercase letters.| -- Example +**Example** ```js fileio.hash(path, "sha256").then(function(str){ console.info("calculate file hash successfully:"+ str); @@ -982,18 +985,18 @@ Asynchronously calculates the hash value of a file. This method uses a promise t hash(path: string, algorithm: string, callback: AsyncCallback<string>): void -Asynchronously calculates the hash value of a file. This method uses a callback to return the result. +Asynchronously calculates the hash value of a file. This API uses a callback to return the result. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters - | Name | Type | Mandatory | Description | - | --------- | --------------------------- | ---- | ---------------------------------------- | - | path | string | Yes | Absolute path of the target file. | - | algorithm | string | Yes | Algorithm used to calculate the hash value. The value can be **md5**, **sha1**, or **sha256**.
**sha256** is recommended for security purposes.| - | callback | AsyncCallback<string> | Yes | Callback used to return the hash value. The hash value is a hexadecimal string consisting of digits and uppercase letters.| +**Parameters** +| Name | Type | Mandatory| Description | +| --------- | --------------------------- | ---- | ------------------------------------------------------------ | +| path | string | Yes | Application sandbox path of the target file. | +| algorithm | string | Yes | Algorithm used to calculate the hash value. The value can be **md5**, **sha1**, or **sha256**. **sha256** is recommended for security purposes.| +| callback | AsyncCallback<string> | Yes | Callback used to return the hash value. The hash value is a hexadecimal string consisting of digits and uppercase letters.| -- Example +**Example** ```js fileio.hash(fpath, "sha256", function(err, hashStr) { if (hashStr) { @@ -1007,22 +1010,22 @@ Asynchronously calculates the hash value of a file. This method uses a callback chmod(path: string, mode: number):Promise<void> -Asynchronously changes the file permissions based on its path. This method uses a promise to return the result. +Asynchronously changes the file permissions based on its path. This API uses a promise to return the result. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters - | Name | Type | Mandatory | Description | - | ---- | ------ | ---- | ---------------------------------------- | - | path | string | Yes | Absolute path of the target file. | - | mode | number | Yes | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (|).
- **0o700**: The owner has the read, write, and execute permissions.
-  **0o400**: The owner has the read permission.
- **0o200**: The owner has the write permission.
- **0o100**: The owner has the execute permission.
- **0o070**: The user group has the read, write, and execute permissions.
- **0o040**: The user group has the read permission.
- **0o020**: The user group has the write permission.
- **0o010**: The user group has the execute permission.
- **0o007**: Other users have the read, write, and execute permissions.
- **0o004**: Other users have the read permission.
- **0o002**: Other users have the write permission.
- **0o001**: Other users have the execute permission.| +**Parameters** +| Name| Type | Mandatory| Description | +| ------ | ------ | ---- | ------------------------------------------------------------ | +| path | string | Yes | Application sandbox path of the target file. | +| mode | number | Yes | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (|).
- **0o700**: The owner has the read, write, and execute permissions.
-  **0o400**: The owner has the read permission.
- **0o200**: The owner has the write permission.
- **0o100**: The owner has the execute permission.
- **0o070**: The user group has the read, write, and execute permissions.
- **0o040**: The user group has the read permission.
- **0o020**: The user group has the write permission.
- **0o010**: The user group has the execute permission.
- **0o007**: Other users have the read, write, and execute permissions.
- **0o004**: Other users have the read permission.
- **0o002**: Other users have the write permission.
- **0o001**: Other users have the execute permission.| -- Return value +**Return value** | Type | Description | | ------------------- | ---------------------------- | | Promise<void> | Promise used to return the result. An empty value is returned.| -- Example +**Example** ```js fileio.chmod(path, mode).then(function() { console.info("chmod successfully"); @@ -1036,18 +1039,18 @@ Asynchronously changes the file permissions based on its path. This method uses chmod(path: string, mode: number, callback: AsyncCallback<void>): void -Asynchronously changes the file permissions based on its path. This method uses a callback to return the result. +Asynchronously changes the file permissions based on its path. This API uses a callback to return the result. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters - | Name | Type | Mandatory | Description | - | -------- | ------------------------- | ---- | ---------------------------------------- | - | path | string | Yes | Absolute path of the target file. | - | mode | number | Yes | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (|).
- **0o700**: The owner has the read, write, and execute permissions.
-  **0o400**: The owner has the read permission.
- **0o200**: The owner has the write permission.
- **0o100**: The owner has the execute permission.
- **0o070**: The user group has the read, write, and execute permissions.
- **0o040**: The user group has the read permission.
- **0o020**: The user group has the write permission.
- **0o010**: The user group has the execute permission.
- **0o007**: Other users have the read, write, and execute permissions.
- **0o004**: Other users have the read permission.
- **0o002**: Other users have the write permission.
- **0o001**: Other users have the execute permission.| - | callback | AsyncCallback<void> | Yes | Callback invoked when the file permissions are changed asynchronously. | +**Parameters** +| Name | Type | Mandatory| Description | +| -------- | ------------------------- | ---- | ------------------------------------------------------------ | +| path | string | Yes | Application sandbox path of the target file. | +| mode | number | Yes | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (|).
- **0o700**: The owner has the read, write, and execute permissions.
-  **0o400**: The owner has the read permission.
- **0o200**: The owner has the write permission.
- **0o100**: The owner has the execute permission.
- **0o070**: The user group has the read, write, and execute permissions.
- **0o040**: The user group has the read permission.
- **0o020**: The user group has the write permission.
- **0o010**: The user group has the execute permission.
- **0o007**: Other users have the read, write, and execute permissions.
- **0o004**: Other users have the read permission.
- **0o002**: Other users have the write permission.
- **0o001**: Other users have the execute permission.| +| callback | AsyncCallback<void> | Yes | Callback invoked when the file permissions are changed asynchronously. | -- Example +**Example** ```js fileio.chmod(path, mode, function (err) { // Do something. @@ -1063,13 +1066,13 @@ Synchronously changes the file permissions based on its path. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters - | Name | Type | Mandatory | Description | - | ---- | ------ | ---- | ---------------------------------------- | - | path | string | Yes | Absolute path of the target file. | - | mode | number | Yes | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (|).
- **0o700**: The owner has the read, write, and execute permissions.
-  **0o400**: The owner has the read permission.
- **0o200**: The owner has the write permission.
- **0o100**: The owner has the execute permission.
- **0o070**: The user group has the read, write, and execute permissions.
- **0o040**: The user group has the read permission.
- **0o020**: The user group has the write permission.
- **0o010**: The user group has the execute permission.
- **0o007**: Other users have the read, write, and execute permissions.
- **0o004**: Other users have the read permission.
- **0o002**: Other users have the write permission.
- **0o001**: Other users have the execute permission.| +**Parameters** +| Name| Type | Mandatory| Description | +| ------ | ------ | ---- | ------------------------------------------------------------ | +| path | string | Yes | Application sandbox path of the target file. | +| mode | number | Yes | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (|).
- **0o700**: The owner has the read, write, and execute permissions.
-  **0o400**: The owner has the read permission.
- **0o200**: The owner has the write permission.
- **0o100**: The owner has the execute permission.
- **0o070**: The user group has the read, write, and execute permissions.
- **0o040**: The user group has the read permission.
- **0o020**: The user group has the write permission.
- **0o010**: The user group has the execute permission.
- **0o007**: Other users have the read, write, and execute permissions.
- **0o004**: Other users have the read permission.
- **0o002**: Other users have the write permission.
- **0o001**: Other users have the execute permission.| -- Example +**Example** ```js fileio.chmodSync(fpath, mode); ``` @@ -1079,21 +1082,21 @@ Synchronously changes the file permissions based on its path. fstat(fd: number): Promise<Stat> -Asynchronously obtains file status information based on the file descriptor. This method uses a promise to return the result. +Asynchronously obtains file information based on the file descriptor. This API uses a promise to return the result. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters +**Parameters** | Name | Type | Mandatory | Description | | ---- | ------ | ---- | ------------ | | fd | number | Yes | File descriptor of the target file.| -- Return value +**Return value** | Type | Description | | ---------------------------- | ---------- | - | Promise<[Stat](#stat)> | Promise used to return the file status information obtained.| + | Promise<[Stat](#stat)> | Promise used to return the file information obtained.| -- Example +**Example** ```js fileio.fstat(fd).then(function(stat){ console.info("fstat successfully:"+ JSON.stringify(stat)); @@ -1107,17 +1110,17 @@ Asynchronously obtains file status information based on the file descriptor. Thi fstat(fd: number, callback: AsyncCallback<Stat>): void -Asynchronously obtains file status information based on the file descriptor. This method uses a callback to return the result. +Asynchronously obtains file information based on the file descriptor. This API uses a callback to return the result. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters +**Parameters** | Name | Type | Mandatory | Description | | -------- | ---------------------------------- | ---- | ---------------- | | fd | number | Yes | File descriptor of the target file. | - | callback | AsyncCallback<[Stat](#stat)> | Yes | Callback invoked when the file status information is obtained asynchronously.| + | callback | AsyncCallback<[Stat](#stat)> | Yes | Callback invoked to return the file information obtained.| -- Example +**Example** ```js let fd = fileio.openSync(path); fileio.fstat(fd, function (err) { @@ -1130,21 +1133,21 @@ Asynchronously obtains file status information based on the file descriptor. Thi fstatSync(fd: number): Stat -Synchronously obtains file status information based on the file descriptor. +Synchronously obtains file information based on the file descriptor. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters +**Parameters** | Name | Type | Mandatory | Description | | ---- | ------ | ---- | ------------ | | fd | number | Yes | File descriptor of the target file.| -- Return value +**Return value** | Type | Description | | ------------- | ---------- | - | [Stat](#stat) | File status information obtained.| + | [Stat](#stat) | File information obtained.| -- Example +**Example** ```js let fd = fileio.openSync(path); let stat = fileio.fstatSync(fd); @@ -1155,22 +1158,22 @@ Synchronously obtains file status information based on the file descriptor. ftruncate(fd: number, len?: number): Promise<void> -Asynchronously truncates a file based on the file descriptor. This method uses a promise to return the result. +Asynchronously truncates a file based on the file descriptor. This API uses a promise to return the result. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters +**Parameters** | Name | Type | Mandatory | Description | | ---- | ------ | ---- | ---------------- | | fd | number | Yes | File descriptor of the file to truncate. | | len | number | Yes | File length, in bytes, after truncation.| -- Return value +**Return value** | Type | Description | | ------------------- | ---------------------------- | | Promise<void> | Promise used to return the result. An empty value is returned.| -- Example +**Example** ```js let fd = fileio.openSync(path); fileio.ftruncate(fd, 5).then(function(err) { @@ -1185,18 +1188,18 @@ Asynchronously truncates a file based on the file descriptor. This method uses a ftruncate(fd: number, len: number, callback:AsyncCallback<void>): void -Asynchronously truncates a file based on the file descriptor. This method uses a callback to return the result. +Asynchronously truncates a file based on the file descriptor. This API uses a callback to return the result. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters +**Parameters** | Name | Type | Mandatory | Description | | -------- | ------------------------- | ---- | ---------------- | | fd | number | Yes | File descriptor of the file to truncate. | | len | number | Yes | File length, in bytes, after truncation.| | callback | AsyncCallback<void> | Yes | Callback invoked when the file is truncated asynchronously. | -- Example +**Example** ```js fileio.ftruncate(fd, len, function(err){ // Do something. @@ -1212,13 +1215,13 @@ Synchronously truncates a file based on the file descriptor. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters +**Parameters** | Name | Type | Mandatory | Description | | ---- | ------ | ---- | ---------------- | | fd | number | Yes | File descriptor of the file to truncate. | | len | number | No | File length, in bytes, after truncation.| -- Example +**Example** ```js fileio.ftruncateSync(fd, len); ``` @@ -1228,22 +1231,22 @@ Synchronously truncates a file based on the file descriptor. truncate(path: string, len?: number): Promise<void> -Asynchronously truncates a file based on its path. This method uses a promise to return the result. +Asynchronously truncates a file based on its path. This API uses a promise to return the result. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters - | Name | Type | Mandatory | Description | - | ---- | ------ | ---- | ---------------- | - | path | string | Yes | Absolute path of the file to truncate. | - | len | number | Yes | File length, in bytes, after truncation.| +**Parameters** +| Name| Type | Mandatory| Description | +| ------ | ------ | ---- | -------------------------------- | +| path | string | Yes | Application sandbox path of the file to truncate. | +| len | number | Yes | File length, in bytes, after truncation.| -- Return value +**Return value** | Type | Description | | ------------------- | ---------------------------- | | Promise<void> | Promise used to return the result. An empty value is returned.| -- Example +**Example** ```js fileio.truncate(path, len).then(function(){ console.info("File truncated successfully."); @@ -1257,18 +1260,18 @@ Asynchronously truncates a file based on its path. This method uses a promise to truncate(path: string, len: number, callback:AsyncCallback<void>): void -Asynchronously truncates a file based on its path. This method uses a callback to return the result. +Asynchronously truncates a file based on its path. This API uses a callback to return the result. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters - | Name | Type | Mandatory | Description | - | -------- | ------------------------- | ---- | ---------------- | - | path | string | Yes | Absolute path of the file to truncate. | - | len | number | Yes | File length, in bytes, after truncation.| - | callback | AsyncCallback<void> | Yes | Callback invoked when the file is truncated asynchronously. | +**Parameters** +| Name | Type | Mandatory| Description | +| -------- | ------------------------- | ---- | -------------------------------- | +| path | string | Yes | Application sandbox path of the file to truncate. | +| len | number | Yes | File length, in bytes, after truncation.| +| callback | AsyncCallback<void> | Yes | Callback invoked when the file is truncated asynchronously. | -- Example +**Example** ```js fileio.truncate(path, len, function(err){ // Do something. @@ -1284,13 +1287,13 @@ Synchronously truncates a file based on the file path. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters - | Name | Type | Mandatory | Description | - | ---- | ------ | ---- | ---------------- | - | path | string | Yes | Absolute path of the file to truncate. | - | len | number | No | File length, in bytes, after truncation.| +**Parameters** +| Name| Type | Mandatory| Description | +| ------ | ------ | ---- | -------------------------------- | +| path | string | Yes | Application sandbox path of the file to be truncate. | +| len | number | No | File length, in bytes, after truncation.| -- Example +**Example** ```js fileio.truncateSync(path, len); ``` @@ -1304,22 +1307,22 @@ readText(filePath: string, options?: { encoding?: string; }): Promise<string> -Asynchronously reads the text of a file. This method uses a promise to return the result. +Asynchronously reads the text of a file. This API uses a promise to return the result. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters - | Name | Type | Mandatory | Description | - | -------- | ------ | ---- | ---------------------------------------- | - | filePath | string | Yes | Absolute path of the file to read. | - | options | Object | No | The options are as follows:
- **position** (number): position of the data to read in the file. By default, data is read from the current position.
- **length** (number): length of the data to read. The default value is the buffer length minus the offset.
- **encoding** (string): format of the data (string) to be encoded. The default value is **utf-8**, which is the only value supported.| +**Parameters** +| Name | Type | Mandatory| Description | +| -------- | ------ | ---- | ------------------------------------------------------------ | +| filePath | string | Yes | Application sandbox path of the file to read. | +| options | Object | No | The options are as follows:
- **position** (number): position of the data to read in the file. By default, data is read from the current position.
- **length** (number): length of the data to read. The default value is the buffer length minus the offset.
- **encoding** (string): format of the data (string) to be encoded. The default value is **utf-8**, which is the only value supported.| -- Return value +**Return value** | Type | Description | | --------------------- | ---------- | | Promise<string> | Promise used to return the content of the file read.| -- Example +**Example** ```js fileio.readText(path).then(function(str) { console.info("readText successfully:"+ str); @@ -1337,18 +1340,18 @@ readText(filePath: string, options: { encoding?: string; }, callback: AsyncCallback<string>): void -Asynchronously reads the text of a file. This method uses a callback to return the result. +Asynchronously reads the text of a file. This API uses a callback to return the result. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters - | Name | Type | Mandatory | Description | - | -------- | --------------------------- | ---- | ---------------------------------------- | - | filePath | string | Yes | Absolute path of the file to read. | - | options | Object | No | The options are as follows:
- **position** (number): position of the data to read in the file. By default, data is read from the current position.
- **length** (number): length of the data to read. The default value is the buffer length minus the offset.
- **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. | +**Parameters** +| Name | Type | Mandatory| Description | +| -------- | --------------------------- | ---- | ------------------------------------------------------------ | +| filePath | string | Yes | Application sandbox path of the file to read. | +| options | Object | No | The options are as follows:
- **position** (number): position of the data to read in the file. By default, data is read from the current position.
- **length** (number): length of the data to read. The default value is the buffer length minus the offset.
- **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 +**Example** ```js fileio.readText(path, function(err, str){ // Do something. @@ -1368,18 +1371,18 @@ Synchronously reads the text of a file. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters - | Name | Type | Mandatory | Description | - | -------- | ------ | ---- | ---------------------------------------- | - | filePath | string | Yes | Absolute path of the file to read. | - | options | Object | No | The options are as follows:
- **position** (number): position of the data to read in the file. By default, data is read from the current position.
- **length** (number): length of the data to read. The default value is the buffer length minus the offset.
- **encoding** (string): format of the data (string) to be encoded. The default value is **utf-8**, which is the only value supported.| +**Parameters** +| Name | Type | Mandatory| Description | +| -------- | ------ | ---- | ------------------------------------------------------------ | +| filePath | string | Yes | Application sandbox path of the file to be read. | +| options | Object | No | The options are as follows:
- **position** (number): position of the data to read in the file. By default, data is read from the current position.
- **length** (number): length of the data to read. The default value is the buffer length minus the offset.
- **encoding** (string): format of the data (string) to be encoded. The default value is **utf-8**, which is the only value supported.| -- Return value +**Return value** | Type | Description | | ------ | -------------------- | - | string | Content of the file read.| + | string | Promise used to return the content of the file read.| -- Example +**Example** ```js let str = fileio.readTextSync(path, {position: 1, length: 3}); ``` @@ -1389,21 +1392,21 @@ Synchronously reads the text of a file. lstat(path: string): Promise<Stat> -Asynchronously obtains link status information. This method uses a promise to return the result. +Asynchronously obtains link information. This API uses a promise to return the result. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters - | Name | Type | Mandatory | Description | - | ---- | ------ | ---- | ----------------- | - | path | string | Yes | Absolute path of the target file, pointing to the link status.| +**Parameters** +| Name| Type | Mandatory| Description | +| ------ | ------ | ---- | -------------------------------------- | +| path | string | Yes | Application sandbox path of the target file, pointing to the link.| -- Return value +**Return value** | Type | Description | | ---------------------------- | ---------- | - | Promise<[Stat](#stat)> | Promise used to return the link status obtained.| + | Promise<[Stat](#stat)> | Promise used to return the link information obtained.| -- Example +**Example** ```js fileio.lstat(path).then(function(stat){ console.info("Link status obtained:"+ number); @@ -1417,17 +1420,17 @@ Asynchronously obtains link status information. This method uses a promise to re lstat(path:string, callback:AsyncCallback<Stat>): void -Asynchronously obtains link status information. This method uses a callback to return the result. +Asynchronously obtains link information. This API uses a callback to return the result. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters - | Name | Type | Mandatory | Description | - | -------- | ---------------------------------- | ---- | ----------------- | - | path | string | Yes | Absolute path of the target file, pointing to the link status.| - | callback | AsyncCallback<[Stat](#stat)> | Yes | Callback invoked when the link status information is obtained asynchronously. | +**Parameters** +| Name | Type | Mandatory| Description | +| -------- | ---------------------------------- | ---- | -------------------------------------- | +| path | string | Yes | Application sandbox path of the target file, pointing to the link.| +| callback | AsyncCallback<[Stat](#stat)> | Yes | Callback invoked to return the link information obtained. | -- Example +**Example** ```js fileio.lstat(path, function (err, stat) { // Do something. @@ -1439,21 +1442,21 @@ Asynchronously obtains link status information. This method uses a callback to r lstatSync(path:string): Stat -Synchronously obtains link status information. +Synchronously obtains the link information. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters - | Name | Type | Mandatory | Description | - | ---- | ------ | ---- | ----------------- | - | path | string | Yes | Absolute path of the target file, pointing to the link status.| +**Parameters** +| Name| Type | Mandatory| Description | +| ------ | ------ | ---- | -------------------------------------- | +| path | string | Yes | Application sandbox path of the target file, pointing to the link.| -- Return value +**Return value** | Type | Description | | ------------- | ---------- | - | [Stat](#stat) | Link status obtained.| + | [Stat](#stat) | Link information obtained.| -- Example +**Example** ```js let stat = fileio.lstatSync(path); ``` @@ -1467,22 +1470,22 @@ read(buffer: ArrayBuffer, options?: { length?: number; }): Promise<ReadOut> -Asynchronously reads data from a file. This method uses a promise to return the result. +Asynchronously reads data from a file. This API uses a promise to return the result. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters +**Parameters** | Name | Type | Mandatory| Description | | ------- | ----------- | ---- | ------------------------------------------------------------ | | buffer | ArrayBuffer | Yes | Buffer used to store the file data read. | - | options | Object | No | The options are as follows:
- **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**.
- **length** (number): length of the data to read. The default value is the buffer length minus the offset.
-  The sum of **offset** and **length** must be less than or equal to the buffer size.| + | options | Object | No | The options are as follows:
- **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**.
- **length** (number): length of the data to read. The default value is the buffer length minus the offset.
Constraints: offset + length <= Buffer size| -- Return value +**Return value** | Type | Description | | ---------------------------------- | ------ | | Promise<[ReadOut](#readout)> | Data read.| -- Example +**Example** ```js fileio.read(new ArrayBuffer(4096)).then(function(readout){ console.info("read file data successfully"); @@ -1501,18 +1504,18 @@ read(buffer: ArrayBuffer, options: { length?: number; }, callback: AsyncCallback<ReadOut>): void -Asynchronously reads data from a file. This method uses a callback to return the result. +Asynchronously reads data from a file. This API uses a callback to return the result. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters +**Parameters** | Name | Type | Mandatory | Description | | -------- | ---------------------------------------- | ---- | ---------------------------------------- | | buffer | ArrayBuffer | Yes | Buffer used to store the file data read. | - | options | Object | No | The options are as follows:
- **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**.
- **length** (number): length of the data to read. The default value is the buffer length minus the offset.
-  The sum of **offset** and **length** must be less than or equal to the buffer size.| + | options | Object | No | The options are as follows:
- **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**.
- **length** (number): length of the data to read. The default value is the buffer length minus the offset.
Constraints: offset + length <= Buffer size| | callback | AsyncCallback<[ReadOut](#readout)> | Yes | Callback invoked when the data is read asynchronously from the file. | -- Example +**Example** ```js let buf = new ArrayBuffer(4096); fileio.read(buf, function (err, readOut) { @@ -1528,22 +1531,22 @@ Asynchronously reads data from a file. This method uses a callback to return the rename(oldPath: string, newPath: string): Promise<void> -Asynchronously renames a file. This method uses a promise to return the result. +Asynchronously renames a file. This API uses a promise to return the result. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters - | Name | Type | Mandatory| Description | - | ------- | ------ | ---- | ------------------------ | - | oldPath | string | Yes | Absolute path of the file to rename.| - | newPath | String | Yes | Absolute path of the file renamed. | +**Parameters** +| Name | Type | Mandatory| Description | +| ------- | ------ | ---- | ---------------------------- | +| oldPath | string | Yes | Application sandbox path of the file to rename.| +| newPath | String | Yes | Application sandbox path of the file renamed. | -- Return value +**Return value** | Type | Description | | ------------------- | ---------------------------- | | Promise<void> | Promise used to return the result. An empty value is returned.| -- Example +**Example** ```js fileio.rename(oldPath, newPath).then(function() { console.info("rename successfully"); @@ -1557,18 +1560,18 @@ Asynchronously renames a file. This method uses a promise to return the result. rename(oldPath: string, newPath: string, callback: AsyncCallback<void>): void -Asynchronously renames a file. This method uses a callback to return the result. +Asynchronously renames a file. This API uses a callback to return the result. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters - | Name | Type | Mandatory | Description | - | -------- | ------------------------- | ---- | ------------- | - | oldPath | string | Yes | Absolute path of the file to rename. | - | newPath | String | Yes | Absolute path of the file renamed. | - | Callback | AsyncCallback<void> | Yes | Callback invoked when the file is asynchronously renamed.| +**Parameters** +| Name | Type | Mandatory| Description | +| -------- | ------------------------- | ---- | ---------------------------- | +| oldPath | string | Yes | Application sandbox path of the file to rename.| +| newPath | String | Yes | Application sandbox path of the file renamed. | +| Callback | AsyncCallback<void> | Yes | Callback invoked when the file is asynchronously renamed. | -- Example +**Example** ```js fileio.rename(oldPath, newPath, function(err){ }); @@ -1583,13 +1586,13 @@ Synchronously renames a file. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters - | Name | Type | Mandatory | Description | - | ------- | ------ | ---- | ------------ | - | oldPath | string | Yes | Absolute path of the file to rename.| - | newPath | String | Yes | Absolute path of the file renamed. | +**Parameters** +| Name | Type | Mandatory| Description | +| ------- | ------ | ---- | ---------------------------- | +| oldPath | string | Yes | Application sandbox path of the file to rename.| +| newPath | String | Yes | Application sandbox path of the file renamed. | -- Example +**Example** ```js fileio.renameSync(oldPath, newPath); ``` @@ -1599,21 +1602,21 @@ Synchronously renames a file. fsync(fd: number): Promise<void> -Asynchronously synchronizes a file. This method uses a promise to return the result. +Asynchronously synchronizes a file. This API uses a promise to return the result. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters +**Parameters** | Name | Type | Mandatory | Description | | ---- | ------ | ---- | ------------ | | fd | number | Yes | File descriptor of the file to synchronize.| -- Return value +**Return value** | Type | Description | | ------------------- | ---------------------------- | | Promise<void> | Promise used to return the result. An empty value is returned.| -- Example +**Example** ```js fileio.fsync(fd).then(function(){ console.info("sync data successfully"); @@ -1627,17 +1630,17 @@ Asynchronously synchronizes a file. This method uses a promise to return the res fsync(fd: number, callback: AsyncCallback<void>): void -Asynchronously synchronizes a file. This method uses a callback to return the result. +Asynchronously synchronizes a file. This API uses a callback to return the result. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters +**Parameters** | Name | Type | Mandatory | Description | | -------- | ------------------------- | ---- | --------------- | | fd | number | Yes | File descriptor of the file to synchronize. | | Callback | AsyncCallback<void> | Yes | Callback invoked when the file is synchronized in asynchronous mode.| -- Example +**Example** ```js fileio.fsync(fd, function(err){ // Do something. @@ -1653,12 +1656,12 @@ Synchronizes a file in synchronous mode. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters +**Parameters** | Name | Type | Mandatory | Description | | ---- | ------ | ---- | ------------ | | fd | number | Yes | File descriptor of the file to synchronize.| -- Example +**Example** ```js fileio.fyncsSync(fd); ``` @@ -1668,21 +1671,21 @@ Synchronizes a file in synchronous mode. fdatasync(fd: number): Promise<void> -Asynchronously synchronizes data in a file. This method uses a promise to return the result. +Asynchronously synchronizes data in a file. This API uses a promise to return the result. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters +**Parameters** | Name | Type | Mandatory | Description | | ---- | ------ | ---- | ------------ | | fd | number | Yes | File descriptor of the file to synchronize.| -- Return value +**Return value** | Type | Description | | ------------------- | ---------------------------- | | Promise<void> | Promise used to return the result asynchronously. An empty value is returned.| -- Example +**Example** ```js fileio.fdatasync(fd).then(function(err) { console.info("sync data successfully"); @@ -1696,17 +1699,17 @@ Asynchronously synchronizes data in a file. This method uses a promise to return fdatasync(fd: number, callback:AsyncCallback<void>): void -Asynchronously synchronizes data in a file. This method uses a callback to return the result. +Asynchronously synchronizes data in a file. This API uses a callback to return the result. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters +**Parameters** | Name | Type | Mandatory | Description | | -------- | ------------------------------- | ---- | ----------------- | | fd | number | Yes | File descriptor of the file to synchronize. | | callback | AsyncCallback <void> | Yes | Callback invoked when the file data is synchronized in asynchronous mode.| -- Example +**Example** ```js fileio.fdatasync (fd, function (err) { // Do something. @@ -1722,12 +1725,12 @@ Synchronizes data in a file in synchronous mode. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters +**Parameters** | Name | Type | Mandatory | Description | | ---- | ------ | ---- | ------------ | | fd | number | Yes | File descriptor of the file to synchronize.| -- Example +**Example** ```js let stat = fileio.fdatasyncSync(fd); ``` @@ -1737,22 +1740,22 @@ Synchronizes data in a file in synchronous mode. symlink(target: string, srcPath: string): Promise<void> -Asynchronously creates a symbolic link based on a path. This method uses a promise to return the result. +Asynchronously creates a symbolic link based on a path. This API uses a promise to return the result. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters - | Name | Type | Mandatory | Description | - | ------- | ------ | ---- | ------------ | - | target | string | Yes | Absolute path of the symbolic link. | - | srcPath | string | Yes | Absolute path of the referenced file or directory contained in the symbolic link.| +**Parameters** +| Name | Type | Mandatory| Description | +| ------- | ------ | ---- | ---------------------------- | +| target | string | Yes | Application sandbox path of the symbolic link. | +| srcPath | string | Yes | Application sandbox path of the referenced file or directory contained in the symbolic link.| -- Return value +**Return value** | Type | Description | | ------------------- | ---------------------------- | | Promise<void> | Promise used to return the result asynchronously. An empty value is returned.| -- Example +**Example** ```js fileio.symlink(target, srcPath).then(function() { console.info("symlink successfully"); @@ -1766,18 +1769,18 @@ Asynchronously creates a symbolic link based on a path. This method uses a promi symlink(target: string, srcPath: string, callback: AsyncCallback<void>): void -Asynchronously creates a symbolic link based on a path. This method uses a callback to return the result. +Asynchronously creates a symbolic link based on a path. This API uses a callback to return the result. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters - | Name | Type | Mandatory | Description | - | -------- | ------------------------- | ---- | ---------------- | - | target | string | Yes | Absolute path of the symbolic link. | - | srcPath | string | Yes | Absolute path of the referenced file or directory contained in the symbolic link. | - | callback | AsyncCallback<void> | Yes | Callback invoked when the symbolic link is created asynchronously.| +**Parameters** +| Name | Type | Mandatory| Description | +| -------- | ------------------------- | ---- | -------------------------------- | +| target | string | Yes | Application sandbox path of the symbolic link. | +| srcPath | string | Yes | Application sandbox path of the referenced file or directory contained in the symbolic link. | +| callback | AsyncCallback<void> | Yes | Callback invoked when the symbolic link is created asynchronously.| -- Example +**Example** ```js fileio.symlink(target, srcPath, function (err) { // Do something. @@ -1793,13 +1796,13 @@ Synchronously creates a symbolic link based on a specified path. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters - | Name | Type | Mandatory | Description | - | ------- | ------ | ---- | ------------ | - | target | string | Yes | Absolute path of the symbolic link. | - | srcPath | string | Yes | Absolute path of the referenced file or directory contained in the symbolic link.| +**Parameters** +| Name | Type | Mandatory| Description | +| ------- | ------ | ---- | ---------------------------- | +| target | string | Yes | Application sandbox path of the symbolic link. | +| srcPath | string | Yes | Application sandbox path the referenced file or directory contained in the symbolic link.| -- Example +**Example** ```js fileio.symlinkSync(target, srcPath); ``` @@ -1809,23 +1812,23 @@ Synchronously creates a symbolic link based on a specified path. chown(path: string, uid: number, gid: number): Promise<void> -Asynchronously changes the file owner based on its path. This method uses a promise to return the result. +Asynchronously changes the file owner based on its path. This API uses a promise to return the result. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters - | Name | Type | Mandatory | Description | - | ---- | ------ | ---- | --------------- | - | path | string | Yes | Absolute path of the target file. | - | uid | number | Yes | New user ID (UID). | - | gid | number | Yes | New group ID (GID).| +**Parameters** +| Name| Type | Mandatory| Description | +| ------ | ------ | ---- | -------------------------- | +| path | string | Yes | Application sandbox path of the target file.| +| uid | number | Yes | New user ID (UID). | +| gid | number | Yes | New group ID (GID). | -- Return value +**Return value** | Type | Description | | ------------------- | ---------------------------- | | Promise<void> | Promise used to return the result asynchronously. An empty value is returned.| -- Example +**Example** ```js let stat = fileio.statSync(path); fileio.chown(path, stat.uid, stat.gid).then(function(){ @@ -1840,19 +1843,19 @@ Asynchronously changes the file owner based on its path. This method uses a prom chown(path: string, uid: number, gid: number, callback: AsyncCallback<void>): void -Asynchronously changes the file owner based on its path. This method uses a callback to return the result. +Asynchronously changes the file owner based on its path. This API uses a callback to return the result. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters - | Name | Type | Mandatory | Description | - | -------- | ------------------------- | ---- | --------------- | - | path | string | Yes | Absolute path of the target file. | - | uid | number | Yes | New UID. | - | gid | number | Yes | New GID. | - | callback | AsyncCallback<void> | Yes | Callback invoked when the file owner is changed asynchronously.| +**Parameters** +| Name | Type | Mandatory| Description | +| -------- | ------------------------- | ---- | ------------------------------ | +| path | string | Yes | Application sandbox path of the target file. | +| uid | number | Yes | New UID. | +| gid | number | Yes | New GID. | +| callback | AsyncCallback<void> | Yes | Callback invoked when the file owner is changed asynchronously.| -- Example +**Example** ```js let stat = fileio.statSync(fpath) fileio.chown(path, stat.uid, stat.gid, function (err){ @@ -1869,14 +1872,14 @@ Synchronously changes the file owner based on its path. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters - | Name | Type | Mandatory | Description | - | ---- | ------ | ---- | ----------- | - | path | string | Yes | Absolute path of the target file.| - | uid | number | Yes | New UID. | - | gid | number | Yes | New GID. | +**Parameters** +| Name| Type | Mandatory| Description | +| ------ | ------ | ---- | -------------------------- | +| path | string | Yes | Application sandbox path of the target file.| +| uid | number | Yes | New UID. | +| gid | number | Yes | New GID. | -- Example +**Example** ```js let stat = fileio.statSync(fpath) fileio.chownSync(path, stat.uid, stat.gid); @@ -1887,21 +1890,21 @@ Synchronously changes the file owner based on its path. mkdtemp(prefix: string): Promise<string> -Asynchronously creates a temporary directory. This method uses a promise to return the result. +Asynchronously creates a temporary directory. This API uses a promise to return the result. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters +**Parameters** | Name | Type | Mandatory | Description | | ------ | ------ | ---- | --------------------------- | | prefix | string | Yes | A randomly generated string used to replace "XXXXXX" in a directory.| -- Return value +**Return value** | Name | Description | | --------------------- | ---------- | | Promise<string> | Unique path generated.| -- Example +**Example** ```js fileio.mkdtemp(path + "XXXX").then(function(path){ console.info("mkdtemp successfully:"+ path); @@ -1915,17 +1918,17 @@ Asynchronously creates a temporary directory. This method uses a promise to retu mkdtemp(prefix: string, callback: AsyncCallback<string>): void -Asynchronously creates a temporary directory. This method uses a callback to return the result. +Asynchronously creates a temporary directory. This API uses a callback to return the result. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters +**Parameters** | Name | Type | Mandatory | Description | | -------- | --------------------------- | ---- | --------------------------- | | prefix | string | Yes | A randomly generated string used to replace "XXXXXX" in a directory.| | callback | AsyncCallback<string> | Yes | Callback invoked when a temporary directory is created asynchronously. | -- Example +**Example** ```js fileio.mkdtemp(path + "XXXX", function (err, res) { // Do something. @@ -1941,17 +1944,17 @@ Synchronously creates a temporary directory. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters +**Parameters** | Name | Type | Mandatory | Description | | ------ | ------ | ---- | --------------------------- | | prefix | string | Yes | A randomly generated string used to replace "XXXXXX" in a directory.| -- Return value +**Return value** | Name | Description | | ------ | ---------- | | string | Unique path generated.| -- Example +**Example** ```js let res = fileio.mkdtempSync(path + "XXXX"); ``` @@ -1961,22 +1964,22 @@ Synchronously creates a temporary directory. fchmod(fd: number, mode: number): Promise<void> -Asynchronously changes the file permissions based on the file descriptor. This method uses a promise to return the result. +Asynchronously changes the file permissions based on the file descriptor. This API uses a promise to return the result. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters +**Parameters** | Name | Type | Mandatory | Description | | ---- | ------ | ---- | ---------------------------------------- | | fd | number | Yes | File descriptor of the target file. | | mode | number | Yes | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (|).
- **0o700**: The owner has the read, write, and execute permissions.
-  **0o400**: The owner has the read permission.
- **0o200**: The owner has the write permission.
- **0o100**: The owner has the execute permission.
- **0o070**: The user group has the read, write, and execute permissions.
- **0o040**: The user group has the read permission.
- **0o020**: The user group has the write permission.
- **0o010**: The user group has the execute permission.
- **0o007**: Other users have the read, write, and execute permissions.
- **0o004**: Other users have the read permission.
- **0o002**: Other users have the write permission.
- **0o001**: Other users have the execute permission.| -- Return value +**Return value** | Name | Description | | ------------------- | ---------------------------- | | Promise<void> | Promise used to return the result asynchronously. An empty value is returned.| -- Example +**Example** ```js fileio.fchmod(fd, mode).then(function() { console.info("chmod successfully"); @@ -1990,18 +1993,18 @@ Asynchronously changes the file permissions based on the file descriptor. This m fchmod(fd: number, mode: number, callback: AsyncCallback<void>): void -Asynchronously changes the file permissions based on the file descriptor. This method uses a callback to return the result. +Asynchronously changes the file permissions based on the file descriptor. This API uses a callback to return the result. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters +**Parameters** | Name | Type | Mandatory | Description | | -------- | ------------------------------- | ---- | ---------------------------------------- | | fd | number | Yes | File descriptor of the target file. | | mode | number | Yes | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (|).
- **0o700**: The owner has the read, write, and execute permissions.
-  **0o400**: The owner has the read permission.
- **0o200**: The owner has the write permission.
- **0o100**: The owner has the execute permission.
- **0o070**: The user group has the read, write, and execute permissions.
- **0o040**: The user group has the read permission.
- **0o020**: The user group has the write permission.
- **0o010**: The user group has the execute permission.
- **0o007**: Other users have the read, write, and execute permissions.
- **0o004**: Other users have the read permission.
- **0o002**: Other users have the write permission.
- **0o001**: Other users have the execute permission.| | callback | AsyncCallback <void> | Yes | Callback invoked when the file permissions are changed asynchronously. | -- Example +**Example** ```js fileio.fchmod(fd, mode, function (err) { // Do something. @@ -2017,13 +2020,13 @@ Synchronously changes the file permissions based on the file descriptor. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters +**Parameters** | Name | Type | Mandatory | Description | | ---- | ------ | ---- | ---------------------------------------- | | fd | number | Yes | File descriptor of the target file. | | mode | number | Yes | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (|).
- **0o700**: The owner has the read, write, and execute permissions.
-  **0o400**: The owner has the read permission.
- **0o200**: The owner has the write permission.
- **0o100**: The owner has the execute permission.
- **0o070**: The user group has the read, write, and execute permissions.
- **0o040**: The user group has the read permission.
- **0o020**: The user group has the write permission.
- **0o010**: The user group has the execute permission.
- **0o007**: Other users have the read, write, and execute permissions.
- **0o004**: Other users have the read permission.
- **0o002**: Other users have the write permission.
- **0o001**: Other users have the execute permission.| -- Example +**Example** ```js fileio.fchmodSync(fd, mode); ``` @@ -2033,22 +2036,22 @@ Synchronously changes the file permissions based on the file descriptor. createStream(path: string, mode: string): Promise<Stream> -Asynchronously opens a stream based on the file path. This method uses a promise to return the result. +Asynchronously opens a stream based on the file path. This API uses a promise to return the result. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters - | Name | Type | Mandatory | Description | - | ---- | ------ | ---- | ---------------------------------------- | - | path | string | Yes | Absolute path of the target file. | - | mode | string | Yes | - **r**: Open a file for reading. The file must exist.
- **r+**: Open a file for both reading and writing. The file must exist.
- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.
- **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.
- **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).
- **a+**: Open a file in append mode for reading or updating at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).| +**Parameters** +| Name| Type | Mandatory| Description | +| ------ | ------ | ---- | ------------------------------------------------------------ | +| path | string | Yes | Application sandbox path of the target file. | +| mode | string | Yes | - **r**: Open a file for reading. The file must exist.
- **r+**: Open a file for both reading and writing. The file must exist.
- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.
- **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.
- **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).
- **a+**: Open a file in append mode for reading or updating at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).| -- Return value +**Return value** | Type | Description | | --------------------------------- | --------- | | Promise<[Stream](#stream7)> | Promise used to return the result.| -- Example +**Example** ```js fileio.createStream(path, "r+").then(function(stream){ console.info("createStream successfully"); @@ -2062,18 +2065,18 @@ Asynchronously opens a stream based on the file path. This method uses a promise createStream(path: string, mode: string, callback: AsyncCallback<Stream>): void -Asynchronously opens a stream based on the file path. This method uses a callback to return the result. +Asynchronously opens a stream based on the file path. This API uses a callback to return the result. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters - | Name | Type | Mandatory | Description | - | -------- | --------------------------------------- | ---- | ---------------------------------------- | - | path | string | Yes | Absolute path of the target file. | - | mode | string | Yes | - **r**: Open a file for reading. The file must exist.
- **r+**: Open a file for both reading and writing. The file must exist.
- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.
- **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.
- **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).
- **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. | +**Parameters** +| Name | Type | Mandatory| Description | +| -------- | --------------------------------------- | ---- | ------------------------------------------------------------ | +| path | string | Yes | Application sandbox path of the target file. | +| mode | string | Yes | - **r**: Open a file for reading. The file must exist.
- **r+**: Open a file for both reading and writing. The file must exist.
- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.
- **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.
- **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).
- **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. | -- Example +**Example** ```js fileio.createStream(path, mode, function(err, stream){ // Do something. @@ -2089,18 +2092,18 @@ Synchronously opens a stream based on the file path. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters - | Name | Type | Mandatory | Description | - | ---- | ------ | ---- | ---------------------------------------- | - | path | string | Yes | Absolute path of the target file. | - | mode | string | Yes | - **r**: Open a file for reading. The file must exist.
- **r+**: Open a file for both reading and writing. The file must exist.
- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.
- **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.
- **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).
- **a+**: Open a file in append mode for reading or updating at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).| +**Parameters** +| Name| Type | Mandatory| Description | +| ------ | ------ | ---- | ------------------------------------------------------------ | +| path | string | Yes | Application sandbox path of the target file. | +| mode | string | Yes | - **r**: Open a file for reading. The file must exist.
- **r+**: Open a file for both reading and writing. The file must exist.
- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.
- **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.
- **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).
- **a+**: Open a file in append mode for reading or updating at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).| -- Return value +**Return value** | Name | Description | | ------------------ | --------- | | [Stream](#stream7) | Stream opened.| -- Example +**Example** ```js let ss = fileio.createStreamSync(path, "r+"); ``` @@ -2110,22 +2113,22 @@ Synchronously opens a stream based on the file path. fdopenStream(fd: number, mode: string): Promise<Stream> -Asynchronously opens a stream based on the file descriptor. This method uses a promise to return the result. +Asynchronously opens a stream based on the file descriptor. This API uses a promise to return the result. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters +**Parameters** | Name | Type | Mandatory | Description | | ---- | ------ | ---- | ---------------------------------------- | | fd | number | Yes | File descriptor of the target file. | | mode | string | Yes | - **r**: Open a file for reading. The file must exist.
- **r+**: Open a file for both reading and writing. The file must exist.
- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.
- **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.
- **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).
- **a+**: Open a file in append mode for reading or updating at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).| -- Return value +**Return value** | Name | Description | | --------------------------------- | --------- | | Promise<[Stream](#stream7)> | Promise used to return the result.| -- Example +**Example** ```js fileio.fdopenStream(fd, mode).then(function(stream){ console.info("openStream successfully"); @@ -2139,18 +2142,18 @@ Asynchronously opens a stream based on the file descriptor. This method uses a p fdopenStream(fd: number, mode: string, callback: AsyncCallback<Stream>): void -Asynchronously opens a stream based on the file descriptor. This method uses a callback to return the result. +Asynchronously opens a stream based on the file descriptor. This API uses a callback to return the result. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters +**Parameters** | Name | Type | Mandatory | Description | | -------- | ---------------------------------------- | ---- | ---------------------------------------- | | fd | number | Yes | File descriptor of the target file. | | mode | string | Yes | - **r**: Open a file for reading. The file must exist.
- **r+**: Open a file for both reading and writing. The file must exist.
- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.
- **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.
- **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).
- **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. | -- Example +**Example** ```js fileio.fdopenStream(fd, mode, function (err, stream) { // Do something. @@ -2166,18 +2169,18 @@ Synchronously opens a stream based on the file descriptor. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters +**Parameters** | Name | Type | Mandatory | Description | | ---- | ------ | ---- | ---------------------------------------- | | fd | number | Yes | File descriptor of the target file. | | mode | string | Yes | - **r**: Open a file for reading. The file must exist.
- **r+**: Open a file for both reading and writing. The file must exist.
- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.
- **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.
- **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).
- **a+**: Open a file in append mode for reading or updating at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).| -- Return value - | Name | Description | +**Return value** + | Type | Description | | ------------------ | --------- | | [Stream](#stream7) | Stream opened.| -- Example +**Example** ```js let ss = fileio.fdopenStreamSync(fd, "r+"); ``` @@ -2187,23 +2190,23 @@ Synchronously opens a stream based on the file descriptor. fchown(fd: number, uid: number, gid: number): Promise<void> -Asynchronously changes the file owner based on the file descriptor. This method uses a promise to return the result. +Asynchronously changes the file owner based on the file descriptor. This API uses a promise to return the result. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters +**Parameters** | Name | Type | Mandatory | Description | | ---- | ------ | ---- | ------------ | | fd | number | Yes | File descriptor of the target file.| | uid | number | Yes | New UID. | | gid | number | Yes | New GID. | -- Return value +**Return value** | Type | Description | | ------------------- | ---------------------------- | | Promise<void> | Promise used to return the result. An empty value is returned.| -- Example +**Example** ```js let stat = fileio.statSync(path); fileio.fchown(fd, stat.uid, stat.gid).then(function() { @@ -2218,11 +2221,11 @@ Asynchronously changes the file owner based on the file descriptor. This method fchown(fd: number, uid: number, gid: number, callback: AsyncCallback<void>): void -Asynchronously changes the file owner based on the file descriptor. This method uses a callback to return the result. +Asynchronously changes the file owner based on the file descriptor. This API uses a callback to return the result. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters +**Parameters** | Name | Type | Mandatory | Description | | -------- | ------------------------- | ---- | --------------- | | fd | number | Yes | File descriptor of the target file. | @@ -2230,7 +2233,7 @@ Asynchronously changes the file owner based on the file descriptor. This method | gid | number | Yes | New GID. | | callback | AsyncCallback<void> | Yes | Callback invoked when the file owner is changed asynchronously.| -- Example +**Example** ```js let stat = fileio.statSync(fpath); fileio.fchown(fd, stat.uid, stat.gid, function (err){ @@ -2247,14 +2250,14 @@ Synchronously changes the file owner based on the file descriptor. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters +**Parameters** | Name | Type | Mandatory | Description | | ---- | ------ | ---- | ------------ | | fd | number | Yes | File descriptor of the target file.| | uid | number | Yes | New UID. | | gid | number | Yes | New GID. | -- Example +**Example** ```js let stat = fileio.statSync(fpath); fileio.fchownSync(fd, stat.uid, stat.gid); @@ -2269,19 +2272,19 @@ Asynchronously changes the file owner based on the file path, changes the owner **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters - | Name | Type | Mandatory | Description | - | ---- | ------ | ---- | ----------- | - | path | string | Yes | Absolute path of the target file.| - | uid | number | Yes | New UID. | - | gid | number | Yes | New GID. | +**Parameters** +| Name| Type | Mandatory| Description | +| ------ | ------ | ---- | -------------------------- | +| path | string | Yes | Application sandbox path of the target file.| +| uid | number | Yes | New UID. | +| gid | number | Yes | New GID. | -- Return value +**Return value** | Type | Description | | ------------------- | ---------------------------- | | Promise<void> | Promise used to return the result. An empty value is returned.| -- Example +**Example** ```js let stat = fileio.statSync(path); fileio.lchown(path, stat.uid, stat.gid).then(function() { @@ -2300,15 +2303,15 @@ Asynchronously changes the file owner based on the file path, changes the owner **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters - | Name | Type | Mandatory | Description | - | -------- | ------------------------- | ---- | --------------- | - | path | string | Yes | Absolute path of the target file. | - | uid | number | Yes | New UID. | - | gid | number | Yes | New GID. | - | callback | AsyncCallback<void> | Yes | Callback invoked when the file owner is changed asynchronously.| +**Parameters** +| Name | Type | Mandatory| Description | +| -------- | ------------------------- | ---- | ------------------------------ | +| path | string | Yes | Application sandbox path of the target file. | +| uid | number | Yes | New UID. | +| gid | number | Yes | New GID. | +| callback | AsyncCallback<void> | Yes | Callback invoked when the file owner is changed asynchronously.| -- Example +**Example** ```js let stat = fileio.statSync(path); fileio.lchown(path, stat.uid, stat.gid, function (err){ @@ -2325,14 +2328,14 @@ Synchronously changes the file owner based on the file path and changes the owne **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters - | Name | Type | Mandatory | Description | - | ---- | ------ | ---- | ----------- | - | path | string | Yes | Absolute path of the target file.| - | uid | number | Yes | New UID. | - | gid | number | Yes | New GID. | +**Parameters** +| Name| Type | Mandatory| Description | +| ------ | ------ | ---- | -------------------------- | +| path | string | Yes | Application sandbox path of the target file.| +| uid | number | Yes | New UID. | +| gid | number | Yes | New GID. | -- Example +**Example** ```js let stat = fileio.statSync(path); fileio.lchownSync(path, stat.uid, stat.gid); @@ -2343,23 +2346,23 @@ Synchronously changes the file owner based on the file path and changes the owne createWatcher(filename: string, events: number, callback: AsyncCallback<number>): Watcher -Asynchronously listens for the changes of a file or directory. This method uses a callback to return the result. +Asynchronously listens for the changes of a file or directory. This API uses a callback to return the result. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters - | Name | Type | Mandatory | Description | - | -------- | --------------------------------- | ---- | ---------------------------------------- | - | filename | string | Yes | Absolute path of the target file. | - | events | Number | Yes | - **1**: The file or directory is renamed.
- **2**: The file or directory is modified.
- **3**: The file or directory is modified and renamed.| - | callback | AsyncCallback<number > | Yes | Called each time a change is detected. | +**Parameters** +| Name | Type | Mandatory| Description | +| -------- | --------------------------------- | ---- | ------------------------------------------------------------ | +| filename | string | Yes | Application sandbox path of the target file. | +| events | Number | Yes | - **1**: The file or directory is renamed.
- **2**: The file or directory is modified.
- **3**: The file or directory is modified and renamed.| +| callback | AsyncCallback<number > | Yes | Called each time a change is detected. | -- Return value +**Return value** | Name | Description | | -------------------- | ---------- | | [Watcher](#watcher7) | Instance for listening for a file change event.| -- Example +**Example** ```js fileio.createWatcher(filename, events, function(watcher){ // Do something. @@ -2412,12 +2415,12 @@ Checks whether this file is a block special file. A block special file supports **System capability**: SystemCapability.FileManagement.File.FileIO -- Return value +**Return value** | Type | Description | | ------- | ---------------- | | boolean | Whether the file is a block special file.| -- Example +**Example** ```js let isBLockDevice = fileio.statSync(path).isBlockDevice(); ``` @@ -2431,12 +2434,12 @@ Checks whether this file is a character special file. A character special file s **System capability**: SystemCapability.FileManagement.File.FileIO -- Return value +**Return value** | Type | Description | | ------- | ----------------- | | boolean | Whether the file is a character special file.| -- Example +**Example** ```js let isCharacterDevice = fileio.statSync(path).isCharacterDevice(); ``` @@ -2450,12 +2453,12 @@ Checks whether this file is a directory. **System capability**: SystemCapability.FileManagement.File.FileIO -- Return value +**Return value** | Type | Description | | ------- | ------------- | | boolean | Whether the file is a directory.| -- Example +**Example** ```js let isDirectory = fileio.statSync(path).isDirectory(); ``` @@ -2469,12 +2472,12 @@ Checks whether this file is a named pipe (or FIFO). Named pipes are used for int **System capability**: SystemCapability.FileManagement.File.FileIO -- Return value +**Return value** | Type | Description | | ------- | --------------------- | | boolean | Whether the file is an FIFO.| -- Example +**Example** ```js let isFIFO = fileio.statSync(path).isFIFO(); ``` @@ -2488,12 +2491,12 @@ Checks whether this file is a regular file. **System capability**: SystemCapability.FileManagement.File.FileIO -- Return value +**Return value** | Type | Description | | ------- | --------------- | | boolean | Whether the file is a regular file.| -- Example +**Example** ```js let isFile = fileio.statSync(fpath).isFile(); ``` @@ -2507,12 +2510,12 @@ Checks whether this file is a socket. **System capability**: SystemCapability.FileManagement.File.FileIO -- Return value +**Return value** | Type | Description | | ------- | -------------- | | boolean | Whether the file is a socket.| -- Example +**Example** ```js let isSocket = fileio.statSync(path).isSocket(); ``` @@ -2526,12 +2529,12 @@ Checks whether this file is a symbolic link. **System capability**: SystemCapability.FileManagement.File.FileIO -- Return value +**Return value** | Type | Description | | ------- | --------------- | | boolean | Whether the file is a symbolic link.| -- Example +**Example** ```js let isSymbolicLink = fileio.statSync(path).isSymbolicLink(); ``` @@ -2546,11 +2549,11 @@ Listens for the changes of a file. You can call the **Watcher.stop()** method sy stop(): Promise<void> -Asynchronously stops **watcher**. This method uses a promise to return the result. +Asynchronously stops **watcher**. This API uses a promise to return the result. **System capability**: SystemCapability.FileManagement.File.FileIO -- Example +**Example** ```js fileio.stop(); ``` @@ -2560,16 +2563,16 @@ Asynchronously stops **watcher**. This method uses a promise to return the resul stop(callback: AsyncCallback<void>): void -Asynchronously stops **watcher**. This method uses a callback to return the result. +Asynchronously stops **watcher**. This API uses a callback to return the result. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters +**Parameters** | Name | Type | Mandatory | Description | | -------- | ------------------------- | ---- | ---------------------- | | callback | AsyncCallback<void> | Yes | Callback invoked when **watcher** is stopped asynchronously.| -- Example +**Example** ```js fileio.stop(function(err){ // Do something. @@ -2587,16 +2590,16 @@ File stream. Before calling a method of the **Stream** class, use the **createSt close(): Promise<void> -Asynchronously closes the stream. This method uses a promise to return the result. +Asynchronously closes the stream. This API uses a promise to return the result. **System capability**: SystemCapability.FileManagement.File.FileIO -- Return value +**Return value** | Type | Description | | ------------------- | ------------- | | Promise<void> | Promise used to return the stream close result.| -- Example +**Example** ```js let ss= fileio.createStreamSync(path); ss.close().then(function(){ @@ -2611,16 +2614,16 @@ Asynchronously closes the stream. This method uses a promise to return the resul close(callback: AsyncCallback<void>): void -Asynchronously closes the stream. This method uses a callback to return the result. +Asynchronously closes the stream. This API uses a callback to return the result. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters +**Parameters** | Name | Type | Mandatory | Description | | -------- | ------------------------- | ---- | ------------- | | callback | AsyncCallback<void> | Yes | Callback invoked when the stream is closed asynchronously.| -- Example +**Example** ```js let ss= fileio.createStreamSync(path); ss.close(function (err) { @@ -2637,7 +2640,7 @@ Synchronously closes the stream. **System capability**: SystemCapability.FileManagement.File.FileIO -- Example +**Example** ```js let ss= fileio.createStreamSync(path); ss.closeSync(); @@ -2648,16 +2651,16 @@ Synchronously closes the stream. flush(): Promise<void> -Asynchronously flushes the stream. This method uses a promise to return the result. +Asynchronously flushes the stream. This API uses a promise to return the result. **System capability**: SystemCapability.FileManagement.File.FileIO -- Return value +**Return value** | Type | Description | | ------------------- | ------------- | | Promise<void> | Promise used to return the stream flushing result.| -- Example +**Example** ```js let ss= fileio.createStreamSync(path); ss.flush().then(function (){ @@ -2672,16 +2675,16 @@ Asynchronously flushes the stream. This method uses a promise to return the resu flush(callback: AsyncCallback<void>): void -Asynchronously flushes the stream. This method uses a callback to return the result. +Asynchronously flushes the stream. This API uses a callback to return the result. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters +**Parameters** | Name | Type | Mandatory | Description | | -------- | ------------------------- | ---- | -------------- | | callback | AsyncCallback<void> | Yes | Callback invoked when the stream is asynchronously flushed.| -- Example +**Example** ```js let ss= fileio.createStreamSync(path); ss.flush(function (err) { @@ -2698,7 +2701,7 @@ Synchronously flushes the stream. **System capability**: SystemCapability.FileManagement.File.FileIO -- Example +**Example** ```js let ss= fileio.createStreamSync(path); ss.flushSync(); @@ -2714,22 +2717,22 @@ write(buffer: ArrayBuffer | string, options?: { encoding?: string; }): Promise<number> -Asynchronously writes data into the stream. This method uses a promise to return the result. +Asynchronously writes data into the stream. This API uses a promise to return the result. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters +**Parameters** | Name | Type | Mandatory | Description | | ------- | ------------------------------- | ---- | ---------------------------------------- | | buffer | ArrayBuffer \| string | Yes | Data to write. It can be a string or data from a buffer. | - | options | Object | No | The options are as follows:
- **offset** (number): position of the data to write in reference to the start address of the data. The default value is **0**.
- **length** (number): length of the data to write. The default value is the buffer length minus the offset.
- **position** (number): start position to write the data in the file. By default, data is written from the current position.
- **encoding** (string): format of the string to be encoded. The default value is **utf-8**, which is the only value supported.
-  The sum of **offset** and **length** must be less than or equal to the buffer size. | + | options | Object | No | The options are as follows:
- **offset** (number): position of the data to write in reference to the start address of the data. The default value is **0**.
- **length** (number): length of the data to write. The default value is the buffer length minus the offset.
- **position** (number): start position to write the data in the file. By default, data is written from the current position.
- **encoding** (string): format of the string to be encoded. The default value is **utf-8**, which is the only value supported.
Constraints: offset + length <= Buffer size | -- Return value +**Return value** | Type | Description | | --------------------- | -------- | | Promise<number> | Length of the data written in the file.| -- Example +**Example** ```js let ss= fileio.createStreamSync(fpath, "r+"); ss.write("hello, world",{offset: 1,length: 5,position: 5,encoding :'utf-8'}).then(function (number){ @@ -2749,18 +2752,18 @@ write(buffer: ArrayBuffer | string, options: { encoding?: string; }, callback: AsyncCallback<number>): void -Asynchronously writes data into the stream. This method uses a callback to return the result. +Asynchronously writes data into the stream. This API uses a callback to return the result. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters +**Parameters** | Name | Type | Mandatory| Description | | -------- | ------------------------------- | ---- | ------------------------------------------------------------ | | buffer | ArrayBuffer \| string | Yes | Data to write. It can be a string or data from a buffer. | - | options | Object | No | The options are as follows:
- **offset** (number): position of the data to write in reference to the start address of the data. The default value is **0**.
- **length** (number): length of the data to write. The default value is the buffer length minus the offset.
- **position** (number): start position to write the data in the file. By default, data is written from the current position.
- **encoding** (string): format of the string to be encoded. The default value is **utf-8**, which is the only value supported.
-  The sum of **offset** and **length** must be less than or equal to the buffer size.| + | options | Object | No | The options are as follows:
- **offset** (number): position of the data to write in reference to the start address of the data. The default value is **0**.
- **length** (number): length of the data to write. The default value is the buffer length minus the offset.
- **position** (number): start position to write the data in the file. By default, data is written from the current position.
- **encoding** (string): format of the string to be encoded. The default value is **utf-8**, which is the only value supported.
Constraints: offset + length <= Buffer size| | callback | AsyncCallback<number> | Yes | Callback invoked when the data is written asynchronously. | -- Example +**Example** ```js let ss= fileio.createStreamSync(fpath, "r+"); ss.write("hello, world", {offset: 1, length: 5, position: 5, encoding :'utf-8'}, function (err, bytesWritten) { @@ -2785,18 +2788,18 @@ Synchronously writes data into the stream. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters +**Parameters** | Name | Type | Mandatory | Description | | ------- | ------------------------------- | ---- | ---------------------------------------- | | buffer | ArrayBuffer \| string | Yes | Data to write. It can be a string or data from a buffer. | - | options | Object | No | The options are as follows:
- **offset** (number): position of the data to write in reference to the start address of the data. The default value is **0**.
- **length** (number): length of the data to write. The default value is the buffer length minus the offset.
- **position** (number): start position to write the data in the file. By default, data is written from the current position.
- **encoding** (string): format of the string to be encoded. The default value is **utf-8**, which is the only value supported.
-  The sum of **offset** and **length** must be less than or equal to the buffer size. | + | options | Object | No | The options are as follows:
- **offset** (number): position of the data to write in reference to the start address of the data. The default value is **0**.
- **length** (number): length of the data to write. The default value is the buffer length minus the offset.
- **position** (number): start position to write the data in the file. By default, data is written from the current position.
- **encoding** (string): format of the string to be encoded. The default value is **utf-8**, which is the only value supported.
Constraints: offset + length <= Buffer size | -- Return value +**Return value** | Type | Description | | ------ | -------- | | number | Length of the data written in the file.| -- Example +**Example** ```js let ss= fileio.createStreamSync(fpath,"r+"); let num = ss.writeSync("hello, world", {offset: 1, length: 5, position: 5, encoding :'utf-8'}); @@ -2811,22 +2814,22 @@ read(buffer: ArrayBuffer, options?: { length?: number; }): Promise<ReadOut> -Asynchronously reads data from the stream. This method uses a promise to return the result. +Asynchronously reads data from the stream. This API uses a promise to return the result. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters +**Parameters** | Name | Type | Mandatory | Description | | ------- | ----------- | ---- | ---------------------------------------- | | buffer | ArrayBuffer | Yes | Buffer used to store the file read. | - | options | Object | No | The options are as follows:
- **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**.
- **length** (number): length of the data to read. The default value is the buffer length minus the offset.
- **position** (number): position of the data to read in the file. By default, data is read from the current position.
-  The sum of **offset** and **length** must be less than or equal to the buffer size. | + | options | Object | No | The options are as follows:
- **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**.
- **length** (number): length of the data to read. The default value is the buffer length minus the offset.
- **position** (number): position of the data to read in the file. By default, data is read from the current position.
Constraints: offset + length <= Buffer size | -- Return value +**Return value** | Type | Description | | ---------------------------------- | ------ | | Promise<[ReadOut](#readout)> | Data read.| -- Example +**Example** ```js let ss = fileio.createStreamSync(fpath, "r+"); ss.read(new ArrayBuffer(4096), {offset: 1, length: 5, position: 5}).then(function (readout){ @@ -2846,18 +2849,18 @@ read(buffer: ArrayBuffer, options: { length?: number; }, callback: AsyncCallback<ReadOut>): void -Asynchronously reads data from the stream. This method uses a callback to return the result. +Asynchronously reads data from the stream. This API uses a callback to return the result. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters +**Parameters** | Name | Type | Mandatory | Description | | -------- | ---------------------------------------- | ---- | ---------------------------------------- | | buffer | ArrayBuffer | Yes | Buffer used to store the file read. | - | options | Object | No | The options are as follows:
- **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**.
- **length** (number): length of the data to read. The default value is the buffer length minus the offset.
- **position** (number): position of the data to read in the file. By default, data is read from the current position.
-  The sum of **offset** and **length** must be less than or equal to the buffer size. | + | options | Object | No | The options are as follows:
- **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**.
- **length** (number): length of the data to read. The default value is the buffer length minus the offset.
- **position** (number): position of the data to read in the file. By default, data is read from the current position.
Constraints: offset + length <= Buffer size | | callback | AsyncCallback<[ReadOut](#readout)> | Yes | Callback invoked when data is read asynchronously from the stream. | -- Example +**Example** ```js let ss = fileio.createStreamSync(fpath, "r+"); ss.read(new ArrayBuffer(4096),{offset: 1, length: 5, position: 5},function (err, readOut) { @@ -2881,18 +2884,20 @@ Synchronously reads data from the stream. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters +**Parameters** + | Name | Type | Mandatory | Description | | ------- | ----------- | ---- | ---------------------------------------- | | buffer | ArrayBuffer | Yes | Buffer used to store the file read. | - | options | Object | No | The options are as follows:
- **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**.
- **length** (number): length of the data to read. The default value is the buffer length minus the offset.
- **position** (number): position of the data to read in the file. By default, data is read from the current position.
-  The sum of **offset** and **length** must be less than or equal to the buffer size. | + | options | Object | No | The options are as follows:
- **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**.
- **length** (number): length of the data to read. The default value is the buffer length minus the offset.
- **position** (number): position of the data to read in the file. By default, data is read from the current position.
Constraints: offset + length <= Buffer size | + +**Return value** -- Return value | Type | Description | | ------ | -------- | | number | Length of the data read.| -- Example +**Example** ```js let ss = fileio.createStreamSync(fpath, "r+"); let num = ss.readSync(new ArrayBuffer(4096), {offset: 1, length: 5, position: 5}); @@ -2908,16 +2913,16 @@ Manages directories. Before calling a method of the **Dir** class, use the [open read(): Promise<Dirent> -Asynchronously reads the next directory entry. This method uses a promise to return the result. +Asynchronously reads the next directory entry. This API uses a promise to return the result. **System capability**: SystemCapability.FileManagement.File.FileIO -- Return value +**Return value** | Type | Description | | -------------------------------- | ------------- | | Promise<[Dirent](#dirent)> | Directory entry that is read asynchronously.| -- Example +**Example** ```js let dir = fileio.opendirSync(path); dir.read().then(function (dirent){ @@ -2932,16 +2937,16 @@ Asynchronously reads the next directory entry. This method uses a promise to ret read(callback: AsyncCallback<Dirent>): void -Asynchronously reads the next directory entry. This method uses a callback to return the result. +Asynchronously reads the next directory entry. This API uses a callback to return the result. **System capability**: SystemCapability.FileManagement.File.FileIO -- Parameters +**Parameters** | Name | Type | Mandatory | Description | | -------- | -------------------------------------- | ---- | ---------------- | | callback | AsyncCallback<[Dirent](#dirent)> | Yes | Callback invoked when the next directory entry is asynchronously read.| -- Example +**Example** ```js let dir = fileio.opendirSync(path); dir.read(function (err, dirent) { @@ -2961,12 +2966,12 @@ Synchronously reads the next directory entry. **System capability**: SystemCapability.FileManagement.File.FileIO -- Return value +**Return value** | Type | Description | | ----------------- | -------- | | [Dirent](#dirent) | Directory entry read.| -- Example +**Example** ```js let dir = fileio.opendirSync(path); let dirent = dir.readSync(); @@ -2981,7 +2986,7 @@ Closes a directory. After a directory is closed, the file descriptor in Dir will **System capability**: SystemCapability.FileManagement.File.FileIO -- Example +**Example** ```js let dir = fileio.opendirSync(path); dir.closeSync(); @@ -3009,12 +3014,12 @@ Checks whether the current directory entry is a block special file. A block spec **System capability**: SystemCapability.FileManagement.File.FileIO -- Return value +**Return value** | Type | Description | | ------- | ---------------- | | boolean | Whether the directory entry is a block special file.| -- Example +**Example** ```js let dir = fileio.opendirSync(path); let isBLockDevice = dir.readSync().isBlockDevice(); @@ -3029,12 +3034,12 @@ Checks whether a directory entry is a character special file. A character specia **System capability**: SystemCapability.FileManagement.File.FileIO -- Return value +**Return value** | Type | Description | | ------- | ----------------- | | boolean | Whether the directory entry is a character special file.| -- Example +**Example** ```js let dir = fileio.opendirSync(path); let isCharacterDevice = dir.readSync().isCharacterDevice(); @@ -3049,12 +3054,12 @@ Checks whether a directory entry is a directory. **System capability**: SystemCapability.FileManagement.File.FileIO -- Return value +**Return value** | Type | Description | | ------- | ------------- | | boolean | Whether the directory entry is a directory.| -- Example +**Example** ```js let dir = fileio.opendirSync(path); let isDirectory = dir.readSync().isDirectory(); @@ -3069,12 +3074,12 @@ Checks whether the current directory entry is a named pipe (or FIFO). Named pipe **System capability**: SystemCapability.FileManagement.File.FileIO -- Return value +**Return value** | Type | Description | | ------- | --------------- | | boolean | Whether the directory entry is a FIFO.| -- Example +**Example** ```js let dir = fileio.opendirSync(path); let isFIFO = dir.readSync().isFIFO(); @@ -3089,12 +3094,12 @@ Checks whether a directory entry is a regular file. **System capability**: SystemCapability.FileManagement.File.FileIO -- Return value +**Return value** | Type | Description | | ------- | --------------- | | boolean | Whether the directory entry is a regular file.| -- Example +**Example** ```js let dir = fileio.opendirSync(path); let isFile = dir.readSync().isFile(); @@ -3109,12 +3114,12 @@ Checks whether a directory entry is a socket. **System capability**: SystemCapability.FileManagement.File.FileIO -- Return value +**Return value** | Type | Description | | ------- | -------------- | | boolean | Whether the directory entry is a socket.| -- Example +**Example** ```js let dir = fileio.opendirSync(dpath); let isSocket = dir.readSync().isSocket(); @@ -3129,12 +3134,12 @@ Checks whether a directory entry is a symbolic link. **System capability**: SystemCapability.FileManagement.File.FileIO -- Return value +**Return value** | Type | Description | | ------- | --------------- | | boolean | Whether the directory entry is a symbolic link.| -- Example +**Example** ```js let dir = fileio.opendirSync(path); let isSymbolicLink = dir.readSync().isSymbolicLink(); -- GitLab