未验证 提交 bb0aeaad 编写于 作者: O openharmony_ci 提交者: Gitee

!7166 update apis

Merge pull request !7166 from zhangxingxia/master
...@@ -35,12 +35,10 @@ getRoot(options? : {dev? : DevInfo}) : Promise<FileInfo[]> ...@@ -35,12 +35,10 @@ getRoot(options? : {dev? : DevInfo}) : Promise<FileInfo[]>
**示例:** **示例:**
```js ```js
filemanager.getRoot().then((fileInfo) => { filemanager.getRoot().then((fileInfos) => {
if(Array.isArray(fileInfo)) { for (var i = 0; i < fileInfos.length; i++) {
for (var i = 0; i < fileInfo.length; i++) { console.log("files:"+JSON.stringify(fileInfos));
console.log("file:"+JSON.stringify(fileInfo)); }
}
}
}).catch((err) => { }).catch((err) => {
console.log(err) console.log(err)
}); });
...@@ -69,14 +67,11 @@ getRoot(options? : {dev? : DevInfo}, callback : AsyncCallback&lt;FileInfo[]&gt;) ...@@ -69,14 +67,11 @@ getRoot(options? : {dev? : DevInfo}, callback : AsyncCallback&lt;FileInfo[]&gt;)
"name":"local" "name":"local"
} }
}; };
filemanager.getRoot(options, (err, fileInfo)=>{ filemanager.getRoot(options, (err, fileInfos)=>{
if(Array.isArray(fileInfo)) { for (var i = 0; i < fileInfos.length; i++) {
for (var i = 0; i < fileInfo.length; i++) { console.log("files:"+JSON.stringify(fileInfos));
console.log("file:"+JSON.stringify(fileInfo)); }
}
}
}); });
``` ```
## filemanager.listFile ## filemanager.listFile
...@@ -111,18 +106,17 @@ listFile(path : string, type : string, options? : {dev? : DevInfo, offset? : num ...@@ -111,18 +106,17 @@ listFile(path : string, type : string, options? : {dev? : DevInfo, offset? : num
**示例:** **示例:**
```js ```js
// 获取目录下所有文件 // 获取目录下所有文件,通过getRoot获取的目录uri
// 通过listFile、getRoot获取的文件uri filemanager.getRoot().then((fileInfos) => {
let media_path = "" let file = fileInfos.find(item => item.name == "file_folder");
filemanager.listFile(media_path, "file") let path = file.path;
.then((fileInfo) => { filemanager.listFile(path, "file").then((files) => {
if(Array.isArray(fileInfo)) { console.log("files:" + JSON.stringify(files));
for (var i = 0; i < fileInfo.length; i++) { }).catch((err) => {
console.log("file:"+JSON.stringify(fileInfo)); console.log("failed to get files" + err);
} });
}
}).catch((err) => { }).catch((err) => {
console.log("failed to get file"+err); console.log("failed to get root" + err);
}); });
``` ```
...@@ -153,33 +147,18 @@ listFile(path : string, type : string, options? : {dev? : DevInfo, offset? : num ...@@ -153,33 +147,18 @@ listFile(path : string, type : string, options? : {dev? : DevInfo, offset? : num
**示例:** **示例:**
```js ```js
// 通过listFile、getRoot获取的文件path // 获取目录下所有文件,通过getRoot获取的目录uri
let fileInfos = filemanager.getRoot(); filemanager.getRoot().then((fileInfos) => {
let media_path = ""; let file = fileInfos.find(item => item.name == "image_album");
for (let i = 0; i < fileInfos.length; i++) { let path = file.path;
if (fileInfos[i].name == "image_album") { filemanager.listFile(path, "image",function(err, files){
media_path = fileInfos[i].path; console.log("files:" + JSON.stringify(files));
} else if (fileInfos[i].name == "audio_album") { })
media_path = fileInfos[i].path; }).catch((err) => {
} else if (fileInfos[i].name == "video_album") { console.log("failed to get root" + err);
media_path = fileInfos[i].path; });
} else if (fileInfos[i].name == "file_folder") { ```
media_path = fileInfos[i].path;
}
}
filemanager.listFile(media_path, "file")
.then((fileInfo) => {
if(Array.isArray(fileInfo)) {
for (var i = 0; i < fileInfo.length; i++) {
console.log("file:"+JSON.stringify(fileInfo));
}
}
}).catch((err) => {
console.log("failed to get file"+err);
});
```
## filemanager.createFile ## filemanager.createFile
......
...@@ -48,8 +48,7 @@ setSecurityLabel(path:string, type:dataLevel):Promise&lt;void&gt; ...@@ -48,8 +48,7 @@ setSecurityLabel(path:string, type:dataLevel):Promise&lt;void&gt;
**示例:** **示例:**
```js ```js
let type = "s4"; securityLabel.setSecurityLabel(path, "s0").then(function(){
securityLabel.setSecurityLabel(path, type).then(function(){
console.info("setSecurityLabel successfully"); console.info("setSecurityLabel successfully");
}).catch(function(error){ }).catch(function(error){
console.info("setSecurityLabel failed with error:" + error); console.info("setSecurityLabel failed with error:" + error);
...@@ -75,8 +74,7 @@ setSecurityLabel(path:string, type:dataLevel, callback: AsyncCallback&lt;void&gt ...@@ -75,8 +74,7 @@ setSecurityLabel(path:string, type:dataLevel, callback: AsyncCallback&lt;void&gt
**示例:** **示例:**
```js ```js
let type = "s4"; securityLabel.setSecurityLabel(path, "s0", function(error){
securityLabel.setSecurityLabel(path, type, function(error){
console.info("setSecurityLabel:" + JSON.stringify(error)); console.info("setSecurityLabel:" + JSON.stringify(error));
}); });
``` ```
...@@ -98,8 +96,7 @@ setSecurityLabelSync(path:string, type:dataLevel):void ...@@ -98,8 +96,7 @@ setSecurityLabelSync(path:string, type:dataLevel):void
**示例:** **示例:**
```js ```js
let type = "s4"; securityLabel.setSecurityLabelSync(path, "s0");
securityLabel.setSecurityLabelSync(path, type);
``` ```
## securityLabel.getSecurityLabel ## securityLabel.getSecurityLabel
...@@ -125,11 +122,10 @@ getSecurityLabel(path:string):Promise&lt;string&gt; ...@@ -125,11 +122,10 @@ getSecurityLabel(path:string):Promise&lt;string&gt;
**示例:** **示例:**
```js ```js
let type = "s4";
securityLabel.getSecurityLabel(path).then(function(type){ securityLabel.getSecurityLabel(path).then(function(type){
console.log("getSecurityLabel successfully:" + type); console.log("getSecurityLabel successfully:" + type);
}).catch(function(error){ }).catch(function(err){
console.log("getSecurityLabel failed with error:" + error); console.log("getSecurityLabel failed with error:" + err);
}); });
``` ```
...@@ -151,8 +147,7 @@ getSecurityLabel(path:string, callback:AsyncCallback&lt;string&gt;): void ...@@ -151,8 +147,7 @@ getSecurityLabel(path:string, callback:AsyncCallback&lt;string&gt;): void
**示例:** **示例:**
```js ```js
let type = "s4"; securityLabel.getSecurityLabel(path, function(err, type){
securityLabel.getSecurityLabel(path,function(error, type){
console.log("getSecurityLabel successfully:" + type); console.log("getSecurityLabel successfully:" + type);
}); });
``` ```
......
...@@ -191,13 +191,13 @@ getVolumeByUuid(uuid: string): Promise&lt;Volume&gt; ...@@ -191,13 +191,13 @@ getVolumeByUuid(uuid: string): Promise&lt;Volume&gt;
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ------ | ---- | ---- | | -------- | ------ | ---- | ---- |
| uuid | string | 是 | 卷uuid | | uuid | string | 是 | 卷uuid |
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| ---------------------------------- | -------------------------- | | ---------------------------------- | -------------------------- |
| Promise&lt;[Volume](#volume)&gt; | 返回当前所有可获得的卷信息 | | Promise&lt;[Volume](#volume)&gt; | 返回当前所有可获得的卷信息 |
**示例:** **示例:**
...@@ -239,7 +239,7 @@ getVolumeByUuid(uuid: string, callback: AsyncCallback&lt;Volume&gt;): void ...@@ -239,7 +239,7 @@ getVolumeByUuid(uuid: string, callback: AsyncCallback&lt;Volume&gt;): void
## volumemanager.getVolumeById ## volumemanager.getVolumeById
getVolumeById(id: string): Promise&lt;Volume&gt; getVolumeById(volumeId: string): Promise&lt;Volume&gt;
异步通过卷id获得卷信息,以promise方式返回。 异步通过卷id获得卷信息,以promise方式返回。
...@@ -251,7 +251,7 @@ getVolumeById(id: string): Promise&lt;Volume&gt; ...@@ -251,7 +251,7 @@ getVolumeById(id: string): Promise&lt;Volume&gt;
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ------ | ---- | ---- | | -------- | ------ | ---- | ---- |
| id | string | 是 | 卷id | | volumeId | string | 是 | 卷id |
**返回值:** **返回值:**
...@@ -262,8 +262,8 @@ getVolumeById(id: string): Promise&lt;Volume&gt; ...@@ -262,8 +262,8 @@ getVolumeById(id: string): Promise&lt;Volume&gt;
**示例:** **示例:**
```js ```js
let id = ""; let volumeId = "";
volumemanager.getVolumeById(id).then(function(volume) { volumemanager.getVolumeById(volumeId).then(function(volume) {
console.info("getVolumeById successfully:" + JSON.stringify(volume)); console.info("getVolumeById successfully:" + JSON.stringify(volume));
}).catch(function(error){ }).catch(function(error){
console.info("getVolumeById failed with error:"+ error); console.info("getVolumeById failed with error:"+ error);
...@@ -272,7 +272,7 @@ getVolumeById(id: string): Promise&lt;Volume&gt; ...@@ -272,7 +272,7 @@ getVolumeById(id: string): Promise&lt;Volume&gt;
## volumemanager.getVolumeById ## volumemanager.getVolumeById
getVolumeById(id: string, callback: AsyncCallback&lt;Volume&gt;): void getVolumeById(volumeId: string, callback: AsyncCallback&lt;Volume&gt;): void
异步通过卷id获得卷信息,以callback方式返回。 异步通过卷id获得卷信息,以callback方式返回。
...@@ -282,16 +282,16 @@ getVolumeById(id: string, callback: AsyncCallback&lt;Volume&gt;): void ...@@ -282,16 +282,16 @@ getVolumeById(id: string, callback: AsyncCallback&lt;Volume&gt;): void
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------ | ---- | -------------------- | | -------- | ------------------------- | ---- | ----------------------------- |
| id | string | 是 | 卷id | | volumeId | string | 是 | 卷id |
| callback | callback:AsyncCallback&lt;[Volume](#volume)&gt; | 是 | 获取卷信息之后的回调 | | callback | callback:AsyncCallback&lt;[Volume](#volume)&gt; | 是 | 获取卷信息之后的回调 |
**示例:** **示例:**
```js ```js
let id = ""; let volumeId = "";
volumemanager.getVolumeById(id, (error, volume) => { volumemanager.getVolumeById(volumeId, (error, volume) => {
// do something // do something
}); });
``` ```
...@@ -361,7 +361,7 @@ setVolumeDescription(uuid: string, description: string, callback: AsyncCallback& ...@@ -361,7 +361,7 @@ setVolumeDescription(uuid: string, description: string, callback: AsyncCallback&
## volumemanager.format ## volumemanager.format
format(volId: string): Promise&lt;void&gt; format(volumeId: string, fsType: string): Promise&lt;void&gt;
异步对指定卷进行格式化,以promise方式返回。 异步对指定卷进行格式化,以promise方式返回。
...@@ -373,19 +373,21 @@ format(volId: string): Promise&lt;void&gt; ...@@ -373,19 +373,21 @@ format(volId: string): Promise&lt;void&gt;
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| ----------- | ------ | ---- | ---- | | ----------- | ------ | ---- | ---- |
| volId | string | 是 | 卷id | | volumeId | string | 是 | 卷id |
| fsType | string | 是 | 文件系统类型 |
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| --------------------- | ----------------------- | | ---------------------- | ---------- |
| Promise&lt;void&gt; | 对指定卷进行格式化 | | Promise&lt;void&gt; | 对指定卷进行格式化 |
**示例:** **示例:**
```js ```js
let volId = ""; let volumeId = "";
volumemanager.format(volId).then(function() { let fsType = "";
volumemanager.format(volumeId, fsType).then(function() {
console.info("format successfully"); console.info("format successfully");
}).catch(function(error){ }).catch(function(error){
console.info("format failed with error:"+ error); console.info("format failed with error:"+ error);
...@@ -394,7 +396,7 @@ format(volId: string): Promise&lt;void&gt; ...@@ -394,7 +396,7 @@ format(volId: string): Promise&lt;void&gt;
## volumemanager.format ## volumemanager.format
format(volId: string, callback: AsyncCallback&lt;void&gt;): void format(volumeId: string, fsType: string, callback: AsyncCallback&lt;void&gt;): void
异步对指定卷进行格式化,以callback方式返回。 异步对指定卷进行格式化,以callback方式返回。
...@@ -404,23 +406,25 @@ format(volId: string, callback: AsyncCallback&lt;void&gt;): void ...@@ -404,23 +406,25 @@ format(volId: string, callback: AsyncCallback&lt;void&gt;): void
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------- | ---- | ---------------- | | -------- | ------------------------- | ---- | ----------------------------- |
| volId | string | 是 | 卷id | | volumeId | string | 是 | 卷id |
| callback | callback:AsyncCallback&lt;void&gt; | 是 | 对指定卷进行格式化 | | fsType | string | 是 | 文件系统类型 |
| callback | callback:AsyncCallback&lt;void&gt; | 是 | 对指定卷格式化后的回调 |
**示例:** **示例:**
```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;
异步对磁盘进行分区,以promise方式返回。 异步对磁盘进行分区,以promise方式返回。
...@@ -431,9 +435,9 @@ partition(volId: string, fstype: string): Promise&lt;void&gt; ...@@ -431,9 +435,9 @@ partition(volId: string, fstype: string): Promise&lt;void&gt;
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| ----------- | ------ | ---- | ---- | | ----------- | ------ | ---- | ---- |
| volId | string | 是 | 卷所属的磁盘id | | diskId | string | 是 | 卷所属的磁盘id |
| fstype | string | 是 | 分区类型 | | type | number | 是 | 分区类型 |
**返回值:** **返回值:**
...@@ -444,9 +448,9 @@ partition(volId: string, fstype: string): Promise&lt;void&gt; ...@@ -444,9 +448,9 @@ partition(volId: string, fstype: string): Promise&lt;void&gt;
**示例:** **示例:**
```js ```js
let volId = ""; let diskId = "";
let fstype = ""; let type = 0;
volumemanager.partition(volId, fstype).then(function() { volumemanager.partition(diskId, type).then(function() {
console.info("partition successfully"); console.info("partition successfully");
}).catch(function(error){ }).catch(function(error){
console.info("partition failed with error:"+ error); console.info("partition failed with error:"+ error);
...@@ -455,7 +459,7 @@ partition(volId: string, fstype: string): Promise&lt;void&gt; ...@@ -455,7 +459,7 @@ partition(volId: string, fstype: string): Promise&lt;void&gt;
## 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
异步对磁盘进行分区,以callback方式返回。 异步对磁盘进行分区,以callback方式返回。
...@@ -467,16 +471,16 @@ partition(volId: string, fstype : string, callback: AsyncCallback&lt;void&gt;): ...@@ -467,16 +471,16 @@ partition(volId: string, fstype : string, callback: AsyncCallback&lt;void&gt;):
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------- | ---- | ---------------- | | -------- | --------------------------------------- | ---- | ---------------- |
| volId | string | 是 | 卷所属的磁盘id | | diskId | string | 是 | 卷所属的磁盘id |
| fstype | string | 是 | 分区类型 | | type | number | 是 | 分区类型 |
| callback | callback:AsyncCallback&lt;void&gt; | 是 | 对磁盘进行分区 | | callback | callback:AsyncCallback&lt;void&gt; | 是 | 对磁盘进行分区 |
**示例:** **示例:**
```js ```js
let volId = ""; let diskId = "";
let fstype = ""; let type = 0;
volumemanager.partition(volId, fstype, (error, bool) => { volumemanager.partition(diskId, type, (error, bool) => {
// do something // do something
}); });
``` ```
...@@ -491,6 +495,7 @@ partition(volId: string, fstype : string, callback: AsyncCallback&lt;void&gt;): ...@@ -491,6 +495,7 @@ partition(volId: string, fstype : string, callback: AsyncCallback&lt;void&gt;):
| ----------- | ------- | -------------------- | | ----------- | ------- | -------------------- |
| id | string | 卷id | | id | string | 卷id |
| uuid | string | 卷uuid | | uuid | string | 卷uuid |
| diskId | string | 卷所属的磁盘id |
| description | string | 卷相关描述 | | description | string | 卷相关描述 |
| removable | boolean | 是否为可移动存储设备 | | removable | boolean | 是否为可移动存储设备 |
| state | number | 当前卷状态 | | state | number | 当前卷状态 |
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册