diff --git a/en/application-dev/reference/apis/js-apis-fileio.md b/en/application-dev/reference/apis/js-apis-fileio.md
index 6e970785345a27be2c2c4d1051f87c13c4d8533f..4d3791fd26788b92c136c32df7f298787f887f3d 100644
--- a/en/application-dev/reference/apis/js-apis-fileio.md
+++ b/en/application-dev/reference/apis/js-apis-fileio.md
@@ -17,15 +17,31 @@ import fileio from '@ohos.fileio';
Before using the APIs provided by this module to perform operations on files or directories, obtain the path of the application sandbox as follows:
+Stage Model
+
+ ```js
+import Ability from '@ohos.application.Ability';
+class MainAbility extends Ability {
+ onWindowStageCreate(windowStage) {
+ let context = this.context;
+ let path = context.filesDir;
+ }
+}
+ ```
+
+ For details about how to obtain the stage model context, see [Stage Model](https://gitee.com/openharmony/docs/blob/master/en/application-dev/reference/apis/js-apis-ability-context.md#abilitycontext).
+
+FA Model
+
```js
import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext();
- let path = '';
context.getFilesDir().then((data) => {
- path = data;
+ let path = data;
})
```
-
+
+ For details about how to obtain the context of the FA model, see [FA Model](https://gitee.com/openharmony/docs/blob/master/en/application-dev/reference/apis/js-apis-Context.md#context).
## fileio.stat
@@ -654,7 +670,7 @@ Reads data from a file. This API uses a promise to return the result.
let fd = fileio.openSync(path, 0o2);
let buf = new ArrayBuffer(4096);
fileio.read(fd, buf).then(function(readOut){
- console.info("Read file data");
+ console.info("Read file data successfully");
console.log(String.fromCharCode.apply(null, new Uint8Array(readOut.buffer)));
}).catch(function(err){
console.info("Failed to read file data. Error:"+ err);
@@ -690,7 +706,7 @@ Reads data from a file. This API uses an asynchronous callback to return the res
let buf = new ArrayBuffer(4096);
fileio.read(fd, buf, function (err, readOut) {
if (readOut) {
- console.info("Read file data");
+ console.info("Read file data successfully");
console.log(String.fromCharCode.apply(null, new Uint8Array(readOut.buffer)));
}
});
@@ -1263,7 +1279,7 @@ Truncates a file based on the file descriptor. This API uses an asynchronous cal
| -------- | ------------------------- | ---- | ---------------- |
| fd | number | Yes | File descriptor of the file to truncate. |
| len | number | Yes | File length, in bytes, after truncation.|
- | callback | AsyncCallback<void> | Yes | Callback that returns no value. |
+ | callback | AsyncCallback<void> | Yes | Callback that returns no value.|
**Example**
@@ -1347,7 +1363,7 @@ Truncates a file based on the file path. This API uses an asynchronous callback
| -------- | ------------------------- | ---- | -------------------------------- |
| path | string | Yes | Application sandbox path of the file to truncate.|
| len | number | Yes | File length, in bytes, after truncation.|
-| callback | AsyncCallback<void> | Yes | Callback that returns no value. |
+| callback | AsyncCallback<void> | Yes | Callback that returns no value.|
**Example**
@@ -1411,7 +1427,7 @@ Reads the text content of a file. This API uses a promise to return the result.
```js
fileio.readText(path).then(function(str) {
- console.info("Read text:"+ str);
+ console.info("Read text successfully:"+ str);
}).catch(function(err){
console.info("Failed to read the text. Error:"+ err);
});
@@ -2159,7 +2175,7 @@ Opens a file stream based on the file path. This API uses a promise to return th
| Type | Description |
| --------------------------------- | --------- |
- | Promise<[Stream](#stream7)> | Promise used to return the result.|
+ | Promise<[Stream](#stream)> | Promise used to return the result.|
**Example**
@@ -2186,7 +2202,7 @@ Opens a file stream based on the file path. This API uses an asynchronous callba
| -------- | --------------------------------------- | ---- | ------------------------------------------------------------ |
| path | string | Yes | Application sandbox path 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](#stream7)> | Yes | Callback invoked when the stream is open asynchronously. |
+| callback | AsyncCallback<[Stream](#stream)> | Yes | Callback invoked when the stream is open asynchronously. |
**Example**
@@ -2216,7 +2232,7 @@ Synchronously opens a stream based on the file path.
| Type | Description |
| ------------------ | --------- |
- | [Stream](#stream7) | Stream opened.|
+ | [Stream](#stream) | Stream opened.|
**Example**
@@ -2244,7 +2260,7 @@ Opens a file stream based on the file descriptor. This API uses a promise to ret
| Type | Description |
| --------------------------------- | --------- |
- | Promise<[Stream](#stream7)> | Promise used to return the result.|
+ | Promise<[Stream](#stream)> | Promise used to return the result.|
**Example**
@@ -2272,7 +2288,7 @@ Opens a file stream based on the file descriptor. This API uses an asynchronous
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| fd | number | Yes | File descriptor of the target file. |
| mode | string | Yes | - **r**: Open a file for reading. The file must exist.
- **r+**: Open a file for both reading and writing. The file must exist.
- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.
- **w+**: Open a file for both reading and writing. If the file exists, clear its content. If the file does not exist, create a file.
- **a**: Open a file in append mode for writing at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).
- **a+**: Open a file in append mode for reading or updating at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).|
- | callback | AsyncCallback <[Stream](#stream7)> | Yes | Callback invoked when the stream is open asynchronously. |
+ | callback | AsyncCallback <[Stream](#stream)> | Yes | Callback invoked when the stream is open asynchronously. |
**Example**
@@ -2303,7 +2319,7 @@ Synchronously opens a stream based on the file descriptor.
| Type | Description |
| ------------------ | --------- |
- | [Stream](#stream7) | Stream opened.|
+ | [Stream](#stream) | Stream opened.|
**Example**
@@ -2720,7 +2736,7 @@ Stops the **watcher** instance. This API uses a promise to return the result.
```js
let filename = path +"/test.txt";
- let watcher = await fileio.createWatcher(filename, 1, function(number){
+ let watcher = fileio.createWatcher(filename, 1, function(number){
console.info("Monitoring times: "+number);
});
watcher.stop().then(function(){
@@ -2747,7 +2763,7 @@ Stops the **watcher** instance. This API uses an asynchronous callback to return
```js
let filename = path +"/test.txt";
- let watcher = await fileio.createWatcher(filename, 1, function(number){
+ let watcher = fileio.createWatcher(filename, 1, function(number){
console.info("Monitoring times: "+number);
});
watcher.stop(function(){
@@ -3124,7 +3140,6 @@ Reads the next directory entry. This API uses a promise to return the result.
**Example**
```js
- let dir = fileio.opendirSync(path);
dir.read().then(function (dirent){
console.log("Read the next directory entry:"+JSON.stringify(dirent));
}).catch(function(err){
@@ -3150,7 +3165,6 @@ Reads the next directory entry. This API uses an asynchronous callback to return
**Example**
```js
- let dir = fileio.opendirSync(path);
dir.read(function (err, dirent) {
if (dirent) {
// Do something
@@ -3177,7 +3191,6 @@ Synchronously reads the next directory entry.
**Example**
```js
- let dir = fileio.opendirSync(path);
let dirent = dir.readSync();
```
@@ -3193,7 +3206,6 @@ Closes a directory. This API uses a promise to return the result. After a direct
**Example**
```js
- let dir = fileio.opendirSync(path);
dir.close().then(function(err){
console.info("close dir successfully");
});
@@ -3211,7 +3223,6 @@ Closes a directory. This API uses an asynchronous callback to return the result.
**Example**
```js
- let dir = fileio.opendirSync(path);
dir.close(function(err){
console.info("close dir successfully");
});
@@ -3229,7 +3240,6 @@ Closes a directory. After a directory is closed, the file descriptor in Dir will
**Example**
```js
- let dir = fileio.opendirSync(path);
dir.closeSync();
```
diff --git a/en/application-dev/reference/apis/js-apis-securityLabel.md b/en/application-dev/reference/apis/js-apis-securityLabel.md
index 86ae51122132f39ce30fe8df4bebc626c8e07d3f..d61e7c1b5a08c7dcdb841742a8359bac5e12ad69 100644
--- a/en/application-dev/reference/apis/js-apis-securityLabel.md
+++ b/en/application-dev/reference/apis/js-apis-securityLabel.md
@@ -1,10 +1,10 @@
# Security Label
+The **secuityLabel** module provides APIs to manage file data security levels, including obtaining and setting file data security levels.
+
> **NOTE**
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
-The **secuityLabel** module provides APIs to manage file data security levels, including obtaining and setting file data security levels.
-
## Modules to Import
```js
@@ -48,8 +48,7 @@ Sets the security label for a file in asynchronous mode. This API uses a promise
**Example**
```js
- let type = "s4";
- securityLabel.setSecurityLabel(path, type).then(function(){
+ securityLabel.setSecurityLabel(path, "s0").then(function(){
console.info("setSecurityLabel successfully");
}).catch(function(error){
console.info("setSecurityLabel failed with error:" + error);
@@ -75,8 +74,7 @@ Sets the security label for a file in asynchronous mode. This API uses a callbac
**Example**
```js
- let type = "s4";
- securityLabel.setSecurityLabel(path, type, function(error){
+ securityLabel.setSecurityLabel(path, "s0", function(error){
console.info("setSecurityLabel:" + JSON.stringify(error));
});
```
@@ -98,8 +96,7 @@ Sets the security label for a file in synchronous mode.
**Example**
```js
-let type = "s4";
-securityLabel.setSecurityLabelSync(path, type);
+securityLabel.setSecurityLabelSync(path, "s0");
```
## securityLabel.getSecurityLabel
@@ -125,11 +122,10 @@ Obtains the security label of a file in asynchronous mode. This API uses a promi
**Example**
```js
- let type = "s4";
securityLabel.getSecurityLabel(path).then(function(type){
console.log("getSecurityLabel successfully:" + type);
- }).catch(function(error){
- console.log("getSecurityLabel failed with error:" + error);
+ }).catch(function(err){
+ console.log("getSecurityLabel failed with error:" + err);
});
```
@@ -151,8 +147,7 @@ Obtains the security label of a file in asynchronous mode. This API uses a callb
**Example**
```js
- let type = "s4";
- securityLabel.getSecurityLabel(path,function(error, type){
+ securityLabel.getSecurityLabel(path, function(err, type){
console.log("getSecurityLabel successfully:" + type);
});
```
diff --git a/en/application-dev/reference/apis/js-apis-storage-statistics.md b/en/application-dev/reference/apis/js-apis-storage-statistics.md
index 5606a2e64372c3e002815d535f59851718e535e9..658082d2690c0ab00d76959a1a7ce1c97574ce5d 100644
--- a/en/application-dev/reference/apis/js-apis-storage-statistics.md
+++ b/en/application-dev/reference/apis/js-apis-storage-statistics.md
@@ -1,12 +1,12 @@
# 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**
>
> - 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.
-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.
-
## Modules to Import
```js
@@ -264,14 +264,13 @@ Asynchronously obtains space information of the current third-party application.
## BundleStats9+
+### Attributes
+
**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
This is a system API and cannot be called by third-party applications.
-
-### Attributes
-
| Name | Type | Description |
| --------- | ------ | -------------- |
| appSize | number | Size of the application. |
@@ -523,14 +522,13 @@ This is a system API and cannot be called by third-party applications.
## StorageStats9+
+### Attributes
+
**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
This is a system API and cannot be called by third-party applications.
-
-### Attributes
-
| Name | Type | Description |
| --------- | ------ | -------------- |
| total | number | Total space of the built-in memory card. |
diff --git a/en/application-dev/reference/apis/js-apis-volumemanager.md b/en/application-dev/reference/apis/js-apis-volumemanager.md
index a91577d272d67835ba1d7194200be508ed44a6ea..87cfad2f83ba3c25d4ab90a874777d86bb2cd473 100644
--- a/en/application-dev/reference/apis/js-apis-volumemanager.md
+++ b/en/application-dev/reference/apis/js-apis-volumemanager.md
@@ -191,20 +191,24 @@ Asynchronously obtains volume information based on the universally unique identi
**Parameters**
| Name | Type | Mandatory| Description|
- | -------- | ------ | ---- | ---- |
+ | -------- | ------ | ---- | ---- |
| uuid | string | Yes | UUID of the volume.|
**Return value**
| Type | Description |
- | ---------------------------------- | -------------------------- |
+ | ---------------------------------- | -------------------------- |
| Promise<[Volume](#volume)> | Promise used to return the volume information obtained.|
**Example**
```js
let uuid = "";
- let volume = await volumemanager.getVolumeByUuid(uuid);
+ volumemanager.getVolumeByUuid(uuid).then(function(volume) {
+ console.info("getVolumeByUuid successfully:" + JSON.stringify(volume));
+ }).catch(function(error){
+ console.info("getVolumeByUuid failed with error:"+ error);
+ });
```
## volumemanager.getVolumeByUuid
@@ -235,7 +239,7 @@ Asynchronously obtains volume information based on the UUID. This API uses a cal
## volumemanager.getVolumeById
-getVolumeById(id: string): Promise<Volume>
+getVolumeById(volumeId: string): Promise<Volume>
Asynchronously obtains volume information based on the volume ID. This API uses a promise to return the result.
@@ -247,7 +251,7 @@ Asynchronously obtains volume information based on the volume ID. This API uses
| Name | Type | Mandatory | Description|
| -------- | ------ | ---- | ---- |
- | id | string | Yes | Volume ID.|
+ | volumeId | string | Yes | Volume ID.|
**Return value**
@@ -258,13 +262,17 @@ Asynchronously obtains volume information based on the volume ID. This API uses
**Example**
```js
- let id = "";
- let volume = await volumemanager.getVolumeById(id);
+ let volumeId = "";
+ volumemanager.getVolumeById(volumeId).then(function(volume) {
+ console.info("getVolumeById successfully:" + JSON.stringify(volume));
+ }).catch(function(error){
+ console.info("getVolumeById failed with error:"+ error);
+ });
```
## volumemanager.getVolumeById
-getVolumeById(id: string, callback: AsyncCallback<Volume>): void
+getVolumeById(volumeId: string, callback: AsyncCallback<Volume>): void
Asynchronously obtains volume information based on the volume ID. This API uses a callback to return the result.
@@ -274,16 +282,16 @@ Asynchronously obtains volume information based on the volume ID. This API uses
**Parameters**
- | Name | Type | Mandatory| Description |
- | -------- | ------------------------------------------------ | ---- | -------------------- |
- | id | string | Yes | Volume ID. |
- | callback | callback:AsyncCallback<[Volume](#volume)> | Yes | Callback invoked to return the volume information obtained.|
+ | Name | Type | Mandatory| Description |
+ | -------- | ------------------------- | ---- | ----------------------------- |
+ | volumeId | string | Yes | Volume ID. |
+ | callback | callback:AsyncCallback<[Volume](#volume)> | Yes | Callback invoked to return the volume information obtained. |
**Example**
```js
- let id = "";
- volumemanager.getVolumeById(id, (error, volume) => {
+ let volumeId = "";
+ volumemanager.getVolumeById(volumeId, (error, volume) => {
// Do something.
});
```
@@ -316,7 +324,11 @@ Asynchronously sets the volume description based on the UUID. This API uses a pr
```js
let uuid = "";
let description = "";
- let bool = await volumemanager.setVolumeDescription(uuid, description);
+ volumemanager.setVolumeDescription(uuid, description).then(function() {
+ console.info("setVolumeDescription successfully");
+ }).catch(function(error){
+ console.info("setVolumeDescription failed with error:"+ error);
+ });
```
## volumemanager.setVolumeDescription
@@ -349,7 +361,7 @@ Asynchronously sets the volume description based on the UUID. This API uses a ca
## volumemanager.format
-format(volId: string): Promise<void>
+format(volumeId: string, fsType: string): Promise<void>
Asynchronously formats a volume. This API uses a promise to return the result.
@@ -361,24 +373,30 @@ Asynchronously formats a volume. This API uses a promise to return the result.
| Name | Type | Mandatory| Description|
| ----------- | ------ | ---- | ---- |
- | volId | string | Yes | Volume ID.|
+ | volumeId | string | Yes | Volume ID.|
+ | fsType | string | Yes | File system type.|
**Return value**
- | Type | Description |
- | --------------------- | ----------------------- |
- | Promise<void> | Promise used to return the result. |
+ | Type | Description |
+ | ---------------------- | ---------- |
+ | Promise<void> | Promise used to return the result.|
**Example**
```js
- let volId = "";
- let bool = await volumemanager.format(volId);
+ let volumeId = "";
+ let fsType = "";
+ volumemanager.format(volumeId, fsType).then(function() {
+ console.info("format successfully");
+ }).catch(function(error){
+ console.info("format failed with error:"+ error);
+ });
```
## volumemanager.format
-format(volId: string, callback: AsyncCallback<void>): void
+format(volumeId: string, fsType: string, callback: AsyncCallback<void>): void
Asynchronously formats a volume. This API uses a callback to return the result.
@@ -388,23 +406,25 @@ Asynchronously formats a volume. This API uses a callback to return the result.
**Parameters**
- | Name | Type | Mandatory| Description |
- | -------- | --------------------------------------- | ---- | ---------------- |
- | volId | string | Yes | Volume ID. |
- | callback | callback:AsyncCallback<void> | Yes | Callback invoked to return the result. |
+ | Name | Type | Mandatory| Description |
+ | -------- | ------------------------- | ---- | ----------------------------- |
+ | volumeId | string | Yes | Volume ID. |
+ | fsType | string | Yes | File system type.|
+ | callback | callback:AsyncCallback<void> | Yes | Called after the volume is formatted. |
**Example**
```js
- let volId = "";
- volumemanager.format(volId, (error, bool) => {
+ let volumeId = "";
+ let fsType = "";
+ volumemanager.format(volumeId, fsType, (error, bool) => {
// Do something.
});
```
## volumemanager.partition
-partition(volId: string, fstype: string): Promise<void>
+partition(diskId: string, type: number): Promise<void>
Asynchronously partitions a disk. This API uses a promise to return the result.
@@ -415,9 +435,9 @@ Asynchronously partitions a disk. This API uses a promise to return the result.
**Parameters**
| Name | Type | Mandatory| Description|
- | ----------- | ------ | ---- | ---- |
- | volId | string | Yes | ID of the disk to which the volume belongs.|
- | fstype | string | Yes | Partition type. |
+ | ----------- | ------ | ---- | ---- |
+ | diskId | string | Yes | ID of the disk to which the volume belongs.|
+ | type | number | Yes | Partition type. |
**Return value**
@@ -428,14 +448,18 @@ Asynchronously partitions a disk. This API uses a promise to return the result.
**Example**
```js
- let volId = "";
- let fstype = "";
- let bool = await volumemanager.partition(volId, fstype);
+ let diskId = "";
+ let type = 0;
+ volumemanager.partition(diskId, type).then(function() {
+ console.info("partition successfully");
+ }).catch(function(error){
+ console.info("partition failed with error:"+ error);
+ });
```
## volumemanager.partition
-partition(volId: string, fstype : string, callback: AsyncCallback<void>): void
+partition(diskId: string, type: number, callback: AsyncCallback<void>): void
Asynchronously partitions a disk. This API uses a callback to return the result.
@@ -447,16 +471,16 @@ Asynchronously partitions a disk. This API uses a callback to return the result.
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ---------------- |
- | volId | string | Yes | ID of the disk to which the volume belongs. |
- | fstype | string | Yes | Partition type. |
+ | diskId | string | Yes | ID of the disk to which the volume belongs. |
+ | type | number | Yes | Partition type. |
| callback | callback:AsyncCallback<void> | Yes | Callback invoked to return the result. |
**Example**
```js
- let volId = "";
- let fstype = "";
- volumemanager.format(volId, fstype, (error, bool) => {
+ let diskId = "";
+ let type = 0;
+ volumemanager.partition(diskId, type, (error, bool) => {
// Do something.
});
```
@@ -471,6 +495,7 @@ Asynchronously partitions a disk. This API uses a callback to return the result.
| ----------- | ------- | -------------------- |
| id | string | Volume ID. |
| uuid | string | UUID of the volume. |
+| diskId | string | ID of the disk to which the volume belongs. |
| description | string | Description of the volume. |
| removable | boolean | Whether the volume is a removable storage device.|
| state | number | Volume state. |