diff --git a/en/application-dev/reference/apis/js-apis-data-rdb.md b/en/application-dev/reference/apis/js-apis-data-rdb.md
index 44af42decf27264828ef50e8925a8fd598527251..2fe4c51fe9dd9195742cd592258ba6e91a75dd72 100644
--- a/en/application-dev/reference/apis/js-apis-data-rdb.md
+++ b/en/application-dev/reference/apis/js-apis-data-rdb.md
@@ -31,7 +31,7 @@ Obtains an RDB store. This API uses an asynchronous callback to return the resul
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------------ | ---- | ------------------------------------------------------------ |
-| context | Context | Yes | Application context.
For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).
For details about the application context of the stage model, see [Context](js-apis-ability-context.md).|
+| context | Context | Yes | Application context.
For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).
For details about the application context of the stage model, see [Context](js-apis-inner-app-context.md).|
| config | [StoreConfig](#storeconfig) | Yes | Configuration of the RDB store. |
| version | number | Yes | RDB store version.
Currently, automatic RDB upgrades and downgrades performed based on **version** is not supported. |
| callback | AsyncCallback<[RdbStore](#rdbstore)> | Yes | Callback invoked to return the RDB store obtained. |
@@ -92,7 +92,7 @@ Obtains an RDB store. This API uses a promise to return the result. You can set
| Name | Type | Mandatory| Description |
| ------- | --------------------------- | ---- | ------------------------------------------------------------ |
-| context | Context | Yes | Application context.
For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).
For details about the application context of the stage model, see [Context](js-apis-ability-context.md).|
+| context | Context | Yes | Application context.
For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).
For details about the application context of the stage model, see [Context](js-apis-inner-app-context.md).|
| config | [StoreConfig](#storeconfig) | Yes | Configuration of the RDB store. |
| version | number | Yes | RDB store version.
Currently, automatic RDB upgrades and downgrades performed based on **version** is not supported. |
@@ -156,7 +156,7 @@ Deletes an RDB store. This API uses an asynchronous callback to return the resul
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ------------------------------------------------------------ |
-| context | Context | Yes | Application context.
For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).
For details about the application context of the stage model, see [Context](js-apis-ability-context.md).|
+| context | Context | Yes | Application context.
For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).
For details about the application context of the stage model, see [Context](js-apis-inner-app-context.md).|
| name | string | Yes | Name of the RDB store to delete. |
| callback | AsyncCallback<void> | Yes | Callback invoked to return the result. |
@@ -214,7 +214,7 @@ Deletes an RDB store. This API uses a promise to return the result.
| Name | Type | Mandatory| Description |
| ------- | ------- | ---- | ------------------------------------------------------------ |
-| context | Context | Yes | Application context.
For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).
For details about the application context of the stage model, see [Context](js-apis-ability-context.md).|
+| context | Context | Yes | Application context.
For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).
For details about the application context of the stage model, see [Context](js-apis-inner-app-context.md).|
| name | string | Yes | Name of the RDB store to delete. |
**Return value**
@@ -404,7 +404,7 @@ Sets an **RdbPredicates** to match the field with data type **ValueType** and va
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| field | string | Yes| Column name in the database table.|
-| value | [ValueType](#valuetype) | Yes| Value to match the **RdbPredicates**. |
+| value | [ValueType](#valuetype) | Yes| Value to match the **RdbPredicates**.|
**Return value**
@@ -433,7 +433,7 @@ Sets an **RdbPredicates** to match the field with data type **ValueType** and va
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| field | string | Yes| Column name in the database table.|
-| value | [ValueType](#valuetype) | Yes| Value to match the **RdbPredicates**. |
+| value | [ValueType](#valuetype) | Yes| Value to match the **RdbPredicates**.|
**Return value**
@@ -560,7 +560,7 @@ Sets an **RdbPredicates** to match a string containing the specified value.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| field | string | Yes| Column name in the database table.|
-| value | string | Yes| Value to match the **RdbPredicates**. |
+| value | string | Yes| Value to match the **RdbPredicates**.|
**Return value**
@@ -588,7 +588,7 @@ Sets an **RdbPredicates** to match a string that starts with the specified value
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| field | string | Yes| Column name in the database table.|
-| value | string | Yes| Value to match the **RdbPredicates**. |
+| value | string | Yes| Value to match the **RdbPredicates**.|
**Return value**
@@ -616,7 +616,7 @@ Sets an **RdbPredicates** to match a string that ends with the specified value.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| field | string | Yes| Column name in the database table.|
-| value | string | Yes| Value to match the **RdbPredicates**. |
+| value | string | Yes| Value to match the **RdbPredicates**.|
**Return value**
@@ -697,7 +697,7 @@ Sets an **RdbPredicates** to match a string that is similar to the specified val
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| field | string | Yes| Column name in the database table.|
-| value | string | Yes| Value to match the **RdbPredicates**. |
+| value | string | Yes| Value to match the **RdbPredicates**.|
**Return value**
@@ -725,7 +725,7 @@ Sets an **RdbPredicates** to match the specified string.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| field | string | Yes| Column name in the database table.|
-| value | string | Yes| Value to match the **RdbPredicates**.
Wildcards are supported. * indicates zero, one, or multiple digits or characters. **?** indicates a single digit or character. |
+| value | string | Yes| Value to match the **RdbPredicates**.
Wildcards are supported. * indicates zero, one, or multiple digits or characters. **?** indicates a single digit or character.|
**Return value**
@@ -753,8 +753,8 @@ Sets an **RdbPredicates** to match the field with data type **ValueType** and va
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| field | string | Yes| Column name in the database table.|
-| low | [ValueType](#valuetype) | Yes| Minimum value to match the **RdbPredicates**. |
-| high | [ValueType](#valuetype) | Yes| Maximum value to match the **RdbPredicates**. |
+| low | [ValueType](#valuetype) | Yes| Minimum value to match the **RdbPredicates**.|
+| high | [ValueType](#valuetype) | Yes| Maximum value to match the **RdbPredicates**.|
**Return value**
@@ -782,8 +782,8 @@ Sets an **RdbPredicates** to match the field with data type **ValueType** and va
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| field | string | Yes| Column name in the database table.|
-| low | [ValueType](#valuetype) | Yes| Minimum value to match the **RdbPredicates**. |
-| high | [ValueType](#valuetype) | Yes| Maximum value to match the **RdbPredicates**. |
+| low | [ValueType](#valuetype) | Yes| Minimum value to match the **RdbPredicates**.|
+| high | [ValueType](#valuetype) | Yes| Maximum value to match the **RdbPredicates**.|
**Return value**
@@ -811,7 +811,7 @@ Sets an **RdbPredicates** to match the field with data type **ValueType** and va
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| field | string | Yes| Column name in the database table.|
-| value | [ValueType](#valuetype) | Yes| Value to match the **RdbPredicates**. |
+| value | [ValueType](#valuetype) | Yes| Value to match the **RdbPredicates**.|
**Return value**
@@ -839,7 +839,7 @@ Sets an **RdbPredicates** to match the field with data type **ValueType** and va
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| field | string | Yes| Column name in the database table.|
-| value | [ValueType](#valuetype) | Yes| Value to match the **RdbPredicates**. |
+| value | [ValueType](#valuetype) | Yes| Value to match the **RdbPredicates**.|
**Return value**
@@ -867,7 +867,7 @@ Sets an **RdbPredicates** to match the field with data type **ValueType** and va
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| field | string | Yes| Column name in the database table.|
-| value | [ValueType](#valuetype) | Yes| Value to match the **RdbPredicates**. |
+| value | [ValueType](#valuetype) | Yes| Value to match the **RdbPredicates**.|
**Return value**
@@ -895,7 +895,7 @@ Sets an **RdbPredicates** to match the field with data type **ValueType** and va
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| field | string | Yes| Column name in the database table.|
-| value | [ValueType](#valuetype) | Yes| Value to match the **RdbPredicates**. |
+| value | [ValueType](#valuetype) | Yes| Value to match the **RdbPredicates**.|
**Return value**
diff --git a/en/application-dev/reference/apis/js-apis-file-fs.md b/en/application-dev/reference/apis/js-apis-file-fs.md
index 748d78b442fd3fefc4180a3f2d9b2bc0dade2500..e4f4476173c0968790437178e78527d4f4846c3e 100644
--- a/en/application-dev/reference/apis/js-apis-file-fs.md
+++ b/en/application-dev/reference/apis/js-apis-file-fs.md
@@ -59,14 +59,14 @@ Obtains detailed file information. This API uses a promise to return the result.
**Return value**
-| Type | Description |
-| ---------------------------- | ---------- |
-| Promise<[Stat](#stat)> | Promise used to return the file information obtained.|
+ | Type | Description |
+ | ---------------------------- | ---------- |
+ | Promise<[Stat](#stat)> | Promise used to return the file information obtained.|
**Example**
```js
- let filePath = pathDir + "test.txt";
+ let filePath = pathDir + "/test.txt";
fs.stat(filePath).then((stat) => {
console.info("get file info succeed, the size of file is " + stat.size);
}).catch((err) => {
@@ -118,9 +118,9 @@ Obtains detailed file information synchronously.
**Return value**
-| Type | Description |
-| ------------- | ---------- |
-| [Stat](#stat) | File information obtained.|
+ | Type | Description |
+ | ------------- | ---------- |
+ | [Stat](#stat) | File information obtained.|
**Example**
@@ -145,9 +145,9 @@ Checks whether a file exists. This API uses a promise to return the result.
**Return value**
-| Type | Description |
-| ------------------- | ---------------------------- |
-| Promise<boolean> | Promise used to return a Boolean value.|
+ | Type | Description |
+ | ------------------- | ---------------------------- |
+ | Promise<boolean> | Promise used to return a Boolean value.|
**Example**
@@ -232,15 +232,15 @@ Closes a file. This API uses a promise to return the result.
**Parameters**
-| Name | Type | Mandatory | Description |
-| ---- | ------ | ---- | ------------ |
-| file | [File](#file)\|number | Yes | File object or FD of the file to close.|
+ | Name | Type | Mandatory | Description |
+ | ---- | ------ | ---- | ------------ |
+ | file | [File](#file)\|number | Yes | File object or FD of the file to close.|
**Return value**
-| Type | Description |
-| ------------------- | ---------------------------- |
-| Promise<void> | Promise that returns no value.|
+ | Type | Description |
+ | ------------------- | ---------------------------- |
+ | Promise<void> | Promise that returns no value.|
**Example**
@@ -265,10 +265,10 @@ Closes a file. This API uses an asynchronous callback to return the result.
**Parameters**
-| Name | Type | Mandatory | Description |
-| -------- | ------------------------- | ---- | ------------ |
-| file | [File](#file)\|number | Yes | File object or FD of the file to close.|
-| callback | AsyncCallback<void> | Yes | Callback invoked when the file is closed asynchronously.|
+ | Name | Type | Mandatory | Description |
+ | -------- | ------------------------- | ---- | ------------ |
+ | file | [File](#file)\|number | Yes | File object or FD of the file to close.|
+ | callback | AsyncCallback<void> | Yes | Callback invoked when the file is closed asynchronously.|
**Example**
@@ -294,9 +294,9 @@ Synchronously closes a file.
**Parameters**
-| Name | Type | Mandatory | Description |
-| ---- | ------ | ---- | ------------ |
-| file | [File](#file)\|number | Yes | File object or FD of the file to close.|
+ | Name | Type | Mandatory | Description |
+ | ---- | ------ | ---- | ------------ |
+ | file | [File](#file)\|number | Yes | File object or FD of the file to close.|
**Example**
@@ -316,23 +316,23 @@ Copies a file. This API uses a promise to return the result.
**Parameters**
-| Name | Type | Mandatory | Description |
-| ---- | -------------------------- | ---- | ---------------------------------------- |
-| src | string\|number | Yes | Path or FD of the file to copy. |
-| dest | string\|number | Yes | Destination path of the file or FD of the file created. |
-| mode | number | No | Whether to overwrite the file of the same name in the destination path. The default value is **0**, which is the only value supported.
**0**: overwrite the file of the same name.|
+ | Name | Type | Mandatory | Description |
+ | ---- | -------------------------- | ---- | ---------------------------------------- |
+ | src | string\|number | Yes | Path or FD of the file to copy. |
+ | dest | string\|number | Yes | Destination path of the file or FD of the file created. |
+ | mode | number | No | Whether to overwrite the file of the same name in the destination path. The default value is **0**, which is the only value supported.
**0**: overwrite the file of the same name.|
**Return value**
-| Type | Description |
-| ------------------- | ---------------------------- |
-| Promise<void> | Promise that returns no value.|
+ | Type | Description |
+ | ------------------- | ---------------------------- |
+ | Promise<void> | Promise that returns no value.|
**Example**
```js
- let srcPath = pathDir + "srcDir/test.txt";
- let dstPath = pathDir + "dstDir/test.txt";
+ let srcPath = pathDir + "/srcDir/test.txt";
+ let dstPath = pathDir + "/dstDir/test.txt";
fs.copyFile(srcPath, dstPath).then(() => {
console.info("copy file succeed");
}).catch((err) => {
@@ -350,18 +350,18 @@ Copies a file. This API uses an asynchronous callback to return the result.
**Parameters**
-| Name | Type | Mandatory | Description |
-| -------- | -------------------------- | ---- | ---------------------------------------- |
-| src | string\|number | Yes | Path or FD of the file to copy. |
-| dest | string\|number | Yes | Destination path of the file or FD of the file created. |
-| mode | number | No | Whether to overwrite the file of the same name in the destination path. The default value is **0**, which is the only value supported.
**0**: overwrite the file with the same name and truncate the part that is not overwritten.|
-| callback | AsyncCallback<void> | Yes | Callback invoked when the file is copied asynchronously. |
+ | Name | Type | Mandatory | Description |
+ | -------- | -------------------------- | ---- | ---------------------------------------- |
+ | src | string\|number | Yes | Path or FD of the file to copy. |
+ | dest | string\|number | Yes | Destination path of the file or FD of the file created. |
+ | mode | number | No | Whether to overwrite the file of the same name in the destination path. The default value is **0**, which is the only value supported.
**0**: overwrite the file with the same name and truncate the part that is not overwritten.|
+ | callback | AsyncCallback<void> | Yes | Callback invoked when the file is copied asynchronously. |
**Example**
```js
- let srcPath = pathDir + "srcDir/test.txt";
- let dstPath = pathDir + "dstDir/test.txt";
+ let srcPath = pathDir + "/srcDir/test.txt";
+ let dstPath = pathDir + "/dstDir/test.txt";
fs.copyFile(srcPath, dstPath, (err) => {
if (err) {
console.info("copy file failed with error message: " + err.message + ", error code: " + err.code);
@@ -382,17 +382,17 @@ Synchronously copies a file.
**Parameters**
-| Name | Type | Mandatory | Description |
-| ---- | -------------------------- | ---- | ---------------------------------------- |
-| src | string\|number | Yes | Path or FD of the file to copy. |
-| dest | string\|number | Yes | Destination path of the file or FD of the file created. |
-| mode | number | No | Whether to overwrite the file of the same name in the destination path. The default value is **0**, which is the only value supported.
**0**: overwrite the file with the same name and truncate the part that is not overwritten.|
+ | Name | Type | Mandatory | Description |
+ | ---- | -------------------------- | ---- | ---------------------------------------- |
+ | src | string\|number | Yes | Path or FD of the file to copy. |
+ | dest | string\|number | Yes | Destination path of the file or FD of the file created. |
+ | mode | number | No | Whether to overwrite the file of the same name in the destination path. The default value is **0**, which is the only value supported.
**0**: overwrite the file with the same name and truncate the part that is not overwritten.|
**Example**
```js
- let srcPath = pathDir + "srcDir/test.txt";
- let dstPath = pathDir + "dstDir/test.txt";
+ let srcPath = pathDir + "/srcDir/test.txt";
+ let dstPath = pathDir + "/dstDir/test.txt";
fs.copyFileSync(srcPath, dstPath);
```
@@ -413,14 +413,14 @@ Creates a directory. This API uses a promise to return the result.
**Return value**
-| Type | Description |
-| ------------------- | ---------------------------- |
-| Promise<void> | Promise that returns no value.|
+ | Type | Description |
+ | ------------------- | ---------------------------- |
+ | Promise<void> | Promise that returns no value.|
**Example**
```js
- let dirPath = pathDir + '/testDir';
+ let dirPath = pathDir + "/testDir";
fs.mkdir(dirPath).then(() => {
console.info("Directory created");
}).catch((err) => {
@@ -447,7 +447,7 @@ Creates a directory. This API uses an asynchronous callback to return the result
**Example**
```js
- let dirPath = pathDir + '/testDir';
+ let dirPath = pathDir + "/testDir";
fs.mkdir(dirPath, (err) => {
if (err) {
console.info("mkdir failed with error message: " + err.message + ", error code: " + err.code);
@@ -475,7 +475,7 @@ Synchronously creates a directory.
**Example**
```js
- let dirPath = pathDir + '/testDir';
+ let dirPath = pathDir + "/testDir";
fs.mkdirSync(dirPath);
```
@@ -497,9 +497,9 @@ Opens a file. This API uses a promise to return the result. File uniform resourc
**Return value**
-| Type | Description |
-| --------------------- | ----------- |
-| Promise<[File](#file)> | Promise used to return the file object.|
+ | Type | Description |
+ | --------------------- | ----------- |
+ | Promise<[File](#file)> | Promise used to return the file object.|
**Example**
@@ -558,9 +558,9 @@ Synchronously opens a file. File URIs are supported.
**Return value**
-| Type | Description |
-| ------ | ----------- |
-| [File](#file) | File object opened.|
+ | Type | Description |
+ | ------ | ----------- |
+ | [File](#file) | File object opened.|
**Example**
@@ -589,9 +589,9 @@ Reads data from a file. This API uses a promise to return the result.
**Return value**
-| Type | Description |
-| ---------------------------------- | ------ |
-| Promise<number> | Promise used to return the data read.|
+ | Type | Description |
+ | ---------------------------------- | ------ |
+ | Promise<number> | Promise used to return the data read.|
**Example**
@@ -601,7 +601,7 @@ Reads data from a file. This API uses a promise to return the result.
let buf = new ArrayBuffer(4096);
fs.read(file.fd, buf).then((readLen) => {
console.info("Read file data successfully");
- console.info(String.fromCharCode.apply(null, new Uint8Array(readLen)));
+ console.info(String.fromCharCode.apply(null, new Uint8Array(buf.slice(0, readLen))));
fs.closeSync(file);
}).catch((err) => {
console.info("read file data failed with error message: " + err.message + ", error code: " + err.code);
@@ -618,12 +618,12 @@ Reads data from a file. This API uses an asynchronous callback to return the res
**Parameters**
-| Name | Type | Mandatory | Description |
-| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
-| fd | number | Yes | FD of the file. |
-| buffer | ArrayBuffer | Yes | Buffer used to store the file data read. |
-| options | Object | No | The options are as follows:
- **offset** (number): position of the data to read in the file. This parameter is optional. By default, data is read from the current position.
- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length.|
-| callback | AsyncCallback<number> | Yes | Callback invoked when the data is read asynchronously. |
+ | Name | Type | Mandatory | Description |
+ | -------- | ---------------------------------------- | ---- | ---------------------------------------- |
+ | fd | number | Yes | FD of the file. |
+ | buffer | ArrayBuffer | Yes | Buffer used to store the file data read. |
+ | options | Object | No | The options are as follows:
- **offset** (number): position of the data to read in the file. This parameter is optional. By default, data is read from the current position.
- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length.|
+ | callback | AsyncCallback<number> | Yes | Callback invoked when the data is read asynchronously. |
**Example**
@@ -636,7 +636,7 @@ Reads data from a file. This API uses an asynchronous callback to return the res
console.info("mkdir failed with error message: " + err.message + ", error code: " + err.code);
} else {
console.info("Read file data successfully");
- console.info(String.fromCharCode.apply(null, new Uint8Array(readLen)));
+ console.info(String.fromCharCode.apply(null, new Uint8Array(buf.slice(0, readLen))));
fs.closeSync(file);
}
});
@@ -653,17 +653,17 @@ Synchronously reads data from a file.
**Parameters**
-| Name | Type | Mandatory | Description |
-| ------- | ----------- | ---- | ---------------------------------------- |
-| fd | number | Yes | FD of the file. |
-| buffer | ArrayBuffer | Yes | Buffer used to store the file data read. |
-| options | Object | No | The options are as follows:
- **offset** (number): position of the data to read in the file. This parameter is optional. By default, data is read from the current position.
- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length.|
+ | Name | Type | Mandatory | Description |
+ | ------- | ----------- | ---- | ---------------------------------------- |
+ | fd | number | Yes | FD of the file. |
+ | buffer | ArrayBuffer | Yes | Buffer used to store the file data read. |
+ | options | Object | No | The options are as follows:
- **offset** (number): position of the data to read in the file. This parameter is optional. By default, data is read from the current position.
- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length.|
**Return value**
-| Type | Description |
-| ------ | -------- |
-| number | Length of the data read.|
+ | Type | Description |
+ | ------ | -------- |
+ | number | Length of the data read.|
**Example**
@@ -692,14 +692,14 @@ Deletes a directory. This API uses a promise to return the result.
**Return value**
-| Type | Description |
-| ------------------- | ---------------------------- |
-| Promise<void> | Promise that returns no value.|
+ | Type | Description |
+ | ------------------- | ---------------------------- |
+ | Promise<void> | Promise that returns no value.|
**Example**
```js
- let dirPath = pathDir + '/testDir';
+ let dirPath = pathDir + "/testDir";
fs.rmdir(dirPath).then(() => {
console.info("Directory deleted");
}).catch((err) => {
@@ -726,7 +726,7 @@ Deletes a directory. This API uses an asynchronous callback to return the result
**Example**
```js
- let dirPath = pathDir + '/testDir';
+ let dirPath = pathDir + "/testDir";
fs.rmdir(dirPath, (err) => {
if (err) {
console.info("rmdir failed with error message: " + err.message + ", error code: " + err.code);
@@ -754,7 +754,7 @@ Synchronously deletes a directory.
**Example**
```js
- let dirPath = pathDir + '/testDir';
+ let dirPath = pathDir + "/testDir";
fs.rmdirSync(dirPath);
```
@@ -775,9 +775,9 @@ Deletes a file. This API uses a promise to return the result.
**Return value**
-| Type | Description |
-| ------------------- | ---------------------------- |
-| Promise<void> | Promise that returns no value.|
+ | Type | Description |
+ | ------------------- | ---------------------------- |
+ | Promise<void> | Promise that returns no value.|
**Example**
@@ -852,17 +852,17 @@ Writes data into a file. This API uses a promise to return the result.
**Parameters**
-| Name | Type | Mandatory | Description |
-| ------- | ------------------------------- | ---- | ---------------------------------------- |
-| fd | number | Yes | FD of the file. |
-| buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. |
-| options | Object | No | The options are as follows:
- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.
- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.
- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.|
+ | Name | Type | Mandatory | Description |
+ | ------- | ------------------------------- | ---- | ---------------------------------------- |
+ | fd | number | Yes | FD of the file. |
+ | buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. |
+ | options | Object | No | The options are as follows:
- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.
- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.
- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.|
**Return value**
-| Type | Description |
-| --------------------- | -------- |
-| Promise<number> | Promise used to return the length of the data written.|
+ | Type | Description |
+ | --------------------- | -------- |
+ | Promise<number> | Promise used to return the length of the data written.|
**Example**
@@ -888,12 +888,12 @@ Writes data into a file. This API uses an asynchronous callback to return the re
**Parameters**
-| Name | Type | Mandatory | Description |
-| -------- | ------------------------------- | ---- | ---------------------------------------- |
-| fd | number | Yes | FD of the file. |
-| buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. |
-| options | Object | No | The options are as follows:
- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.
- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.
- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.|
-| callback | AsyncCallback<number> | Yes | Callback invoked when the data is written asynchronously. |
+ | Name | Type | Mandatory | Description |
+ | -------- | ------------------------------- | ---- | ---------------------------------------- |
+ | fd | number | Yes | FD of the file. |
+ | buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. |
+ | options | Object | No | The options are as follows:
- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.
- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.
- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.|
+ | callback | AsyncCallback<number> | Yes | Callback invoked when the data is written asynchronously. |
**Example**
@@ -921,17 +921,17 @@ Synchronously writes data into a file.
**Parameters**
-| Name | Type | Mandatory | Description |
-| ------- | ------------------------------- | ---- | ---------------------------------------- |
-| fd | number | Yes | FD of the file. |
-| buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. |
-| options | Object | No | The options are as follows:
- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.
- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.
- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.|
+ | Name | Type | Mandatory | Description |
+ | ------- | ------------------------------- | ---- | ---------------------------------------- |
+ | fd | number | Yes | FD of the file. |
+ | buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. |
+ | options | Object | No | The options are as follows:
- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.
- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.
- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.|
**Return value**
-| Type | Description |
-| ------ | -------- |
-| number | Length of the data written in the file.|
+ | Type | Description |
+ | ------ | -------- |
+ | number | Length of the data written in the file.|
**Example**
@@ -960,9 +960,9 @@ Truncates a file. This API uses a promise to return the result.
**Return value**
-| Type | Description |
-| ------------------- | ---------------------------- |
-| Promise<void> | Promise that returns no value.|
+ | Type | Description |
+ | ------------------- | ---------------------------- |
+ | Promise<void> | Promise that returns no value.|
**Example**
@@ -1049,9 +1049,9 @@ Reads the text content of a file. This API uses a promise to return the result.
**Return value**
-| Type | Description |
-| --------------------- | ---------- |
-| Promise<string> | Promise used to return the content read.|
+ | Type | Description |
+ | --------------------- | ---------- |
+ | Promise<string> | Promise used to return the content read.|
**Example**
@@ -1112,9 +1112,9 @@ Synchronously reads the text of a file.
**Return value**
-| Type | Description |
-| ------ | -------------------- |
-| string | Promise used to return the content of the file read.|
+ | Type | Description |
+ | ------ | -------------------- |
+ | string | Promise used to return the content of the file read.|
**Example**
@@ -1140,9 +1140,9 @@ Obtains information about a symbolic link. This API uses a promise to return the
**Return value**
-| Type | Description |
-| ---------------------------- | ---------- |
-| Promise<[Stat](#stat)> | Promise used to return the symbolic link information obtained. For details, see **stat**.|
+ | Type | Description |
+ | ---------------------------- | ---------- |
+ | Promise<[Stat](#stat)> | Promise used to return the symbolic link information obtained. For details, see **stat**.|
**Example**
@@ -1200,9 +1200,9 @@ Obtains information about a symbolic link synchronously.
**Return value**
-| Type | Description |
-| ------------- | ---------- |
-| [Stat](#stat) | File information obtained.|
+ | Type | Description |
+ | ------------- | ---------- |
+ | [Stat](#stat) | File information obtained.|
**Example**
@@ -1228,15 +1228,15 @@ Renames a file or directory. This API uses a promise to return the result.
**Return value**
-| Type | Description |
-| ------------------- | ---------------------------- |
-| Promise<void> | Promise that returns no value.|
+ | Type | Description |
+ | ------------------- | ---------------------------- |
+ | Promise<void> | Promise that returns no value.|
**Example**
```js
let srcFile = pathDir + "/test.txt";
- let dstFile = pathDir + '/new.txt';
+ let dstFile = pathDir + "/new.txt";
fs.rename(srcFile, dstFile).then(() => {
console.info("File renamed");
}).catch((err) => {
@@ -1264,7 +1264,7 @@ Renames a file or directory. This API uses an asynchronous callback to return th
```js
let srcFile = pathDir + "/test.txt";
- let dstFile = pathDir + '/new.txt';
+ let dstFile = pathDir + "/new.txt";
fs.rename(srcFile, dstFile, (err) => {
if (err) {
console.info("rename failed with error message: " + err.message + ", error code: " + err.code);
@@ -1293,7 +1293,7 @@ Renames a file or directory synchronously.
```js
let srcFile = pathDir + "/test.txt";
- let dstFile = pathDir + '/new.txt';
+ let dstFile = pathDir + "/new.txt";
fs.renameSync(srcFile, dstFile);
```
@@ -1308,15 +1308,15 @@ Flushes data of a file to disk. This API uses a promise to return the result.
**Parameters**
-| Name | Type | Mandatory | Description |
-| ---- | ------ | ---- | ------------ |
-| fd | number | Yes | FD of the file.|
+ | Name | Type | Mandatory | Description |
+ | ---- | ------ | ---- | ------------ |
+ | fd | number | Yes | FD of the file.|
**Return value**
-| Type | Description |
-| ------------------- | ---------------------------- |
-| Promise<void> | Promise that returns no value.|
+ | Type | Description |
+ | ------------------- | ---------------------------- |
+ | Promise<void> | Promise that returns no value.|
**Example**
@@ -1341,10 +1341,10 @@ Flushes data of a file to disk. This API uses an asynchronous callback to return
**Parameters**
-| Name | Type | Mandatory | Description |
-| -------- | ------------------------- | ---- | --------------- |
-| fd | number | Yes | FD of the file. |
-| Callback | AsyncCallback<void> | Yes | Callback invoked when the file data is synchronized in asynchronous mode.|
+ | Name | Type | Mandatory | Description |
+ | -------- | ------------------------- | ---- | --------------- |
+ | fd | number | Yes | FD of the file. |
+ | Callback | AsyncCallback<void> | Yes | Callback invoked when the file data is synchronized in asynchronous mode.|
**Example**
@@ -1372,9 +1372,9 @@ Flushes data of a file to disk synchronously.
**Parameters**
-| Name | Type | Mandatory | Description |
-| ---- | ------ | ---- | ------------ |
-| fd | number | Yes | FD of the file.|
+ | Name | Type | Mandatory | Description |
+ | ---- | ------ | ---- | ------------ |
+ | fd | number | Yes | FD of the file.|
**Example**
@@ -1396,15 +1396,15 @@ Flushes data of a file to disk. This API uses a promise to return the result. **
**Parameters**
-| Name | Type | Mandatory | Description |
-| ---- | ------ | ---- | ------------ |
-| fd | number | Yes | FD of the file.|
+ | Name | Type | Mandatory | Description |
+ | ---- | ------ | ---- | ------------ |
+ | fd | number | Yes | FD of the file.|
**Return value**
-| Type | Description |
-| ------------------- | ---------------------------- |
-| Promise<void> | Promise that returns no value.|
+ | Type | Description |
+ | ------------------- | ---------------------------- |
+ | Promise<void> | Promise that returns no value.|
**Example**
@@ -1430,10 +1430,10 @@ Flushes data of a file to disk. This API uses an asynchronous callback to return
**Parameters**
-| Name | Type | Mandatory | Description |
-| -------- | ------------------------------- | ---- | ----------------- |
-| fd | number | Yes | FD of the file. |
-| callback | AsyncCallback<void> | Yes | Callback invoked when the file data is synchronized in asynchronous mode.|
+ | Name | Type | Mandatory | Description |
+ | -------- | ------------------------------- | ---- | ----------------- |
+ | fd | number | Yes | FD of the file. |
+ | callback | AsyncCallback<void> | Yes | Callback invoked when the file data is synchronized in asynchronous mode.|
**Example**
@@ -1460,9 +1460,9 @@ Synchronizes data in a file synchronously.
**Parameters**
-| Name | Type | Mandatory | Description |
-| ---- | ------ | ---- | ------------ |
-| fd | number | Yes | FD of the file.|
+ | Name | Type | Mandatory | Description |
+ | ---- | ------ | ---- | ------------ |
+ | fd | number | Yes | FD of the file.|
**Example**
@@ -1491,15 +1491,15 @@ Creates a symbolic link based on a file path. This API uses a promise to return
**Return value**
-| Type | Description |
-| ------------------- | ---------------------------- |
-| Promise<void> | Promise that returns no value.|
+ | Type | Description |
+ | ------------------- | ---------------------------- |
+ | Promise<void> | Promise that returns no value.|
**Example**
```js
let srcFile = pathDir + "/test.txt";
- let dstFile = pathDir + '/test';
+ let dstFile = pathDir + "/test";
fs.symlink(srcFile, dstFile).then(() => {
console.info("Symbolic link created");
}).catch((err) => {
@@ -1527,7 +1527,7 @@ Creates a symbolic link based on a file path. This API uses an asynchronous call
```js
let srcFile = pathDir + "/test.txt";
- let dstFile = pathDir + '/test';
+ let dstFile = pathDir + "/test";
fs.symlink(srcFile, dstFile, (err) => {
if (err) {
console.info("symlink failed with error message: " + err.message + ", error code: " + err.code);
@@ -1556,7 +1556,7 @@ Synchronously creates a symbolic link based on a file path.
```js
let srcFile = pathDir + "/test.txt";
- let dstFile = pathDir + '/test';
+ let dstFile = pathDir + "/test";
fs.symlinkSync(srcFile, dstFile);
```
@@ -1573,24 +1573,24 @@ Lists all files in a directory. This API uses a promise to return the result.
;
+moveFile(src: string, dest: string, mode?: number): Promise\;
Moves a file. This API uses a promise to return the result.
@@ -1725,17 +1725,17 @@ Moves a file. This API uses a promise to return the result.
**Parameters**
-| Name | Type | Mandatory | Description |
-| ------ | ------ | ---- | --------------------------- |
-| src | string | Yes | Path of the file to move in the application sandbox.|
-| dest | string | Yes | Destination path of the file in the application sandbox.|
-| mode | number | No | Whether to overwrite the file of the same name in the destination directory. The value **0** means to overwrite the file of the same name in the destination directory. The value **1** means to throw an exception if a file of the same name exists in the destination directory. The default value is **0**.|
+ | Name | Type | Mandatory | Description |
+ | ------ | ------ | ---- | --------------------------- |
+ | src | string | Yes | Path of the file to move in the application sandbox.|
+ | dest | string | Yes | Destination path of the file in the application sandbox.|
+ | mode | number | No | Whether to overwrite the file of the same name in the destination directory. The value **0** means to overwrite the file of the same name in the destination directory. The value **1** means to throw an exception if a file of the same name exists in the destination directory. The default value is **0**.|
**Example**
```js
- let srcPath = pathDir + '/source.txt';
- let destPath = pathDir + '/dest.txt';
+ let srcPath = pathDir + "/source.txt";
+ let destPath = pathDir + "/dest.txt";
fs.moveFile(srcPath, destPath, 0).then(() => {
console.info("move file succeed");
}).catch((err) => {
@@ -1745,7 +1745,7 @@ Moves a file. This API uses a promise to return the result.
## fs.moveFile
-moveFile(src: string, dest: string, mode?: number, callback: AsyncCallback): void;
+moveFile(src: string, dest: string, mode?: number, callback: AsyncCallback\): void;
Moves a file. This API uses an asynchronous callback to return the result.
@@ -1753,18 +1753,18 @@ Moves a file. This API uses an asynchronous callback to return the result.
**Parameters**
-| Name | Type | Mandatory | Description |
-| ------ | ------ | ---- | --------------------------- |
-| src | string | Yes | Path of the file to move in the application sandbox.|
-| dest | string | Yes | Destination path of the file in the application sandbox.|
-| mode | number | No | Whether to overwrite the file of the same name in the destination directory. The value **0** means to overwrite the file of the same name in the destination directory. The value **1** means to throw an exception if a file of the same name exists in the destination directory. The default value is **0**.|
-| callback | AsyncCallback<void> | Yes | Callback invoked when the file is moved. |
+ | Name | Type | Mandatory | Description |
+ | ------ | ------ | ---- | --------------------------- |
+ | src | string | Yes | Path of the file to move in the application sandbox.|
+ | dest | string | Yes | Destination path of the file in the application sandbox.|
+ | mode | number | No | Whether to overwrite the file of the same name in the destination directory. The value **0** means to overwrite the file of the same name in the destination directory. The value **1** means to throw an exception if a file of the same name exists in the destination directory. The default value is **0**.|
+ | callback | AsyncCallback<void> | Yes | Callback invoked when the file is moved. |
**Example**
```js
- let srcPath = pathDir + '/source.txt';
- let destPath = pathDir + '/dest.txt';
+ let srcPath = pathDir + "/source.txt";
+ let destPath = pathDir + "/dest.txt";
fs.moveFile(srcPath, destPath, 0, (err) => {
if (err) {
console.info("move file failed with error message: " + err.message + ", error code: " + err.code);
@@ -1784,17 +1784,17 @@ Moves a file synchronously.
**Parameters**
-| Name | Type | Mandatory | Description |
-| ------ | ------ | ---- | --------------------------- |
-| src | string | Yes | Path of the file to move in the application sandbox.|
-| dest | string | Yes | Destination path of the file in the application sandbox.|
-| mode | number | No | Whether to overwrite the file of the same name in the destination directory. The value **0** means to overwrite the file of the same name in the destination directory. The value **1** means to throw an exception if a file of the same name exists in the destination directory. The default value is **0**.|
+ | Name | Type | Mandatory | Description |
+ | ------ | ------ | ---- | --------------------------- |
+ | src | string | Yes | Path of the source file in the application sandbox.|
+ | dest | string | Yes | Destination path of the file in the application sandbox.|
+ | mode | number | No | Whether to overwrite the file of the same name in the destination directory. The value **0** means to overwrite the file of the same name in the destination directory. The value **1** means to throw an exception if a file of the same name exists in the destination directory. The default value is **0**.|
**Example**
```js
- let srcPath = pathDir + '/source.txt';
- let destPath = pathDir + '/dest.txt';
+ let srcPath = pathDir + "/source.txt";
+ let destPath = pathDir + "/dest.txt";
fs.moveFileSync(srcPath, destPath, 0);
console.info("move file succeed");
```
@@ -1809,15 +1809,15 @@ Creates a temporary directory. This API uses a promise to return the result.
**Parameters**
-| Name | Type | Mandatory | Description |
-| ------ | ------ | ---- | --------------------------- |
-| prefix | string | Yes | A randomly generated string used to replace "XXXXXX" in a directory.|
+ | Name | Type | Mandatory | Description |
+ | ------ | ------ | ---- | --------------------------- |
+ | prefix | string | Yes | A randomly generated string used to replace "XXXXXX" in a directory.|
**Return value**
-| Type | Description |
-| --------------------- | ---------- |
-| Promise<string> | Promise used to return the unique directory generated.|
+ | Type | Description |
+ | --------------------- | ---------- |
+ | Promise<string> | Promise used to return the unique directory generated.|
**Example**
@@ -1840,10 +1840,10 @@ Creates a temporary directory. This API uses an asynchronous callback to return
**Parameters**
-| Name | Type | Mandatory | Description |
-| -------- | --------------------------- | ---- | --------------------------- |
-| prefix | string | Yes | A randomly generated string used to replace "XXXXXX" in a directory.|
-| callback | AsyncCallback<string> | Yes | Callback invoked when a temporary directory is created asynchronously. |
+ | Name | Type | Mandatory | Description |
+ | -------- | --------------------------- | ---- | --------------------------- |
+ | prefix | string | Yes | A randomly generated string used to replace "XXXXXX" in a directory.|
+ | callback | AsyncCallback<string> | Yes | Callback invoked when a temporary directory is created asynchronously. |
**Example**
@@ -1867,21 +1867,21 @@ Synchronously creates a temporary directory.
**Parameters**
-| Name | Type | Mandatory | Description |
-| ------ | ------ | ---- | --------------------------- |
-| prefix | string | Yes | A randomly generated string used to replace "XXXXXX" in a directory.|
+ | Name | Type | Mandatory | Description |
+ | ------ | ------ | ---- | --------------------------- |
+ | prefix | string | Yes | A randomly generated string used to replace "XXXXXX" in a directory.|
**Return value**
-| Type | Description |
-| ------ | ---------- |
-| string | Unique path generated.|
+ | Type | Description |
+ | ------ | ---------- |
+ | string | Unique path generated.|
**Example**
```js
let res = fs.mkdtempSync(pathDir + "/XXXXXX");
- ```
+ ```
## fs.createStream
@@ -1900,9 +1900,9 @@ Opens a file stream based on the file path. This API uses a promise to return th
**Return value**
-| Type | Description |
-| --------------------------------- | --------- |
-| Promise<[Stream](#stream)> | Promise used to return the result.|
+ | Type | Description |
+ | --------------------------------- | --------- |
+ | Promise<[Stream](#stream)> | Promise used to return the result.|
**Example**
@@ -1962,9 +1962,9 @@ Synchronously opens a stream based on the file path.
**Return value**
-| Type | Description |
-| ------------------ | --------- |
-| [Stream](#stream) | Stream opened.|
+ | Type | Description |
+ | ------------------ | --------- |
+ | [Stream](#stream) | Stream opened.|
**Example**
@@ -1984,16 +1984,16 @@ Opens a file stream based on the file descriptor. This API uses a promise to ret
**Parameters**
-| Name | Type | Mandatory | Description |
-| ---- | ------ | ---- | ---------------------------------------- |
-| fd | number | Yes | FD of the file. |
-| mode | string | Yes | - **r**: Open a file for reading. The file must exist.
- **r+**: Open a file for both reading and writing. The file must exist.
- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.
- **w+**: Open a file for both reading and writing. If the file exists, clear its content. If the file does not exist, create a file.
- **a**: Open a file in append mode for writing at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).
- **a+**: Open a file in append mode for reading or updating at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).|
+ | Name | Type | Mandatory | Description |
+ | ---- | ------ | ---- | ---------------------------------------- |
+ | fd | number | Yes | FD of the file. |
+ | mode | string | Yes | - **r**: Open a file for reading. The file must exist.
- **r+**: Open a file for both reading and writing. The file must exist.
- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.
- **w+**: Open a file for both reading and writing. If the file exists, clear its content. If the file does not exist, create a file.
- **a**: Open a file in append mode for writing at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).
- **a+**: Open a file in append mode for reading or updating at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).|
**Return value**
-| Type | Description |
-| --------------------------------- | --------- |
-| Promise<[Stream](#stream)> | Promise used to return the result.|
+ | Type | Description |
+ | --------------------------------- | --------- |
+ | Promise<[Stream](#stream)> | Promise used to return the result.|
**Example**
@@ -2019,11 +2019,11 @@ Opens a file stream based on the file descriptor. This API uses an asynchronous
**Parameters**
-| Name | Type | Mandatory | Description |
-| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
-| fd | number | Yes | FD of the file. |
-| mode | string | Yes | - **r**: Open a file for reading. The file must exist.
- **r+**: Open a file for both reading and writing. The file must exist.
- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.
- **w+**: Open a file for both reading and writing. If the file exists, clear its content. If the file does not exist, create a file.
- **a**: Open a file in append mode for writing at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).
- **a+**: Open a file in append mode for reading or updating at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).|
-| callback | AsyncCallback<[Stream](#stream)> | Yes | Callback invoked when the stream is open asynchronously. |
+ | Name | Type | Mandatory | Description |
+ | -------- | ---------------------------------------- | ---- | ---------------------------------------- |
+ | fd | number | Yes | FD of the file. |
+ | mode | string | Yes | - **r**: Open a file for reading. The file must exist.
- **r+**: Open a file for both reading and writing. The file must exist.
- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.
- **w+**: Open a file for both reading and writing. If the file exists, clear its content. If the file does not exist, create a file.
- **a**: Open a file in append mode for writing at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).
- **a+**: Open a file in append mode for reading or updating at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).|
+ | callback | AsyncCallback<[Stream](#stream)> | Yes | Callback invoked when the stream is open asynchronously. |
**Example**
@@ -2050,16 +2050,16 @@ Synchronously opens a stream based on the file descriptor.
**Parameters**
-| Name | Type | Mandatory | Description |
-| ---- | ------ | ---- | ---------------------------------------- |
-| fd | number | Yes | FD of the file. |
-| mode | string | Yes | - **r**: Open a file for reading. The file must exist.
- **r+**: Open a file for both reading and writing. The file must exist.
- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.
- **w+**: Open a file for both reading and writing. If the file exists, clear its content. If the file does not exist, create a file.
- **a**: Open a file in append mode for writing at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).
- **a+**: Open a file in append mode for reading or updating at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).|
+ | Name | Type | Mandatory | Description |
+ | ---- | ------ | ---- | ---------------------------------------- |
+ | fd | number | Yes | FD of the file. |
+ | mode | string | Yes | - **r**: Open a file for reading. The file must exist.
- **r+**: Open a file for both reading and writing. The file must exist.
- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.
- **w+**: Open a file for both reading and writing. If the file exists, clear its content. If the file does not exist, create a file.
- **a**: Open a file in append mode for writing at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).
- **a+**: Open a file in append mode for reading or updating at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).|
**Return value**
-| Type | Description |
-| ------------------ | --------- |
-| [Stream](#stream) | Stream opened.|
+ | Type | Description |
+ | ------------------ | --------- |
+ | [Stream](#stream) | Stream opened.|
**Example**
@@ -2079,7 +2079,7 @@ Represents detailed file information. Before calling any API of the **Stat()** c
### Attributes
| Name | Type | Readable | Writable | Description |
-| ------ | ------ | ---- | ---- | ---------------------------------------- |
+| ------ | ------ | ---- | ---- | ---------------------------------------- |
| ino | number | Yes | No | File ID. Different files on the same device have different **ino**s.| |
| mode | number | Yes | No | File permissions. The meaning of each bit is as follows:
- **0o400**: The owner has the read permission on a regular file or a directory entry.
- **0o200**: The owner has the permission to write a regular file or create and delete a directory entry.
- **0o100**: The owner has the permission to execute a regular file or search for the specified path in a directory.
- **0o040**: The user group has the read permission on a regular file or a directory entry.
- **0o020**: The user group has the permission to write a regular file or create and delete a directory entry.
- **0o010**: The user group has the permission to execute a regular file or search for the specified path in a directory.
- **0o004**: Other users have the permission to read a regular file or read a directory entry.
- **0o002**: Other users have the permission to write a regular file or create and delete a directory entry.
- **0o001**: Other users have the permission to execute a regular file or search for the specified path in a directory.|
| uid | number | Yes | No | ID of the file owner.|
@@ -2100,9 +2100,9 @@ Checks whether this file is a block special file. A block special file supports
**Return value**
-| Type | Description |
-| ------- | ---------------- |
-| boolean | Whether the file is a block special file.|
+ | Type | Description |
+ | ------- | ---------------- |
+ | boolean | Whether the file is a block special file.|
**Example**
@@ -2121,9 +2121,9 @@ Checks whether this file is a character special file. A character special file s
**Return value**
-| Type | Description |
-| ------- | ----------------- |
-| boolean | Whether the file is a character special file.|
+ | Type | Description |
+ | ------- | ----------------- |
+ | boolean | Whether the file is a character special file.|
**Example**
@@ -2143,9 +2143,9 @@ Checks whether this file is a directory.
**Return value**
-| Type | Description |
-| ------- | ------------- |
-| boolean | Whether the file is a directory.|
+ | Type | Description |
+ | ------- | ------------- |
+ | boolean | Whether the file is a directory.|
**Example**
@@ -2165,9 +2165,9 @@ Checks whether this file is a named pipe (or FIFO). Named pipes are used for int
**Return value**
-| Type | Description |
-| ------- | --------------------- |
-| boolean | Whether the file is a FIFO.|
+ | Type | Description |
+ | ------- | --------------------- |
+ | boolean | Whether the file is a FIFO.|
**Example**
@@ -2187,9 +2187,9 @@ Checks whether this file is a regular file.
**Return value**
-| Type | Description |
-| ------- | --------------- |
-| boolean | Whether the file is a regular file.|
+ | Type | Description |
+ | ------- | --------------- |
+ | boolean | Whether the file is a regular file.|
**Example**
@@ -2209,9 +2209,9 @@ Checks whether this file is a socket.
**Return value**
-| Type | Description |
-| ------- | -------------- |
-| boolean | Whether the file is a socket.|
+ | Type | Description |
+ | ------- | -------------- |
+ | boolean | Whether the file is a socket.|
**Example**
@@ -2231,9 +2231,9 @@ Checks whether this file is a symbolic link.
**Return value**
-| Type | Description |
-| ------- | --------------- |
-| boolean | Whether the file is a symbolic link.|
+ | Type | Description |
+ | ------- | --------------- |
+ | boolean | Whether the file is a symbolic link.|
**Example**
@@ -2257,9 +2257,9 @@ Closes the stream. This API uses a promise to return the result.
**Return value**
-| Type | Description |
-| ------------------- | ------------- |
-| Promise<void> | Promise used to return the stream close result.|
+ | Type | Description |
+ | ------------------- | ------------- |
+ | Promise<void> | Promise used to return the stream close result.|
**Example**
@@ -2284,9 +2284,9 @@ Closes the stream. This API uses an asynchronous callback to return the result.
**Parameters**
-| Name | Type | Mandatory | Description |
-| -------- | ------------------------- | ---- | ------------- |
-| callback | AsyncCallback<void> | Yes | Callback invoked when the stream is closed asynchronously.|
+ | Name | Type | Mandatory | Description |
+ | -------- | ------------------------- | ---- | ------------- |
+ | callback | AsyncCallback<void> | Yes | Callback invoked when the stream is closed asynchronously.|
**Example**
@@ -2328,9 +2328,9 @@ Flushes the stream. This API uses a promise to return the result.
**Return value**
-| Type | Description |
-| ------------------- | ------------- |
-| Promise<void> | Promise used to return the stream flushing result.|
+ | Type | Description |
+ | ------------------- | ------------- |
+ | Promise<void> | Promise used to return the stream flushing result.|
**Example**
@@ -2355,9 +2355,9 @@ Flushes the stream. This API uses an asynchronous callback to return the result.
**Parameters**
-| Name | Type | Mandatory | Description |
-| -------- | ------------------------- | ---- | -------------- |
-| callback | AsyncCallback<void> | Yes | Callback invoked when the stream is asynchronously flushed.|
+ | Name | Type | Mandatory | Description |
+ | -------- | ------------------------- | ---- | -------------- |
+ | callback | AsyncCallback<void> | Yes | Callback invoked when the stream is asynchronously flushed.|
**Example**
@@ -2399,16 +2399,16 @@ Writes data into the stream. This API uses a promise to return the result.
**Parameters**
-| Name | Type | Mandatory | Description |
-| ------- | ------------------------------- | ---- | ---------------------------------------- |
-| buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. |
-| options | Object | No | The options are as follows:
- **length** (number): length of the data to write. The default value is the buffer length.
- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.
- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.|
+ | Name | Type | Mandatory | Description |
+ | ------- | ------------------------------- | ---- | ---------------------------------------- |
+ | buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. |
+ | options | Object | No | The options are as follows:
- **length** (number): length of the data to write. The default value is the buffer length.
- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.
- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.|
**Return value**
-| Type | Description |
-| --------------------- | -------- |
-| Promise<number> | Promise used to return the length of the data written.|
+ | Type | Description |
+ | --------------------- | -------- |
+ | Promise<number> | Promise used to return the length of the data written.|
**Example**
@@ -2433,11 +2433,11 @@ Writes data into the stream. This API uses an asynchronous callback to return th
**Parameters**
-| Name | Type | Mandatory| Description |
-| -------- | ------------------------------- | ---- | ------------------------------------------------------------ |
-| buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. |
-| options | Object | No | The options are as follows:
- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.
- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.
- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.|
-| callback | AsyncCallback<number> | Yes | Callback invoked when the data is written asynchronously. |
+ | Name | Type | Mandatory| Description |
+ | -------- | ------------------------------- | ---- | ------------------------------------------------------------ |
+ | buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. |
+ | options | Object | No | The options are as follows:
- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.
- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.
- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.|
+ | callback | AsyncCallback<number> | Yes | Callback invoked when the data is written asynchronously. |
**Example**
@@ -2465,16 +2465,16 @@ Synchronously writes data into the stream.
**Parameters**
-| Name | Type | Mandatory | Description |
-| ------- | ------------------------------- | ---- | ---------------------------------------- |
-| buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. |
-| options | Object | No | The options are as follows:
- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.
- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.
- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.|
+ | Name | Type | Mandatory | Description |
+ | ------- | ------------------------------- | ---- | ---------------------------------------- |
+ | buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. |
+ | options | Object | No | The options are as follows:
- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.
- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.
- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.|
**Return value**
-| Type | Description |
-| ------ | -------- |
-| number | Length of the data written in the file.|
+ | Type | Description |
+ | ------ | -------- |
+ | number | Length of the data written in the file.|
**Example**
@@ -2494,16 +2494,16 @@ Reads data from the stream. This API uses a promise to return the result.
**Parameters**
-| Name | Type | Mandatory | Description |
-| ------- | ----------- | ---- | ---------------------------------------- |
-| buffer | ArrayBuffer | Yes | Buffer used to store the file read. |
-| options | Object | No | The options are as follows:
- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length.
- **offset** (number): position of the data to read in the file. By default, data is read from the current position.|
+ | Name | Type | Mandatory | Description |
+ | ------- | ----------- | ---- | ---------------------------------------- |
+ | buffer | ArrayBuffer | Yes | Buffer used to store the file read. |
+ | options | Object | No | The options are as follows:
- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length.
- **offset** (number): position of the data to read in the file. By default, data is read from the current position.|
**Return value**
-| Type | Description |
-| ---------------------------------- | ------ |
-| Promise<number> | Promise used to return the data read.|
+ | Type | Description |
+ | ---------------------------------- | ------ |
+ | Promise<number> | Promise used to return the data read.|
**Example**
@@ -2513,7 +2513,7 @@ Reads data from the stream. This API uses a promise to return the result.
let buf = new ArrayBuffer(4096);
ss.read(buf, {offset: 5, length: 5}).then((readLen) => {
console.info("Read data successfully");
- console.log(String.fromCharCode.apply(null, new Uint8Array(buf)));
+ console.log(String.fromCharCode.apply(null, new Uint8Array(buf.slice(0, readLen))));
}).catch((err) => {
console.info("read data failed with error message: " + err.message + ", error code: " + err.code);
});
@@ -2530,11 +2530,11 @@ Reads data from the stream. This API uses an asynchronous callback to return the
**Parameters**
-| Name | Type | Mandatory | Description |
-| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
-| buffer | ArrayBuffer | Yes | Buffer used to store the file read. |
-| options | Object | No | The options are as follows:
- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length.
- **offset** (number): position of the data to read in the file. This parameter is optional. By default, data is read from the current position.|
-| callback | AsyncCallback<number> | Yes | Callback invoked when data is read asynchronously from the stream. |
+ | Name | Type | Mandatory | Description |
+ | -------- | ---------------------------------------- | ---- | ---------------------------------------- |
+ | buffer | ArrayBuffer | Yes | Buffer used to store the file read. |
+ | options | Object | No | The options are as follows:
- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length.
- **offset** (number): position of the data to read in the file. This parameter is optional. By default, data is read from the current position.|
+ | callback | AsyncCallback<number> | Yes | Callback invoked when data is read asynchronously from the stream. |
**Example**
@@ -2547,7 +2547,7 @@ Reads data from the stream. This API uses an asynchronous callback to return the
console.info("read stream failed with error message: " + err.message + ", error code: " + err.code);
} else {
console.info("Read data successfully");
- console.log(String.fromCharCode.apply(null, new Uint8Array(buf)));
+ console.log(String.fromCharCode.apply(null, new Uint8Array(buf.slice(0, readLen))));
}
});
```
@@ -2562,16 +2562,16 @@ Synchronously reads data from the stream.
**Parameters**
-| Name | Type | Mandatory | Description |
-| ------- | ----------- | ---- | ---------------------------------------- |
-| buffer | ArrayBuffer | Yes | Buffer used to store the file read. |
-| options | Object | No | The options are as follows:
- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length.
- **offset** (number): position of the data to read in the file. This parameter is optional. By default, data is read from the current position.
|
+ | Name | Type | Mandatory | Description |
+ | ------- | ----------- | ---- | ---------------------------------------- |
+ | buffer | ArrayBuffer | Yes | Buffer used to store the file read. |
+ | options | Object | No | The options are as follows:
- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length.
- **offset** (number): position of the data to read in the file. By default, data is read from the current position.
|
**Return value**
-| Type | Description |
-| ------ | -------- |
-| number | Length of the data read.|
+ | Type | Description |
+ | ------ | -------- |
+ | number | Length of the data read.|
**Example**
@@ -2595,7 +2595,7 @@ Represents a **File** object opened by **open()**.
### lock
-lock(exclusive?: boolean): Promise;
+lock(exclusive?: boolean): Promise\;
Applies an exclusive lock or a shared lock on this file in blocking mode. This API uses a promise to return the result.
@@ -2603,15 +2603,15 @@ Applies an exclusive lock or a shared lock on this file in blocking mode. This A
**Parameters**
-| Name | Type | Mandatory | Description |
-| ------- | ----------- | ---- | ---------------------------------------- |
-| exclusive | boolean | No | Lock to apply. The value **true** means an exclusive lock, and the value **false** (default) means a shared lock. |
+ | Name | Type | Mandatory | Description |
+ | ------- | ----------- | ---- | ---------------------------------------- |
+ | exclusive | boolean | No | Lock to apply. The value **true** means an exclusive lock, and the value **false** (default) means a shared lock. |
**Return value**
-| Type | Description |
-| ---------------------------------- | ------ |
-| Promise<void> | Promise that returns no value.|
+ | Type | Description |
+ | ---------------------------------- | ------ |
+ | Promise<void> | Promise that returns no value.|
**Example**
@@ -2626,7 +2626,7 @@ Applies an exclusive lock or a shared lock on this file in blocking mode. This A
### lock
-lock(exclusive?: boolean, callback: AsyncCallback): void;
+lock(exclusive?: boolean, callback: AsyncCallback\): void;
Applies an exclusive lock or a shared lock on this file in blocking mode. This API uses a promise to return the result.
@@ -2634,10 +2634,10 @@ Applies an exclusive lock or a shared lock on this file in blocking mode. This A
**Parameters**
-| Name | Type | Mandatory | Description |
-| ------- | ----------- | ---- | ---------------------------------------- |
-| exclusive | boolean | No | Lock to apply. The value **true** means an exclusive lock, and the value **false** (default) means a shared lock. |
-| callback | AsyncCallback<void> | Yes | Callback invoked when the file is locked. |
+ | Name | Type | Mandatory | Description |
+ | ------- | ----------- | ---- | ---------------------------------------- |
+ | exclusive | boolean | No | Lock to apply. The value **true** means an exclusive lock, and the value **false** (default) means a shared lock. |
+ | callback | AsyncCallback<void> | Yes | Callback invoked when the file is locked. |
**Example**
@@ -2662,9 +2662,9 @@ Applies an exclusive lock or a shared lock on this file in non-blocking mode.
**Parameters**
-| Name | Type | Mandatory | Description |
-| ------- | ----------- | ---- | ---------------------------------------- |
-| exclusive | boolean | No | Lock to apply. The value **true** means an exclusive lock, and the value **false** (default) means a shared lock. |
+ | Name | Type | Mandatory | Description |
+ | ------- | ----------- | ---- | ---------------------------------------- |
+ | exclusive | boolean | No | Lock to apply. The value **true** means an exclusive lock, and the value **false** (default) means a shared lock. |
**Example**