提交 36836e10 编写于 作者: A Annie_wang

update docs

Signed-off-by: NAnnie_wang <annie.wangli@huawei.com>
上级 de8dd534
File Management # File Management
The fileio module provides APIs for file storage and management, including basic file management, directory management, file information statistics, and stream read and write.
> **NOTE**<br> > **NOTE**<br>
> The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version. > 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.
Provides file storage and management capabilities, including basic file management, file directory management, file information statistics, and stream read and write.
## Modules to Import ## Modules to Import
...@@ -46,6 +47,7 @@ Obtains file information. This API uses a promise to return the result. ...@@ -46,6 +47,7 @@ Obtains file information. This API uses a promise to return the result.
| Promise&lt;[Stat](#stat)&gt; | Promise used to return the file information obtained.| | Promise&lt;[Stat](#stat)&gt; | Promise used to return the file information obtained.|
**Example** **Example**
```js ```js
fileio.stat(path).then(function(stat){ fileio.stat(path).then(function(stat){
console.info("Got file info:"+ JSON.stringify(stat)); console.info("Got file info:"+ JSON.stringify(stat));
...@@ -64,12 +66,14 @@ Obtains file information. This API uses an asynchronous callback to return the r ...@@ -64,12 +66,14 @@ Obtains file information. This API uses an asynchronous callback to return the r
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ---------------------------------- | ---- | ------------------------------ | | -------- | ---------------------------------- | ---- | ------------------------------ |
| path | string | Yes | Application sandbox path of the file. | | path | string | Yes | Application sandbox path of the file. |
| callback | AsyncCallback&lt;[Stat](#stat)&gt; | Yes | Callback invoked to return the file information obtained.| | callback | AsyncCallback&lt;[Stat](#stat)&gt; | Yes | Callback invoked to return the file information obtained.|
**Example** **Example**
```js ```js
fileio.stat(path, function (err, stat) { fileio.stat(path, function (err, stat) {
// Example code in Stat // Example code in Stat
...@@ -86,17 +90,20 @@ Synchronously obtains file information. ...@@ -86,17 +90,20 @@ Synchronously obtains file information.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------ | ---- | -------------------------- | | ------ | ------ | ---- | -------------------------- |
| path | string | Yes | Application sandbox path of the file.| | path | string | Yes | Application sandbox path of the file.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------- | ---------- | | ------------- | ---------- |
| [Stat](#stat) | File information obtained.| | [Stat](#stat) | File information obtained.|
**Example** **Example**
```js ```js
let stat = fileio.statSync(path); let stat = fileio.statSync(path);
// Example code in Stat // Example code in Stat
...@@ -112,16 +119,19 @@ Opens a file directory. This API uses a promise to return the result. ...@@ -112,16 +119,19 @@ Opens a file directory. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------------ | | ------ | ------ | ---- | ------------------------------ |
| path | string | Yes | Application sandbox path of the directory to open.| | path | string | Yes | Application sandbox path of the directory to open.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| -------------------------- | -------- | | -------------------------- | -------- |
| Promise&lt;[Dir](#dir)&gt; | Promise used to return the **Dir** object.| | Promise&lt;[Dir](#dir)&gt; | Promise used to return the **Dir** object.|
**Example** **Example**
```js ```js
fileio.opendir(path).then(function(dir){ fileio.opendir(path).then(function(dir){
console.info("Directory opened:"+ JSON.stringify(dir)); console.info("Directory opened:"+ JSON.stringify(dir));
...@@ -147,6 +157,7 @@ Opens a file directory. This API uses an asynchronous callback to return the res ...@@ -147,6 +157,7 @@ Opens a file directory. This API uses an asynchronous callback to return the res
| callback | AsyncCallback&lt;[Dir](#dir)&gt; | Yes | Callback invoked when the directory is open asynchronously. | | callback | AsyncCallback&lt;[Dir](#dir)&gt; | Yes | Callback invoked when the directory is open asynchronously. |
**Example** **Example**
```js ```js
fileio.opendir(path, function (err, dir) { fileio.opendir(path, function (err, dir) {
// Example code in Dir struct // Example code in Dir struct
...@@ -171,11 +182,13 @@ Synchronously opens a directory. ...@@ -171,11 +182,13 @@ Synchronously opens a directory.
| path | string | Yes | Application sandbox path of the directory to open.| | path | string | Yes | Application sandbox path of the directory to open.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ----------- | -------- | | ----------- | -------- |
| [Dir](#dir) | A **Dir** instance corresponding to the directory.| | [Dir](#dir) | A **Dir** instance corresponding to the directory.|
**Example** **Example**
```js ```js
let dir = fileio.opendirSync(path); let dir = fileio.opendirSync(path);
// Example code in Dir struct // Example code in Dir struct
...@@ -199,11 +212,13 @@ Checks whether the current process can access a file. This API uses a promise to ...@@ -199,11 +212,13 @@ Checks whether the current process can access a file. This API uses a promise to
| mode | number | No | Options for accessing the file. You can specify multiple options, separated with a bitwise OR operator (&#124;). The default value is **0**.<br>The options are as follows:<br>-&nbsp;**0**: check whether the file exists.<br>-&nbsp;**1**: check whether the current process has the execute permission on the file.<br>-&nbsp;**2**: check whether the current process has the write permission on the file.<br>-&nbsp;**4**: check whether the current process has the read permission on the file.| | mode | number | No | Options for accessing the file. You can specify multiple options, separated with a bitwise OR operator (&#124;). The default value is **0**.<br>The options are as follows:<br>-&nbsp;**0**: check whether the file exists.<br>-&nbsp;**1**: check whether the current process has the execute permission on the file.<br>-&nbsp;**2**: check whether the current process has the write permission on the file.<br>-&nbsp;**4**: check whether the current process has the read permission on the file.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
```js ```js
fileio.access(path).then(function() { fileio.access(path).then(function() {
console.info("Access successful"); console.info("Access successful");
...@@ -222,6 +237,7 @@ Checks whether the current process can access a file. This API uses an asynchron ...@@ -222,6 +237,7 @@ Checks whether the current process can access a file. This API uses an asynchron
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ------------------------------------------------------------ | | -------- | ------------------------- | ---- | ------------------------------------------------------------ |
| path | string | Yes | Application sandbox path of the file. | | path | string | Yes | Application sandbox path of the file. |
...@@ -229,6 +245,7 @@ Checks whether the current process can access a file. This API uses an asynchron ...@@ -229,6 +245,7 @@ Checks whether the current process can access a file. This API uses an asynchron
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file is asynchronously checked. | | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file is asynchronously checked. |
**Example** **Example**
```js ```js
fileio.access(path, function (err) { fileio.access(path, function (err) {
// Do something. // Do something.
...@@ -245,12 +262,14 @@ Synchronously checks whether the current process can access the specified file. ...@@ -245,12 +262,14 @@ Synchronously checks whether the current process can access the specified file.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------------------------------------------ | | ------ | ------ | ---- | ------------------------------------------------------------ |
| path | string | Yes | Application sandbox path of the file. | | path | string | Yes | Application sandbox path of the file. |
| mode | number | No | Options for accessing the file. You can specify multiple options, separated with a bitwise OR operator (&#124;). The default value is **0**.<br>The options are as follows:<br>-&nbsp;**0**: check whether the file exists.<br>-&nbsp;**1**: check whether the current process has the execute permission on the file.<br>-&nbsp;**2**: check whether the current process has the write permission on the file.<br>-&nbsp;**4**: check whether the current process has the read permission on the file.| | mode | number | No | Options for accessing the file. You can specify multiple options, separated with a bitwise OR operator (&#124;). The default value is **0**.<br>The options are as follows:<br>-&nbsp;**0**: check whether the file exists.<br>-&nbsp;**1**: check whether the current process has the execute permission on the file.<br>-&nbsp;**2**: check whether the current process has the write permission on the file.<br>-&nbsp;**4**: check whether the current process has the read permission on the file.|
**Example** **Example**
```js ```js
try { try {
fileio.accessSync(path); fileio.accessSync(path);
...@@ -269,16 +288,19 @@ Closes a file. This API uses a promise to return the result. ...@@ -269,16 +288,19 @@ Closes a file. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ------------ | | ---- | ------ | ---- | ------------ |
| fd | number | Yes | File descriptor of the file to close.| | fd | number | Yes | File descriptor of the file to close.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
```js ```js
let fd = fileio.openSync(path); let fd = fileio.openSync(path);
fileio.close(fd).then(function(){ fileio.close(fd).then(function(){
...@@ -298,12 +320,14 @@ Closes a file. This API uses an asynchronous callback to return the result. ...@@ -298,12 +320,14 @@ Closes a file. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | ------------ | | -------- | ------------------------- | ---- | ------------ |
| fd | number | Yes | File descriptor of the file to close.| | fd | number | Yes | File descriptor of the file to close.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file is closed asynchronously.| | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file is closed asynchronously.|
**Example** **Example**
```js ```js
let fd = fileio.openSync(path); let fd = fileio.openSync(path);
fileio.close(fd, function (err) { fileio.close(fd, function (err) {
...@@ -321,11 +345,13 @@ Synchronously closes a file. ...@@ -321,11 +345,13 @@ Synchronously closes a file.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ------------ | | ---- | ------ | ---- | ------------ |
| fd | number | Yes | File descriptor of the file to close.| | fd | number | Yes | File descriptor of the file to close.|
**Example** **Example**
```js ```js
fileio.closeSync(fd); fileio.closeSync(fd);
``` ```
...@@ -340,11 +366,13 @@ Closes the stream. This API uses a promise to return the result. ...@@ -340,11 +366,13 @@ Closes the stream. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
```js ```js
fileio.close().then(function(){ fileio.close().then(function(){
console.info("File stream closed"); console.info("File stream closed");
...@@ -363,11 +391,13 @@ Closes the stream. This API uses an asynchronous callback to return the result. ...@@ -363,11 +391,13 @@ Closes the stream. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | ------------- | | -------- | ------------------------- | ---- | ------------- |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the stream is closed asynchronously.| | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the stream is closed asynchronously.|
**Example** **Example**
```js ```js
fileio.close(function(err){ fileio.close(function(err){
// Do something. // Do something.
...@@ -384,6 +414,7 @@ Copies a file. This API uses a promise to return the result. ...@@ -384,6 +414,7 @@ Copies a file. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | -------------------------- | ---- | ---------------------------------------- | | ---- | -------------------------- | ---- | ---------------------------------------- |
| src | string&nbsp;\|&nbsp;number | Yes | Path or file descriptor of the file to copy. | | src | string&nbsp;\|&nbsp;number | Yes | Path or file descriptor of the file to copy. |
...@@ -391,11 +422,13 @@ Copies a file. This API uses a promise to return the result. ...@@ -391,11 +422,13 @@ Copies a file. This API uses a promise to return the result.
| mode | number | No | Option for overwriting the file of the same name in the destination path. The default value is **0**, which is the only value supported.<br>**0**: Completely overwrite the file with the same name and truncate the part that is not overwritten.| | mode | number | No | Option for overwriting the file of the same name in the destination path. The default value is **0**, which is the only value supported.<br>**0**: Completely overwrite the file with the same name and truncate the part that is not overwritten.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
```js ```js
fileio.copyFile(src, dest).then(function(){ fileio.copyFile(src, dest).then(function(){
console.info("File copied"); console.info("File copied");
...@@ -414,6 +447,7 @@ Copies a file. This API uses an asynchronous callback to return the result. ...@@ -414,6 +447,7 @@ Copies a file. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | -------------------------- | ---- | ---------------------------------------- | | -------- | -------------------------- | ---- | ---------------------------------------- |
| src | string&nbsp;\|&nbsp;number | Yes | Path or file descriptor of the file to copy. | | src | string&nbsp;\|&nbsp;number | Yes | Path or file descriptor of the file to copy. |
...@@ -422,6 +456,7 @@ Copies a file. This API uses an asynchronous callback to return the result. ...@@ -422,6 +456,7 @@ Copies a file. This API uses an asynchronous callback to return the result.
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file is copied asynchronously. | | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file is copied asynchronously. |
**Example** **Example**
```js ```js
fileio.copyFile(src, dest, function (err) { fileio.copyFile(src, dest, function (err) {
// Do something. // Do something.
...@@ -438,6 +473,7 @@ Synchronously copies a file. ...@@ -438,6 +473,7 @@ Synchronously copies a file.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | -------------------------- | ---- | ---------------------------------------- | | ---- | -------------------------- | ---- | ---------------------------------------- |
| src | string&nbsp;\|&nbsp;number | Yes | Path or file descriptor of the file to copy. | | src | string&nbsp;\|&nbsp;number | Yes | Path or file descriptor of the file to copy. |
...@@ -445,6 +481,7 @@ Synchronously copies a file. ...@@ -445,6 +481,7 @@ Synchronously copies a file.
| mode | number | No | Option for overwriting the file of the same name in the destination path. The default value is **0**, which is the only value supported.<br>**0**: Completely overwrite the file with the same name and truncate the part that is not overwritten.| | mode | number | No | Option for overwriting the file of the same name in the destination path. The default value is **0**, which is the only value supported.<br>**0**: Completely overwrite the file with the same name and truncate the part that is not overwritten.|
**Example** **Example**
```js ```js
fileio.copyFileSync(src, dest); fileio.copyFileSync(src, dest);
``` ```
...@@ -459,17 +496,20 @@ Creates a directory. This API uses a promise to return the result. ...@@ -459,17 +496,20 @@ Creates a directory. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------------------------------------------ | | ------ | ------ | ---- | ------------------------------------------------------------ |
| path | string | Yes | Application sandbox path of the directory. | | path | string | Yes | Application sandbox path of the directory. |
| mode | number | No | Permission on the directory to create. You can specify multiple permissions, separated using a bitwise OR operator (&#124;). The default value is **0o775**.<br>-&nbsp;**0o775**: The owner has the read, write, and execute permissions, and other users have the read and execute permissions.<br>-&nbsp;**0o700**: The owner has the read, write, and execute permissions.<br>- &nbsp;**0o400**: The owner has the read permission.<br>-&nbsp;**0o200**: The owner has the write permission.<br>-&nbsp;**0o100**: The owner has the execute permission.<br>-&nbsp;**0o070**: The user group has the read, write, and execute permissions.<br>-&nbsp;**0o040**: The user group has the read permission.<br>-&nbsp;**0o020**: The user group has the write permission.<br>-&nbsp;**0o010**: The user group has the execute permission.<br>-&nbsp;**0o007**: Other users have the read, write, and execute permissions.<br>-&nbsp;**0o004**: Other users have the read permission.<br>-&nbsp;**0o002**: Other users have the write permission.<br>-&nbsp;**0o001**: Other users have the execute permission.| | mode | number | No | Permission on the directory to create. You can specify multiple permissions, separated using a bitwise OR operator (&#124;). The default value is **0o775**.<br>-&nbsp;**0o775**: The owner has the read, write, and execute permissions, and other users have the read and execute permissions.<br>-&nbsp;**0o700**: The owner has the read, write, and execute permissions.<br>- &nbsp;**0o400**: The owner has the read permission.<br>-&nbsp;**0o200**: The owner has the write permission.<br>-&nbsp;**0o100**: The owner has the execute permission.<br>-&nbsp;**0o070**: The user group has the read, write, and execute permissions.<br>-&nbsp;**0o040**: The user group has the read permission.<br>-&nbsp;**0o020**: The user group has the write permission.<br>-&nbsp;**0o010**: The user group has the execute permission.<br>-&nbsp;**0o007**: Other users have the read, write, and execute permissions.<br>-&nbsp;**0o004**: Other users have the read permission.<br>-&nbsp;**0o002**: Other users have the write permission.<br>-&nbsp;**0o001**: Other users have the execute permission.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
```js ```js
fileio.mkdir(path).then(function() { fileio.mkdir(path).then(function() {
console.info("Directory created"); console.info("Directory created");
...@@ -488,6 +528,7 @@ Creates a directory. This API uses an asynchronous callback to return the result ...@@ -488,6 +528,7 @@ Creates a directory. This API uses an asynchronous callback to return the result
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ------------------------------------------------------------ | | -------- | ------------------------- | ---- | ------------------------------------------------------------ |
| path | string | Yes | Application sandbox path of the directory. | | path | string | Yes | Application sandbox path of the directory. |
...@@ -495,6 +536,7 @@ Creates a directory. This API uses an asynchronous callback to return the result ...@@ -495,6 +536,7 @@ Creates a directory. This API uses an asynchronous callback to return the result
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the directory is created asynchronously. | | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the directory is created asynchronously. |
**Example** **Example**
```js ```js
fileio.mkdir(path, function(err) { fileio.mkdir(path, function(err) {
console.info("Directory created"); console.info("Directory created");
...@@ -511,12 +553,14 @@ Synchronously creates a directory. ...@@ -511,12 +553,14 @@ Synchronously creates a directory.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------------------------------------------ | | ------ | ------ | ---- | ------------------------------------------------------------ |
| path | string | Yes | Application sandbox path of the directory. | | path | string | Yes | Application sandbox path of the directory. |
| mode | number | No | Permission on the directory to create. You can specify multiple permissions, separated using a bitwise OR operator (&#124;). The default value is **0o775**.<br>-&nbsp;**0o775**: The owner has the read, write, and execute permissions, and other users have the read and execute permissions.<br>-&nbsp;**0o700**: The owner has the read, write, and execute permissions.<br>- &nbsp;**0o400**: The owner has the read permission.<br>-&nbsp;**0o200**: The owner has the write permission.<br>-&nbsp;**0o100**: The owner has the execute permission.<br>-&nbsp;**0o070**: The user group has the read, write, and execute permissions.<br>-&nbsp;**0o040**: The user group has the read permission.<br>-&nbsp;**0o020**: The user group has the write permission.<br>-&nbsp;**0o010**: The user group has the execute permission.<br>-&nbsp;**0o007**: Other users have the read, write, and execute permissions.<br>-&nbsp;**0o004**: Other users have the read permission.<br>-&nbsp;**0o002**: Other users have the write permission.<br>-&nbsp;**0o001**: Other users have the execute permission.| | mode | number | No | Permission on the directory to create. You can specify multiple permissions, separated using a bitwise OR operator (&#124;). The default value is **0o775**.<br>-&nbsp;**0o775**: The owner has the read, write, and execute permissions, and other users have the read and execute permissions.<br>-&nbsp;**0o700**: The owner has the read, write, and execute permissions.<br>- &nbsp;**0o400**: The owner has the read permission.<br>-&nbsp;**0o200**: The owner has the write permission.<br>-&nbsp;**0o100**: The owner has the execute permission.<br>-&nbsp;**0o070**: The user group has the read, write, and execute permissions.<br>-&nbsp;**0o040**: The user group has the read permission.<br>-&nbsp;**0o020**: The user group has the write permission.<br>-&nbsp;**0o010**: The user group has the execute permission.<br>-&nbsp;**0o007**: Other users have the read, write, and execute permissions.<br>-&nbsp;**0o004**: Other users have the read permission.<br>-&nbsp;**0o002**: Other users have the write permission.<br>-&nbsp;**0o001**: Other users have the execute permission.|
**Example** **Example**
```js ```js
fileio.mkdirSync(path); fileio.mkdirSync(path);
``` ```
...@@ -531,6 +575,7 @@ Opens a file. This API uses a promise to return the result. ...@@ -531,6 +575,7 @@ Opens a file. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------------------------------------------ | | ------ | ------ | ---- | ------------------------------------------------------------ |
| path | string | Yes | Application sandbox path of the file. | | path | string | Yes | Application sandbox path of the file. |
...@@ -538,11 +583,13 @@ Opens a file. This API uses a promise to return the result. ...@@ -538,11 +583,13 @@ Opens a file. This API uses a promise to return the result.
| mode | number | No | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (&#124;). The default value is **0o666**.<br>-&nbsp;**0o666**: The owner, user group, and other users have the read and write permissions on the file.<br>-&nbsp;**0o700**: The owner has the read, write, and execute permissions.<br>- &nbsp;**0o400**: The owner has the read permission.<br>-&nbsp;**0o200**: The owner has the write permission.<br>-&nbsp;**0o100**: The owner has the execute permission.<br>-&nbsp;**0o070**: The user group has the read, write, and execute permissions.<br>-&nbsp;**0o040**: The user group has the read permission.<br>-&nbsp;**0o020**: The user group has the write permission.<br>-&nbsp;**0o010**: The user group has the execute permission.<br>-&nbsp;**0o007**: Other users have the read, write, and execute permissions.<br>-&nbsp;**0o004**: Other users have the read permission.<br>-&nbsp;**0o002**: Other users have the write permission.<br>-&nbsp;**0o001**: Other users have the execute permission.| | mode | number | No | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (&#124;). The default value is **0o666**.<br>-&nbsp;**0o666**: The owner, user group, and other users have the read and write permissions on the file.<br>-&nbsp;**0o700**: The owner has the read, write, and execute permissions.<br>- &nbsp;**0o400**: The owner has the read permission.<br>-&nbsp;**0o200**: The owner has the write permission.<br>-&nbsp;**0o100**: The owner has the execute permission.<br>-&nbsp;**0o070**: The user group has the read, write, and execute permissions.<br>-&nbsp;**0o040**: The user group has the read permission.<br>-&nbsp;**0o020**: The user group has the write permission.<br>-&nbsp;**0o010**: The user group has the execute permission.<br>-&nbsp;**0o007**: Other users have the read, write, and execute permissions.<br>-&nbsp;**0o004**: Other users have the read permission.<br>-&nbsp;**0o002**: Other users have the write permission.<br>-&nbsp;**0o001**: Other users have the execute permission.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| --------------------- | ----------- | | --------------------- | ----------- |
| Promise&lt;number&gt; | Promise used to return the file descriptor of the file opened.| | Promise&lt;number&gt; | Promise used to return the file descriptor of the file opened.|
**Example** **Example**
```js ```js
fileio.open(path, 0o1, 0o0200).then(function(number){ fileio.open(path, 0o1, 0o0200).then(function(number){
console.info("File opened"); console.info("File opened");
...@@ -561,6 +608,7 @@ Opens a file. This API uses an asynchronous callback to return the result. ...@@ -561,6 +608,7 @@ Opens a file. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------------- | ---- | ------------------------------------------------------------ | | -------- | ------------------------------- | ---- | ------------------------------------------------------------ |
| path | string | Yes | Application sandbox path of the file. | | path | string | Yes | Application sandbox path of the file. |
...@@ -569,6 +617,7 @@ Opens a file. This API uses an asynchronous callback to return the result. ...@@ -569,6 +617,7 @@ Opens a file. This API uses an asynchronous callback to return the result.
| callback | AsyncCallback&nbsp;&lt;void&gt; | Yes | Callback invoked when the file is open asynchronously. | | callback | AsyncCallback&nbsp;&lt;void&gt; | Yes | Callback invoked when the file is open asynchronously. |
**Example** **Example**
```js ```js
fileio.open(path, 0, function(err, fd) { fileio.open(path, 0, function(err, fd) {
// Do something. // Do something.
...@@ -585,6 +634,7 @@ Synchronously opens a file. ...@@ -585,6 +634,7 @@ Synchronously opens a file.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------------------------------------------ | | ------ | ------ | ---- | ------------------------------------------------------------ |
| path | string | Yes | Application sandbox path of the file. | | path | string | Yes | Application sandbox path of the file. |
...@@ -592,11 +642,13 @@ Synchronously opens a file. ...@@ -592,11 +642,13 @@ Synchronously opens a file.
| mode | number | No | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (&#124;). The default value is **0o666**.<br>-&nbsp;**0o666**: The owner, user group, and other users have the read and write permissions on the file.<br>-&nbsp;**0o640**: The owner has the read and write permissions, and the user group has the read permission.<br>-&nbsp;**0o700**: The owner has the read, write, and execute permissions.<br>- &nbsp;**0o400**: The owner has the read permission.<br>-&nbsp;**0o200**: The owner has the write permission.<br>-&nbsp;**0o100**: The owner has the execute permission.<br>-&nbsp;**0o070**: The user group has the read, write, and execute permissions.<br>-&nbsp;**0o040**: The user group has the read permission.<br>-&nbsp;**0o020**: The user group has the write permission.<br>-&nbsp;**0o010**: The user group has the execute permission.<br>-&nbsp;**0o007**: Other users have the read, write, and execute permissions.<br>-&nbsp;**0o004**: Other users have the read permission.<br>-&nbsp;**0o002**: Other users have the write permission.<br>-&nbsp;**0o001**: Other users have the execute permission.<br>The file permissions on newly created files are affected by umask, which is set as the process starts. Currently, the modification of umask is not open.| | mode | number | No | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (&#124;). The default value is **0o666**.<br>-&nbsp;**0o666**: The owner, user group, and other users have the read and write permissions on the file.<br>-&nbsp;**0o640**: The owner has the read and write permissions, and the user group has the read permission.<br>-&nbsp;**0o700**: The owner has the read, write, and execute permissions.<br>- &nbsp;**0o400**: The owner has the read permission.<br>-&nbsp;**0o200**: The owner has the write permission.<br>-&nbsp;**0o100**: The owner has the execute permission.<br>-&nbsp;**0o070**: The user group has the read, write, and execute permissions.<br>-&nbsp;**0o040**: The user group has the read permission.<br>-&nbsp;**0o020**: The user group has the write permission.<br>-&nbsp;**0o010**: The user group has the execute permission.<br>-&nbsp;**0o007**: Other users have the read, write, and execute permissions.<br>-&nbsp;**0o004**: Other users have the read permission.<br>-&nbsp;**0o002**: Other users have the write permission.<br>-&nbsp;**0o001**: Other users have the execute permission.<br>The file permissions on newly created files are affected by umask, which is set as the process starts. Currently, the modification of umask is not open.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------ | ----------- | | ------ | ----------- |
| number | File descriptor of the file opened.| | number | File descriptor of the file opened.|
**Example** **Example**
```js ```js
let fd = fileio.openSync(path, 0o102, 0o640); let fd = fileio.openSync(path, 0o102, 0o640);
``` ```
...@@ -623,6 +675,7 @@ Reads data from a file. This API uses a promise to return the result. ...@@ -623,6 +675,7 @@ Reads data from a file. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ------- | ----------- | ---- | ------------------------------------------------------------ | | ------- | ----------- | ---- | ------------------------------------------------------------ |
| fd | number | Yes | File descriptor of the file to read. | | fd | number | Yes | File descriptor of the file to read. |
...@@ -636,6 +689,7 @@ Reads data from a file. This API uses a promise to return the result. ...@@ -636,6 +689,7 @@ Reads data from a file. This API uses a promise to return the result.
| Promise&lt;[ReadOut](#readout)&gt; | Promise used to return the data read.| | Promise&lt;[ReadOut](#readout)&gt; | Promise used to return the data read.|
**Example** **Example**
```js ```js
let fd = fileio.openSync(path, 0o2); let fd = fileio.openSync(path, 0o2);
let buf = new ArrayBuffer(4096); let buf = new ArrayBuffer(4096);
...@@ -661,6 +715,7 @@ Reads data from a file. This API uses an asynchronous callback to return the res ...@@ -661,6 +715,7 @@ Reads data from a file. This API uses an asynchronous callback to return the res
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- | | -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| fd | number | Yes | File descriptor of the file to read. | | fd | number | Yes | File descriptor of the file to read. |
...@@ -669,6 +724,7 @@ Reads data from a file. This API uses an asynchronous callback to return the res ...@@ -669,6 +724,7 @@ Reads data from a file. This API uses an asynchronous callback to return the res
| callback | AsyncCallback&lt;[ReadOut](#readout)&gt; | Yes | Callback invoked when the data is read asynchronously. | | callback | AsyncCallback&lt;[ReadOut](#readout)&gt; | Yes | Callback invoked when the data is read asynchronously. |
**Example** **Example**
```js ```js
let fd = fileio.openSync(path, 0o2); let fd = fileio.openSync(path, 0o2);
let buf = new ArrayBuffer(4096); let buf = new ArrayBuffer(4096);
...@@ -694,6 +750,7 @@ Synchronously reads data from a file. ...@@ -694,6 +750,7 @@ Synchronously reads data from a file.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------- | ----------- | ---- | ---------------------------------------- | | ------- | ----------- | ---- | ---------------------------------------- |
| fd | number | Yes | File descriptor of the file to read. | | fd | number | Yes | File descriptor of the file to read. |
...@@ -701,11 +758,13 @@ Synchronously reads data from a file. ...@@ -701,11 +758,13 @@ Synchronously reads data from a file.
| options | Object | No | The options are as follows:<br>-&nbsp;**offset** (number): position to store the data read in the buffer in reference to the start address of the buffer. The default value is **0**.<br>-&nbsp;**length** (number): length of the data to read. The default value is the buffer length minus the offset.<br>-&nbsp;**position** (number): position of the data to read in the file. By default, data is read from the current position.<br>Constraints: offset + length <= Buffer size | | options | Object | No | The options are as follows:<br>-&nbsp;**offset** (number): position to store the data read in the buffer in reference to the start address of the buffer. The default value is **0**.<br>-&nbsp;**length** (number): length of the data to read. The default value is the buffer length minus the offset.<br>-&nbsp;**position** (number): position of the data to read in the file. By default, data is read from the current position.<br>Constraints: offset + length <= Buffer size |
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------ | -------- | | ------ | -------- |
| number | Length of the data read.| | number | Length of the data read.|
**Example** **Example**
```js ```js
let fd = fileio.openSync(path, 0o2); let fd = fileio.openSync(path, 0o2);
let buf = new ArrayBuffer(4096); let buf = new ArrayBuffer(4096);
...@@ -722,16 +781,19 @@ Deletes a directory. This API uses a promise to return the result. ...@@ -722,16 +781,19 @@ Deletes a directory. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------ | ---- | -------------------------- | | ------ | ------ | ---- | -------------------------- |
| path | string | Yes | Application sandbox path of the directory.| | path | string | Yes | Application sandbox path of the directory.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
```js ```js
fileio.rmdir(path).then(function() { fileio.rmdir(path).then(function() {
console.info("Directory deleted"); console.info("Directory deleted");
...@@ -750,12 +812,14 @@ Deletes a directory. This API uses an asynchronous callback to return the result ...@@ -750,12 +812,14 @@ Deletes a directory. This API uses an asynchronous callback to return the result
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | -------------------------- | | -------- | ------------------------- | ---- | -------------------------- |
| path | string | Yes | Application sandbox path of the directory.| | path | string | Yes | Application sandbox path of the directory.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the directory is deleted asynchronously. | | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the directory is deleted asynchronously. |
**Example** **Example**
```js ```js
fileio.rmdir(path, function(err){ fileio.rmdir(path, function(err){
// Do something. // Do something.
...@@ -773,11 +837,13 @@ Synchronously deletes a directory. ...@@ -773,11 +837,13 @@ Synchronously deletes a directory.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------ | ---- | -------------------------- | | ------ | ------ | ---- | -------------------------- |
| path | string | Yes | Application sandbox path of the directory.| | path | string | Yes | Application sandbox path of the directory.|
**Example** **Example**
```js ```js
fileio.rmdirSync(path); fileio.rmdirSync(path);
``` ```
...@@ -792,16 +858,19 @@ Deletes a file. This API uses a promise to return the result. ...@@ -792,16 +858,19 @@ Deletes a file. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------ | ---- | -------------------------- | | ------ | ------ | ---- | -------------------------- |
| path | string | Yes | Application sandbox path of the file.| | path | string | Yes | Application sandbox path of the file.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
```js ```js
fileio.unlink(path).then(function(){ fileio.unlink(path).then(function(){
console.info("File deleted"); console.info("File deleted");
...@@ -820,12 +889,14 @@ Deletes a file. This API uses an asynchronous callback to return the result. ...@@ -820,12 +889,14 @@ Deletes a file. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | -------------------------- | | -------- | ------------------------- | ---- | -------------------------- |
| path | string | Yes | Application sandbox path of the file.| | path | string | Yes | Application sandbox path of the file.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file is deleted asynchronously. | | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file is deleted asynchronously. |
**Example** **Example**
```js ```js
fileio.unlink(path, function(err) { fileio.unlink(path, function(err) {
console.info("File deleted"); console.info("File deleted");
...@@ -842,11 +913,13 @@ Synchronously deletes a file. ...@@ -842,11 +913,13 @@ Synchronously deletes a file.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------ | ---- | -------------------------- | | ------ | ------ | ---- | -------------------------- |
| path | string | Yes | Application sandbox path of the file.| | path | string | Yes | Application sandbox path of the file.|
**Example** **Example**
```js ```js
fileio.unlinkSync(path); fileio.unlinkSync(path);
``` ```
...@@ -866,6 +939,7 @@ Writes data into a file. This API uses a promise to return the result. ...@@ -866,6 +939,7 @@ Writes data into a file. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------- | ------------------------------- | ---- | ---------------------------------------- | | ------- | ------------------------------- | ---- | ---------------------------------------- |
| fd | number | Yes | File descriptor of the file to write. | | fd | number | Yes | File descriptor of the file to write. |
...@@ -873,11 +947,13 @@ Writes data into a file. This API uses a promise to return the result. ...@@ -873,11 +947,13 @@ Writes data into a file. This API uses a promise to return the result.
| options | Object | No | The options are as follows:<br>-&nbsp;**offset** (number): position of the data to write in reference to the start address of the data. The default value is **0**.<br>-&nbsp;**length** (number): length of the data to write. The default value is the buffer length minus the offset.<br>-&nbsp;**position** (number): start position to write the data in the file. By default, data is written from the current position.<br>-&nbsp;**encoding** (string): format of the string to be encoded. The default value is **utf-8**, which is the only value supported.<br>Constraints: offset + length <= Buffer size| | options | Object | No | The options are as follows:<br>-&nbsp;**offset** (number): position of the data to write in reference to the start address of the data. The default value is **0**.<br>-&nbsp;**length** (number): length of the data to write. The default value is the buffer length minus the offset.<br>-&nbsp;**position** (number): start position to write the data in the file. By default, data is written from the current position.<br>-&nbsp;**encoding** (string): format of the string to be encoded. The default value is **utf-8**, which is the only value supported.<br>Constraints: offset + length <= Buffer size|
**Return value** **Return value**
| Type | Description | | Type | Description |
| --------------------- | -------- | | --------------------- | -------- |
| Promise&lt;number&gt; | Promise used to return the length of the data written.| | Promise&lt;number&gt; | Promise used to return the length of the data written.|
**Example** **Example**
```js ```js
let fd = fileio.openSync(path, 0o100 | 0o2, 0o666); let fd = fileio.openSync(path, 0o100 | 0o2, 0o666);
fileio.write(fd, "hello, world").then(function(number){ fileio.write(fd, "hello, world").then(function(number){
...@@ -902,6 +978,7 @@ Writes data into a file. This API uses an asynchronous callback to return the re ...@@ -902,6 +978,7 @@ Writes data into a file. This API uses an asynchronous callback to return the re
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ------------------------------- | ---- | ---------------------------------------- | | -------- | ------------------------------- | ---- | ---------------------------------------- |
| fd | number | Yes | File descriptor of the file to write. | | fd | number | Yes | File descriptor of the file to write. |
...@@ -910,6 +987,7 @@ Writes data into a file. This API uses an asynchronous callback to return the re ...@@ -910,6 +987,7 @@ Writes data into a file. This API uses an asynchronous callback to return the re
| callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked when the data is written asynchronously. | | callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked when the data is written asynchronously. |
**Example** **Example**
```js ```js
let fd = fileio.openSync(path, 0o100 | 0o2, 0o666); let fd = fileio.openSync(path, 0o100 | 0o2, 0o666);
fileio.write(fd, "hello, world", function (err, bytesWritten) { fileio.write(fd, "hello, world", function (err, bytesWritten) {
...@@ -934,6 +1012,7 @@ Synchronously writes data into a file. ...@@ -934,6 +1012,7 @@ Synchronously writes data into a file.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------- | ------------------------------- | ---- | ---------------------------------------- | | ------- | ------------------------------- | ---- | ---------------------------------------- |
| fd | number | Yes | File descriptor of the file to write. | | fd | number | Yes | File descriptor of the file to write. |
...@@ -941,11 +1020,13 @@ Synchronously writes data into a file. ...@@ -941,11 +1020,13 @@ Synchronously writes data into a file.
| options | Object | No | The options are as follows:<br>-&nbsp;**offset** (number): position of the data to write in reference to the start address of the data. The default value is **0**.<br>-&nbsp;**length** (number): length of the data to write. The default value is the buffer length minus the offset.<br>-&nbsp;**position** (number): start position to write the data in the file. By default, data is written from the current position.<br>-&nbsp;**encoding** (string): format of the string to be encoded. The default value is **utf-8**, which is the only value supported.<br>Constraints: offset + length <= Buffer size| | options | Object | No | The options are as follows:<br>-&nbsp;**offset** (number): position of the data to write in reference to the start address of the data. The default value is **0**.<br>-&nbsp;**length** (number): length of the data to write. The default value is the buffer length minus the offset.<br>-&nbsp;**position** (number): start position to write the data in the file. By default, data is written from the current position.<br>-&nbsp;**encoding** (string): format of the string to be encoded. The default value is **utf-8**, which is the only value supported.<br>Constraints: offset + length <= Buffer size|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------ | -------- | | ------ | -------- |
| number | Length of the data written in the file.| | number | Length of the data written in the file.|
**Example** **Example**
```js ```js
let fd = fileio.openSync(path, 0o100 | 0o2, 0o666); let fd = fileio.openSync(path, 0o100 | 0o2, 0o666);
let num = fileio.writeSync(fd, "hello, world"); let num = fileio.writeSync(fd, "hello, world");
...@@ -961,17 +1042,20 @@ Calculates the hash value of a file. This API uses a promise to return the resul ...@@ -961,17 +1042,20 @@ Calculates the hash value of a file. This API uses a promise to return the resul
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| --------- | ------ | ---- | ------------------------------------------------------------ | | --------- | ------ | ---- | ------------------------------------------------------------ |
| path | string | Yes | Application sandbox path of the file. | | path | string | Yes | Application sandbox path of the file. |
| algorithm | string | Yes | Algorithm used to calculate the hash value. The value can be **md5**, **sha1**, or **sha256**. **sha256** is recommended for security purposes.| | 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 | | Type | Description |
| --------------------- | -------------------------- | | --------------------- | -------------------------- |
| Promise&lt;string&gt; | Promise used to return the hash value obtained. The hash value is a hexadecimal string consisting of digits and uppercase letters.| | Promise&lt;string&gt; | Promise used to return the hash value obtained. The hash value is a hexadecimal string consisting of digits and uppercase letters.|
**Example** **Example**
```js ```js
fileio.hash(path, "sha256").then(function(str){ fileio.hash(path, "sha256").then(function(str){
console.info("Calculated file hash:"+ str); console.info("Calculated file hash:"+ str);
...@@ -990,6 +1074,7 @@ Calculates the hash value of a file. This API uses an asynchronous callback to r ...@@ -990,6 +1074,7 @@ Calculates the hash value of a file. This API uses an asynchronous callback to r
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| --------- | --------------------------- | ---- | ------------------------------------------------------------ | | --------- | --------------------------- | ---- | ------------------------------------------------------------ |
| path | string | Yes | Application sandbox path of the file. | | path | string | Yes | Application sandbox path of the file. |
...@@ -997,6 +1082,7 @@ Calculates the hash value of a file. This API uses an asynchronous callback to r ...@@ -997,6 +1082,7 @@ Calculates the hash value of a file. This API uses an asynchronous callback to r
| callback | AsyncCallback&lt;string&gt; | Yes | Callback used to return the hash value obtained. The hash value is a hexadecimal string consisting of digits and uppercase letters.| | callback | AsyncCallback&lt;string&gt; | Yes | Callback used to return the hash value obtained. The hash value is a hexadecimal string consisting of digits and uppercase letters.|
**Example** **Example**
```js ```js
fileio.hash(path, "sha256", function(err, hashStr) { fileio.hash(path, "sha256", function(err, hashStr) {
if (hashStr) { if (hashStr) {
...@@ -1015,17 +1101,20 @@ Changes file permissions. This API uses a promise to return the result. ...@@ -1015,17 +1101,20 @@ Changes file permissions. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------------------------------------------ | | ------ | ------ | ---- | ------------------------------------------------------------ |
| path | string | Yes | Application sandbox path of the file. | | path | string | Yes | Application sandbox path of the file. |
| mode | number | Yes | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (&#124;).<br>-&nbsp;**0o700**: The owner has the read, write, and execute permissions.<br>- &nbsp;**0o400**: The owner has the read permission.<br>-&nbsp;**0o200**: The owner has the write permission.<br>-&nbsp;**0o100**: The owner has the execute permission.<br>-&nbsp;**0o070**: The user group has the read, write, and execute permissions.<br>-&nbsp;**0o040**: The user group has the read permission.<br>-&nbsp;**0o020**: The user group has the write permission.<br>-&nbsp;**0o010**: The user group has the execute permission.<br>-&nbsp;**0o007**: Other users have the read, write, and execute permissions.<br>-&nbsp;**0o004**: Other users have the read permission.<br>-&nbsp;**0o002**: Other users have the write permission.<br>-&nbsp;**0o001**: Other users have the execute permission.| | mode | number | Yes | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (&#124;).<br>-&nbsp;**0o700**: The owner has the read, write, and execute permissions.<br>- &nbsp;**0o400**: The owner has the read permission.<br>-&nbsp;**0o200**: The owner has the write permission.<br>-&nbsp;**0o100**: The owner has the execute permission.<br>-&nbsp;**0o070**: The user group has the read, write, and execute permissions.<br>-&nbsp;**0o040**: The user group has the read permission.<br>-&nbsp;**0o020**: The user group has the write permission.<br>-&nbsp;**0o010**: The user group has the execute permission.<br>-&nbsp;**0o007**: Other users have the read, write, and execute permissions.<br>-&nbsp;**0o004**: Other users have the read permission.<br>-&nbsp;**0o002**: Other users have the write permission.<br>-&nbsp;**0o001**: Other users have the execute permission.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
```js ```js
fileio.chmod(path, mode).then(function() { fileio.chmod(path, mode).then(function() {
console.info("File permissions changed"); console.info("File permissions changed");
...@@ -1044,6 +1133,7 @@ Changes file permissions. This API uses an asynchronous callback to return the r ...@@ -1044,6 +1133,7 @@ Changes file permissions. This API uses an asynchronous callback to return the r
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ------------------------------------------------------------ | | -------- | ------------------------- | ---- | ------------------------------------------------------------ |
| path | string | Yes | Application sandbox path of the file. | | path | string | Yes | Application sandbox path of the file. |
...@@ -1051,6 +1141,7 @@ Changes file permissions. This API uses an asynchronous callback to return the r ...@@ -1051,6 +1141,7 @@ Changes file permissions. This API uses an asynchronous callback to return the r
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file permissions are changed asynchronously. | | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file permissions are changed asynchronously. |
**Example** **Example**
```js ```js
fileio.chmod(path, mode, function (err) { fileio.chmod(path, mode, function (err) {
// Do something. // Do something.
...@@ -1067,12 +1158,14 @@ Synchronously changes file permissions. ...@@ -1067,12 +1158,14 @@ Synchronously changes file permissions.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------------------------------------------ | | ------ | ------ | ---- | ------------------------------------------------------------ |
| path | string | Yes | Application sandbox path of the file. | | path | string | Yes | Application sandbox path of the file. |
| mode | number | Yes | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (&#124;).<br>-&nbsp;**0o700**: The owner has the read, write, and execute permissions.<br>- &nbsp;**0o400**: The owner has the read permission.<br>-&nbsp;**0o200**: The owner has the write permission.<br>-&nbsp;**0o100**: The owner has the execute permission.<br>-&nbsp;**0o070**: The user group has the read, write, and execute permissions.<br>-&nbsp;**0o040**: The user group has the read permission.<br>-&nbsp;**0o020**: The user group has the write permission.<br>-&nbsp;**0o010**: The user group has the execute permission.<br>-&nbsp;**0o007**: Other users have the read, write, and execute permissions.<br>-&nbsp;**0o004**: Other users have the read permission.<br>-&nbsp;**0o002**: Other users have the write permission.<br>-&nbsp;**0o001**: Other users have the execute permission.| | mode | number | Yes | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (&#124;).<br>-&nbsp;**0o700**: The owner has the read, write, and execute permissions.<br>- &nbsp;**0o400**: The owner has the read permission.<br>-&nbsp;**0o200**: The owner has the write permission.<br>-&nbsp;**0o100**: The owner has the execute permission.<br>-&nbsp;**0o070**: The user group has the read, write, and execute permissions.<br>-&nbsp;**0o040**: The user group has the read permission.<br>-&nbsp;**0o020**: The user group has the write permission.<br>-&nbsp;**0o010**: The user group has the execute permission.<br>-&nbsp;**0o007**: Other users have the read, write, and execute permissions.<br>-&nbsp;**0o004**: Other users have the read permission.<br>-&nbsp;**0o002**: Other users have the write permission.<br>-&nbsp;**0o001**: Other users have the execute permission.|
**Example** **Example**
```js ```js
fileio.chmodSync(path, mode); fileio.chmodSync(path, mode);
``` ```
...@@ -1087,16 +1180,19 @@ Obtains file information based on the file descriptor. This API uses a promise t ...@@ -1087,16 +1180,19 @@ Obtains file information based on the file descriptor. This API uses a promise t
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ------------ | | ---- | ------ | ---- | ------------ |
| fd | number | Yes | File descriptor of the target file.| | fd | number | Yes | File descriptor of the target file.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ---------------------------- | ---------- | | ---------------------------- | ---------- |
| Promise&lt;[Stat](#stat)&gt; | Promise used to return the file information.| | Promise&lt;[Stat](#stat)&gt; | Promise used to return the file information.|
**Example** **Example**
```js ```js
fileio.fstat(fd).then(function(stat){ fileio.fstat(fd).then(function(stat){
console.info("File information obtained:"+ JSON.stringify(stat)); console.info("File information obtained:"+ JSON.stringify(stat));
...@@ -1115,12 +1211,14 @@ Obtains file information based on the file descriptor. This API uses an asynchro ...@@ -1115,12 +1211,14 @@ Obtains file information based on the file descriptor. This API uses an asynchro
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------------------- | ---- | ---------------- | | -------- | ---------------------------------- | ---- | ---------------- |
| fd | number | Yes | File descriptor of the target file. | | fd | number | Yes | File descriptor of the target file. |
| callback | AsyncCallback&lt;[Stat](#stat)&gt; | Yes | Callback invoked to return the file information obtained.| | callback | AsyncCallback&lt;[Stat](#stat)&gt; | Yes | Callback invoked to return the file information obtained.|
**Example** **Example**
```js ```js
let fd = fileio.openSync(path); let fd = fileio.openSync(path);
fileio.fstat(fd, function (err) { fileio.fstat(fd, function (err) {
...@@ -1138,16 +1236,19 @@ Synchronously obtains file information based on the file descriptor. ...@@ -1138,16 +1236,19 @@ Synchronously obtains file information based on the file descriptor.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ------------ | | ---- | ------ | ---- | ------------ |
| fd | number | Yes | File descriptor of the target file.| | fd | number | Yes | File descriptor of the target file.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------- | ---------- | | ------------- | ---------- |
| [Stat](#stat) | File information obtained.| | [Stat](#stat) | File information obtained.|
**Example** **Example**
```js ```js
let fd = fileio.openSync(path); let fd = fileio.openSync(path);
let stat = fileio.fstatSync(fd); let stat = fileio.fstatSync(fd);
...@@ -1163,17 +1264,20 @@ Truncates a file based on the file descriptor. This API uses a promise to return ...@@ -1163,17 +1264,20 @@ Truncates a file based on the file descriptor. This API uses a promise to return
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ---------------- | | ---- | ------ | ---- | ---------------- |
| fd | number | Yes | File descriptor of the file to truncate. | | fd | number | Yes | File descriptor of the file to truncate. |
| len | number | No | File length, in bytes, after truncation.| | len | number | No | File length, in bytes, after truncation.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
```js ```js
let fd = fileio.openSync(path); let fd = fileio.openSync(path);
fileio.ftruncate(fd, 5).then(function(err) { fileio.ftruncate(fd, 5).then(function(err) {
...@@ -1193,6 +1297,7 @@ Truncates a file based on the file descriptor. This API uses an asynchronous cal ...@@ -1193,6 +1297,7 @@ Truncates a file based on the file descriptor. This API uses an asynchronous cal
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | ---------------- | | -------- | ------------------------- | ---- | ---------------- |
| fd | number | Yes | File descriptor of the file to truncate. | | fd | number | Yes | File descriptor of the file to truncate. |
...@@ -1200,6 +1305,7 @@ Truncates a file based on the file descriptor. This API uses an asynchronous cal ...@@ -1200,6 +1305,7 @@ Truncates a file based on the file descriptor. This API uses an asynchronous cal
| callback | AsyncCallback&lt;void&gt; | Yes | Callback that returns no value. | | callback | AsyncCallback&lt;void&gt; | Yes | Callback that returns no value. |
**Example** **Example**
```js ```js
fileio.ftruncate(fd, len, function(err){ fileio.ftruncate(fd, len, function(err){
// Do something. // Do something.
...@@ -1216,12 +1322,14 @@ Synchronously truncates a file based on the file descriptor. ...@@ -1216,12 +1322,14 @@ Synchronously truncates a file based on the file descriptor.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ---------------- | | ---- | ------ | ---- | ---------------- |
| fd | number | Yes | File descriptor of the file to truncate. | | fd | number | Yes | File descriptor of the file to truncate. |
| len | number | No | File length, in bytes, after truncation.| | len | number | No | File length, in bytes, after truncation.|
**Example** **Example**
```js ```js
fileio.ftruncateSync(fd, len); fileio.ftruncateSync(fd, len);
``` ```
...@@ -1236,17 +1344,20 @@ Truncates a file based on the file path. This API uses a promise to return the r ...@@ -1236,17 +1344,20 @@ Truncates a file based on the file path. This API uses a promise to return the r
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------ | ---- | -------------------------------- | | ------ | ------ | ---- | -------------------------------- |
| path | string | Yes | Application sandbox path of the file to truncate. | | path | string | Yes | Application sandbox path of the file to truncate. |
| len | number | No | File length, in bytes, after truncation.| | len | number | No | File length, in bytes, after truncation.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
```js ```js
fileio.truncate(path, len).then(function(){ fileio.truncate(path, len).then(function(){
console.info("File truncated"); console.info("File truncated");
...@@ -1265,6 +1376,7 @@ Truncates a file based on the file path. This API uses an asynchronous callback ...@@ -1265,6 +1376,7 @@ Truncates a file based on the file path. This API uses an asynchronous callback
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | -------------------------------- | | -------- | ------------------------- | ---- | -------------------------------- |
| path | string | Yes | Application sandbox path of the file to truncate.| | path | string | Yes | Application sandbox path of the file to truncate.|
...@@ -1272,6 +1384,7 @@ Truncates a file based on the file path. This API uses an asynchronous callback ...@@ -1272,6 +1384,7 @@ Truncates a file based on the file path. This API uses an asynchronous callback
| callback | AsyncCallback&lt;void&gt; | Yes | Callback that returns no value. | | callback | AsyncCallback&lt;void&gt; | Yes | Callback that returns no value. |
**Example** **Example**
```js ```js
fileio.truncate(path, len, function(err){ fileio.truncate(path, len, function(err){
// Do something. // Do something.
...@@ -1288,12 +1401,14 @@ Synchronously truncates a file based on the file path. ...@@ -1288,12 +1401,14 @@ Synchronously truncates a file based on the file path.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------ | ---- | -------------------------------- | | ------ | ------ | ---- | -------------------------------- |
| path | string | Yes | Application sandbox path of the file to truncate.| | path | string | Yes | Application sandbox path of the file to truncate.|
| len | number | No | File length, in bytes, after truncation.| | len | number | No | File length, in bytes, after truncation.|
**Example** **Example**
```js ```js
fileio.truncateSync(path, len); fileio.truncateSync(path, len);
``` ```
...@@ -1312,17 +1427,20 @@ Reads the text content of a file. This API uses a promise to return the result. ...@@ -1312,17 +1427,20 @@ Reads the text content of a file. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------ | ---- | ------------------------------------------------------------ | | -------- | ------ | ---- | ------------------------------------------------------------ |
| filePath | string | Yes | Application sandbox path of the file to read. | | filePath | string | Yes | Application sandbox path of the file to read. |
| options | Object | No | The options are as follows:<br>-&nbsp;**position** (number): position of the data to read in the file. By default, data is read from the current position.<br>-&nbsp;**length** (number): length of the data to read. The default value is the buffer length minus the offset.<br>-&nbsp;**encoding** (string): format of the data (string) to be encoded. The default value is **utf-8**, which is the only value supported.| | options | Object | No | The options are as follows:<br>-&nbsp;**position** (number): position of the data to read in the file. By default, data is read from the current position.<br>-&nbsp;**length** (number): length of the data to read. The default value is the buffer length minus the offset.<br>-&nbsp;**encoding** (string): format of the data (string) to be encoded. The default value is **utf-8**, which is the only value supported.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| --------------------- | ---------- | | --------------------- | ---------- |
| Promise&lt;string&gt; | Promise used to return the content read.| | Promise&lt;string&gt; | Promise used to return the content read.|
**Example** **Example**
```js ```js
fileio.readText(path).then(function(str) { fileio.readText(path).then(function(str) {
console.info("Read file text:"+ str); console.info("Read file text:"+ str);
...@@ -1345,6 +1463,7 @@ Reads the text content of a file. This API uses an asynchronous callback to retu ...@@ -1345,6 +1463,7 @@ Reads the text content of a file. This API uses an asynchronous callback to retu
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | --------------------------- | ---- | ------------------------------------------------------------ | | -------- | --------------------------- | ---- | ------------------------------------------------------------ |
| filePath | string | Yes | Application sandbox path of the file to read. | | filePath | string | Yes | Application sandbox path of the file to read. |
...@@ -1352,6 +1471,7 @@ Reads the text content of a file. This API uses an asynchronous callback to retu ...@@ -1352,6 +1471,7 @@ Reads the text content of a file. This API uses an asynchronous callback to retu
| callback | AsyncCallback&lt;string&gt; | Yes | Callback used to return the content read. | | callback | AsyncCallback&lt;string&gt; | Yes | Callback used to return the content read. |
**Example** **Example**
```js ```js
fileio.readText(path, function(err, str){ fileio.readText(path, function(err, str){
// Do something. // Do something.
...@@ -1372,17 +1492,20 @@ Synchronously reads the text of a file. ...@@ -1372,17 +1492,20 @@ Synchronously reads the text of a file.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------ | ---- | ------------------------------------------------------------ | | -------- | ------ | ---- | ------------------------------------------------------------ |
| filePath | string | Yes | Application sandbox path of the file to read. | | filePath | string | Yes | Application sandbox path of the file to read. |
| options | Object | No | The options are as follows:<br>-&nbsp;**position** (number): position of the data to read in the file. By default, data is read from the current position.<br>-&nbsp;**length** (number): length of the data to read. The default value is the buffer length minus the offset.<br>-&nbsp;**encoding** (string): format of the data (string) to be encoded. The default value is **utf-8**, which is the only value supported.| | options | Object | No | The options are as follows:<br>-&nbsp;**position** (number): position of the data to read in the file. By default, data is read from the current position.<br>-&nbsp;**length** (number): length of the data to read. The default value is the buffer length minus the offset.<br>-&nbsp;**encoding** (string): format of the data (string) to be encoded. The default value is **utf-8**, which is the only value supported.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------ | -------------------- | | ------ | -------------------- |
| string | Promise used to return the content of the file read.| | string | Promise used to return the content of the file read.|
**Example** **Example**
```js ```js
let str = fileio.readTextSync(path, {position: 1, length: 3}); let str = fileio.readTextSync(path, {position: 1, length: 3});
``` ```
...@@ -1397,16 +1520,19 @@ Obtains link information. This API uses a promise to return the result. ...@@ -1397,16 +1520,19 @@ Obtains link information. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------ | ---- | -------------------------------------- | | ------ | ------ | ---- | -------------------------------------- |
| path | string | Yes | Application sandbox path of the target file.| | path | string | Yes | Application sandbox path of the target file.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ---------------------------- | ---------- | | ---------------------------- | ---------- |
| Promise&lt;[Stat](#stat)&gt; | Promise used to return the link information obtained. For details, see [Stat](#stat).| | Promise&lt;[Stat](#stat)&gt; | Promise used to return the link information obtained. For details, see [Stat](#stat).|
**Example** **Example**
```js ```js
fileio.lstat(path).then(function(stat){ fileio.lstat(path).then(function(stat){
console.info("Got link info:"+ JSON.stringify(stat)); console.info("Got link info:"+ JSON.stringify(stat));
...@@ -1425,12 +1551,14 @@ Obtains link information. This API uses an asynchronous callback to return the r ...@@ -1425,12 +1551,14 @@ Obtains link information. This API uses an asynchronous callback to return the r
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ---------------------------------- | ---- | -------------------------------------- | | -------- | ---------------------------------- | ---- | -------------------------------------- |
| path | string | Yes | Application sandbox path of the target file.| | path | string | Yes | Application sandbox path of the target file.|
| callback | AsyncCallback&lt;[Stat](#stat)&gt; | Yes | Callback used to return the link information obtained. | | callback | AsyncCallback&lt;[Stat](#stat)&gt; | Yes | Callback used to return the link information obtained. |
**Example** **Example**
```js ```js
fileio.lstat(path, function (err, stat) { fileio.lstat(path, function (err, stat) {
// Do something. // Do something.
...@@ -1447,16 +1575,19 @@ Synchronously obtains the link information. ...@@ -1447,16 +1575,19 @@ Synchronously obtains the link information.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------ | ---- | -------------------------------------- | | ------ | ------ | ---- | -------------------------------------- |
| path | string | Yes | Application sandbox path of the target file.| | path | string | Yes | Application sandbox path of the target file.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------- | ---------- | | ------------- | ---------- |
| [Stat](#stat) | Link information obtained.| | [Stat](#stat) | Link information obtained.|
**Example** **Example**
```js ```js
let stat = fileio.lstatSync(path); let stat = fileio.lstatSync(path);
``` ```
...@@ -1475,17 +1606,20 @@ Reads data from a file. This API uses a promise to return the result. ...@@ -1475,17 +1606,20 @@ Reads data from a file. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ------- | ----------- | ---- | ------------------------------------------------------------ | | ------- | ----------- | ---- | ------------------------------------------------------------ |
| buffer | ArrayBuffer | Yes | Buffer used to store the file data read. | | buffer | ArrayBuffer | Yes | Buffer used to store the file data read. |
| options | Object | No | The options are as follows:<br>-&nbsp;**offset** (number): position to store the data read in the buffer in reference to the start address of the buffer. The default value is **0**.<br>-&nbsp;**length** (number): length of the data to read. The default value is the buffer length minus the offset.<br>Constraints: offset + length <= Buffer size| | options | Object | No | The options are as follows:<br>-&nbsp;**offset** (number): position to store the data read in the buffer in reference to the start address of the buffer. The default value is **0**.<br>-&nbsp;**length** (number): length of the data to read. The default value is the buffer length minus the offset.<br>Constraints: offset + length <= Buffer size|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ---------------------------------- | ------ | | ---------------------------------- | ------ |
| Promise&lt;[ReadOut](#readout)&gt; | Promise used to return the data read.| | Promise&lt;[ReadOut](#readout)&gt; | Promise used to return the data read.|
**Example** **Example**
```js ```js
fileio.read(new ArrayBuffer(4096)).then(function(readout){ fileio.read(new ArrayBuffer(4096)).then(function(readout){
console.info("Read file data"); console.info("Read file data");
...@@ -1509,6 +1643,7 @@ Reads data from a file. This API uses an asynchronous callback to return the res ...@@ -1509,6 +1643,7 @@ Reads data from a file. This API uses an asynchronous callback to return the res
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- | | -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| buffer | ArrayBuffer | Yes | Buffer used to store the file data read. | | buffer | ArrayBuffer | Yes | Buffer used to store the file data read. |
...@@ -1516,6 +1651,7 @@ Reads data from a file. This API uses an asynchronous callback to return the res ...@@ -1516,6 +1651,7 @@ Reads data from a file. This API uses an asynchronous callback to return the res
| callback | AsyncCallback&lt;[ReadOut](#readout)&gt; | Yes | Callback invoked when the data is read asynchronously from the file. | | callback | AsyncCallback&lt;[ReadOut](#readout)&gt; | Yes | Callback invoked when the data is read asynchronously from the file. |
**Example** **Example**
```js ```js
let buf = new ArrayBuffer(4096); let buf = new ArrayBuffer(4096);
fileio.read(buf, function (err, readOut) { fileio.read(buf, function (err, readOut) {
...@@ -1536,17 +1672,20 @@ Renames a file. This API uses a promise to return the result. ...@@ -1536,17 +1672,20 @@ Renames a file. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ------- | ------ | ---- | ---------------------------- | | ------- | ------ | ---- | ---------------------------- |
| oldPath | string | Yes | Application sandbox path of the file to rename.| | oldPath | string | Yes | Application sandbox path of the file to rename.|
| newPath | String | Yes | Application sandbox path of the file renamed. | | newPath | String | Yes | Application sandbox path of the file renamed. |
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
```js ```js
fileio.rename(oldPath, newPath).then(function() { fileio.rename(oldPath, newPath).then(function() {
console.info("File renamed"); console.info("File renamed");
...@@ -1565,6 +1704,7 @@ Renames a file. This API uses an asynchronous callback to return the result. ...@@ -1565,6 +1704,7 @@ Renames a file. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ---------------------------- | | -------- | ------------------------- | ---- | ---------------------------- |
| oldPath | string | Yes | Application sandbox path of the file to rename.| | oldPath | string | Yes | Application sandbox path of the file to rename.|
...@@ -1572,6 +1712,7 @@ Renames a file. This API uses an asynchronous callback to return the result. ...@@ -1572,6 +1712,7 @@ Renames a file. This API uses an asynchronous callback to return the result.
| Callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file is asynchronously renamed. | | Callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file is asynchronously renamed. |
**Example** **Example**
```js ```js
fileio.rename(oldPath, newPath, function(err){ fileio.rename(oldPath, newPath, function(err){
}); });
...@@ -1587,12 +1728,14 @@ Synchronously renames a file. ...@@ -1587,12 +1728,14 @@ Synchronously renames a file.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ------- | ------ | ---- | ---------------------------- | | ------- | ------ | ---- | ---------------------------- |
| oldPath | string | Yes | Application sandbox path of the file to rename.| | oldPath | string | Yes | Application sandbox path of the file to rename.|
| newPath | String | Yes | Application sandbox path of the file renamed. | | newPath | String | Yes | Application sandbox path of the file renamed. |
**Example** **Example**
```js ```js
fileio.renameSync(oldPath, newPath); fileio.renameSync(oldPath, newPath);
``` ```
...@@ -1607,16 +1750,19 @@ Flushes data of a file to disk. This API uses a promise to return the result. ...@@ -1607,16 +1750,19 @@ Flushes data of a file to disk. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ------------ | | ---- | ------ | ---- | ------------ |
| fd | number | Yes | File descriptor of the file to flush.| | fd | number | Yes | File descriptor of the file to flush.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
```js ```js
fileio.fsync(fd).then(function(){ fileio.fsync(fd).then(function(){
console.info("Data flushed"); console.info("Data flushed");
...@@ -1635,12 +1781,14 @@ Flushes data of a file to disk. This API uses an asynchronous callback to return ...@@ -1635,12 +1781,14 @@ Flushes data of a file to disk. This API uses an asynchronous callback to return
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | --------------- | | -------- | ------------------------- | ---- | --------------- |
| fd | number | Yes | File descriptor of the file to flush. | | fd | number | Yes | File descriptor of the file to flush. |
| Callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file is synchronized in asynchronous mode.| | Callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file is synchronized in asynchronous mode.|
**Example** **Example**
```js ```js
fileio.fsync(fd, function(err){ fileio.fsync(fd, function(err){
// Do something. // Do something.
...@@ -1657,11 +1805,13 @@ Flushes data of a file to disk in synchronous mode. ...@@ -1657,11 +1805,13 @@ Flushes data of a file to disk in synchronous mode.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ------------ | | ---- | ------ | ---- | ------------ |
| fd | number | Yes | File descriptor of the file to flush.| | fd | number | Yes | File descriptor of the file to flush.|
**Example** **Example**
```js ```js
fileio.fsyncSync(fd); fileio.fsyncSync(fd);
``` ```
...@@ -1676,16 +1826,19 @@ Flushes data of a file to disk. This API uses a promise to return the result. ** ...@@ -1676,16 +1826,19 @@ Flushes data of a file to disk. This API uses a promise to return the result. **
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ------------ | | ---- | ------ | ---- | ------------ |
| fd | number | Yes | File descriptor of the file to flush.| | fd | number | Yes | File descriptor of the file to flush.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
```js ```js
fileio.fdatasync(fd).then(function(err) { fileio.fdatasync(fd).then(function(err) {
console.info("Data flushed"); console.info("Data flushed");
...@@ -1704,12 +1857,14 @@ Flushes data of a file to disk. This API uses an asynchronous callback to return ...@@ -1704,12 +1857,14 @@ Flushes data of a file to disk. This API uses an asynchronous callback to return
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ------------------------------- | ---- | ----------------- | | -------- | ------------------------------- | ---- | ----------------- |
| fd | number | Yes | File descriptor of the file to synchronize. | | fd | number | Yes | File descriptor of the file to synchronize. |
| callback | AsyncCallback&nbsp;&lt;void&gt; | Yes | Callback invoked when the file data is synchronized in asynchronous mode.| | callback | AsyncCallback&nbsp;&lt;void&gt; | Yes | Callback invoked when the file data is synchronized in asynchronous mode.|
**Example** **Example**
```js ```js
fileio.fdatasync (fd, function (err) { fileio.fdatasync (fd, function (err) {
// Do something. // Do something.
...@@ -1726,11 +1881,13 @@ Synchronizes data in a file in synchronous mode. ...@@ -1726,11 +1881,13 @@ Synchronizes data in a file in synchronous mode.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ------------ | | ---- | ------ | ---- | ------------ |
| fd | number | Yes | File descriptor of the file to flush.| | fd | number | Yes | File descriptor of the file to flush.|
**Example** **Example**
```js ```js
let stat = fileio.fdatasyncSync(fd); let stat = fileio.fdatasyncSync(fd);
``` ```
...@@ -1745,17 +1902,20 @@ Creates a symbolic link based on the file path. This API uses a promise to retur ...@@ -1745,17 +1902,20 @@ Creates a symbolic link based on the file path. This API uses a promise to retur
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ------- | ------ | ---- | ---------------------------- | | ------- | ------ | ---- | ---------------------------- |
| target | string | Yes | Application sandbox path of the target file. | | target | string | Yes | Application sandbox path of the target file. |
| srcPath | string | Yes | Application sandbox path of the symbolic link file.| | srcPath | string | Yes | Application sandbox path of the symbolic link file.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
```js ```js
fileio.symlink(target, srcPath).then(function() { fileio.symlink(target, srcPath).then(function() {
console.info("Symbolic link created"); console.info("Symbolic link created");
...@@ -1774,6 +1934,7 @@ Creates a symbolic link based on the file path. This API uses an asynchronous ca ...@@ -1774,6 +1934,7 @@ Creates a symbolic link based on the file path. This API uses an asynchronous ca
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | -------------------------------- | | -------- | ------------------------- | ---- | -------------------------------- |
| target | string | Yes | Application sandbox path of the target file. | | target | string | Yes | Application sandbox path of the target file. |
...@@ -1781,6 +1942,7 @@ Creates a symbolic link based on the file path. This API uses an asynchronous ca ...@@ -1781,6 +1942,7 @@ Creates a symbolic link based on the file path. This API uses an asynchronous ca
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the symbolic link is created asynchronously.| | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the symbolic link is created asynchronously.|
**Example** **Example**
```js ```js
fileio.symlink(target, srcPath, function (err) { fileio.symlink(target, srcPath, function (err) {
// Do something. // Do something.
...@@ -1797,12 +1959,14 @@ Synchronously creates a symbolic link based on a specified path. ...@@ -1797,12 +1959,14 @@ Synchronously creates a symbolic link based on a specified path.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ------- | ------ | ---- | ---------------------------- | | ------- | ------ | ---- | ---------------------------- |
| target | string | Yes | Application sandbox path of the target file. | | target | string | Yes | Application sandbox path of the target file. |
| srcPath | string | Yes | Application sandbox path of the symbolic link file.| | srcPath | string | Yes | Application sandbox path of the symbolic link file.|
**Example** **Example**
```js ```js
fileio.symlinkSync(target, srcPath); fileio.symlinkSync(target, srcPath);
``` ```
...@@ -1817,6 +1981,7 @@ Changes the file owner based on the file path. This API uses a promise to return ...@@ -1817,6 +1981,7 @@ Changes the file owner based on the file path. This API uses a promise to return
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------ | ---- | -------------------------- | | ------ | ------ | ---- | -------------------------- |
| path | string | Yes | Application sandbox path of the file.| | path | string | Yes | Application sandbox path of the file.|
...@@ -1824,11 +1989,13 @@ Changes the file owner based on the file path. This API uses a promise to return ...@@ -1824,11 +1989,13 @@ Changes the file owner based on the file path. This API uses a promise to return
| gid | number | Yes | New group ID (GID). | | gid | number | Yes | New group ID (GID). |
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
```js ```js
let stat = fileio.statSync(path); let stat = fileio.statSync(path);
fileio.chown(path, stat.uid, stat.gid).then(function(){ fileio.chown(path, stat.uid, stat.gid).then(function(){
...@@ -1848,6 +2015,7 @@ Changes the file owner based on the file path. This API uses an asynchronous cal ...@@ -1848,6 +2015,7 @@ Changes the file owner based on the file path. This API uses an asynchronous cal
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ------------------------------ | | -------- | ------------------------- | ---- | ------------------------------ |
| path | string | Yes | Application sandbox path of the file. | | path | string | Yes | Application sandbox path of the file. |
...@@ -1856,6 +2024,7 @@ Changes the file owner based on the file path. This API uses an asynchronous cal ...@@ -1856,6 +2024,7 @@ Changes the file owner based on the file path. This API uses an asynchronous cal
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file owner is changed asynchronously.| | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file owner is changed asynchronously.|
**Example** **Example**
```js ```js
let stat = fileio.statSync(path) let stat = fileio.statSync(path)
fileio.chown(path, stat.uid, stat.gid, function (err){ fileio.chown(path, stat.uid, stat.gid, function (err){
...@@ -1873,6 +2042,7 @@ Synchronously changes the file owner based on its path. ...@@ -1873,6 +2042,7 @@ Synchronously changes the file owner based on its path.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------ | ---- | -------------------------- | | ------ | ------ | ---- | -------------------------- |
| path | string | Yes | Application sandbox path of the file.| | path | string | Yes | Application sandbox path of the file.|
...@@ -1880,6 +2050,7 @@ Synchronously changes the file owner based on its path. ...@@ -1880,6 +2050,7 @@ Synchronously changes the file owner based on its path.
| gid | number | Yes | New GID. | | gid | number | Yes | New GID. |
**Example** **Example**
```js ```js
let stat = fileio.statSync(path) let stat = fileio.statSync(path)
fileio.chownSync(path, stat.uid, stat.gid); fileio.chownSync(path, stat.uid, stat.gid);
...@@ -1895,16 +2066,19 @@ Creates a temporary directory. This API uses a promise to return the result. ...@@ -1895,16 +2066,19 @@ Creates a temporary directory. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- | | ------ | ------ | ---- | --------------------------- |
| prefix | string | Yes | A randomly generated string used to replace "XXXXXX" in a directory.| | prefix | string | Yes | A randomly generated string used to replace "XXXXXX" in a directory.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| --------------------- | ---------- | | --------------------- | ---------- |
| Promise&lt;string&gt; | Promise used to return the unique directory generated.| | Promise&lt;string&gt; | Promise used to return the unique directory generated.|
**Example** **Example**
```js ```js
fileio.mkdtemp(path + "XXXX").then(function(path){ fileio.mkdtemp(path + "XXXX").then(function(path){
console.info("Temporary directory created:"+ path); console.info("Temporary directory created:"+ path);
...@@ -1923,12 +2097,14 @@ Creates a temporary directory. This API uses an asynchronous callback to return ...@@ -1923,12 +2097,14 @@ Creates a temporary directory. This API uses an asynchronous callback to return
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | --------------------------- | ---- | --------------------------- | | -------- | --------------------------- | ---- | --------------------------- |
| prefix | string | Yes | A randomly generated string used to replace "XXXXXX" in a directory.| | prefix | string | Yes | A randomly generated string used to replace "XXXXXX" in a directory.|
| callback | AsyncCallback&lt;string&gt; | Yes | Callback invoked when a temporary directory is created asynchronously. | | callback | AsyncCallback&lt;string&gt; | Yes | Callback invoked when a temporary directory is created asynchronously. |
**Example** **Example**
```js ```js
fileio.mkdtemp(path + "XXXX", function (err, res) { fileio.mkdtemp(path + "XXXX", function (err, res) {
// Do something. // Do something.
...@@ -1945,16 +2121,19 @@ Synchronously creates a temporary directory. ...@@ -1945,16 +2121,19 @@ Synchronously creates a temporary directory.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- | | ------ | ------ | ---- | --------------------------- |
| prefix | string | Yes | A randomly generated string used to replace "XXXXXX" in a directory.| | prefix | string | Yes | A randomly generated string used to replace "XXXXXX" in a directory.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------ | ---------- | | ------ | ---------- |
| string | Unique path generated.| | string | Unique path generated.|
**Example** **Example**
```js ```js
let res = fileio.mkdtempSync(path + "XXXX"); let res = fileio.mkdtempSync(path + "XXXX");
``` ```
...@@ -1969,17 +2148,20 @@ Changes file permissions based on the file descriptor. This API uses a promise t ...@@ -1969,17 +2148,20 @@ Changes file permissions based on the file descriptor. This API uses a promise t
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ---------------------------------------- | | ---- | ------ | ---- | ---------------------------------------- |
| fd | number | Yes | File descriptor of the target file. | | fd | number | Yes | File descriptor of the target file. |
| mode | number | Yes | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (&#124;).<br>-&nbsp;**0o700**: The owner has the read, write, and execute permissions.<br>- &nbsp;**0o400**: The owner has the read permission.<br>-&nbsp;**0o200**: The owner has the write permission.<br>-&nbsp;**0o100**: The owner has the execute permission.<br>-&nbsp;**0o070**: The user group has the read, write, and execute permissions.<br>-&nbsp;**0o040**: The user group has the read permission.<br>-&nbsp;**0o020**: The user group has the write permission.<br>-&nbsp;**0o010**: The user group has the execute permission.<br>-&nbsp;**0o007**: Other users have the read, write, and execute permissions.<br>-&nbsp;**0o004**: Other users have the read permission.<br>-&nbsp;**0o002**: Other users have the write permission.<br>-&nbsp;**0o001**: Other users have the execute permission.| | mode | number | Yes | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (&#124;).<br>-&nbsp;**0o700**: The owner has the read, write, and execute permissions.<br>- &nbsp;**0o400**: The owner has the read permission.<br>-&nbsp;**0o200**: The owner has the write permission.<br>-&nbsp;**0o100**: The owner has the execute permission.<br>-&nbsp;**0o070**: The user group has the read, write, and execute permissions.<br>-&nbsp;**0o040**: The user group has the read permission.<br>-&nbsp;**0o020**: The user group has the write permission.<br>-&nbsp;**0o010**: The user group has the execute permission.<br>-&nbsp;**0o007**: Other users have the read, write, and execute permissions.<br>-&nbsp;**0o004**: Other users have the read permission.<br>-&nbsp;**0o002**: Other users have the write permission.<br>-&nbsp;**0o001**: Other users have the execute permission.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
```js ```js
fileio.fchmod(fd, mode).then(function() { fileio.fchmod(fd, mode).then(function() {
console.info("File permissions changed"); console.info("File permissions changed");
...@@ -1998,6 +2180,7 @@ Changes file permissions based on the file descriptor. This API uses an asynchro ...@@ -1998,6 +2180,7 @@ Changes file permissions based on the file descriptor. This API uses an asynchro
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ------------------------------- | ---- | ---------------------------------------- | | -------- | ------------------------------- | ---- | ---------------------------------------- |
| fd | number | Yes | File descriptor of the target file. | | fd | number | Yes | File descriptor of the target file. |
...@@ -2005,6 +2188,7 @@ Changes file permissions based on the file descriptor. This API uses an asynchro ...@@ -2005,6 +2188,7 @@ Changes file permissions based on the file descriptor. This API uses an asynchro
| callback | AsyncCallback&nbsp;&lt;void&gt; | Yes | Callback invoked when the file permissions are changed asynchronously. | | callback | AsyncCallback&nbsp;&lt;void&gt; | Yes | Callback invoked when the file permissions are changed asynchronously. |
**Example** **Example**
```js ```js
fileio.fchmod(fd, mode, function (err) { fileio.fchmod(fd, mode, function (err) {
// Do something. // Do something.
...@@ -2021,12 +2205,14 @@ Synchronously changes the file permissions based on the file descriptor. ...@@ -2021,12 +2205,14 @@ Synchronously changes the file permissions based on the file descriptor.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ---------------------------------------- | | ---- | ------ | ---- | ---------------------------------------- |
| fd | number | Yes | File descriptor of the target file. | | fd | number | Yes | File descriptor of the target file. |
| mode | number | Yes | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (&#124;).<br>-&nbsp;**0o700**: The owner has the read, write, and execute permissions.<br>- &nbsp;**0o400**: The owner has the read permission.<br>-&nbsp;**0o200**: The owner has the write permission.<br>-&nbsp;**0o100**: The owner has the execute permission.<br>-&nbsp;**0o070**: The user group has the read, write, and execute permissions.<br>-&nbsp;**0o040**: The user group has the read permission.<br>-&nbsp;**0o020**: The user group has the write permission.<br>-&nbsp;**0o010**: The user group has the execute permission.<br>-&nbsp;**0o007**: Other users have the read, write, and execute permissions.<br>-&nbsp;**0o004**: Other users have the read permission.<br>-&nbsp;**0o002**: Other users have the write permission.<br>-&nbsp;**0o001**: Other users have the execute permission.| | mode | number | Yes | Permissions on the file. You can specify multiple permissions, separated using a bitwise OR operator (&#124;).<br>-&nbsp;**0o700**: The owner has the read, write, and execute permissions.<br>- &nbsp;**0o400**: The owner has the read permission.<br>-&nbsp;**0o200**: The owner has the write permission.<br>-&nbsp;**0o100**: The owner has the execute permission.<br>-&nbsp;**0o070**: The user group has the read, write, and execute permissions.<br>-&nbsp;**0o040**: The user group has the read permission.<br>-&nbsp;**0o020**: The user group has the write permission.<br>-&nbsp;**0o010**: The user group has the execute permission.<br>-&nbsp;**0o007**: Other users have the read, write, and execute permissions.<br>-&nbsp;**0o004**: Other users have the read permission.<br>-&nbsp;**0o002**: Other users have the write permission.<br>-&nbsp;**0o001**: Other users have the execute permission.|
**Example** **Example**
```js ```js
fileio.fchmodSync(fd, mode); fileio.fchmodSync(fd, mode);
``` ```
...@@ -2041,17 +2227,20 @@ Opens a file stream based on the file path. This API uses a promise to return th ...@@ -2041,17 +2227,20 @@ Opens a file stream based on the file path. This API uses a promise to return th
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------------------------------------------ | | ------ | ------ | ---- | ------------------------------------------------------------ |
| path | string | Yes | Application sandbox path of the file. | | path | string | Yes | Application sandbox path of the file. |
| mode | string | Yes | -&nbsp;**r**: Open a file for reading. The file must exist.<br>-&nbsp;**r+**: Open a file for both reading and writing. The file must exist.<br>-&nbsp;**w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.<br>-&nbsp;**w+**: Open a file for both reading and writing. If the file exists, clear its content. If the file does not exist, create a file.<br>-&nbsp;**a**: Open a file in append mode for writing at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).<br>-&nbsp;**a+**: Open a file in append mode for reading or updating at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).| | mode | string | Yes | -&nbsp;**r**: Open a file for reading. The file must exist.<br>-&nbsp;**r+**: Open a file for both reading and writing. The file must exist.<br>-&nbsp;**w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.<br>-&nbsp;**w+**: Open a file for both reading and writing. If the file exists, clear its content. If the file does not exist, create a file.<br>-&nbsp;**a**: Open a file in append mode for writing at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).<br>-&nbsp;**a+**: Open a file in append mode for reading or updating at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).|
**Return value** **Return value**
| Type | Description | | Type | Description |
| --------------------------------- | --------- | | --------------------------------- | --------- |
| Promise&lt;[Stream](#stream7)&gt; | Promise used to return the result.| | Promise&lt;[Stream](#stream7)&gt; | Promise used to return the result.|
**Example** **Example**
```js ```js
fileio.createStream(path, "r+").then(function(stream){ fileio.createStream(path, "r+").then(function(stream){
console.info("Stream opened"); console.info("Stream opened");
...@@ -2070,6 +2259,7 @@ Opens a file stream based on the file path. This API uses an asynchronous callba ...@@ -2070,6 +2259,7 @@ Opens a file stream based on the file path. This API uses an asynchronous callba
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ------------------------------------------------------------ | | -------- | --------------------------------------- | ---- | ------------------------------------------------------------ |
| path | string | Yes | Application sandbox path of the file. | | path | string | Yes | Application sandbox path of the file. |
...@@ -2077,6 +2267,7 @@ Opens a file stream based on the file path. This API uses an asynchronous callba ...@@ -2077,6 +2267,7 @@ Opens a file stream based on the file path. This API uses an asynchronous callba
| callback | AsyncCallback&lt;[Stream](#stream7)&gt; | Yes | Callback invoked when the stream is open asynchronously. | | callback | AsyncCallback&lt;[Stream](#stream7)&gt; | Yes | Callback invoked when the stream is open asynchronously. |
**Example** **Example**
```js ```js
fileio.createStream(path, "r+", function(err, stream){ fileio.createStream(path, "r+", function(err, stream){
// Do something. // Do something.
...@@ -2093,17 +2284,20 @@ Synchronously opens a stream based on the file path. ...@@ -2093,17 +2284,20 @@ Synchronously opens a stream based on the file path.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------------------------------------------ | | ------ | ------ | ---- | ------------------------------------------------------------ |
| path | string | Yes | Application sandbox path of the file. | | path | string | Yes | Application sandbox path of the file. |
| mode | string | Yes | -&nbsp;**r**: Open a file for reading. The file must exist.<br>-&nbsp;**r+**: Open a file for both reading and writing. The file must exist.<br>-&nbsp;**w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.<br>-&nbsp;**w+**: Open a file for both reading and writing. If the file exists, clear its content. If the file does not exist, create a file.<br>-&nbsp;**a**: Open a file in append mode for writing at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).<br>-&nbsp;**a+**: Open a file in append mode for reading or updating at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).| | mode | string | Yes | -&nbsp;**r**: Open a file for reading. The file must exist.<br>-&nbsp;**r+**: Open a file for both reading and writing. The file must exist.<br>-&nbsp;**w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.<br>-&nbsp;**w+**: Open a file for both reading and writing. If the file exists, clear its content. If the file does not exist, create a file.<br>-&nbsp;**a**: Open a file in append mode for writing at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).<br>-&nbsp;**a+**: Open a file in append mode for reading or updating at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------ | --------- | | ------------------ | --------- |
| [Stream](#stream7) | Stream opened.| | [Stream](#stream7) | Stream opened.|
**Example** **Example**
```js ```js
let ss = fileio.createStreamSync(path, "r+"); let ss = fileio.createStreamSync(path, "r+");
``` ```
...@@ -2118,17 +2312,20 @@ Opens a file stream based on the file descriptor. This API uses a promise to ret ...@@ -2118,17 +2312,20 @@ Opens a file stream based on the file descriptor. This API uses a promise to ret
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ---------------------------------------- | | ---- | ------ | ---- | ---------------------------------------- |
| fd | number | Yes | File descriptor of the target file. | | fd | number | Yes | File descriptor of the target file. |
| mode | string | Yes | -&nbsp;**r**: Open a file for reading. The file must exist.<br>-&nbsp;**r+**: Open a file for both reading and writing. The file must exist.<br>-&nbsp;**w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.<br>-&nbsp;**w+**: Open a file for both reading and writing. If the file exists, clear its content. If the file does not exist, create a file.<br>-&nbsp;**a**: Open a file in append mode for writing at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).<br>-&nbsp;**a+**: Open a file in append mode for reading or updating at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).| | mode | string | Yes | -&nbsp;**r**: Open a file for reading. The file must exist.<br>-&nbsp;**r+**: Open a file for both reading and writing. The file must exist.<br>-&nbsp;**w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.<br>-&nbsp;**w+**: Open a file for both reading and writing. If the file exists, clear its content. If the file does not exist, create a file.<br>-&nbsp;**a**: Open a file in append mode for writing at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).<br>-&nbsp;**a+**: Open a file in append mode for reading or updating at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).|
**Return value** **Return value**
| Type | Description | | Type | Description |
| --------------------------------- | --------- | | --------------------------------- | --------- |
| Promise&lt;[Stream](#stream7)&gt; | Promise used to return the result.| | Promise&lt;[Stream](#stream7)&gt; | Promise used to return the result.|
**Example** **Example**
```js ```js
let fd = fileio.openSync(path); let fd = fileio.openSync(path);
fileio.fdopenStream(fd, "r+").then(function(stream){ fileio.fdopenStream(fd, "r+").then(function(stream){
...@@ -2148,6 +2345,7 @@ Opens a file stream based on the file descriptor. This API uses an asynchronous ...@@ -2148,6 +2345,7 @@ Opens a file stream based on the file descriptor. This API uses an asynchronous
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- | | -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| fd | number | Yes | File descriptor of the target file. | | fd | number | Yes | File descriptor of the target file. |
...@@ -2155,6 +2353,7 @@ Opens a file stream based on the file descriptor. This API uses an asynchronous ...@@ -2155,6 +2353,7 @@ Opens a file stream based on the file descriptor. This API uses an asynchronous
| callback | AsyncCallback&nbsp;&lt;[Stream](#stream7)&gt; | Yes | Callback invoked when the stream is open asynchronously. | | callback | AsyncCallback&nbsp;&lt;[Stream](#stream7)&gt; | Yes | Callback invoked when the stream is open asynchronously. |
**Example** **Example**
```js ```js
let fd = fileio.openSync(path); let fd = fileio.openSync(path);
fileio.fdopenStream(fd, "r+", function (err, stream) { fileio.fdopenStream(fd, "r+", function (err, stream) {
...@@ -2172,17 +2371,20 @@ Synchronously opens a stream based on the file descriptor. ...@@ -2172,17 +2371,20 @@ Synchronously opens a stream based on the file descriptor.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ---------------------------------------- | | ---- | ------ | ---- | ---------------------------------------- |
| fd | number | Yes | File descriptor of the target file. | | fd | number | Yes | File descriptor of the target file. |
| mode | string | Yes | -&nbsp;**r**: Open a file for reading. The file must exist.<br>-&nbsp;**r+**: Open a file for both reading and writing. The file must exist.<br>-&nbsp;**w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.<br>-&nbsp;**w+**: Open a file for both reading and writing. If the file exists, clear its content. If the file does not exist, create a file.<br>-&nbsp;**a**: Open a file in append mode for writing at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).<br>-&nbsp;**a+**: Open a file in append mode for reading or updating at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).| | mode | string | Yes | -&nbsp;**r**: Open a file for reading. The file must exist.<br>-&nbsp;**r+**: Open a file for both reading and writing. The file must exist.<br>-&nbsp;**w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.<br>-&nbsp;**w+**: Open a file for both reading and writing. If the file exists, clear its content. If the file does not exist, create a file.<br>-&nbsp;**a**: Open a file in append mode for writing at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).<br>-&nbsp;**a+**: Open a file in append mode for reading or updating at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------ | --------- | | ------------------ | --------- |
| [Stream](#stream7) | Stream opened.| | [Stream](#stream7) | Stream opened.|
**Example** **Example**
```js ```js
let fd = fileio.openSync(path); let fd = fileio.openSync(path);
let ss = fileio.fdopenStreamSync(fd, "r+"); let ss = fileio.fdopenStreamSync(fd, "r+");
...@@ -2198,6 +2400,7 @@ Changes the file owner based on the file descriptor. This API uses a promise to ...@@ -2198,6 +2400,7 @@ Changes the file owner based on the file descriptor. This API uses a promise to
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ------------ | | ---- | ------ | ---- | ------------ |
| fd | number | Yes | File descriptor of the target file.| | fd | number | Yes | File descriptor of the target file.|
...@@ -2205,11 +2408,13 @@ Changes the file owner based on the file descriptor. This API uses a promise to ...@@ -2205,11 +2408,13 @@ Changes the file owner based on the file descriptor. This API uses a promise to
| gid | number | Yes | New GID. | | gid | number | Yes | New GID. |
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
```js ```js
let stat = fileio.statSync(path); let stat = fileio.statSync(path);
fileio.fchown(fd, stat.uid, stat.gid).then(function() { fileio.fchown(fd, stat.uid, stat.gid).then(function() {
...@@ -2229,6 +2434,7 @@ Changes the file owner based on the file descriptor. This API uses an asynchrono ...@@ -2229,6 +2434,7 @@ Changes the file owner based on the file descriptor. This API uses an asynchrono
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | --------------- | | -------- | ------------------------- | ---- | --------------- |
| fd | number | Yes | File descriptor of the target file. | | fd | number | Yes | File descriptor of the target file. |
...@@ -2237,6 +2443,7 @@ Changes the file owner based on the file descriptor. This API uses an asynchrono ...@@ -2237,6 +2443,7 @@ Changes the file owner based on the file descriptor. This API uses an asynchrono
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file owner is changed asynchronously.| | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file owner is changed asynchronously.|
**Example** **Example**
```js ```js
let stat = fileio.statSync(path); let stat = fileio.statSync(path);
fileio.fchown(fd, stat.uid, stat.gid, function (err){ fileio.fchown(fd, stat.uid, stat.gid, function (err){
...@@ -2254,6 +2461,7 @@ Synchronously changes the file owner based on the file descriptor. ...@@ -2254,6 +2461,7 @@ Synchronously changes the file owner based on the file descriptor.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ------------ | | ---- | ------ | ---- | ------------ |
| fd | number | Yes | File descriptor of the target file.| | fd | number | Yes | File descriptor of the target file.|
...@@ -2261,6 +2469,7 @@ Synchronously changes the file owner based on the file descriptor. ...@@ -2261,6 +2469,7 @@ Synchronously changes the file owner based on the file descriptor.
| gid | number | Yes | New GID. | | gid | number | Yes | New GID. |
**Example** **Example**
```js ```js
let stat = fileio.statSync(path); let stat = fileio.statSync(path);
fileio.fchownSync(fd, stat.uid, stat.gid); fileio.fchownSync(fd, stat.uid, stat.gid);
...@@ -2276,6 +2485,7 @@ Changes the file owner (owner of the symbolic link, not the file referred to by ...@@ -2276,6 +2485,7 @@ Changes the file owner (owner of the symbolic link, not the file referred to by
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------ | ---- | -------------------------- | | ------ | ------ | ---- | -------------------------- |
| path | string | Yes | Application sandbox path of the file.| | path | string | Yes | Application sandbox path of the file.|
...@@ -2283,11 +2493,13 @@ Changes the file owner (owner of the symbolic link, not the file referred to by ...@@ -2283,11 +2493,13 @@ Changes the file owner (owner of the symbolic link, not the file referred to by
| gid | number | Yes | New GID. | | gid | number | Yes | New GID. |
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
```js ```js
let stat = fileio.statSync(path); let stat = fileio.statSync(path);
fileio.lchown(path, stat.uid, stat.gid).then(function() { fileio.lchown(path, stat.uid, stat.gid).then(function() {
...@@ -2307,6 +2519,7 @@ Changes the file owner (owner of the symbolic link, not the file referred to by ...@@ -2307,6 +2519,7 @@ Changes the file owner (owner of the symbolic link, not the file referred to by
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ------------------------------ | | -------- | ------------------------- | ---- | ------------------------------ |
| path | string | Yes | Application sandbox path of the file. | | path | string | Yes | Application sandbox path of the file. |
...@@ -2315,6 +2528,7 @@ Changes the file owner (owner of the symbolic link, not the file referred to by ...@@ -2315,6 +2528,7 @@ Changes the file owner (owner of the symbolic link, not the file referred to by
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file owner is changed asynchronously.| | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file owner is changed asynchronously.|
**Example** **Example**
```js ```js
let stat = fileio.statSync(path); let stat = fileio.statSync(path);
fileio.lchown(path, stat.uid, stat.gid, function (err){ fileio.lchown(path, stat.uid, stat.gid, function (err){
...@@ -2332,6 +2546,7 @@ Synchronously changes the file owner based on the file path and changes the owne ...@@ -2332,6 +2546,7 @@ Synchronously changes the file owner based on the file path and changes the owne
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------ | ---- | -------------------------- | | ------ | ------ | ---- | -------------------------- |
| path | string | Yes | Application sandbox path of the file.| | path | string | Yes | Application sandbox path of the file.|
...@@ -2339,6 +2554,7 @@ Synchronously changes the file owner based on the file path and changes the owne ...@@ -2339,6 +2554,7 @@ Synchronously changes the file owner based on the file path and changes the owne
| gid | number | Yes | New GID. | | gid | number | Yes | New GID. |
**Example** **Example**
```js ```js
let stat = fileio.statSync(path); let stat = fileio.statSync(path);
fileio.lchownSync(path, stat.uid, stat.gid); fileio.lchownSync(path, stat.uid, stat.gid);
...@@ -2354,6 +2570,7 @@ Listens for file or directory changes. This API uses an asynchronous callback to ...@@ -2354,6 +2570,7 @@ Listens for file or directory changes. This API uses an asynchronous callback to
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | --------------------------------- | ---- | ------------------------------------------------------------ | | -------- | --------------------------------- | ---- | ------------------------------------------------------------ |
| filename | string | Yes | Application sandbox path of the file. | | filename | string | Yes | Application sandbox path of the file. |
...@@ -2361,11 +2578,13 @@ Listens for file or directory changes. This API uses an asynchronous callback to ...@@ -2361,11 +2578,13 @@ Listens for file or directory changes. This API uses an asynchronous callback to
| callback | AsyncCallback&lt;number&nbsp;&gt; | Yes | Called each time a change is detected. | | callback | AsyncCallback&lt;number&nbsp;&gt; | Yes | Called each time a change is detected. |
**Return value** **Return value**
| Type | Description | | Type | Description |
| -------------------- | ---------- | | -------------------- | ---------- |
| [Watcher](#watcher7) | Promise used to return the **Watcher** instance.| | [Watcher](#watcher7) | Promise used to return the **Watcher** instance.|
**Example** **Example**
```js ```js
let filename = path +"/test.txt"; let filename = path +"/test.txt";
fileio.createWatcher(filename, 1, function(number){ fileio.createWatcher(filename, 1, function(number){
...@@ -2421,11 +2640,13 @@ Checks whether this file is a block special file. A block special file supports ...@@ -2421,11 +2640,13 @@ Checks whether this file is a block special file. A block special file supports
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------- | ---------------- | | ------- | ---------------- |
| boolean | Whether the file is a block special file.| | boolean | Whether the file is a block special file.|
**Example** **Example**
```js ```js
let isBLockDevice = fileio.statSync(path).isBlockDevice(); let isBLockDevice = fileio.statSync(path).isBlockDevice();
``` ```
...@@ -2440,11 +2661,13 @@ Checks whether this file is a character special file. A character special file s ...@@ -2440,11 +2661,13 @@ Checks whether this file is a character special file. A character special file s
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------- | ----------------- | | ------- | ----------------- |
| boolean | Whether the file is a character special file.| | boolean | Whether the file is a character special file.|
**Example** **Example**
```js ```js
let isCharacterDevice = fileio.statSync(path).isCharacterDevice(); let isCharacterDevice = fileio.statSync(path).isCharacterDevice();
``` ```
...@@ -2459,11 +2682,13 @@ Checks whether this file is a directory. ...@@ -2459,11 +2682,13 @@ Checks whether this file is a directory.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------- | ------------- | | ------- | ------------- |
| boolean | Whether the file is a directory.| | boolean | Whether the file is a directory.|
**Example** **Example**
```js ```js
let isDirectory = fileio.statSync(path).isDirectory(); let isDirectory = fileio.statSync(path).isDirectory();
``` ```
...@@ -2478,11 +2703,13 @@ Checks whether this file is a named pipe (or FIFO). Named pipes are used for int ...@@ -2478,11 +2703,13 @@ Checks whether this file is a named pipe (or FIFO). Named pipes are used for int
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------- | --------------------- | | ------- | --------------------- |
| boolean | Whether the file is an FIFO.| | boolean | Whether the file is an FIFO.|
**Example** **Example**
```js ```js
let isFIFO = fileio.statSync(path).isFIFO(); let isFIFO = fileio.statSync(path).isFIFO();
``` ```
...@@ -2497,11 +2724,13 @@ Checks whether this file is a regular file. ...@@ -2497,11 +2724,13 @@ Checks whether this file is a regular file.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------- | --------------- | | ------- | --------------- |
| boolean | Whether the file is a regular file.| | boolean | Whether the file is a regular file.|
**Example** **Example**
```js ```js
let isFile = fileio.statSync(path).isFile(); let isFile = fileio.statSync(path).isFile();
``` ```
...@@ -2516,11 +2745,13 @@ Checks whether this file is a socket. ...@@ -2516,11 +2745,13 @@ Checks whether this file is a socket.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------- | -------------- | | ------- | -------------- |
| boolean | Whether the file is a socket.| | boolean | Whether the file is a socket.|
**Example** **Example**
```js ```js
let isSocket = fileio.statSync(path).isSocket(); let isSocket = fileio.statSync(path).isSocket();
``` ```
...@@ -2535,11 +2766,13 @@ Checks whether this file is a symbolic link. ...@@ -2535,11 +2766,13 @@ Checks whether this file is a symbolic link.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------- | --------------- | | ------- | --------------- |
| boolean | Whether the file is a symbolic link.| | boolean | Whether the file is a symbolic link.|
**Example** **Example**
```js ```js
let isSymbolicLink = fileio.statSync(path).isSymbolicLink(); let isSymbolicLink = fileio.statSync(path).isSymbolicLink();
``` ```
...@@ -2559,6 +2792,7 @@ Stops the **watcher** instance. This API uses a promise to return the result. ...@@ -2559,6 +2792,7 @@ Stops the **watcher** instance. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Example** **Example**
```js ```js
let filename = path +"/test.txt"; let filename = path +"/test.txt";
let watcher = await fileio.createWatcher(filename, 1, function(number){ let watcher = await fileio.createWatcher(filename, 1, function(number){
...@@ -2579,11 +2813,13 @@ Stops the **watcher** instance. This API uses an asynchronous callback to return ...@@ -2579,11 +2813,13 @@ Stops the **watcher** instance. This API uses an asynchronous callback to return
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | ---------------------- | | -------- | ------------------------- | ---- | ---------------------- |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when **watcher** is stopped asynchronously.| | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when **watcher** is stopped asynchronously.|
**Example** **Example**
```js ```js
let filename = path +"/test.txt"; let filename = path +"/test.txt";
let watcher = await fileio.createWatcher(filename, 1, function(number){ let watcher = await fileio.createWatcher(filename, 1, function(number){
...@@ -2608,11 +2844,13 @@ Closes the stream. This API uses a promise to return the result. ...@@ -2608,11 +2844,13 @@ Closes the stream. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ------------- | | ------------------- | ------------- |
| Promise&lt;void&gt; | Promise used to return the stream close result.| | Promise&lt;void&gt; | Promise used to return the stream close result.|
**Example** **Example**
```js ```js
let ss= fileio.createStreamSync(path, "r+"); let ss= fileio.createStreamSync(path, "r+");
ss.close().then(function(){ ss.close().then(function(){
...@@ -2632,11 +2870,13 @@ Closes the stream. This API uses an asynchronous callback to return the result. ...@@ -2632,11 +2870,13 @@ Closes the stream. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | ------------- | | -------- | ------------------------- | ---- | ------------- |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the stream is closed asynchronously.| | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the stream is closed asynchronously.|
**Example** **Example**
```js ```js
let ss= fileio.createStreamSync(path, "r+"); let ss= fileio.createStreamSync(path, "r+");
ss.close(function (err) { ss.close(function (err) {
...@@ -2654,6 +2894,7 @@ Synchronously closes the stream. ...@@ -2654,6 +2894,7 @@ Synchronously closes the stream.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Example** **Example**
```js ```js
let ss= fileio.createStreamSync(path, "r+"); let ss= fileio.createStreamSync(path, "r+");
ss.closeSync(); ss.closeSync();
...@@ -2669,11 +2910,13 @@ Flushes the stream. This API uses a promise to return the result. ...@@ -2669,11 +2910,13 @@ Flushes the stream. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ------------- | | ------------------- | ------------- |
| Promise&lt;void&gt; | Promise used to return the stream flushing result.| | Promise&lt;void&gt; | Promise used to return the stream flushing result.|
**Example** **Example**
```js ```js
let ss= fileio.createStreamSync(path, "r+"); let ss= fileio.createStreamSync(path, "r+");
ss.flush().then(function (){ ss.flush().then(function (){
...@@ -2693,11 +2936,13 @@ Flushes the stream. This API uses an asynchronous callback to return the result. ...@@ -2693,11 +2936,13 @@ Flushes the stream. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | -------------- | | -------- | ------------------------- | ---- | -------------- |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the stream is asynchronously flushed.| | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the stream is asynchronously flushed.|
**Example** **Example**
```js ```js
let ss= fileio.createStreamSync(path, "r+"); let ss= fileio.createStreamSync(path, "r+");
ss.flush(function (err) { ss.flush(function (err) {
...@@ -2715,6 +2960,7 @@ Synchronously flushes the stream. ...@@ -2715,6 +2960,7 @@ Synchronously flushes the stream.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Example** **Example**
```js ```js
let ss= fileio.createStreamSync(path, "r+"); let ss= fileio.createStreamSync(path, "r+");
ss.flushSync(); ss.flushSync();
...@@ -2735,23 +2981,26 @@ Writes data into the stream. This API uses a promise to return the result. ...@@ -2735,23 +2981,26 @@ Writes data into the stream. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------- | ------------------------------- | ---- | ---------------------------------------- | | ------- | ------------------------------- | ---- | ---------------------------------------- |
| buffer | ArrayBuffer&nbsp;\|&nbsp;string | Yes | Data to write. It can be a string or data from a buffer. | | buffer | ArrayBuffer&nbsp;\|&nbsp;string | Yes | Data to write. It can be a string or data from a buffer. |
| options | Object | No | The options are as follows:<br>-&nbsp;**offset** (number): position of the data to write in reference to the start address of the data. The default value is **0**.<br>-&nbsp;**length** (number): length of the data to write. The default value is the buffer length minus the offset.<br>-&nbsp;**position** (number): start position to write the data in the file. By default, data is written from the current position.<br>-&nbsp;**encoding** (string): format of the string to be encoded. The default value is **utf-8**, which is the only value supported.<br>Constraints: offset + length <= Buffer size | | options | Object | No | The options are as follows:<br>-&nbsp;**offset** (number): position of the data to write in reference to the start address of the data. The default value is **0**.<br>-&nbsp;**length** (number): length of the data to write. The default value is the buffer length minus the offset.<br>-&nbsp;**position** (number): start position to write the data in the file. By default, data is written from the current position.<br>-&nbsp;**encoding** (string): format of the string to be encoded. The default value is **utf-8**, which is the only value supported.<br>Constraints: offset + length <= Buffer size |
**Return value** **Return value**
| Type | Description | | Type | Description |
| --------------------- | -------- | | --------------------- | -------- |
| Promise&lt;number&gt; | Promise used to return the length of the data written.| | Promise&lt;number&gt; | Promise used to return the length of the data written.|
**Example** **Example**
```js ```js
let ss= fileio.createStreamSync(path, "r+"); let ss= fileio.createStreamSync(path, "r+");
ss.write("hello, world",{offset: 1,length: 5,position: 5,encoding :'utf-8'}).then(function (number){ ss.write("hello, world",{offset: 1,length: 5,position: 5,encoding :'utf-8'}).then(function (number){
console.info("Data written to the stream and size is:"+ number); console.info("Data written to the stream. Size is:"+ number);
}).catch(function(err){ }).catch(function(err){
console.info("Failed to write data into the stream. Error:"+ err); console.info("Failed to write data to the stream. Error:"+ err);
}); });
``` ```
...@@ -2770,6 +3019,7 @@ Writes data into the stream. This API uses an asynchronous callback to return th ...@@ -2770,6 +3019,7 @@ Writes data into the stream. This API uses an asynchronous callback to return th
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------------- | ---- | ------------------------------------------------------------ | | -------- | ------------------------------- | ---- | ------------------------------------------------------------ |
| buffer | ArrayBuffer&nbsp;\|&nbsp;string | Yes | Data to write. It can be a string or data from a buffer. | | buffer | ArrayBuffer&nbsp;\|&nbsp;string | Yes | Data to write. It can be a string or data from a buffer. |
...@@ -2777,12 +3027,13 @@ Writes data into the stream. This API uses an asynchronous callback to return th ...@@ -2777,12 +3027,13 @@ Writes data into the stream. This API uses an asynchronous callback to return th
| callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked when the data is written asynchronously. | | callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked when the data is written asynchronously. |
**Example** **Example**
```js ```js
let ss= fileio.createStreamSync(path, "r+"); let ss= fileio.createStreamSync(path, "r+");
ss.write("hello, world", {offset: 1, length: 5, position: 5, encoding :'utf-8'}, function (err, bytesWritten) { ss.write("hello, world", {offset: 1, length: 5, position: 5, encoding :'utf-8'}, function (err, bytesWritten) {
if (bytesWritten) { if (bytesWritten) {
// Do something // Do something
console.info("Data written to the stream and size is:"+ bytesWritten); console.info("Data written to the stream. Size is:"+ bytesWritten);
} }
}); });
``` ```
...@@ -2802,17 +3053,20 @@ Synchronously writes data into the stream. ...@@ -2802,17 +3053,20 @@ Synchronously writes data into the stream.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------- | ------------------------------- | ---- | ---------------------------------------- | | ------- | ------------------------------- | ---- | ---------------------------------------- |
| buffer | ArrayBuffer&nbsp;\|&nbsp;string | Yes | Data to write. It can be a string or data from a buffer. | | buffer | ArrayBuffer&nbsp;\|&nbsp;string | Yes | Data to write. It can be a string or data from a buffer. |
| options | Object | No | The options are as follows:<br>-&nbsp;**offset** (number): position of the data to write in reference to the start address of the data. The default value is **0**.<br>-&nbsp;**length** (number): length of the data to write. The default value is the buffer length minus the offset.<br>-&nbsp;**position** (number): start position to write the data in the file. By default, data is written from the current position.<br>-&nbsp;**encoding** (string): format of the string to be encoded. The default value is **utf-8**, which is the only value supported.<br>Constraints: offset + length <= Buffer size | | options | Object | No | The options are as follows:<br>-&nbsp;**offset** (number): position of the data to write in reference to the start address of the data. The default value is **0**.<br>-&nbsp;**length** (number): length of the data to write. The default value is the buffer length minus the offset.<br>-&nbsp;**position** (number): start position to write the data in the file. By default, data is written from the current position.<br>-&nbsp;**encoding** (string): format of the string to be encoded. The default value is **utf-8**, which is the only value supported.<br>Constraints: offset + length <= Buffer size |
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------ | -------- | | ------ | -------- |
| number | Length of the data written in the file.| | number | Length of the data written in the file.|
**Example** **Example**
```js ```js
let ss= fileio.createStreamSync(path,"r+"); let ss= fileio.createStreamSync(path,"r+");
let num = ss.writeSync("hello, world", {offset: 1, length: 5, position: 5, encoding :'utf-8'}); let num = ss.writeSync("hello, world", {offset: 1, length: 5, position: 5, encoding :'utf-8'});
...@@ -2832,17 +3086,20 @@ Reads data from the stream. This API uses a promise to return the result. ...@@ -2832,17 +3086,20 @@ Reads data from the stream. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------- | ----------- | ---- | ---------------------------------------- | | ------- | ----------- | ---- | ---------------------------------------- |
| buffer | ArrayBuffer | Yes | Buffer used to store the file read. | | buffer | ArrayBuffer | Yes | Buffer used to store the file read. |
| options | Object | No | The options are as follows:<br>-&nbsp;**offset** (number): position to store the data read in the buffer in reference to the start address of the buffer. The default value is **0**.<br>-&nbsp;**length** (number): length of the data to read. The default value is the buffer length minus the offset.<br>-&nbsp;**position** (number): position of the data to read in the file. By default, data is read from the current position.<br>Constraints: offset + length <= Buffer size | | options | Object | No | The options are as follows:<br>-&nbsp;**offset** (number): position to store the data read in the buffer in reference to the start address of the buffer. The default value is **0**.<br>-&nbsp;**length** (number): length of the data to read. The default value is the buffer length minus the offset.<br>-&nbsp;**position** (number): position of the data to read in the file. By default, data is read from the current position.<br>Constraints: offset + length <= Buffer size |
**Return value** **Return value**
| Type | Description | | Type | Description |
| ---------------------------------- | ------ | | ---------------------------------- | ------ |
| Promise&lt;[ReadOut](#readout)&gt; | Promise used to return the data read.| | Promise&lt;[ReadOut](#readout)&gt; | Promise used to return the data read.|
**Example** **Example**
```js ```js
let ss = fileio.createStreamSync(path, "r+"); let ss = fileio.createStreamSync(path, "r+");
ss.read(new ArrayBuffer(4096), {offset: 1, length: 5, position: 5}).then(function (readout){ ss.read(new ArrayBuffer(4096), {offset: 1, length: 5, position: 5}).then(function (readout){
...@@ -2867,6 +3124,7 @@ Reads data from the stream. This API uses an asynchronous callback to return the ...@@ -2867,6 +3124,7 @@ Reads data from the stream. This API uses an asynchronous callback to return the
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- | | -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| buffer | ArrayBuffer | Yes | Buffer used to store the file read. | | buffer | ArrayBuffer | Yes | Buffer used to store the file read. |
...@@ -2874,6 +3132,7 @@ Reads data from the stream. This API uses an asynchronous callback to return the ...@@ -2874,6 +3132,7 @@ Reads data from the stream. This API uses an asynchronous callback to return the
| callback | AsyncCallback&lt;[ReadOut](#readout)&gt; | Yes | Callback invoked when data is read asynchronously from the stream. | | callback | AsyncCallback&lt;[ReadOut](#readout)&gt; | Yes | Callback invoked when data is read asynchronously from the stream. |
**Example** **Example**
```js ```js
let ss = fileio.createStreamSync(path, "r+"); let ss = fileio.createStreamSync(path, "r+");
ss.read(new ArrayBuffer(4096),{offset: 1, length: 5, position: 5},function (err, readOut) { ss.read(new ArrayBuffer(4096),{offset: 1, length: 5, position: 5},function (err, readOut) {
...@@ -2911,6 +3170,7 @@ Synchronously reads data from the stream. ...@@ -2911,6 +3170,7 @@ Synchronously reads data from the stream.
| number | Length of the data read.| | number | Length of the data read.|
**Example** **Example**
```js ```js
let ss = fileio.createStreamSync(path, "r+"); let ss = fileio.createStreamSync(path, "r+");
let num = ss.readSync(new ArrayBuffer(4096), {offset: 1, length: 5, position: 5}); let num = ss.readSync(new ArrayBuffer(4096), {offset: 1, length: 5, position: 5});
...@@ -2931,17 +3191,19 @@ Reads the next directory entry. This API uses a promise to return the result. ...@@ -2931,17 +3191,19 @@ Reads the next directory entry. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Return value** **Return value**
| Type | Description | | Type | Description |
| -------------------------------- | ------------- | | -------------------------------- | ------------- |
| Promise&lt;[Dirent](#dirent)&gt; | Promise used to return the directory entry read.| | Promise&lt;[Dirent](#dirent)&gt; | Promise used to return the directory entry read.|
**Example** **Example**
```js ```js
let dir = fileio.opendirSync(path); let dir = fileio.opendirSync(path);
dir.read().then(function (dirent){ dir.read().then(function (dirent){
console.log("Read the next directory entry:"+JSON.stringify(dirent)); console.log("Read the next directory entry:"+JSON.stringify(dirent));
}).catch(function(err){ }).catch(function(err){
console.info("Failed to read data. Error:"+ err); console.info("Failed to read the next directory entry. Error:"+ err);
}); });
``` ```
...@@ -2955,11 +3217,13 @@ Reads the next directory entry. This API uses an asynchronous callback to return ...@@ -2955,11 +3217,13 @@ Reads the next directory entry. This API uses an asynchronous callback to return
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | -------------------------------------- | ---- | ---------------- | | -------- | -------------------------------------- | ---- | ---------------- |
| callback | AsyncCallback&lt;[Dirent](#dirent)&gt; | Yes | Callback invoked when the next directory entry is asynchronously read.| | callback | AsyncCallback&lt;[Dirent](#dirent)&gt; | Yes | Callback invoked when the next directory entry is asynchronously read.|
**Example** **Example**
```js ```js
let dir = fileio.opendirSync(path); let dir = fileio.opendirSync(path);
dir.read(function (err, dirent) { dir.read(function (err, dirent) {
...@@ -2980,11 +3244,13 @@ Synchronously reads the next directory entry. ...@@ -2980,11 +3244,13 @@ Synchronously reads the next directory entry.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Return value** **Return value**
| Type | Description | | Type | Description |
| ----------------- | -------- | | ----------------- | -------- |
| [Dirent](#dirent) | Directory entry read.| | [Dirent](#dirent) | Directory entry read.|
**Example** **Example**
```js ```js
let dir = fileio.opendirSync(path); let dir = fileio.opendirSync(path);
let dirent = dir.readSync(); let dirent = dir.readSync();
...@@ -3000,6 +3266,7 @@ Closes a directory. This API uses a promise to return the result. After a direct ...@@ -3000,6 +3266,7 @@ Closes a directory. This API uses a promise to return the result. After a direct
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Example** **Example**
```js ```js
let dir = fileio.opendirSync(path); let dir = fileio.opendirSync(path);
dir.close().then(function(err){ dir.close().then(function(err){
...@@ -3017,6 +3284,7 @@ Closes a directory. This API uses an asynchronous callback to return the result. ...@@ -3017,6 +3284,7 @@ Closes a directory. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Example** **Example**
```js ```js
let dir = fileio.opendirSync(path); let dir = fileio.opendirSync(path);
dir.close(function(err){ dir.close(function(err){
...@@ -3034,6 +3302,7 @@ Closes a directory. After a directory is closed, the file descriptor in Dir will ...@@ -3034,6 +3302,7 @@ Closes a directory. After a directory is closed, the file descriptor in Dir will
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Example** **Example**
```js ```js
let dir = fileio.opendirSync(path); let dir = fileio.opendirSync(path);
dir.closeSync(); dir.closeSync();
...@@ -3062,11 +3331,13 @@ Checks whether this directory entry is a block special file. A block special fil ...@@ -3062,11 +3331,13 @@ Checks whether this directory entry is a block special file. A block special fil
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------- | ---------------- | | ------- | ---------------- |
| boolean | Whether the directory entry is a block special file.| | boolean | Whether the directory entry is a block special file.|
**Example** **Example**
```js ```js
let dir = fileio.opendirSync(path); let dir = fileio.opendirSync(path);
let isBLockDevice = dir.readSync().isBlockDevice(); let isBLockDevice = dir.readSync().isBlockDevice();
...@@ -3082,11 +3353,13 @@ Checks whether a directory entry is a character special file. A character specia ...@@ -3082,11 +3353,13 @@ Checks whether a directory entry is a character special file. A character specia
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------- | ----------------- | | ------- | ----------------- |
| boolean | Whether the directory entry is a character special file.| | boolean | Whether the directory entry is a character special file.|
**Example** **Example**
```js ```js
let dir = fileio.opendirSync(path); let dir = fileio.opendirSync(path);
let isCharacterDevice = dir.readSync().isCharacterDevice(); let isCharacterDevice = dir.readSync().isCharacterDevice();
...@@ -3102,11 +3375,13 @@ Checks whether a directory entry is a directory. ...@@ -3102,11 +3375,13 @@ Checks whether a directory entry is a directory.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------- | ------------- | | ------- | ------------- |
| boolean | Whether the directory entry is a directory.| | boolean | Whether the directory entry is a directory.|
**Example** **Example**
```js ```js
let dir = fileio.opendirSync(path); let dir = fileio.opendirSync(path);
let isDirectory = dir.readSync().isDirectory(); let isDirectory = dir.readSync().isDirectory();
...@@ -3122,11 +3397,13 @@ Checks whether this directory entry is a named pipe (or FIFO). Named pipes are u ...@@ -3122,11 +3397,13 @@ Checks whether this directory entry is a named pipe (or FIFO). Named pipes are u
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------- | --------------- | | ------- | --------------- |
| boolean | Whether the directory entry is a FIFO.| | boolean | Whether the directory entry is a FIFO.|
**Example** **Example**
```js ```js
let dir = fileio.opendirSync(path); let dir = fileio.opendirSync(path);
let isFIFO = dir.readSync().isFIFO(); let isFIFO = dir.readSync().isFIFO();
...@@ -3142,11 +3419,13 @@ Checks whether a directory entry is a regular file. ...@@ -3142,11 +3419,13 @@ Checks whether a directory entry is a regular file.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------- | --------------- | | ------- | --------------- |
| boolean | Whether the directory entry is a regular file.| | boolean | Whether the directory entry is a regular file.|
**Example** **Example**
```js ```js
let dir = fileio.opendirSync(path); let dir = fileio.opendirSync(path);
let isFile = dir.readSync().isFile(); let isFile = dir.readSync().isFile();
...@@ -3162,11 +3441,13 @@ Checks whether a directory entry is a socket. ...@@ -3162,11 +3441,13 @@ Checks whether a directory entry is a socket.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------- | -------------- | | ------- | -------------- |
| boolean | Whether the directory entry is a socket.| | boolean | Whether the directory entry is a socket.|
**Example** **Example**
```js ```js
let dir = fileio.opendirSync(dpath); let dir = fileio.opendirSync(dpath);
let isSocket = dir.readSync().isSocket(); let isSocket = dir.readSync().isSocket();
...@@ -3182,11 +3463,13 @@ Checks whether a directory entry is a symbolic link. ...@@ -3182,11 +3463,13 @@ Checks whether a directory entry is a symbolic link.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------- | --------------- | | ------- | --------------- |
| boolean | Whether the directory entry is a symbolic link.| | boolean | Whether the directory entry is a symbolic link.|
**Example** **Example**
```js ```js
let dir = fileio.opendirSync(path); let dir = fileio.opendirSync(path);
let isSymbolicLink = dir.readSync().isSymbolicLink(); let isSymbolicLink = dir.readSync().isSymbolicLink();
......
# User File Access and Management # User File Access and Management
The fileManager module provides APIs for accessing and managing user files. It interworks with the underlying file management services to implement media library and external card management, and provides capabilities for applications to query and create user files.
>**NOTE**<br/> >**NOTE**<br/>
> >
>- The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. >- The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
>- The APIs of this module are system APIs and cannot be called by third-party applications. Currently, these APIs can be called only by **filepicker**. >- The APIs of this module are system APIs and cannot be called by third-party applications. Currently, these APIs can be called only by **filepicker**.
Provides service APIs for accessing and managing user files. It interworks with the underlying file management services to implement media library and external card management, and provides capabilities for applications to query and create user files.
## Modules to Import ## Modules to Import
```js ```js
......
# Security Label # Security Label
The secuityLabel module provides APIs to manage file data security levels, including obtaining and setting file data security levels.
> **NOTE**<br/> > **NOTE**<br/>
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
Manages file data security levels, including obtaining and setting file data security levels.
## Modules to Import ## Modules to Import
```js ```js
......
# statfs # statfs
> **NOTE:**<br> The statfs module provides APIs for obtaining file system information, including the total number of bytes and the number of idle bytes of the file system.
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
This module provides information related to the file system. It provides JS APIs to obtain the total number of bytes and the number of idle bytes of the file system. > **NOTE**<br>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import ## Modules to Import
```js ```js
import statfs from '@ohos.statfs'; import statfs from '@ohos.statfs';
``` ```
## Guidelines
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).
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 application sandbox path of the file is as follows:
```js
let path = dir + "xxx.txt";
```
## statfs.getFreeBytes ## statfs.getFreeBytes
getFreeBytes(path:string):Promise&lt;number&gt; getFreeBytes(path:string):Promise&lt;number&gt;
...@@ -72,8 +59,12 @@ Obtains the number of free bytes of the specified file system in asynchronous mo ...@@ -72,8 +59,12 @@ Obtains the number of free bytes of the specified file system in asynchronous mo
- Example - Example
```js ```js
import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext();
context.getFilesDir().then(function (path) {
statfs.getFreeBytes(path, function(err, number){ statfs.getFreeBytes(path, function(err, number){
console.info("getFreeBytes callback successfully:"+ number); console.info("Got free bytes successfully:"+ number);
});
}); });
``` ```
...@@ -126,7 +117,11 @@ Obtains the total number of bytes of the specified file system in asynchronous m ...@@ -126,7 +117,11 @@ Obtains the total number of bytes of the specified file system in asynchronous m
- Example - Example
```js ```js
import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext();
context.getFilesDir().then(function (path) {
statfs.getTotalBytes(path, function(err, number){ statfs.getTotalBytes(path, function(err, number){
console.info("getTotalBytes callback successfully:"+ number); console.info("Got total bytes successfully:"+ number);
});
}); });
``` ```
# App Storage Statistics # App Storage Statistics
The storageStatistics module provides APIs for obtaining storage space information, including the space of built-in and plug-in memory cards, space occupied by different types of data, and space of application data.
> **NOTE**<br/> > **NOTE**<br/>
> >
> - The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. > - The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> - API version 9 is a canary version for trial use. The APIs of this version may be unstable. > - API version 9 is a canary version for trial use. The APIs of this version may be unstable.
Obtains storage space information, including the space of built-in and plug-in memory cards, space occupied by different types of data, and space of application data.
## Modules to Import ## Modules to Import
```js ```js
......
# File Storage # File Storage
> **NOTE**<br>
> - The APIs of this module are no longer maintained since API version 6. You are advised to use [`@ohos.fileio`](js-apis-fileio.md).
> ![icon-note.gif](public_sys-resources/icon-note.gif) **Note:**
> - The APIs of this module are no longer maintained since API version 6. It is recommended that you use [`@ohos.fileio`](js-apis-fileio.md) instead.
> >
> - The initial APIs of this module are supported since API version 3. Newly added APIs will be marked with a superscript to indicate their earliest API version. > - The initial APIs of this module are supported since API version 3. Newly added APIs will be marked with a superscript to indicate their earliest API version.
...@@ -26,21 +24,21 @@ Moves a specified file to a given location. ...@@ -26,21 +24,21 @@ Moves a specified file to a given location.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| srcUri | string | Yes | URI&nbsp;of&nbsp;the&nbsp;file&nbsp;to&nbsp;move. | | srcUri | string | Yes| Uniform resource identifier (URI) of the file to move. <br/>The URI can contain a maximum of 128 characters, excluding the following characters: "\*+,:;&lt;=&gt;?[]\|\x7F |
| dstUri | string | Yes | URI&nbsp;of&nbsp;the&nbsp;location&nbsp;to&nbsp;which&nbsp;the&nbsp;file&nbsp;is&nbsp;to&nbsp;move. | | dstUri | string | Yes| URI of the location to which the file is to move. <br/>The URI can contain a maximum of 128 characters, excluding the following characters: "\*+,:;&lt;=&gt;?[]\|\x7F |
| success | Function | No | Called&nbsp;when&nbsp;the&nbsp;source&nbsp;file&nbsp;is&nbsp;moved&nbsp;to&nbsp;the&nbsp;specified&nbsp;location&nbsp;successfully.&nbsp;This&nbsp;function&nbsp;returns&nbsp;the&nbsp;URI&nbsp;of&nbsp;the&nbsp;destination&nbsp;location. | | success | Function | No| Called when the file is moved to the specified location. This API returns the URI of the destination location.|
| fail | Function | No | Called&nbsp;when&nbsp;the&nbsp;operation&nbsp;fails. | | fail | Function | No| Called when the file fails to be moved.|
| complete | Function | No | Called&nbsp;when&nbsp;the&nbsp;execution&nbsp;is&nbsp;complete. | | complete | Function | No| Called when the execution is complete.|
One of the following error codes will be returned if the operation fails. **Return value of fail()**
| Error&nbsp;Code | Description | | Error Code| Description|
| -------- | -------- | | -------- | -------- |
| 202 | Invalid&nbsp;parameter. | | 202 | Incorrect parameters are detected.|
| 300 | I/O&nbsp;error. | | 300 | An I/O error occurs.|
| 301 | File&nbsp;or&nbsp;directory&nbsp;not&nbsp;exist. | | 301 | The file or directory does not exist.|
**Example** **Example**
...@@ -66,27 +64,27 @@ export default { ...@@ -66,27 +64,27 @@ export default {
copy(Object): void copy(Object): void
Copies a file and saves the copy to a specified location. Copies a file to the given URI.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| srcUri | string | Yes | URI&nbsp;of&nbsp;the&nbsp;file&nbsp;to&nbsp;copy. | | srcUri | string | Yes| URI of the file to copy.|
| dstUri | string | Yes | URI&nbsp;of&nbsp;the&nbsp;location&nbsp;to&nbsp;which&nbsp;the&nbsp;copy&nbsp;is&nbsp;to&nbsp;save.<br>The&nbsp;directory&nbsp;of&nbsp;application&nbsp;resources&nbsp;and&nbsp;URI&nbsp;of&nbsp;the&nbsp;**tmp**&nbsp;type&nbsp;are&nbsp;not&nbsp;supported. | | dstUri | string | Yes| URI of the location to which the copy is to be saved.<br>The directory of application resources and URI of the **tmp** type are not supported.|
| success | Function | No | Called&nbsp;when&nbsp;the&nbsp;source&nbsp;file&nbsp;is&nbsp;copied&nbsp;and&nbsp;saved&nbsp;to&nbsp;the&nbsp;specified&nbsp;location&nbsp;successfully.&nbsp;This&nbsp;function&nbsp;returns&nbsp;the&nbsp;URI&nbsp;of&nbsp;the&nbsp;destination&nbsp;location. | | success | Function | No| Called when the file is copied and saved to the specified location. This API returns the URI of the destination location.|
| fail | Function | No | Called&nbsp;when&nbsp;the&nbsp;operation&nbsp;fails. | | fail | Function | No| Called when the file fails to be copied.|
| complete | Function | No | Called&nbsp;when&nbsp;the&nbsp;execution&nbsp;is&nbsp;complete. | | complete | Function | No| Called when the execution is complete.|
One of the following error codes will be returned if the operation fails. **Return value of fail()**
| Error&nbsp;Code | Description | | Error Code| Description|
| -------- | -------- | | -------- | -------- |
| 202 | Invalid&nbsp;parameter. | | 202 | Incorrect parameters are detected.|
| 300 | I/O&nbsp;error. | | 300 | An I/O error occurs.|
| 301 | File&nbsp;or&nbsp;directory&nbsp;not&nbsp;exist. | | 301 | The file or directory does not exist.|
**Example** **Example**
...@@ -112,41 +110,41 @@ export default { ...@@ -112,41 +110,41 @@ export default {
list(Object): void list(Object): void
Obtains the list of all files in a specified directory. Obtains all files in the specified directory.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| uri | string | Yes | URI&nbsp;of&nbsp;the&nbsp;directory. | | uri | string | Yes| URI of the directory. <br/>The URI can contain a maximum of 128 characters, excluding the following characters: "\*+,:;&lt;=&gt;?[]\|\x7F |
| success | Function | No | Called&nbsp;when&nbsp;the&nbsp;operation&nbsp;is&nbsp;successful. | | success | Function | No| Called when the file list is obtained.|
| fail | Function | No | Called&nbsp;when&nbsp;the&nbsp;operation&nbsp;fails. | | fail | Function | No| Called when the file list fails to be obtained.|
| complete | Function | No | Called&nbsp;when&nbsp;the&nbsp;execution&nbsp;is&nbsp;complete. | | complete | Function | No| Called when the execution is complete.|
Return values of the **success** callback **Return value of success()**
| Name | Type | Description | | Name| Type| Description|
| -------- | -------- | -------- | | -------- | -------- | -------- |
| fileList | Array&lt;FileInfo&gt; | File&nbsp;list.&nbsp;The&nbsp;format&nbsp;of&nbsp;each&nbsp;file&nbsp;is&nbsp;as&nbsp;follows:<br/>{<br/>uri:'file1',<br/>lastModifiedTime:1589965924479,<br/>length:10240,<br/>type:&nbsp;'file'<br/>} | | fileList | Array&lt;FileInfo&gt; | File list. The format of each file is as follows:<br>{<br>uri:'file1',<br>lastModifiedTime:1589965924479,<br>length:10240,<br>type:&nbsp;'file'<br>} |
**Table1** FileInfo **Table 1** FileInfo
| Name | Type | Description | | Name| Type| Description|
| -------- | -------- | -------- | | -------- | -------- | -------- |
| uri | string | File&nbsp;URI. | | uri | string | URI of the file.|
| lastModifiedTime | number | Timestamp&nbsp;when&nbsp;the&nbsp;file&nbsp;is&nbsp;stored&nbsp;the&nbsp;last&nbsp;time,&nbsp;which&nbsp;is&nbsp;the&nbsp;number&nbsp;of&nbsp;milliseconds&nbsp;elapsed&nbsp;since&nbsp;1970/01/01&nbsp;00:00:00&nbsp;GMT. | | lastModifiedTime | number | Timestamp when the file is saved the last time, which is the number of milliseconds elapsed since 1970/01/01 00:00:00 GMT.|
| length | number | File&nbsp;size,&nbsp;in&nbsp;bytes. | | length | number | File size, in bytes.|
| type | string | File&nbsp;type.&nbsp;Available&nbsp;values&nbsp;are&nbsp;as&nbsp;follows:<br/>-&nbsp;**dir**:&nbsp;directory<br/>-&nbsp;**file**:&nbsp;file | | type | string | File type. Available values are as follows:<br>- **dir**: directory<br>-&nbsp;**file**: file |
One of the following error codes will be returned if the operation fails. **Return value of fail()**
| Error&nbsp;Code | Description | | Error Code| Description|
| -------- | -------- | | -------- | -------- |
| 202 | Invalid&nbsp;parameter. | | 202 | Incorrect parameters are detected.|
| 300 | I/O&nbsp;error. | | 300 | An I/O error occurs.|
| 301 | File&nbsp;or&nbsp;directory&nbsp;not&nbsp;exist. | | 301 | The file or directory does not exist.|
**Example** **Example**
...@@ -156,7 +154,7 @@ export default { ...@@ -156,7 +154,7 @@ export default {
file.list({ file.list({
uri: 'internal://app/pic', uri: 'internal://app/pic',
success: function(data) { success: function(data) {
console.log(data.fileList); console.log(JSON.stringify(data.fileList));
}, },
fail: function(data, code) { fail: function(data, code) {
console.error('call fail callback fail, code: ' + code + ', data: ' + data); console.error('call fail callback fail, code: ' + code + ', data: ' + data);
...@@ -171,37 +169,37 @@ export default { ...@@ -171,37 +169,37 @@ export default {
get(Object): void get(Object): void
Obtains information about a specified local file. Obtains information about a local file.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| uri | string | Yes | File&nbsp;URI. | | uri | string | Yes| URI of the file.|
| recursive | boolean | No | Whether&nbsp;to&nbsp;recursively&nbsp;obtain&nbsp;the&nbsp;file&nbsp;list&nbsp;under&nbsp;a&nbsp;subdirectory.&nbsp;The&nbsp;default&nbsp;value&nbsp;is&nbsp;**false**. | | recursive | boolean | No| Whether to recursively obtain the file list under a subdirectory. The default value is **false**.|
| success | Function | No | Called&nbsp;when&nbsp;the&nbsp;operation&nbsp;is&nbsp;successful. | | success | Function | No| Called when the file information is obtained.|
| fail | Function | No | Called&nbsp;when&nbsp;the&nbsp;operation&nbsp;fails. | | fail | Function | No| Called when the file information fails to be obtained.|
| complete | Function | No | Called&nbsp;when&nbsp;the&nbsp;execution&nbsp;is&nbsp;complete. | | complete | Function | No| Called when the execution is complete.|
Return values of the **success** callback **Return value of success()**
| Name | Type | Description | | Name| Type| Description|
| -------- | -------- | -------- | | -------- | -------- | -------- |
| uri | string | File&nbsp;URI. | | uri | string | URI of the file.|
| length | number | File&nbsp;size,&nbsp;in&nbsp;bytes. | | length | number | File size, in bytes.|
| lastModifiedTime | number | Timestamp&nbsp;when&nbsp;the&nbsp;file&nbsp;is&nbsp;stored&nbsp;the&nbsp;last&nbsp;time,&nbsp;which&nbsp;is&nbsp;the&nbsp;number&nbsp;of&nbsp;milliseconds&nbsp;elapsed&nbsp;since&nbsp;1970/01/01&nbsp;00:00:00&nbsp;GMT. | | lastModifiedTime | number | Timestamp when the file is saved the last time, which is the number of milliseconds elapsed since 1970/01/01 00:00:00 GMT.|
| type | string | File&nbsp;type.&nbsp;The&nbsp;values&nbsp;are&nbsp;as&nbsp;follows:<br/>-&nbsp;**dir**:&nbsp;directory<br/>-&nbsp;**file**:&nbsp;file | | type | string | File type. Available values are as follows:<br>-&nbsp;**dir**: directory<br>-&nbsp;**file**: file |
| subFiles | Array | File&nbsp;list. | | subFiles | Array | List of files.|
One of the following error codes will be returned if the operation fails. **Return value of fail()**
| Error&nbsp;Code | Description | | Error Code| Description|
| -------- | -------- | | -------- | -------- |
| 202 | Invalid&nbsp;parameter. | | 202 | Incorrect parameters are detected.|
| 300 | I/O&nbsp;error. | | 300 | An I/O error occurs.|
| 301 | File&nbsp;or&nbsp;directory&nbsp;not&nbsp;exist. | | 301 | The file or directory does not exist.|
**Example** **Example**
...@@ -226,26 +224,26 @@ export default { ...@@ -226,26 +224,26 @@ export default {
delete(Object): void delete(Object): void
Deletes local files. Deletes a local file.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| uri | string | Yes | URI&nbsp;of&nbsp;the&nbsp;file&nbsp;to&nbsp;delete,&nbsp;which&nbsp;cannot&nbsp;be&nbsp;an&nbsp;application&nbsp;resource&nbsp;path. | | uri | string | Yes| URI of the file to delete. It cannot be an application resource path.|
| success | Function | No | Called&nbsp;when&nbsp;the&nbsp;operation&nbsp;is&nbsp;successful. | | success | Function | No| Called when the file is deleted.|
| fail | Function | No | Called&nbsp;when&nbsp;the&nbsp;operation&nbsp;fails. | | fail | Function | No| Called when the file fails to be deleted.|
| complete | Function | No | Called&nbsp;when&nbsp;the&nbsp;execution&nbsp;is&nbsp;complete. | | complete | Function | No| Called when the execution is complete.|
One of the following error codes will be returned if the operation fails. **Return value of fail()**
| Error&nbsp;Code | Description | | Error Code| Description|
| -------- | -------- | | -------- | -------- |
| 202 | Incorrect&nbsp;parameter. | | 202 | Incorrect parameters are detected.|
| 300 | I/O&nbsp;error. | | 300 | An I/O error occurs.|
| 301 | File&nbsp;or&nbsp;directory&nbsp;not&nbsp;exist. | | 301 | The file or directory does not exist.|
**Example** **Example**
...@@ -270,28 +268,28 @@ export default { ...@@ -270,28 +268,28 @@ export default {
writeText(Object): void writeText(Object): void
Writes text into a specified file. Writes text into a file. Only text files can be read and written.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| uri | string | Yes | URI&nbsp;of&nbsp;a&nbsp;local&nbsp;file.&nbsp;If&nbsp;it&nbsp;does&nbsp;not&nbsp;exist,&nbsp;a&nbsp;file&nbsp;will&nbsp;be&nbsp;created. | | uri | string | Yes| URI of a local file. If it does not exist, a file will be created.|
| text | string | Yes | Character&nbsp;string&nbsp;to&nbsp;write&nbsp;into&nbsp;the&nbsp;local&nbsp;file. | | text | string | Yes| Text to write into the file. |
| encoding | string | No | Encoding&nbsp;format.&nbsp;The&nbsp;default&nbsp;format&nbsp;is&nbsp;UTF-8. | | encoding | string | No| Encoding format. The default format is **UTF-8**.|
| append | boolean | No | Whether&nbsp;to&nbsp;enable&nbsp;the&nbsp;append&nbsp;mode.&nbsp;The&nbsp;default&nbsp;value&nbsp;is&nbsp;**false**. | | append | boolean | No| Whether to enable the append mode. The default value is **false**.|
| success | Function | No | Called&nbsp;when&nbsp;the&nbsp;operation&nbsp;is&nbsp;successful. | | success | Function | No| Called when the text is written into the specified file.|
| fail | Function | No | Called&nbsp;when&nbsp;the&nbsp;operation&nbsp;fails. | | fail | Function | No| Called when the text fails to be written into the file.|
| complete | Function | No | Called&nbsp;when&nbsp;the&nbsp;execution&nbsp;is&nbsp;complete. | | complete | Function | No| Called when the execution is complete.|
One of the following error codes will be returned if the operation fails. **Return value of fail()**
| Error&nbsp;Code | Description | | Error Code| Description|
| -------- | -------- | | -------- | -------- |
| 202 | Incorrect&nbsp;parameter. | | 202 | Incorrect parameters are detected.|
| 300 | I/O&nbsp;error. | | 300 | An I/O error occurs.|
**Example** **Example**
...@@ -317,28 +315,28 @@ export default { ...@@ -317,28 +315,28 @@ export default {
writeArrayBuffer(Object): void writeArrayBuffer(Object): void
Writes buffer data into a specified file. Writes buffer data into a file. Only text files can be read and written.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| uri | string | Yes | URI&nbsp;of&nbsp;a&nbsp;local&nbsp;file.&nbsp;If&nbsp;it&nbsp;does&nbsp;not&nbsp;exist,&nbsp;a&nbsp;file&nbsp;will&nbsp;be&nbsp;created. | | uri | string | Yes| URI of a local file. If it does not exist, a file will be created.|
| buffer | Uint8Array | Yes | Buffer&nbsp;from&nbsp;which&nbsp;the&nbsp;data&nbsp;is&nbsp;derived. | | buffer | Uint8Array | Yes| Buffer from which the data is derived.|
| position | number | No | Offset&nbsp;to&nbsp;the&nbsp;position&nbsp;where&nbsp;the&nbsp;writing&nbsp;starts.&nbsp;The&nbsp;default&nbsp;value&nbsp;is&nbsp;**0**. | | position | number | No| Offset to the position where the writing starts. The default value is **0**.|
| append | boolean | No | Whether&nbsp;to&nbsp;enable&nbsp;the&nbsp;append&nbsp;mode.&nbsp;The&nbsp;default&nbsp;value&nbsp;is&nbsp;**false**.&nbsp;If&nbsp;the&nbsp;value&nbsp;is&nbsp;**true**,&nbsp;the&nbsp;**position**&nbsp;parameter&nbsp;will&nbsp;become&nbsp;invalid. | | append | boolean | No| Whether to enable the append mode. The default value is **false**. If the value is **true**, the **position** parameter will become invalid.|
| success | Function | No | Called&nbsp;when&nbsp;the&nbsp;operation&nbsp;is&nbsp;successful. | | success | Function | No| Called when buffer data is written into the file. |
| fail | Function | No | Called&nbsp;when&nbsp;the&nbsp;operation&nbsp;fails. | | fail | Function | No| Called when buffer data fails to be written into the file.|
| complete | Function | No | Called&nbsp;when&nbsp;the&nbsp;execution&nbsp;is&nbsp;complete. | | complete | Function | No| Called when the execution is complete.|
One of the following error codes will be returned if the operation fails. **Return value of fail()**
| Error&nbsp;Code | Description | | Error Code| Description|
| -------- | -------- | | -------- | -------- |
| 202 | Invalid&nbsp;parameter. | | 202 | Incorrect parameters are detected.|
| 300 | I/O&nbsp;error. | | 300 | An I/O error occurs.|
**Example** **Example**
...@@ -364,36 +362,36 @@ export default { ...@@ -364,36 +362,36 @@ export default {
readText(Object): void readText(Object): void
Reads text from a specified file. Reads text from a file. Only text files can be read and written.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| uri | string | Yes | URI&nbsp;of&nbsp;a&nbsp;local&nbsp;file. | | uri | string | Yes| URI of a local file.|
| encoding | string | No | Encoding&nbsp;format.&nbsp;The&nbsp;default&nbsp;format&nbsp;is&nbsp;UTF-8. | | encoding | string | No| Encoding format. The default format is **UTF-8**.|
| position | number | No | Position&nbsp;where&nbsp;the&nbsp;reading&nbsp;starts.&nbsp;The&nbsp;default&nbsp;value&nbsp;is&nbsp;the&nbsp;start&nbsp;position&nbsp;of&nbsp;the&nbsp;file. | | position | number | No| Position where the reading starts. The default value is the start position of the file.|
| length | number | No | Length&nbsp;of&nbsp;the&nbsp;text&nbsp;to&nbsp;be&nbsp;read&nbsp;(in&nbsp;bytes).&nbsp;The&nbsp;default&nbsp;value&nbsp;is&nbsp;**4096**. | | length | number | No| Length of the text to read, in bytes. The default value is **4096**.|
| success | Function | No | Called&nbsp;when&nbsp;the&nbsp;operation&nbsp;is&nbsp;successful. | | success | Function | No| Called when the text is read successfully.|
| fail | Function | No | Called&nbsp;when&nbsp;the&nbsp;operation&nbsp;fails. | | fail | Function | No| Called when the text failed to be read.|
| complete | Function | No | Called&nbsp;when&nbsp;the&nbsp;execution&nbsp;is&nbsp;complete. | | complete | Function | No| Called when the execution is complete.|
Return values of the **success** callback **Return value of success()**
| Name | Type | Description | | Name| Type| Description|
| -------- | -------- | -------- | | -------- | -------- | -------- |
| text | string | Text&nbsp;read&nbsp;from&nbsp;the&nbsp;specified&nbsp;file. | | text | string | Text read from the specified file.|
One of the following error codes will be returned if the operation fails. **Return value of fail()**
| Error&nbsp;Code | Description | | Error Code| Description|
| -------- | -------- | | -------- | -------- |
| 202 | Invalid&nbsp;parameter. | | 202 | Incorrect parameters are detected.|
| 300 | I/O&nbsp;error. | | 300 | An I/O error occurs.|
| 301 | The&nbsp;file&nbsp;or&nbsp;directory&nbsp;does&nbsp;not&nbsp;exist. | | 301 | The file or directory does not exist.|
| 302 | The&nbsp;size&nbsp;of&nbsp;text&nbsp;to&nbsp;read&nbsp;exceeds&nbsp;4096&nbsp;bytes. | | 302 | The text to read exceeds 4 KB.|
**Example** **Example**
...@@ -418,34 +416,34 @@ export default { ...@@ -418,34 +416,34 @@ export default {
readArrayBuffer(Object): void readArrayBuffer(Object): void
Reads buffer data from a specified file. Reads buffer data from a file. Only text files can be read and written.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| uri | string | Yes | URI&nbsp;of&nbsp;a&nbsp;local&nbsp;file. | | uri | string | Yes| URI of a local file.|
| position | number | No | Position&nbsp;where&nbsp;the&nbsp;reading&nbsp;starts.&nbsp;The&nbsp;default&nbsp;value&nbsp;is&nbsp;the&nbsp;start&nbsp;position&nbsp;of&nbsp;the&nbsp;file. | | position | number | No| Position where the reading starts. The default value is the start position of the file.|
| length | number | No | Length&nbsp;of&nbsp;data&nbsp;to&nbsp;read.&nbsp;If&nbsp;this&nbsp;parameter&nbsp;is&nbsp;not&nbsp;set,&nbsp;the&nbsp;reading&nbsp;proceeds&nbsp;until&nbsp;the&nbsp;end&nbsp;of&nbsp;the&nbsp;file. | | length | number | No| Length of data to read. If this parameter is not set, the reading proceeds until the end of the file.|
| success | Function | No | Called&nbsp;when&nbsp;the&nbsp;operation&nbsp;is&nbsp;successful. | | success | Function | No| Called when the buffer data is read successfully.|
| fail | Function | No | Called&nbsp;when&nbsp;the&nbsp;operation&nbsp;fails. | | fail | Function | No| Called when the buffer data fails to be read.|
| complete | Function | No | Called&nbsp;when&nbsp;the&nbsp;execution&nbsp;is&nbsp;complete. | | complete | Function | No| Called when the execution is complete.|
Return values of the **success** callback **Return value of success()**
| Name | Type | Description | | Name| Type| Description|
| -------- | -------- | -------- | | -------- | -------- | -------- |
| buffer | Uint8Array | File&nbsp;content&nbsp;that&nbsp;is&nbsp;read | | buffer | Uint8Array | Data read.|
One of the following error codes will be returned if the operation fails. **Return value of fail()**
| Error&nbsp;Code | Description | | Error Code| Description|
| -------- | -------- | | -------- | -------- |
| 202 | Invalid&nbsp;parameter. | | 202 | Incorrect parameters are detected.|
| 300 | I/O&nbsp;error. | | 300 | An I/O error occurs.|
| 301 | File&nbsp;or&nbsp;directory&nbsp;not&nbsp;exist. | | 301 | The file or directory does not exist.|
**Example** **Example**
...@@ -472,26 +470,26 @@ export default { ...@@ -472,26 +470,26 @@ export default {
access(Object): void access(Object): void
Checks whether a specified file or directory exists. Checks whether a file or directory exists.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| uri | string | Yes | URI&nbsp;of&nbsp;the&nbsp;directory&nbsp;or&nbsp;file. | | uri | string | Yes| URI of the directory or file to check.|
| success | Function | No | Called&nbsp;when&nbsp;the&nbsp;operation&nbsp;is&nbsp;successful. | | success | Function | No| Called when the operation is successful.|
| fail | Function | No | Called&nbsp;when&nbsp;the&nbsp;operation&nbsp;fails. | | fail | Function | No| Called when the operation fails.|
| complete | Function | No | Called&nbsp;when&nbsp;the&nbsp;execution&nbsp;is&nbsp;complete. | | complete | Function | No| Called when the execution is complete.|
One of the following error codes will be returned if the operation fails. **Return value of fail()**
| Error&nbsp;Code | Description | | Error Code| Description|
| -------- | -------- | | -------- | -------- |
| 202 | Invalid&nbsp;parameter. | | 202 | Incorrect parameters are detected.|
| 300 | I/O&nbsp;error. | | 300 | An I/O error occurs.|
| 301 | File&nbsp;or&nbsp;directory&nbsp;not&nbsp;exist. | | 301 | The file or directory does not exist.|
**Example** **Example**
...@@ -516,26 +514,26 @@ export default { ...@@ -516,26 +514,26 @@ export default {
mkdir(Object): void mkdir(Object): void
Creates a specified directory. Creates a directory.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| uri | string | Yes | URI&nbsp;of&nbsp;the&nbsp;directory. | | uri | string | Yes| URI of the directory to create.|
| recursive | boolean | No | Whether&nbsp;to&nbsp;recursively&nbsp;create&nbsp;upper-level&nbsp;directories&nbsp;of&nbsp;the&nbsp;specified&nbsp;directory.&nbsp;The&nbsp;default&nbsp;value&nbsp;is&nbsp;**false**. | | recursive | boolean | No| Whether to recursively create upper-level directories of the specified directory. The default value is **false**.|
| success | Function | No | Called&nbsp;when&nbsp;the&nbsp;operation&nbsp;is&nbsp;successful. | | success | Function | No| Called when the directory is created.|
| fail | Function | No | Called&nbsp;when&nbsp;the&nbsp;operation&nbsp;fails. | | fail | Function | No| Called when the directory fails to be created.|
| complete | Function | No | Called&nbsp;when&nbsp;the&nbsp;execution&nbsp;is&nbsp;complete. | | complete | Function | No| Called when the execution is complete.|
One of the following error codes will be returned if the operation fails. **Return value of fail()**
| Error&nbsp;Code | Description | | Error Code| Description|
| -------- | -------- | | -------- | -------- |
| 202 | Invalid&nbsp;parameter. | | 202 | Incorrect parameters are detected.|
| 300 | I/O&nbsp;error. | | 300 | An I/O error occurs.|
**Example** **Example**
...@@ -560,27 +558,27 @@ export default { ...@@ -560,27 +558,27 @@ export default {
rmdir(Object): void rmdir(Object): void
Deletes a specified directory. Deletes a directory.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| uri | string | Yes | URI&nbsp;of&nbsp;the&nbsp;directory. | | uri | string | Yes| URI of the directory to delete.|
| recursive | boolean | No | Whether&nbsp;to&nbsp;recursively&nbsp;delete&nbsp;subfiles&nbsp;and&nbsp;subdirectories&nbsp;of&nbsp;the&nbsp;specified&nbsp;directory.&nbsp;The&nbsp;default&nbsp;value&nbsp;is&nbsp;**false**. | | recursive | boolean | No| Whether to recursively delete files and subdirectories of the specified directory. The default value is **false**.|
| success | Function | No | Called&nbsp;when&nbsp;the&nbsp;operation&nbsp;is&nbsp;successful. | | success | Function | No| Called when the directory is deleted.|
| fail | Function | No | Called&nbsp;when&nbsp;the&nbsp;operation&nbsp;fails. | | fail | Function | No| Called when the directory fails to be deleted.|
| complete | Function | No | Called&nbsp;when&nbsp;the&nbsp;execution&nbsp;is&nbsp;complete. | | complete | Function | No| Called when the execution is complete.|
One of the following error codes will be returned if the operation fails. **Return value of fail()**
| Error&nbsp;Code | Description | | Error Code| Description|
| -------- | -------- | | -------- | -------- |
| 202 | Invalid&nbsp;parameter. | | 202 | Incorrect parameters are detected.|
| 300 | I/O&nbsp;error. | | 300 | An I/O error occurs.|
| 301 | File&nbsp;or&nbsp;directory&nbsp;not&nbsp;exist. | | 301 | The file or directory does not exist.|
**Example** **Example**
......
# Volume Management # Volume Management
The volumeManager module provides APIs for volume and disk management, including obtaining volume information, mounting or unmounting volumes, partitioning disks, and formatting volumes.
> **NOTE**<br> > **NOTE**<br>
> >
> - The initial APIs of this module are supported since API version 9. > - The initial APIs of this module are supported since API version 9.
> - API version 9 is a canary version for trial use. The APIs of this version may be unstable. > - API version 9 is a canary version for trial use. The APIs of this version may be unstable.
> - The APIs of this module are system APIs and cannot be called by third-party applications. > - The APIs of this module are system APIs and cannot be called by third-party applications.
The APIs of this module can be used to perform volume and disk management, including obtaining volume information, mounting and unmounting volumes, partitioning disks, and formatting volumes.
## Modules to Import ## Modules to Import
```js ```js
...@@ -20,19 +20,21 @@ getAllVolumes(): Promise&lt;Array&lt;Volume&gt;&gt; ...@@ -20,19 +20,21 @@ getAllVolumes(): Promise&lt;Array&lt;Volume&gt;&gt;
Asynchronously obtains information about all available volumes. This API uses a promise to return the result. Asynchronously obtains information about all available volumes. This API uses a promise to return the result.
**Required permissions**: ohos.permission.STORAGE_MANAGER
**System capability**: SystemCapability.FileManagement.StorageService.Volume **System capability**: SystemCapability.FileManagement.StorageService.Volume
- Return value **Return value**
| Type | Description | | Type | Description |
| ---------------------------------- | -------------------------- | | ---------------------------------- | -------------------------- |
| Promise&lt;[Volume](#volume)[]&gt; | Promise used to return the execution result.| | Promise&lt;[Volume](#volume)[]&gt; | Promise used to return the execution result.|
- Example **Example**
```js ```js
volumemanager.getAllVolumes().then(function(volumes){ volumemanager.getAllVolumes().then(function(volumes){
// do something // Do something.
}); });
``` ```
...@@ -42,20 +44,22 @@ getAllVolumes(callback: AsyncCallback&lt;Array&lt;Volume&gt;&gt;): void ...@@ -42,20 +44,22 @@ getAllVolumes(callback: AsyncCallback&lt;Array&lt;Volume&gt;&gt;): void
Asynchronously obtains information about all available volumes. This API uses a callback to return the result. Asynchronously obtains information about all available volumes. This API uses a callback to return the result.
**Required permissions**: ohos.permission.STORAGE_MANAGER
**System capability**: SystemCapability.FileManagement.StorageService.Volume **System capability**: SystemCapability.FileManagement.StorageService.Volume
- Parameters **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------------------------------- | ---- | ------------------------------------ | | -------- | ------------------------------------------------- | ---- | ------------------------------------ |
| callback | callback:AsyncCallback&lt;[Volume](#volume)[]&gt; | Yes | Callback invoked to return the volume information obtained.| | callback | callback:AsyncCallback&lt;[Volume](#volume)[]&gt; | Yes | Callback invoked to return the volume information obtained.|
- Example **Example**
```js ```js
let uuid = ""; let uuid = "";
volumemanager.getAllVolumes(uuid, function(error, volumes){ volumemanager.getAllVolumes(function(error, volumes){
// do something // Do something
}); });
``` ```
...@@ -66,26 +70,28 @@ mount(volumeId: string): Promise&lt;boolean&gt; ...@@ -66,26 +70,28 @@ mount(volumeId: string): Promise&lt;boolean&gt;
Asynchronously mounts a volume. This API uses a promise to return the result. Asynchronously mounts a volume. This API uses a promise to return the result.
**Required permissions**: ohos.permission.MOUNT_UNMOUNT_MANAGER
**System capability**: SystemCapability.FileManagement.StorageService.Volume **System capability**: SystemCapability.FileManagement.StorageService.Volume
- Parameters **Parameters**
| Name | Type | Mandatory| Description| | Name | Type | Mandatory| Description|
| -------- | ------ | ---- | ---- | | -------- | ------ | ---- | ---- |
| volumeId | string | Yes | Volume ID.| | volumeId | string | Yes | Volume ID.|
- Return value **Return value**
| Type | Description | | Type | Description |
| ---------------------- | ---------- | | ---------------------- | ---------- |
| Promise&lt;boolean&gt; | Promise used to return the execution result.| | Promise&lt;boolean&gt; | Promise used to return the execution result.|
- Example **Example**
```js ```js
let volumeId = ""; let volumeId = "";
volumemanager.mount(volumeId).then(function(flag){ volumemanager.mount(volumeId).then(function(flag){
// do something // Do something
}); });
``` ```
...@@ -95,21 +101,23 @@ mount(volumeId: string, callback:AsyncCallback&lt;boolean&gt;):void ...@@ -95,21 +101,23 @@ mount(volumeId: string, callback:AsyncCallback&lt;boolean&gt;):void
Asynchronously obtains the available space of the specified volume. This API uses a callback to return the result. Asynchronously obtains the available space of the specified volume. This API uses a callback to return the result.
**Required permissions**: ohos.permission.MOUNT_UNMOUNT_MANAGER
**System capability**: SystemCapability.FileManagement.StorageService.Volume **System capability**: SystemCapability.FileManagement.StorageService.Volume
- Parameters **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------------------- | ---- | -------------------- | | -------- | ------------------------------------- | ---- | -------------------- |
| volumeId | string | Yes | Volume ID. | | volumeId | string | Yes | Volume ID. |
| callback | callback:AsyncCallback&lt;boolean&gt; | Yes | Callback invoked to return the execution result.| | callback | callback:AsyncCallback&lt;boolean&gt; | Yes | Callback invoked to return the execution result.|
- Example **Example**
```js ```js
let volumeId = ""; let volumeId = "";
volumemanager.mount(volumeId, function(error, flag){ volumemanager.mount(volumeId, function(error, flag){
// do something // Do something
}); });
``` ```
...@@ -119,26 +127,28 @@ unmount(volumeId: string): Promise&lt;boolean&gt; ...@@ -119,26 +127,28 @@ unmount(volumeId: string): Promise&lt;boolean&gt;
Asynchronously unmounts a volume. This API uses a promise to return the result. Asynchronously unmounts a volume. This API uses a promise to return the result.
**Required permissions**: ohos.permission.MOUNT_UNMOUNT_MANAGER
**System capability**: SystemCapability.FileManagement.StorageService.Volume **System capability**: SystemCapability.FileManagement.StorageService.Volume
- Parameters **Parameters**
| Name | Type | Mandatory| Description| | Name | Type | Mandatory| Description|
| -------- | ------ | ---- | ---- | | -------- | ------ | ---- | ---- |
| volumeId | string | Yes | Volume ID.| | volumeId | string | Yes | Volume ID.|
- Return value **Return value**
| Type | Description | | Type | Description |
| ---------------------- | ---------- | | ---------------------- | ---------- |
| Promise&lt;boolean&gt; | Promise used to return the execution result.| | Promise&lt;boolean&gt; | Promise used to return the execution result.|
- Example **Example**
```js ```js
let volumeId = ""; let volumeId = "";
volumemanager.unmount(volumeId).then(function(flag){ volumemanager.unmount(volumeId).then(function(flag){
// do something // Do something
}); });
``` ```
...@@ -148,21 +158,306 @@ unmount(volumeId: string, callback:AsyncCallback&lt;boolean&gt;):void ...@@ -148,21 +158,306 @@ unmount(volumeId: string, callback:AsyncCallback&lt;boolean&gt;):void
Asynchronously unmounts a volume. This API uses a callback to return the result. Asynchronously unmounts a volume. This API uses a callback to return the result.
**Required permissions**: ohos.permission.MOUNT_UNMOUNT_MANAGER
**System capability**: SystemCapability.FileManagement.StorageService.Volume **System capability**: SystemCapability.FileManagement.StorageService.Volume
- Parameters **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------------------- | ---- | -------------------- | | -------- | ------------------------------------- | ---- | -------------------- |
| volumeId | string | Yes | Volume ID. | | volumeId | string | Yes | Volume ID. |
| callback | callback:AsyncCallback&lt;boolean&gt; | Yes | Callback invoked to return the execution result.| | callback | callback:AsyncCallback&lt;boolean&gt; | Yes | Callback invoked to return the execution result.|
- Example **Example**
```js ```js
let volumeId = ""; let volumeId = "";
volumemanager.unmount(volumeId, function(error, flag){ volumemanager.unmount(volumeId, function(error, flag){
// do something // Do something
});
```
## volumemanager.getVolumeByUuid
getVolumeByUuid(uuid: string): Promise&lt;Volume&gt;
Asynchronously obtains volume information based on the universally unique identifier (UUID). This API uses a promise to return the result.
**Required permissions**: ohos.permission.STORAGE_MANAGER
**System capability**: SystemCapability.FileManagement.StorageService.Volume
**Parameters**
| Name | Type | Mandatory| Description|
| -------- | ------ | ---- | ---- |
| uuid | string | Yes | UUID of the volume.|
**Return value**
| Type | Description |
| ---------------------------------- | -------------------------- |
| Promise&lt;[Volume](#volume)&gt; | Promise used to return the volume information obtained.|
**Example**
```js
let uuid = "";
let volume = await volumemanager.getVolumeByUuid(uuid);
```
## volumemanager.getVolumeByUuid
getVolumeByUuid(uuid: string, callback: AsyncCallback&lt;Volume&gt;): void
Asynchronously obtains volume information based on the UUID. This API uses a callback to return the result.
**Required permissions**: ohos.permission.STORAGE_MANAGER
**System capability**: SystemCapability.FileManagement.StorageService.Volume
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------------------ | ---- | -------------------- |
| uuid | string | Yes | UUID of the volume. |
| callback | callback:AsyncCallback&lt;[Volume](#volume)&gt; | Yes | Callback invoked to return the volume information obtained.|
**Example**
```js
let uuid = "";
volumemanager.getVolumeByUuid(uuid, (error, volume) => {
// Do something.
});
```
## volumemanager.getVolumeById
getVolumeById(id: string): Promise&lt;Volume&gt;
Asynchronously obtains volume information based on the volume ID. This API uses a promise to return the result.
**Required permissions**: ohos.permission.STORAGE_MANAGER
**System capability**: SystemCapability.FileManagement.StorageService.Volume
**Parameters**
| Name | Type | Mandatory | Description|
| -------- | ------ | ---- | ---- |
| id | string | Yes | Volume ID.|
**Return value**
| Type | Description |
| ---------------------------------- | -------------------------- |
| Promise&lt;[Volume](#volume)&gt; | Promise used to return the volume information obtained.|
**Example**
```js
let id = "";
let volume = await volumemanager.getVolumeById(id);
```
## volumemanager.getVolumeById
getVolumeById(id: string, callback: AsyncCallback&lt;Volume&gt;): void
Asynchronously obtains volume information based on the volume ID. This API uses a callback to return the result.
**Required permissions**: ohos.permission.STORAGE_MANAGER
**System capability**: SystemCapability.FileManagement.StorageService.Volume
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------------------ | ---- | -------------------- |
| id | string | Yes | Volume ID. |
| callback | callback:AsyncCallback&lt;[Volume](#volume)&gt; | Yes | Callback invoked to return the volume information obtained.|
**Example**
```js
let id = "";
volumemanager.getVolumeById(id, (error, volume) => {
// Do something.
});
```
## volumemanager.setVolumeDescription
setVolumeDescription(uuid: string, description: string): Promise&lt;void&gt;
Asynchronously sets the volume description based on the UUID. This API uses a promise to return the result.
**Required permissions**: ohos.permission.MOUNT_UNMOUNT_MANAGER
**System capability**: SystemCapability.FileManagement.StorageService.Volume
**Parameters**
| Name | Type | Mandatory| Description|
| --------- | ------ | ---- | ---- |
| uuid | string | Yes | UUID of the volume.|
| description | string | Yes | Volume description.|
**Return value**
| Type | Description |
| ---------------------- | -------------------------- |
| Promise&lt;void&gt; | Promise used to return the result. |
**Example**
```js
let uuid = "";
let description = "";
let bool = await volumemanager.setVolumeDescription(uuid, description);
```
## volumemanager.setVolumeDescription
setVolumeDescription(uuid: string, description: string, callback: AsyncCallback&lt;void&gt;): void
Asynchronously sets the volume description based on the UUID. This API uses a callback to return the result.
**Required permissions**: ohos.permission.MOUNT_UNMOUNT_MANAGER
**System capability**: SystemCapability.FileManagement.StorageService.Volume
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | --------------------------------------- | ---- | ---------------- |
| uuid | string | Yes | UUID of the volume. |
| description | string | Yes | Volume description. |
| callback | callback:AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result.|
**Example**
```js
let uuid = "";
let description = "";
volumemanager.setVolumeDescription(uuid, description, (error, bool) => {
// Do something.
});
```
## volumemanager.format
format(volId: string): Promise&lt;void&gt;
Asynchronously formats a volume. This API uses a promise to return the result.
**Required permissions**: ohos.permission.MOUNT_FORMAT_MANAGER
**System capability**: SystemCapability.FileManagement.StorageService.Volume
**Parameters**
| Name | Type | Mandatory| Description|
| ----------- | ------ | ---- | ---- |
| volId | string | Yes | Volume ID.|
**Return value**
| Type | Description |
| --------------------- | ----------------------- |
| Promise&lt;void&gt; | Promise used to return the result. |
**Example**
```js
let volId = "";
let bool = await volumemanager.format(volId);
```
## volumemanager.format
format(volId: string, callback: AsyncCallback&lt;void&gt;): void
Asynchronously formats a volume. This API uses a callback to return the result.
**Required permissions**: ohos.permission.MOUNT_FORMAT_MANAGER
**System capability**: SystemCapability.FileManagement.StorageService.Volume
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ---------------- |
| volId | string | Yes | Volume ID. |
| callback | callback:AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. |
**Example**
```js
let volId = "";
volumemanager.format(volId, (error, bool) => {
// Do something.
});
```
## volumemanager.partition
partition(volId: string, fstype: string): Promise&lt;void&gt;
Asynchronously partitions a disk. This API uses a promise to return the result.
**Required permissions**: ohos.permission.MOUNT_FORMAT_MANAGER
**System capability**: SystemCapability.FileManagement.StorageService.Volume
**Parameters**
| Name | Type | Mandatory| Description|
| ----------- | ------ | ---- | ---- |
| volId | string | Yes | ID of the disk to which the volume belongs.|
| fstype | string | Yes | Partition type. |
**Return value**
| Type | Description |
| --------------------- | ----------------------- |
| Promise&lt;void&gt; | Promise used to return the result. |
**Example**
```js
let volId = "";
let fstype = "";
let bool = await volumemanager.partition(volId, fstype);
```
## volumemanager.partition
partition(volId: string, fstype : string, callback: AsyncCallback&lt;void&gt;): void
Asynchronously partitions a disk. This API uses a callback to return the result.
**Required permissions**: ohos.permission.MOUNT_FORMAT_MANAGER
**System capability**: SystemCapability.FileManagement.StorageService.Volume
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ---------------- |
| volId | string | Yes | ID of the disk to which the volume belongs. |
| fstype | string | Yes | Partition type. |
| callback | callback:AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. |
**Example**
```js
let volId = "";
let fstype = "";
volumemanager.format(volId, fstype, (error, bool) => {
// Do something.
}); });
``` ```
...@@ -174,9 +469,9 @@ Asynchronously unmounts a volume. This API uses a callback to return the result. ...@@ -174,9 +469,9 @@ Asynchronously unmounts a volume. This API uses a callback to return the result.
| Name | Type | Description | | Name | Type | Description |
| ----------- | ------- | -------------------- | | ----------- | ------- | -------------------- |
| id | number | Volume ID. | | id | string | Volume ID. |
| uuid | string | Universally unique identifier (UUID) of the volume. | | uuid | string | UUID of the volume. |
| description | string | Description of the volume. | | description | string | Description of the volume. |
| removable | boolean | Whether the volume is a removable storage device.| | removable | boolean | Whether the volume is a removable storage device.|
| state | int | Current volume status. | | state | number | Volume state. |
| path | string | Mount address of the volume. | | path | string | Mount address of the volume. |
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册