提交 5c4bda73 编写于 作者: R raoxian

fixed 5f9f9d93 from https://gitee.com/storage-sandboxing/docs/pulls/6733

修改fileio、securityLabel、storage-statistics、volumemanager文档
Signed-off-by: Nraoxian <raoxian@huawei.com>
上级 83170f09
......@@ -354,58 +354,11 @@ closeSync(fd: number): void
**示例:**
```js
let fd = fileio.openSync(path);
fileio.closeSync(fd);
```
## fileio.close<sup>7+</sup>
close(): Promise&lt;void&gt;
关闭文件流,使用Promise异步回调。
**系统能力**:SystemCapability.FileManagement.File.FileIO
**返回值:**
| 类型 | 说明 |
| ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise对象。无返回值。 |
**示例:**
```js
fileio.close().then(function(){
console.info("close file stream succeed");
}).catch(function(err){
console.info("close file stream failed with error:"+ err);
});
```
## fileio.close<sup>7+</sup>
close(callback: AsyncCallback&lt;void&gt;): void
关闭文件流,使用callback异步回调。
**系统能力**:SystemCapability.FileManagement.File.FileIO
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------- | ---- | ------------- |
| callback | AsyncCallback&lt;void&gt; | 是 | 异步关闭文件流之后的回调。 |
**示例:**
```js
fileio.close(function(err){
// do something
});
```
## fileio.copyFile
copyFile(src:string | number, dest:string | number, mode?:number):Promise&lt;void&gt;
......@@ -431,6 +384,8 @@ copyFile(src:string | number, dest:string | number, mode?:number):Promise&lt;voi
**示例:**
```js
let src = path;
let dest = src + 'tgt';
fileio.copyFile(src, dest).then(function(){
console.info("copyFile succeed");
}).catch(function(err){
......@@ -459,6 +414,8 @@ copyFile(src: string | number, dest: string | number, mode: number, callback: As
**示例:**
```js
let src = path;
let dest = src + 'tgt';
fileio.copyFile(src, dest, function (err) {
// do something
});
......@@ -484,6 +441,8 @@ copyFileSync(src: string | number, dest: string | number, mode?: number): void
**示例:**
```js
let src = path;
let dest = src + 'tgt';
fileio.copyFileSync(src, dest);
```
......@@ -1060,7 +1019,7 @@ hash(path: string, algorithm: string): Promise&lt;string&gt;
```js
fileio.hash(path, "sha256").then(function(str){
console.info("calculate file hash succeed:"+ str);
}).catch(function(error){
}).catch(function(err){
console.info("calculate file hash failed with error:"+ err);
});
```
......@@ -1117,7 +1076,7 @@ chmod(path: string, mode: number):Promise&lt;void&gt;
**示例:**
```js
fileio.chmod(path, mode).then(function() {
fileio.chmod(path, 0o700).then(function() {
console.info("chmod succeed");
}).catch(function(err){
console.info("chmod failed with error:"+ err);
......@@ -1144,7 +1103,7 @@ chmod(path: string, mode: number, callback: AsyncCallback&lt;void&gt;): void
**示例:**
```js
fileio.chmod(path, mode, function (err) {
fileio.chmod(path, 0o700, function (err) {
// do something
});
```
......@@ -1168,7 +1127,7 @@ chmodSync(path: string, mode: number): void
**示例:**
```js
fileio.chmodSync(path, mode);
fileio.chmodSync(path, 0o700);
```
......@@ -1195,6 +1154,7 @@ fstat(fd: number): Promise&lt;Stat&gt;
**示例:**
```js
let fd = fileio.openSync(path);
fileio.fstat(fd).then(function(stat){
console.info("fstat succeed:"+ JSON.stringify(stat));
}).catch(function(err){
......@@ -1308,7 +1268,9 @@ ftruncate(fd: number, len: number, callback:AsyncCallback&lt;void&gt;): void
**示例:**
```js
fileio.ftruncate(fd, len, function(err){
let fd = fileio.openSync(path);
let len = 5;
fileio.ftruncate(fd, 5, function(err){
// do something
});
```
......@@ -1332,6 +1294,8 @@ ftruncateSync(fd: number, len?: number): void
**示例:**
```js
let fd = fileio.openSync(path);
let len = 5;
fileio.ftruncateSync(fd, len);
```
......@@ -1360,6 +1324,7 @@ truncate(path: string, len?: number): Promise&lt;void&gt;
**示例:**
```js
let len = 5;
fileio.truncate(path, len).then(function(){
console.info("truncate file succeed");
}).catch(function(err){
......@@ -1387,6 +1352,7 @@ truncate(path: string, len: number, callback:AsyncCallback&lt;void&gt;): void
**示例:**
```js
let len = 5;
fileio.truncate(path, len, function(err){
// do something
});
......@@ -1411,6 +1377,7 @@ truncateSync(path: string, len?: number): void
**示例:**
```js
let len = 5;
fileio.truncateSync(path, len);
```
......@@ -1468,13 +1435,13 @@ readText(filePath: string, options: {
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------- | ---- | ------------------------------------------------------------ |
| filePath | string | 是 | 待读取文件的应用沙箱路径。 |
| options | Object | | 支持如下选项:<br/>-&nbsp;position,number类型,表示期望读取文件的位置。可选,默认从当前位置开始读取。<br/>-&nbsp;length,number类型,表示期望读取数据的长度。可选,默认缓冲区长度减去偏移长度。<br/>-&nbsp;encoding,string类型,表示数据的编码方式,默认&nbsp;'utf-8',仅支持&nbsp;'utf-8'。 |
| options | Object | | 支持如下选项:<br/>-&nbsp;position,number类型,表示期望读取文件的位置。可选,默认从当前位置开始读取。<br/>-&nbsp;length,number类型,表示期望读取数据的长度。可选,默认缓冲区长度减去偏移长度。<br/>-&nbsp;encoding,string类型,表示数据的编码方式,默认&nbsp;'utf-8',仅支持&nbsp;'utf-8'。 |
| callback | AsyncCallback&lt;string&gt; | 是 | 回调函数,返回读取文件的内容。 |
**示例:**
```js
fileio.readText(path, function(err, str){
fileio.readText(path, { position: 1, encoding: 'UTF-8' }, function(err, str){
// do something
});
```
......@@ -1594,76 +1561,6 @@ lstatSync(path:string): Stat
```
## fileio.read<sup>7+</sup>
read(buffer: ArrayBuffer, options?: {
position?: number;
offset?: number;
length?: number;
}): Promise&lt;ReadOut&gt;
从文件读取数据,使用Promise异步回调。
**系统能力**:SystemCapability.FileManagement.File.FileIO
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------- | ----------- | ---- | ------------------------------------------------------------ |
| buffer | ArrayBuffer | 是 | 用于保存读取到的文件数据的缓冲区。 |
| options | Object | 否 | 支持如下选项:<br/>-&nbsp;offset,number类型,表示将数据读取到缓冲区的位置,即相对于缓冲区首地址的偏移。可选,默认为0。<br/>-&nbsp;length,number类型,表示期望读取数据的长度。可选,默认缓冲区长度减去偏移长度。<br/>约束:offset+length<=buffer.size。 |
**返回值:**
| 类型 | 说明 |
| ---------------------------------- | ------ |
| Promise&lt;[ReadOut](#readout)&gt; | Promise对象。返回读取的结果。 |
**示例:**
```js
fileio.read(new ArrayBuffer(4096)).then(function(readout){
console.info("read file data succeed");
console.log(String.fromCharCode.apply(null, new Uint8Array(readOut.buffer)));
}).catch(function(err){
console.info("read file data failed with error:"+ err);
});
```
## fileio.read<sup>7+</sup>
read(buffer: ArrayBuffer, options: {
position?: number;
offset?: number;
length?: number;
}, callback: AsyncCallback&lt;ReadOut&gt;): void
从文件读取数据,使用callback异步回调。
**系统能力**:SystemCapability.FileManagement.File.FileIO
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| buffer | ArrayBuffer | 是 | 用于保存读取到的文件数据的缓冲区。 |
| options | Object | 否 | 支持如下选项:<br/>-&nbsp;offset,number类型,表示将数据读取到缓冲区的位置,即相对于缓冲区首地址的偏移。可选,默认为0。<br/>-&nbsp;length,number类型,表示期望读取数据的长度。可选,默认缓冲区长度减去偏移长度。<br/>约束:offset+length<=buffer.size。 |
| callback | AsyncCallback&lt;[ReadOut](#readout)&gt; | 是 | 异步从文件读取数据之后的回调。 |
**示例:**
```js
let buf = new ArrayBuffer(4096);
fileio.read(buf, function (err, readOut) {
if (readOut) {
console.info("read file data succeed");
console.log(String.fromCharCode.apply(null, new Uint8Array(readOut.buffer)));
}
});
```
## fileio.rename<sup>7+</sup>
rename(oldPath: string, newPath: string): Promise&lt;void&gt;
......@@ -1688,6 +1585,8 @@ rename(oldPath: string, newPath: string): Promise&lt;void&gt;
**示例:**
```js
let oldPath = path;
let newPath = oldPath + '123';
fileio.rename(oldPath, newPath).then(function() {
console.info("rename succeed");
}).catch(function(err){
......@@ -1715,6 +1614,8 @@ rename(oldPath: string, newPath: string, callback: AsyncCallback&lt;void&gt;): v
**示例:**
```js
let oldPath = path;
let newPath = oldPath + '123';
fileio.rename(oldPath, newPath, function(err){
});
```
......@@ -1738,6 +1639,8 @@ renameSync(oldPath: string, newPath: string): void
**示例:**
```js
let oldPath = path;
let newPath = oldPath + '123';
fileio.renameSync(oldPath, newPath);
```
......@@ -1765,6 +1668,7 @@ fsync(fd: number): Promise&lt;void&gt;
**示例:**
```js
let fd = fileio.openSync(path);
fileio.fsync(fd).then(function(){
console.info("sync data succeed");
}).catch(function(err){
......@@ -1791,6 +1695,7 @@ fsync(fd: number, callback: AsyncCallback&lt;void&gt;): void
**示例:**
```js
let fd = fileio.openSync(path);
fileio.fsync(fd, function(err){
// do something
});
......@@ -1814,6 +1719,7 @@ fsyncSync(fd: number): void
**示例:**
```js
let fd = fileio.openSync(path);
fileio.fsyncSync(fd);
```
......@@ -1841,6 +1747,7 @@ fdatasync(fd: number): Promise&lt;void&gt;
**示例:**
```js
let fd = fileio.openSync(path);
fileio.fdatasync(fd).then(function(err) {
console.info("sync data succeed");
}).catch(function(err){
......@@ -1867,6 +1774,7 @@ fdatasync(fd: number, callback:AsyncCallback&lt;void&gt;): void
**示例:**
```js
let fd = fileio.openSync(path);
fileio.fdatasync (fd, function (err) {
// do something
});
......@@ -1890,6 +1798,7 @@ fdatasyncSync(fd: number): void
**示例:**
```js
let fd = fileio.openSync(path);
let stat = fileio.fdatasyncSync(fd);
```
......@@ -1918,6 +1827,8 @@ symlink(target: string, srcPath: string): Promise&lt;void&gt;
**示例:**
```js
let target = path;
let srcPath = target + 'aaa';
fileio.symlink(target, srcPath).then(function() {
console.info("symlink succeed");
}).catch(function(err){
......@@ -1945,6 +1856,8 @@ symlink(target: string, srcPath: string, callback: AsyncCallback&lt;void&gt;): v
**示例:**
```js
let target = path;
let srcPath = target + 'aaa';
fileio.symlink(target, srcPath, function (err) {
// do something
});
......@@ -1969,6 +1882,8 @@ symlinkSync(target: string, srcPath: string): void
**示例:**
```js
let target = path;
let srcPath = target + 'aaa';
fileio.symlinkSync(target, srcPath);
```
......@@ -2164,6 +2079,8 @@ fchmod(fd: number, mode: number): Promise&lt;void&gt;
**示例:**
```js
let fd = fileio.openSync(path);
let mode = 0o700;
fileio.fchmod(fd, mode).then(function() {
console.info("chmod succeed");
}).catch(function(err){
......@@ -2191,6 +2108,8 @@ fchmod(fd: number, mode: number, callback: AsyncCallback&lt;void&gt;): void
**示例:**
```js
let fd = fileio.openSync(path);
let mode = 0o700;
fileio.fchmod(fd, mode, function (err) {
// do something
});
......@@ -2215,6 +2134,8 @@ fchmodSync(fd: number, mode: number): void
**示例:**
```js
let fd = fileio.openSync(path);
let mode = 0o700;
fileio.fchmodSync(fd, mode);
```
......@@ -2417,6 +2338,7 @@ fchown(fd: number, uid: number, gid: number): Promise&lt;void&gt;
**示例:**
```js
let fd = fileio.openSync(path);
let stat = fileio.statSync(path);
fileio.fchown(fd, stat.uid, stat.gid).then(function() {
console.info("chown succeed");
......@@ -2446,6 +2368,7 @@ fchown(fd: number, uid: number, gid: number, callback: AsyncCallback&lt;void&gt;
**示例:**
```js
let fd = fileio.openSync(path);
let stat = fileio.statSync(path);
fileio.fchown(fd, stat.uid, stat.gid, function (err){
// do something
......@@ -2472,6 +2395,7 @@ fchownSync(fd: number, uid: number, gid: number): void
**示例:**
```js
let fd = fileio.openSync(path);
let stat = fileio.statSync(path);
fileio.fchownSync(fd, stat.uid, stat.gid);
```
......@@ -3104,7 +3028,7 @@ read(buffer: ArrayBuffer, options?: {
```js
let ss = fileio.createStreamSync(path, "r+");
ss.read(new ArrayBuffer(4096), {offset: 1, length: 5, position: 5}).then(function (readout){
ss.read(new ArrayBuffer(4096), {offset: 1, length: 5, position: 5}).then(function (readOut){
console.info("read data succeed");
console.log(String.fromCharCode.apply(null, new Uint8Array(readOut.buffer)));
}).catch(function(err){
......@@ -3181,7 +3105,7 @@ readSync(buffer: ArrayBuffer, options?: {
## Dir
管理目录,在调用Dir的方法前,需要先通过[opendir()](#fileioopendir)方法(同步或异步)来构建一个Dir实例。
管理目录,在调用Dir的方法前,需要先通过opendir方法(同步或异步)来构建一个Dir实例。
### read
......@@ -3451,7 +3375,7 @@ isSocket(): boolean
**示例:**
```js
let dir = fileio.opendirSync(dpath);
let dir = fileio.opendirSync(path);
let isSocket = dir.readSync().isSocket();
```
......
......@@ -18,7 +18,10 @@ import securityLabel from '@ohos.securityLabel';
```js
import featureAbility from '@ohos.ability.featureAbility';
let context = featureAbility.getContext();
let path = context.getFilesDir();
let path = '';
context.getFilesDir().then((data) => {
path = data;
})
```
## securityLabel.setSecurityLabel
......
......@@ -470,7 +470,7 @@ getUserStorageStats(userId? : number): Promise&lt;StorageStats&gt;
| 参数名 | 类型 | 必填 | 说明 |
| ---------- | ------ | ---- | ---- |
| userId | string | 否 | 用户id <br/>确认当前用户:<br/>-&nbsp;有值:表示指定用户。<br/>-&nbsp;无值:表示当前用户。|
| userId | number | 否 | 用户id <br/>确认当前用户:<br/>-&nbsp;有值:表示指定用户。<br/>-&nbsp;无值:表示当前用户。|
**返回值:**
......@@ -481,7 +481,7 @@ getUserStorageStats(userId? : number): Promise&lt;StorageStats&gt;
**示例:**
```js
let userId = "";
let userId = 1;
storageStatistics.getUserStorageStats(userId).then(function(StorageStats){
console.info("getUserStorageStats successfully:"+ JSON.stringify(StorageStats));
}).catch(function(err){
......@@ -507,13 +507,13 @@ getUserStorageStats(userId: number, callback:AsyncCallback&lt;StorageStats&gt;):
| 参数名 | 类型 | 必填 | 说明 |
| ---------- | ------------------------------------ | ---- | -------------------------- |
| userId | string | 否 | 用户id <br/>确认当前用户:<br/>-&nbsp;有值:表示指定用户。<br/>-&nbsp;无值:表示当前用户。 |
| userId | number | 否 | 用户id <br/>确认当前用户:<br/>-&nbsp;有值:表示指定用户。<br/>-&nbsp;无值:表示当前用户。 |
| callback | callback:AsyncCallback&lt;[StorageStats](#StorageStats)&gt; | 是 | 返回各类别数据大小之后的回调 |
**示例:**
```js
let userId = "";
let userId = 1;
storageStatistics.getUserStorageStats(userId, function(error, StorageStats){
// do something
console.info("getUserStorageStats successfully:"+ JSON.stringify(StorageStats));
......
......@@ -204,7 +204,11 @@ getVolumeByUuid(uuid: string): Promise&lt;Volume&gt;
```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
......@@ -259,7 +263,11 @@ getVolumeById(id: string): Promise&lt;Volume&gt;
```js
let id = "";
let volume = await volumemanager.getVolumeById(id);
volumemanager.getVolumeById(id).then(function(volume) {
console.info("getVolumeById successfully:" + JSON.stringify(volume));
}).catch(function(error){
console.info("getVolumeById failed with error:"+ error);
});
```
## volumemanager.getVolumeById
......@@ -316,7 +324,11 @@ setVolumeDescription(uuid: string, description: string): Promise&lt;void&gt;
```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
......@@ -373,7 +385,11 @@ format(volId: string): Promise&lt;void&gt;
```js
let volId = "";
let bool = await volumemanager.format(volId);
volumemanager.format(volId).then(function() {
console.info("format successfully");
}).catch(function(error){
console.info("format failed with error:"+ error);
});
```
## volumemanager.format
......@@ -430,7 +446,11 @@ partition(volId: string, fstype: string): Promise&lt;void&gt;
```js
let volId = "";
let fstype = "";
let bool = await volumemanager.partition(volId, fstype);
volumemanager.partition(volId, fstype).then(function() {
console.info("partition successfully");
}).catch(function(error){
console.info("partition failed with error:"+ error);
});
```
## volumemanager.partition
......@@ -456,7 +476,7 @@ partition(volId: string, fstype : string, callback: AsyncCallback&lt;void&gt;):
```js
let volId = "";
let fstype = "";
volumemanager.format(volId, fstype, (error, bool) => {
volumemanager.partition(volId, fstype, (error, bool) => {
// do something
});
```
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册