提交 8d619288 编写于 作者: A Annie_wang

update docs

Signed-off-by: NAnnie_wang <annie.wangli@huawei.com>
上级 4954436a
...@@ -17,15 +17,31 @@ import fileio from '@ohos.fileio'; ...@@ -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: 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 ```js
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext(); let context = featureAbility.getContext();
let path = '';
context.getFilesDir().then((data) => { 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 ## fileio.stat
...@@ -654,7 +670,7 @@ Reads data from a file. This API uses a promise to return the result. ...@@ -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 fd = fileio.openSync(path, 0o2);
let buf = new ArrayBuffer(4096); let buf = new ArrayBuffer(4096);
fileio.read(fd, buf).then(function(readOut){ 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))); console.log(String.fromCharCode.apply(null, new Uint8Array(readOut.buffer)));
}).catch(function(err){ }).catch(function(err){
console.info("Failed to read file data. Error:"+ 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 ...@@ -690,7 +706,7 @@ Reads data from a file. This API uses an asynchronous callback to return the res
let buf = new ArrayBuffer(4096); let buf = new ArrayBuffer(4096);
fileio.read(fd, buf, function (err, readOut) { fileio.read(fd, buf, function (err, readOut) {
if (readOut) { if (readOut) {
console.info("Read file data"); console.info("Read file data successfully");
console.log(String.fromCharCode.apply(null, new Uint8Array(readOut.buffer))); 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 ...@@ -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. | | fd | number | Yes | File descriptor of the file to truncate. |
| len | number | Yes | File length, in bytes, after truncation.| | len | number | Yes | File length, in bytes, after truncation.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback that returns no value. | | callback | AsyncCallback&lt;void&gt; | Yes | Callback that returns no value.|
**Example** **Example**
...@@ -1347,7 +1363,7 @@ Truncates a file based on the file path. This API uses an asynchronous callback ...@@ -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.| | path | string | Yes | Application sandbox path of the file to truncate.|
| len | number | Yes | File length, in bytes, after truncation.| | len | number | Yes | File length, in bytes, after truncation.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback that returns no value. | | callback | AsyncCallback&lt;void&gt; | Yes | Callback that returns no value.|
**Example** **Example**
...@@ -1411,7 +1427,7 @@ Reads the text content of a file. This API uses a promise to return the result. ...@@ -1411,7 +1427,7 @@ Reads the text content of a file. This API uses a promise to return the result.
```js ```js
fileio.readText(path).then(function(str) { fileio.readText(path).then(function(str) {
console.info("Read text:"+ str); console.info("Read text successfully:"+ str);
}).catch(function(err){ }).catch(function(err){
console.info("Failed to read the text. Error:"+ err); console.info("Failed to read the text. Error:"+ err);
}); });
...@@ -2720,7 +2736,7 @@ Stops the **watcher** instance. This API uses a promise to return the result. ...@@ -2720,7 +2736,7 @@ Stops the **watcher** instance. This API uses a promise to return the result.
```js ```js
let filename = path +"/test.txt"; 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); console.info("Monitoring times: "+number);
}); });
watcher.stop().then(function(){ watcher.stop().then(function(){
...@@ -2747,7 +2763,7 @@ Stops the **watcher** instance. This API uses an asynchronous callback to return ...@@ -2747,7 +2763,7 @@ Stops the **watcher** instance. This API uses an asynchronous callback to return
```js ```js
let filename = path +"/test.txt"; 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); console.info("Monitoring times: "+number);
}); });
watcher.stop(function(){ watcher.stop(function(){
...@@ -3124,7 +3140,6 @@ Reads the next directory entry. This API uses a promise to return the result. ...@@ -3124,7 +3140,6 @@ Reads the next directory entry. This API uses a promise to return the result.
**Example** **Example**
```js ```js
let dir = fileio.opendirSync(path);
dir.read().then(function (dirent){ dir.read().then(function (dirent){
console.log("Read the next directory entry:"+JSON.stringify(dirent)); console.log("Read the next directory entry:"+JSON.stringify(dirent));
}).catch(function(err){ }).catch(function(err){
...@@ -3150,7 +3165,6 @@ Reads the next directory entry. This API uses an asynchronous callback to return ...@@ -3150,7 +3165,6 @@ Reads the next directory entry. This API uses an asynchronous callback to return
**Example** **Example**
```js ```js
let dir = fileio.opendirSync(path);
dir.read(function (err, dirent) { dir.read(function (err, dirent) {
if (dirent) { if (dirent) {
// Do something // Do something
...@@ -3177,7 +3191,6 @@ Synchronously reads the next directory entry. ...@@ -3177,7 +3191,6 @@ Synchronously reads the next directory entry.
**Example** **Example**
```js ```js
let dir = fileio.opendirSync(path);
let dirent = dir.readSync(); let dirent = dir.readSync();
``` ```
...@@ -3193,7 +3206,6 @@ Closes a directory. This API uses a promise to return the result. After a direct ...@@ -3193,7 +3206,6 @@ Closes a directory. This API uses a promise to return the result. After a direct
**Example** **Example**
```js ```js
let dir = fileio.opendirSync(path);
dir.close().then(function(err){ dir.close().then(function(err){
console.info("close dir successfully"); console.info("close dir successfully");
}); });
...@@ -3211,7 +3223,6 @@ Closes a directory. This API uses an asynchronous callback to return the result. ...@@ -3211,7 +3223,6 @@ Closes a directory. This API uses an asynchronous callback to return the result.
**Example** **Example**
```js ```js
let dir = fileio.opendirSync(path);
dir.close(function(err){ dir.close(function(err){
console.info("close dir successfully"); console.info("close dir successfully");
}); });
...@@ -3229,7 +3240,6 @@ Closes a directory. After a directory is closed, the file descriptor in Dir will ...@@ -3229,7 +3240,6 @@ Closes a directory. After a directory is closed, the file descriptor in Dir will
**Example** **Example**
```js ```js
let dir = fileio.opendirSync(path);
dir.closeSync(); dir.closeSync();
``` ```
......
# Security Label # Security Label
The secuityLabel module provides APIs to manage file data security levels, including obtaining and setting file data security levels. The **secuityLabel** module provides APIs to manage file data security levels, including obtaining and setting file data security levels.
> **NOTE**<br/> > **NOTE**<br/>
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
......
# App Storage Statistics # App Storage Statistics
The storageStatistics module provides APIs for obtaining storage space information, including the space of built-in and plug-in memory cards, space occupied by different types of data, and space of application data. The **storageStatistics** module provides APIs for obtaining storage space information, including the space of built-in and plug-in memory cards, space occupied by different types of data, and space of application data.
> **NOTE**<br/> > **NOTE**<br/>
> >
...@@ -264,14 +264,13 @@ Asynchronously obtains space information of the current third-party application. ...@@ -264,14 +264,13 @@ Asynchronously obtains space information of the current third-party application.
## BundleStats<sup>9+</sup> ## BundleStats<sup>9+</sup>
### Attributes
**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics **System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
This is a system API and cannot be called by third-party applications. This is a system API and cannot be called by third-party applications.
### Attributes
| Name | Type | Description | | Name | Type | Description |
| --------- | ------ | -------------- | | --------- | ------ | -------------- |
| appSize | number | Size of the application. | | appSize | number | Size of the application. |
...@@ -523,14 +522,13 @@ This is a system API and cannot be called by third-party applications. ...@@ -523,14 +522,13 @@ This is a system API and cannot be called by third-party applications.
## StorageStats<sup>9+</sup> ## StorageStats<sup>9+</sup>
### Attributes
**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics **System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
This is a system API and cannot be called by third-party applications. This is a system API and cannot be called by third-party applications.
### Attributes
| Name | Type | Description | | Name | Type | Description |
| --------- | ------ | -------------- | | --------- | ------ | -------------- |
| total | number | Total space of the built-in memory card. | | total | number | Total space of the built-in memory card. |
......
...@@ -204,7 +204,11 @@ Asynchronously obtains volume information based on the universally unique identi ...@@ -204,7 +204,11 @@ Asynchronously obtains volume information based on the universally unique identi
```js ```js
let uuid = ""; 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 ## volumemanager.getVolumeByUuid
...@@ -235,7 +239,7 @@ Asynchronously obtains volume information based on the UUID. This API uses a cal ...@@ -235,7 +239,7 @@ Asynchronously obtains volume information based on the UUID. This API uses a cal
## volumemanager.getVolumeById ## volumemanager.getVolumeById
getVolumeById(id: string): Promise&lt;Volume&gt; getVolumeById(volumeId: string): Promise&lt;Volume&gt;
Asynchronously obtains volume information based on the volume ID. This API uses a promise to return the result. 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 ...@@ -247,7 +251,7 @@ Asynchronously obtains volume information based on the volume ID. This API uses
| Name | Type | Mandatory | Description| | Name | Type | Mandatory | Description|
| -------- | ------ | ---- | ---- | | -------- | ------ | ---- | ---- |
| id | string | Yes | Volume ID.| | volumeId | string | Yes | Volume ID.|
**Return value** **Return value**
...@@ -258,13 +262,17 @@ Asynchronously obtains volume information based on the volume ID. This API uses ...@@ -258,13 +262,17 @@ Asynchronously obtains volume information based on the volume ID. This API uses
**Example** **Example**
```js ```js
let id = ""; let volumeId = "";
let volume = await volumemanager.getVolumeById(id); 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 ## volumemanager.getVolumeById
getVolumeById(id: string, callback: AsyncCallback&lt;Volume&gt;): void getVolumeById(volumeId: string, callback: AsyncCallback&lt;Volume&gt;): void
Asynchronously obtains volume information based on the volume ID. This API uses a callback to return the result. Asynchronously obtains volume information based on the volume ID. This API uses a callback to return the result.
...@@ -275,15 +283,15 @@ Asynchronously obtains volume information based on the volume ID. This API uses ...@@ -275,15 +283,15 @@ Asynchronously obtains volume information based on the volume ID. This API uses
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------------------------------ | ---- | -------------------- | | -------- | ------------------------- | ---- | ----------------------------- |
| id | string | Yes | Volume ID. | | volumeId | string | Yes | Volume ID. |
| callback | callback:AsyncCallback&lt;[Volume](#volume)&gt; | Yes | Callback invoked to return the volume information obtained.| | callback | callback:AsyncCallback&lt;[Volume](#volume)&gt; | Yes | Callback invoked to return the volume information obtained. |
**Example** **Example**
```js ```js
let id = ""; let volumeId = "";
volumemanager.getVolumeById(id, (error, volume) => { volumemanager.getVolumeById(volumeId, (error, volume) => {
// Do something. // Do something.
}); });
``` ```
...@@ -316,7 +324,11 @@ Asynchronously sets the volume description based on the UUID. This API uses a pr ...@@ -316,7 +324,11 @@ Asynchronously sets the volume description based on the UUID. This API uses a pr
```js ```js
let uuid = ""; let uuid = "";
let description = ""; 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 ## volumemanager.setVolumeDescription
...@@ -349,7 +361,7 @@ Asynchronously sets the volume description based on the UUID. This API uses a ca ...@@ -349,7 +361,7 @@ Asynchronously sets the volume description based on the UUID. This API uses a ca
## volumemanager.format ## volumemanager.format
format(volId: string): Promise&lt;void&gt; format(volumeId: string, fsType: string): Promise&lt;void&gt;
Asynchronously formats a volume. This API uses a promise to return the result. 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. ...@@ -361,24 +373,30 @@ Asynchronously formats a volume. This API uses a promise to return the result.
| Name | Type | Mandatory| Description| | Name | Type | Mandatory| Description|
| ----------- | ------ | ---- | ---- | | ----------- | ------ | ---- | ---- |
| volId | string | Yes | Volume ID.| | volumeId | string | Yes | Volume ID.|
| fsType | string | Yes | File system type.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| --------------------- | ----------------------- | | ---------------------- | ---------- |
| Promise&lt;void&gt; | Promise used to return the result. | | Promise&lt;void&gt; | Promise used to return the result.|
**Example** **Example**
```js ```js
let volId = ""; let volumeId = "";
let bool = await volumemanager.format(volId); let fsType = "";
volumemanager.format(volumeId, fsType).then(function() {
console.info("format successfully");
}).catch(function(error){
console.info("format failed with error:"+ error);
});
``` ```
## volumemanager.format ## volumemanager.format
format(volId: string, callback: AsyncCallback&lt;void&gt;): void format(volumeId: string, fsType: string, callback: AsyncCallback&lt;void&gt;): void
Asynchronously formats a volume. This API uses a callback to return the result. Asynchronously formats a volume. This API uses a callback to return the result.
...@@ -389,22 +407,24 @@ Asynchronously formats a volume. This API uses a callback to return the result. ...@@ -389,22 +407,24 @@ Asynchronously formats a volume. This API uses a callback to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ---------------- | | -------- | ------------------------- | ---- | ----------------------------- |
| volId | string | Yes | Volume ID. | | volumeId | string | Yes | Volume ID. |
| callback | callback:AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. | | fsType | string | Yes | File system type.|
| callback | callback:AsyncCallback&lt;void&gt; | Yes | Called after the volume is formatted. |
**Example** **Example**
```js ```js
let volId = ""; let volumeId = "";
volumemanager.format(volId, (error, bool) => { let fsType = "";
volumemanager.format(volumeId, fsType, (error, bool) => {
// Do something. // Do something.
}); });
``` ```
## volumemanager.partition ## volumemanager.partition
partition(volId: string, fstype: string): Promise&lt;void&gt; partition(diskId: string, type: number): Promise&lt;void&gt;
Asynchronously partitions a disk. This API uses a promise to return the result. Asynchronously partitions a disk. This API uses a promise to return the result.
...@@ -416,8 +436,8 @@ Asynchronously partitions a disk. This API uses a promise to return the result. ...@@ -416,8 +436,8 @@ Asynchronously partitions a disk. This API uses a promise to return the result.
| Name | Type | Mandatory| Description| | Name | Type | Mandatory| Description|
| ----------- | ------ | ---- | ---- | | ----------- | ------ | ---- | ---- |
| volId | string | Yes | ID of the disk to which the volume belongs.| | diskId | string | Yes | ID of the disk to which the volume belongs.|
| fstype | string | Yes | Partition type. | | type | number | Yes | Partition type. |
**Return value** **Return value**
...@@ -428,14 +448,18 @@ Asynchronously partitions a disk. This API uses a promise to return the result. ...@@ -428,14 +448,18 @@ Asynchronously partitions a disk. This API uses a promise to return the result.
**Example** **Example**
```js ```js
let volId = ""; let diskId = "";
let fstype = ""; let type = 0;
let bool = await volumemanager.partition(volId, fstype); volumemanager.partition(diskId, type).then(function() {
console.info("partition successfully");
}).catch(function(error){
console.info("partition failed with error:"+ error);
});
``` ```
## volumemanager.partition ## volumemanager.partition
partition(volId: string, fstype : string, callback: AsyncCallback&lt;void&gt;): void partition(diskId: string, type: number, callback: AsyncCallback&lt;void&gt;): void
Asynchronously partitions a disk. This API uses a callback to return the result. 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. ...@@ -447,16 +471,16 @@ Asynchronously partitions a disk. This API uses a callback to return the result.
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ---------------- | | -------- | --------------------------------------- | ---- | ---------------- |
| volId | string | Yes | ID of the disk to which the volume belongs. | | diskId | string | Yes | ID of the disk to which the volume belongs. |
| fstype | string | Yes | Partition type. | | type | number | Yes | Partition type. |
| callback | callback:AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. | | callback | callback:AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. |
**Example** **Example**
```js ```js
let volId = ""; let diskId = "";
let fstype = ""; let type = 0;
volumemanager.format(volId, fstype, (error, bool) => { volumemanager.partition(diskId, type, (error, bool) => {
// Do something. // Do something.
}); });
``` ```
...@@ -471,6 +495,7 @@ Asynchronously partitions a disk. This API uses a callback to return the result. ...@@ -471,6 +495,7 @@ Asynchronously partitions a disk. This API uses a callback to return the result.
| ----------- | ------- | -------------------- | | ----------- | ------- | -------------------- |
| id | string | Volume ID. | | id | string | Volume ID. |
| uuid | string | UUID of the volume. | | uuid | string | UUID of the volume. |
| diskId | string | ID of the disk to which the volume belongs. |
| description | string | Description of the volume. | | description | string | Description of the volume. |
| removable | boolean | Whether the volume is a removable storage device.| | removable | boolean | Whether the volume is a removable storage device.|
| state | number | Volume state. | | state | number | Volume state. |
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册