Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
e5ffd739
D
Docs
项目概览
OpenHarmony
/
Docs
大约 2 年 前同步成功
通知
161
Star
293
Fork
28
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Docs
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
e5ffd739
编写于
7月 06, 2022
作者:
A
Annie_wang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update docs
Signed-off-by:
N
Annie_wang
<
annie.wangli@huawei.com
>
上级
62d32cd7
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
80 addition
and
80 deletion
+80
-80
en/application-dev/reference/apis/js-apis-fileio.md
en/application-dev/reference/apis/js-apis-fileio.md
+80
-80
未找到文件。
en/application-dev/reference/apis/js-apis-fileio.md
浏览文件 @
e5ffd739
...
@@ -48,9 +48,9 @@ Obtains file information. This API uses a promise to return the result.
...
@@ -48,9 +48,9 @@ Obtains file information. This API uses a promise to return the result.
**Example**
**Example**
```
js
```
js
fileio
.
stat
(
path
).
then
(
function
(
stat
){
fileio
.
stat
(
path
).
then
(
function
(
stat
){
console
.
info
(
"
getFileInfo succeed
:
"
+
JSON
.
stringify
(
stat
));
console
.
info
(
"
Got file info
:
"
+
JSON
.
stringify
(
stat
));
}).
catch
(
function
(
err
){
}).
catch
(
function
(
err
){
console
.
info
(
"
getFileInfo failed with e
rror:
"
+
err
);
console
.
info
(
"
Failed to get file info. E
rror:
"
+
err
);
});
});
```
```
...
@@ -124,9 +124,9 @@ Opens a file directory. This API uses a promise to return the result.
...
@@ -124,9 +124,9 @@ Opens a file directory. This API uses a promise to return the result.
**Example**
**Example**
```
js
```
js
fileio
.
opendir
(
path
).
then
(
function
(
dir
){
fileio
.
opendir
(
path
).
then
(
function
(
dir
){
console
.
info
(
"
opendir succe
ed:
"
+
JSON
.
stringify
(
dir
));
console
.
info
(
"
Directory open
ed:
"
+
JSON
.
stringify
(
dir
));
}).
catch
(
function
(
err
){
}).
catch
(
function
(
err
){
console
.
info
(
"
opendir failed with e
rror:
"
+
err
);
console
.
info
(
"
Failed to open the directory. E
rror:
"
+
err
);
});
});
```
```
...
@@ -206,9 +206,9 @@ Checks whether the current process can access a file. This API uses a promise to
...
@@ -206,9 +206,9 @@ Checks whether the current process can access a file. This API uses a promise to
**Example**
**Example**
```
js
```
js
fileio
.
access
(
path
).
then
(
function
()
{
fileio
.
access
(
path
).
then
(
function
()
{
console
.
info
(
"
access succeed
"
);
console
.
info
(
"
Access successful
"
);
}).
catch
(
function
(
err
){
}).
catch
(
function
(
err
){
console
.
info
(
"
access failed with e
rror:
"
+
err
);
console
.
info
(
"
Access failed. E
rror:
"
+
err
);
});
});
```
```
...
@@ -255,7 +255,7 @@ Synchronously checks whether the current process can access the specified file.
...
@@ -255,7 +255,7 @@ Synchronously checks whether the current process can access the specified file.
try
{
try
{
fileio
.
accessSync
(
path
);
fileio
.
accessSync
(
path
);
}
catch
(
err
)
{
}
catch
(
err
)
{
console
.
info
(
"
accessSync failed
with e
rror:
"
+
err
);
console
.
info
(
"
accessSync failed
. E
rror:
"
+
err
);
}
}
```
```
...
@@ -282,9 +282,9 @@ Closes a file. This API uses a promise to return the result.
...
@@ -282,9 +282,9 @@ Closes a file. This API uses a promise to return the result.
```
js
```
js
let
fd
=
fileio
.
openSync
(
path
);
let
fd
=
fileio
.
openSync
(
path
);
fileio
.
close
(
fd
).
then
(
function
(){
fileio
.
close
(
fd
).
then
(
function
(){
console
.
info
(
"
close file succe
ed
"
);
console
.
info
(
"
File clos
ed
"
);
}).
catch
(
function
(
err
){
}).
catch
(
function
(
err
){
console
.
info
(
"
close file failed with e
rror:
"
+
err
);
console
.
info
(
"
Failed to close the file. E
rror:
"
+
err
);
});
});
```
```
...
@@ -347,9 +347,9 @@ Closes the stream. This API uses a promise to return the result.
...
@@ -347,9 +347,9 @@ Closes the stream. This API uses a promise to return the result.
**Example**
**Example**
```
js
```
js
fileio
.
close
().
then
(
function
(){
fileio
.
close
().
then
(
function
(){
console
.
info
(
"
close file stream succe
ed
"
);
console
.
info
(
"
File stream clos
ed
"
);
}).
catch
(
function
(
err
){
}).
catch
(
function
(
err
){
console
.
info
(
"
close file stream failed with e
rror:
"
+
err
);
console
.
info
(
"
Failed to close the file stream. E
rror:
"
+
err
);
});
});
```
```
...
@@ -398,9 +398,9 @@ Copies a file. This API uses a promise to return the result.
...
@@ -398,9 +398,9 @@ Copies a file. This API uses a promise to return the result.
**Example**
**Example**
```
js
```
js
fileio
.
copyFile
(
src
,
dest
).
then
(
function
(){
fileio
.
copyFile
(
src
,
dest
).
then
(
function
(){
console
.
info
(
"
copyFile succe
ed
"
);
console
.
info
(
"
File copi
ed
"
);
}).
catch
(
function
(
err
){
}).
catch
(
function
(
err
){
console
.
info
(
"
copyFile failed with e
rror:
"
+
err
);
console
.
info
(
"
Failed to copy the file. E
rror:
"
+
err
);
});
});
```
```
...
@@ -472,9 +472,9 @@ Creates a directory. This API uses a promise to return the result.
...
@@ -472,9 +472,9 @@ Creates a directory. This API uses a promise to return the result.
**Example**
**Example**
```
js
```
js
fileio
.
mkdir
(
path
).
then
(
function
()
{
fileio
.
mkdir
(
path
).
then
(
function
()
{
console
.
info
(
"
mkdir succe
ed
"
);
console
.
info
(
"
Directory creat
ed
"
);
}).
catch
(
function
(
error
){
}).
catch
(
function
(
error
){
console
.
info
(
"
mkdir failed with e
rror:
"
+
error
);
console
.
info
(
"
Failed to create the directory. E
rror:
"
+
error
);
});
});
```
```
...
@@ -497,7 +497,7 @@ Creates a directory. This API uses an asynchronous callback to return the result
...
@@ -497,7 +497,7 @@ Creates a directory. This API uses an asynchronous callback to return the result
**Example**
**Example**
```
js
```
js
fileio
.
mkdir
(
path
,
function
(
err
)
{
fileio
.
mkdir
(
path
,
function
(
err
)
{
console
.
info
(
"
mkdir succe
ed
"
);
console
.
info
(
"
Directory creat
ed
"
);
});
});
```
```
...
@@ -545,9 +545,9 @@ Opens a file. This API uses a promise to return the result.
...
@@ -545,9 +545,9 @@ Opens a file. This API uses a promise to return the result.
**Example**
**Example**
```
js
```
js
fileio
.
open
(
path
,
0o1
,
0o0200
).
then
(
function
(
number
){
fileio
.
open
(
path
,
0o1
,
0o0200
).
then
(
function
(
number
){
console
.
info
(
"
open file succe
ed
"
);
console
.
info
(
"
File open
ed
"
);
}).
catch
(
function
(
err
){
}).
catch
(
function
(
err
){
console
.
info
(
"
open file failed with e
rror:
"
+
err
);
console
.
info
(
"
Failed to open the file. E
rror:
"
+
err
);
});
});
```
```
...
@@ -640,7 +640,7 @@ Reads data from a file. This API uses a promise to return the result.
...
@@ -640,7 +640,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 succeed
"
);
console
.
info
(
"
Read file data
"
);
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
);
...
@@ -674,7 +674,7 @@ Reads data from a file. This API uses an asynchronous callback to return the res
...
@@ -674,7 +674,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 succeed
"
);
console
.
info
(
"
Read file data
"
);
console
.
log
(
String
.
fromCharCode
.
apply
(
null
,
new
Uint8Array
(
readOut
.
buffer
)));
console
.
log
(
String
.
fromCharCode
.
apply
(
null
,
new
Uint8Array
(
readOut
.
buffer
)));
}
}
});
});
...
@@ -734,9 +734,9 @@ Deletes a directory. This API uses a promise to return the result.
...
@@ -734,9 +734,9 @@ Deletes a directory. This API uses a promise to return the result.
**Example**
**Example**
```
js
```
js
fileio
.
rmdir
(
path
).
then
(
function
()
{
fileio
.
rmdir
(
path
).
then
(
function
()
{
console
.
info
(
"
rmdir succe
ed
"
);
console
.
info
(
"
Directory delet
ed
"
);
}).
catch
(
function
(
err
){
}).
catch
(
function
(
err
){
console
.
info
(
"
rmdir failed with e
rror:
"
+
err
);
console
.
info
(
"
Failed to delete the directory. E
rror:
"
+
err
);
});
});
```
```
...
@@ -759,7 +759,7 @@ Deletes a directory. This API uses an asynchronous callback to return the result
...
@@ -759,7 +759,7 @@ Deletes a directory. This API uses an asynchronous callback to return the result
```
js
```
js
fileio
.
rmdir
(
path
,
function
(
err
){
fileio
.
rmdir
(
path
,
function
(
err
){
// Do something.
// Do something.
console
.
info
(
"
rmdir succe
ed
"
);
console
.
info
(
"
Directory delet
ed
"
);
});
});
```
```
...
@@ -804,9 +804,9 @@ Deletes a file. This API uses a promise to return the result.
...
@@ -804,9 +804,9 @@ Deletes a file. This API uses a promise to return the result.
**Example**
**Example**
```
js
```
js
fileio
.
unlink
(
path
).
then
(
function
(){
fileio
.
unlink
(
path
).
then
(
function
(){
console
.
info
(
"
remove file succe
ed
"
);
console
.
info
(
"
File delet
ed
"
);
}).
catch
(
function
(
error
){
}).
catch
(
function
(
error
){
console
.
info
(
"
remove file failed with e
rror:
"
+
error
);
console
.
info
(
"
Failed to delete the file. E
rror:
"
+
error
);
});
});
```
```
...
@@ -828,7 +828,7 @@ Deletes a file. This API uses an asynchronous callback to return the result.
...
@@ -828,7 +828,7 @@ Deletes a file. This API uses an asynchronous callback to return the result.
**Example**
**Example**
```
js
```
js
fileio
.
unlink
(
path
,
function
(
err
)
{
fileio
.
unlink
(
path
,
function
(
err
)
{
console
.
info
(
"
remove file succe
ed
"
);
console
.
info
(
"
File delet
ed
"
);
});
});
```
```
...
@@ -881,9 +881,9 @@ Writes data into a file. This API uses a promise to return the result.
...
@@ -881,9 +881,9 @@ Writes data into a file. This API uses a promise to return the result.
```
js
```
js
let
fd
=
fileio
.
openSync
(
path
,
0o100
|
0o2
,
0o666
);
let
fd
=
fileio
.
openSync
(
path
,
0o100
|
0o2
,
0o666
);
fileio
.
write
(
fd
,
"
hello, world
"
).
then
(
function
(
number
){
fileio
.
write
(
fd
,
"
hello, world
"
).
then
(
function
(
number
){
console
.
info
(
"
write data to file succeed
and size is:
"
+
number
);
console
.
info
(
"
Data written to file
and size is:
"
+
number
);
}).
catch
(
function
(
err
){
}).
catch
(
function
(
err
){
console
.
info
(
"
write data to file failed with e
rror:
"
+
err
);
console
.
info
(
"
Failed to write data to the file. E
rror:
"
+
err
);
});
});
```
```
...
@@ -914,7 +914,7 @@ Writes data into a file. This API uses an asynchronous callback to return the re
...
@@ -914,7 +914,7 @@ Writes data into a file. This API uses an asynchronous callback to return the re
let
fd
=
fileio
.
openSync
(
path
,
0o100
|
0o2
,
0o666
);
let
fd
=
fileio
.
openSync
(
path
,
0o100
|
0o2
,
0o666
);
fileio
.
write
(
fd
,
"
hello, world
"
,
function
(
err
,
bytesWritten
)
{
fileio
.
write
(
fd
,
"
hello, world
"
,
function
(
err
,
bytesWritten
)
{
if
(
bytesWritten
)
{
if
(
bytesWritten
)
{
console
.
info
(
"
write data to file succeed
and size is:
"
+
bytesWritten
);
console
.
info
(
"
Data written to file
and size is:
"
+
bytesWritten
);
}
}
});
});
```
```
...
@@ -974,9 +974,9 @@ Calculates the hash value of a file. This API uses a promise to return the resul
...
@@ -974,9 +974,9 @@ Calculates the hash value of a file. This API uses a promise to return the resul
**Example**
**Example**
```
js
```
js
fileio
.
hash
(
path
,
"
sha256
"
).
then
(
function
(
str
){
fileio
.
hash
(
path
,
"
sha256
"
).
then
(
function
(
str
){
console
.
info
(
"
calculate file hash succeed
:
"
+
str
);
console
.
info
(
"
Calculated file hash
:
"
+
str
);
}).
catch
(
function
(
error
){
}).
catch
(
function
(
error
){
console
.
info
(
"
calculate file hash failed with e
rror:
"
+
err
);
console
.
info
(
"
Failed to calculate the file hash. E
rror:
"
+
err
);
});
});
```
```
...
@@ -1000,7 +1000,7 @@ Calculates the hash value of a file. This API uses an asynchronous callback to r
...
@@ -1000,7 +1000,7 @@ Calculates the hash value of a file. This API uses an asynchronous callback to r
```
js
```
js
fileio
.
hash
(
path
,
"
sha256
"
,
function
(
err
,
hashStr
)
{
fileio
.
hash
(
path
,
"
sha256
"
,
function
(
err
,
hashStr
)
{
if
(
hashStr
)
{
if
(
hashStr
)
{
console
.
info
(
"
calculate file hash succeed
:
"
+
hashStr
);
console
.
info
(
"
Calculated file hash
:
"
+
hashStr
);
}
}
});
});
```
```
...
@@ -1028,9 +1028,9 @@ Changes file permissions. This API uses a promise to return the result.
...
@@ -1028,9 +1028,9 @@ Changes file permissions. This API uses a promise to return the result.
**Example**
**Example**
```
js
```
js
fileio
.
chmod
(
path
,
mode
).
then
(
function
()
{
fileio
.
chmod
(
path
,
mode
).
then
(
function
()
{
console
.
info
(
"
chmod succe
ed
"
);
console
.
info
(
"
File permissions chang
ed
"
);
}).
catch
(
function
(
err
){
}).
catch
(
function
(
err
){
console
.
info
(
"
chmod failed with e
rror:
"
+
err
);
console
.
info
(
"
Failed to change file permissions. E
rror:
"
+
err
);
});
});
```
```
...
@@ -1099,9 +1099,9 @@ Obtains file information based on the file descriptor. This API uses a promise t
...
@@ -1099,9 +1099,9 @@ Obtains file information based on the file descriptor. This API uses a promise t
**Example**
**Example**
```
js
```
js
fileio
.
fstat
(
fd
).
then
(
function
(
stat
){
fileio
.
fstat
(
fd
).
then
(
function
(
stat
){
console
.
info
(
"
fstat succe
ed:
"
+
JSON
.
stringify
(
stat
));
console
.
info
(
"
File information obtain
ed:
"
+
JSON
.
stringify
(
stat
));
}).
catch
(
function
(
err
){
}).
catch
(
function
(
err
){
console
.
info
(
"
fstat failed with e
rror:
"
+
err
);
console
.
info
(
"
Failed to obtain file information. E
rror:
"
+
err
);
});
});
```
```
...
@@ -1177,7 +1177,7 @@ Truncates a file based on the file descriptor. This API uses a promise to return
...
@@ -1177,7 +1177,7 @@ Truncates a file based on the file descriptor. This API uses a promise to return
```
js
```
js
let
fd
=
fileio
.
openSync
(
path
);
let
fd
=
fileio
.
openSync
(
path
);
fileio
.
ftruncate
(
fd
,
5
).
then
(
function
(
err
)
{
fileio
.
ftruncate
(
fd
,
5
).
then
(
function
(
err
)
{
console
.
info
(
"
truncate file succe
ed
"
);
console
.
info
(
"
File truncat
ed
"
);
}).
catch
(
function
(
err
){
}).
catch
(
function
(
err
){
console
.
info
(
"
Failed to truncate the file. Error:
"
+
err
);
console
.
info
(
"
Failed to truncate the file. Error:
"
+
err
);
});
});
...
@@ -1249,7 +1249,7 @@ Truncates a file based on the file path. This API uses a promise to return the r
...
@@ -1249,7 +1249,7 @@ Truncates a file based on the file path. This API uses a promise to return the r
**Example**
**Example**
```
js
```
js
fileio
.
truncate
(
path
,
len
).
then
(
function
(){
fileio
.
truncate
(
path
,
len
).
then
(
function
(){
console
.
info
(
"
truncate file succe
ed
"
);
console
.
info
(
"
File truncat
ed
"
);
}).
catch
(
function
(
err
){
}).
catch
(
function
(
err
){
console
.
info
(
"
Failed to truncate the file. Error:
"
+
err
);
console
.
info
(
"
Failed to truncate the file. Error:
"
+
err
);
});
});
...
@@ -1325,9 +1325,9 @@ Reads the text content of a file. This API uses a promise to return the result.
...
@@ -1325,9 +1325,9 @@ Reads the text content of a file. This API uses a promise to return the result.
**Example**
**Example**
```
js
```
js
fileio
.
readText
(
path
).
then
(
function
(
str
)
{
fileio
.
readText
(
path
).
then
(
function
(
str
)
{
console
.
info
(
"
readText succeed
:
"
+
str
);
console
.
info
(
"
Read file text
:
"
+
str
);
}).
catch
(
function
(
err
){
}).
catch
(
function
(
err
){
console
.
info
(
"
readText failed with e
rror:
"
+
err
);
console
.
info
(
"
Failed to read text. E
rror:
"
+
err
);
});
});
```
```
...
@@ -1409,7 +1409,7 @@ Obtains link information. This API uses a promise to return the result.
...
@@ -1409,7 +1409,7 @@ Obtains link information. This API uses a promise to return the result.
**Example**
**Example**
```
js
```
js
fileio
.
lstat
(
path
).
then
(
function
(
stat
){
fileio
.
lstat
(
path
).
then
(
function
(
stat
){
console
.
info
(
"
get link status succeed
:
"
+
JSON
.
stringify
(
stat
));
console
.
info
(
"
Got link info
:
"
+
JSON
.
stringify
(
stat
));
}).
catch
(
function
(
err
){
}).
catch
(
function
(
err
){
console
.
info
(
"
Failed to obtain the link status. Error:
"
+
err
);
console
.
info
(
"
Failed to obtain the link status. Error:
"
+
err
);
});
});
...
@@ -1488,7 +1488,7 @@ Reads data from a file. This API uses a promise to return the result.
...
@@ -1488,7 +1488,7 @@ Reads data from a file. This API uses a promise to return the result.
**Example**
**Example**
```
js
```
js
fileio
.
read
(
new
ArrayBuffer
(
4096
)).
then
(
function
(
readout
){
fileio
.
read
(
new
ArrayBuffer
(
4096
)).
then
(
function
(
readout
){
console
.
info
(
"
read file data succeed
"
);
console
.
info
(
"
Read file data
"
);
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
);
...
@@ -1520,7 +1520,7 @@ Reads data from a file. This API uses an asynchronous callback to return the res
...
@@ -1520,7 +1520,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
(
buf
,
function
(
err
,
readOut
)
{
fileio
.
read
(
buf
,
function
(
err
,
readOut
)
{
if
(
readOut
)
{
if
(
readOut
)
{
console
.
info
(
"
read file data succeed
"
);
console
.
info
(
"
Read file data
"
);
console
.
log
(
String
.
fromCharCode
.
apply
(
null
,
new
Uint8Array
(
readOut
.
buffer
)));
console
.
log
(
String
.
fromCharCode
.
apply
(
null
,
new
Uint8Array
(
readOut
.
buffer
)));
}
}
});
});
...
@@ -1549,9 +1549,9 @@ Renames a file. This API uses a promise to return the result.
...
@@ -1549,9 +1549,9 @@ Renames a file. This API uses a promise to return the result.
**Example**
**Example**
```
js
```
js
fileio
.
rename
(
oldPath
,
newPath
).
then
(
function
()
{
fileio
.
rename
(
oldPath
,
newPath
).
then
(
function
()
{
console
.
info
(
"
rename succe
ed
"
);
console
.
info
(
"
File renam
ed
"
);
}).
catch
(
function
(
err
){
}).
catch
(
function
(
err
){
console
.
info
(
"
rename failed with e
rror:
"
+
err
);
console
.
info
(
"
Failed to rename the file. E
rror:
"
+
err
);
});
});
```
```
...
@@ -1619,9 +1619,9 @@ Flushes data of a file to disk. This API uses a promise to return the result.
...
@@ -1619,9 +1619,9 @@ Flushes data of a file to disk. This API uses a promise to return the result.
**Example**
**Example**
```
js
```
js
fileio
.
fsync
(
fd
).
then
(
function
(){
fileio
.
fsync
(
fd
).
then
(
function
(){
console
.
info
(
"
sync data succe
ed
"
);
console
.
info
(
"
Data flush
ed
"
);
}).
catch
(
function
(
err
){
}).
catch
(
function
(
err
){
console
.
info
(
"
sync data failed with e
rror:
"
+
err
);
console
.
info
(
"
Failed to flush data. E
rror:
"
+
err
);
});
});
```
```
...
@@ -1688,9 +1688,9 @@ Flushes data of a file to disk. This API uses a promise to return the result. **
...
@@ -1688,9 +1688,9 @@ Flushes data of a file to disk. This API uses a promise to return the result. **
**Example**
**Example**
```
js
```
js
fileio
.
fdatasync
(
fd
).
then
(
function
(
err
)
{
fileio
.
fdatasync
(
fd
).
then
(
function
(
err
)
{
console
.
info
(
"
sync data succe
ed
"
);
console
.
info
(
"
Data flush
ed
"
);
}).
catch
(
function
(
err
){
}).
catch
(
function
(
err
){
console
.
info
(
"
sync data failed with e
rror:
"
+
err
);
console
.
info
(
"
Failed to flush data. E
rror:
"
+
err
);
});
});
```
```
...
@@ -1758,9 +1758,9 @@ Creates a symbolic link based on the file path. This API uses a promise to retur
...
@@ -1758,9 +1758,9 @@ Creates a symbolic link based on the file path. This API uses a promise to retur
**Example**
**Example**
```
js
```
js
fileio
.
symlink
(
target
,
srcPath
).
then
(
function
()
{
fileio
.
symlink
(
target
,
srcPath
).
then
(
function
()
{
console
.
info
(
"
symlink succe
ed
"
);
console
.
info
(
"
Symbolic link creat
ed
"
);
}).
catch
(
function
(
err
){
}).
catch
(
function
(
err
){
console
.
info
(
"
symlink failed with e
rror:
"
+
err
);
console
.
info
(
"
Failed to create the symbolic link. E
rror:
"
+
err
);
});
});
```
```
...
@@ -1832,9 +1832,9 @@ Changes the file owner based on the file path. This API uses a promise to return
...
@@ -1832,9 +1832,9 @@ Changes the file owner based on the file path. This API uses a promise to return
```
js
```
js
let
stat
=
fileio
.
statSync
(
path
);
let
stat
=
fileio
.
statSync
(
path
);
fileio
.
chown
(
path
,
stat
.
uid
,
stat
.
gid
).
then
(
function
(){
fileio
.
chown
(
path
,
stat
.
uid
,
stat
.
gid
).
then
(
function
(){
console
.
info
(
"
chown succe
ed
"
);
console
.
info
(
"
File owner chang
ed
"
);
}).
catch
(
function
(
err
){
}).
catch
(
function
(
err
){
console
.
info
(
"
chown failed with e
rror:
"
+
err
);
console
.
info
(
"
Failed to change the file owner. E
rror:
"
+
err
);
});
});
```
```
...
@@ -1907,9 +1907,9 @@ Creates a temporary directory. This API uses a promise to return the result.
...
@@ -1907,9 +1907,9 @@ Creates a temporary directory. This API uses a promise to return the result.
**Example**
**Example**
```
js
```
js
fileio
.
mkdtemp
(
path
+
"
XXXX
"
).
then
(
function
(
path
){
fileio
.
mkdtemp
(
path
+
"
XXXX
"
).
then
(
function
(
path
){
console
.
info
(
"
mkdtemp succe
ed:
"
+
path
);
console
.
info
(
"
Temporary directory creat
ed:
"
+
path
);
}).
catch
(
function
(
err
){
}).
catch
(
function
(
err
){
console
.
info
(
"
mkdtemp failed with e
rror:
"
+
err
);
console
.
info
(
"
Failed to create a temporary directory. E
rror:
"
+
err
);
});
});
```
```
...
@@ -1982,9 +1982,9 @@ Changes file permissions based on the file descriptor. This API uses a promise t
...
@@ -1982,9 +1982,9 @@ Changes file permissions based on the file descriptor. This API uses a promise t
**Example**
**Example**
```
js
```
js
fileio
.
fchmod
(
fd
,
mode
).
then
(
function
()
{
fileio
.
fchmod
(
fd
,
mode
).
then
(
function
()
{
console
.
info
(
"
chmod succe
ed
"
);
console
.
info
(
"
File permissions chang
ed
"
);
}).
catch
(
function
(
err
){
}).
catch
(
function
(
err
){
console
.
info
(
"
chmod failed with e
rror:
"
+
err
);
console
.
info
(
"
Failed to change file permissions. E
rror:
"
+
err
);
});
});
```
```
...
@@ -2054,9 +2054,9 @@ Opens a file stream based on the file path. This API uses a promise to return th
...
@@ -2054,9 +2054,9 @@ Opens a file stream based on the file path. This API uses a promise to return th
**Example**
**Example**
```
js
```
js
fileio
.
createStream
(
path
,
"
r+
"
).
then
(
function
(
stream
){
fileio
.
createStream
(
path
,
"
r+
"
).
then
(
function
(
stream
){
console
.
info
(
"
createStream succe
ed
"
);
console
.
info
(
"
Stream open
ed
"
);
}).
catch
(
function
(
err
){
}).
catch
(
function
(
err
){
console
.
info
(
"
createStream failed with e
rror:
"
+
err
);
console
.
info
(
"
Failed to create the stream. E
rror:
"
+
err
);
});
});
```
```
...
@@ -2132,9 +2132,9 @@ Opens a file stream based on the file descriptor. This API uses a promise to ret
...
@@ -2132,9 +2132,9 @@ Opens a file stream based on the file descriptor. This API uses a promise to ret
```
js
```
js
let
fd
=
fileio
.
openSync
(
path
);
let
fd
=
fileio
.
openSync
(
path
);
fileio
.
fdopenStream
(
fd
,
"
r+
"
).
then
(
function
(
stream
){
fileio
.
fdopenStream
(
fd
,
"
r+
"
).
then
(
function
(
stream
){
console
.
info
(
"
openStream succe
ed
"
);
console
.
info
(
"
Stream open
ed
"
);
}).
catch
(
function
(
err
){
}).
catch
(
function
(
err
){
console
.
info
(
"
openStream failed with e
rror:
"
+
err
);
console
.
info
(
"
Failed to open the stream. E
rror:
"
+
err
);
});
});
```
```
...
@@ -2213,9 +2213,9 @@ Changes the file owner based on the file descriptor. This API uses a promise to
...
@@ -2213,9 +2213,9 @@ Changes the file owner based on the file descriptor. This API uses a promise to
```
js
```
js
let
stat
=
fileio
.
statSync
(
path
);
let
stat
=
fileio
.
statSync
(
path
);
fileio
.
fchown
(
fd
,
stat
.
uid
,
stat
.
gid
).
then
(
function
()
{
fileio
.
fchown
(
fd
,
stat
.
uid
,
stat
.
gid
).
then
(
function
()
{
console
.
info
(
"
chown succe
ed
"
);
console
.
info
(
"
File owner chang
ed
"
);
}).
catch
(
function
(
err
){
}).
catch
(
function
(
err
){
console
.
info
(
"
chown failed with e
rror:
"
+
err
);
console
.
info
(
"
Failed to change the file owner. E
rror:
"
+
err
);
});
});
```
```
...
@@ -2291,9 +2291,9 @@ Changes the file owner (owner of the symbolic link, not the file referred to by
...
@@ -2291,9 +2291,9 @@ Changes the file owner (owner of the symbolic link, not the file referred to by
```
js
```
js
let
stat
=
fileio
.
statSync
(
path
);
let
stat
=
fileio
.
statSync
(
path
);
fileio
.
lchown
(
path
,
stat
.
uid
,
stat
.
gid
).
then
(
function
()
{
fileio
.
lchown
(
path
,
stat
.
uid
,
stat
.
gid
).
then
(
function
()
{
console
.
info
(
"
chown succe
ed
"
);
console
.
info
(
"
File owner chang
ed
"
);
}).
catch
(
function
(
err
){
}).
catch
(
function
(
err
){
console
.
info
(
"
chown failed with e
rror:
"
+
err
);
console
.
info
(
"
Failed to change the file owner. E
rror:
"
+
err
);
});
});
```
```
...
@@ -2565,7 +2565,7 @@ Stops the **watcher** instance. This API uses a promise to return the result.
...
@@ -2565,7 +2565,7 @@ Stops the **watcher** instance. This API uses a promise to return the result.
console
.
info
(
"
Monitoring times:
"
+
number
);
console
.
info
(
"
Monitoring times:
"
+
number
);
});
});
watcher
.
stop
().
then
(
function
(){
watcher
.
stop
().
then
(
function
(){
console
.
info
(
"
close watcher succe
ed
"
);
console
.
info
(
"
Watcher stopp
ed
"
);
});
});
```
```
...
@@ -2590,7 +2590,7 @@ Stops the **watcher** instance. This API uses an asynchronous callback to return
...
@@ -2590,7 +2590,7 @@ Stops the **watcher** instance. This API uses an asynchronous callback to return
console
.
info
(
"
Monitoring times:
"
+
number
);
console
.
info
(
"
Monitoring times:
"
+
number
);
});
});
watcher
.
stop
(
function
(){
watcher
.
stop
(
function
(){
console
.
info
(
"
close watcher succe
ed
"
);
console
.
info
(
"
Watcher stopp
ed
"
);
})
})
```
```
...
@@ -2616,9 +2616,9 @@ Closes the stream. This API uses a promise to return the result.
...
@@ -2616,9 +2616,9 @@ Closes the stream. This API uses a promise to return the result.
```
js
```
js
let
ss
=
fileio
.
createStreamSync
(
path
,
"
r+
"
);
let
ss
=
fileio
.
createStreamSync
(
path
,
"
r+
"
);
ss
.
close
().
then
(
function
(){
ss
.
close
().
then
(
function
(){
console
.
info
(
"
close fileStream succe
ed
"
);
console
.
info
(
"
Stream clos
ed
"
);
}).
catch
(
function
(
err
){
}).
catch
(
function
(
err
){
console
.
info
(
"
close fileStream failed with e
rror:
"
+
err
);
console
.
info
(
"
Failed to close the file stream. E
rror:
"
+
err
);
});
});
```
```
...
@@ -2677,9 +2677,9 @@ Flushes the stream. This API uses a promise to return the result.
...
@@ -2677,9 +2677,9 @@ Flushes the stream. This API uses a promise to return the result.
```
js
```
js
let
ss
=
fileio
.
createStreamSync
(
path
,
"
r+
"
);
let
ss
=
fileio
.
createStreamSync
(
path
,
"
r+
"
);
ss
.
flush
().
then
(
function
(){
ss
.
flush
().
then
(
function
(){
console
.
info
(
"
flush succe
ed
"
);
console
.
info
(
"
Stream flush
ed
"
);
}).
catch
(
function
(
err
){
}).
catch
(
function
(
err
){
console
.
info
(
"
flush failed with e
rror:
"
+
err
);
console
.
info
(
"
Failed to flush the stream. E
rror:
"
+
err
);
});
});
```
```
...
@@ -2749,9 +2749,9 @@ Writes data into the stream. This API uses a promise to return the result.
...
@@ -2749,9 +2749,9 @@ Writes data into the stream. This API uses a promise to return the result.
```
js
```
js
let
ss
=
fileio
.
createStreamSync
(
path
,
"
r+
"
);
let
ss
=
fileio
.
createStreamSync
(
path
,
"
r+
"
);
ss
.
write
(
"
hello, world
"
,{
offset
:
1
,
length
:
5
,
position
:
5
,
encoding
:
'
utf-8
'
}).
then
(
function
(
number
){
ss
.
write
(
"
hello, world
"
,{
offset
:
1
,
length
:
5
,
position
:
5
,
encoding
:
'
utf-8
'
}).
then
(
function
(
number
){
console
.
info
(
"
write succeed
and size is:
"
+
number
);
console
.
info
(
"
Data written to the stream
and size is:
"
+
number
);
}).
catch
(
function
(
err
){
}).
catch
(
function
(
err
){
console
.
info
(
"
write failed with e
rror:
"
+
err
);
console
.
info
(
"
Failed to write data into the stream. E
rror:
"
+
err
);
});
});
```
```
...
@@ -2782,7 +2782,7 @@ Writes data into the stream. This API uses an asynchronous callback to return th
...
@@ -2782,7 +2782,7 @@ Writes data into the stream. This API uses an asynchronous callback to return th
ss
.
write
(
"
hello, world
"
,
{
offset
:
1
,
length
:
5
,
position
:
5
,
encoding
:
'
utf-8
'
},
function
(
err
,
bytesWritten
)
{
ss
.
write
(
"
hello, world
"
,
{
offset
:
1
,
length
:
5
,
position
:
5
,
encoding
:
'
utf-8
'
},
function
(
err
,
bytesWritten
)
{
if
(
bytesWritten
)
{
if
(
bytesWritten
)
{
// Do something
// Do something
console
.
info
(
"
write succeed
and size is:
"
+
bytesWritten
);
console
.
info
(
"
Data written to the stream
and size is:
"
+
bytesWritten
);
}
}
});
});
```
```
...
@@ -2846,10 +2846,10 @@ Reads data from the stream. This API uses a promise to return the result.
...
@@ -2846,10 +2846,10 @@ Reads data from the stream. This API uses a promise to return the result.
```
js
```
js
let
ss
=
fileio
.
createStreamSync
(
path
,
"
r+
"
);
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
.
info
(
"
Read 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
(
"
read data failed with e
rror:
"
+
err
);
console
.
info
(
"
Failed to read data. E
rror:
"
+
err
);
});
});
```
```
...
@@ -2878,7 +2878,7 @@ Reads data from the stream. This API uses an asynchronous callback to return the
...
@@ -2878,7 +2878,7 @@ Reads data from the stream. This API uses an asynchronous callback to return the
let
ss
=
fileio
.
createStreamSync
(
path
,
"
r+
"
);
let
ss
=
fileio
.
createStreamSync
(
path
,
"
r+
"
);
ss
.
read
(
new
ArrayBuffer
(
4096
),{
offset
:
1
,
length
:
5
,
position
:
5
},
function
(
err
,
readOut
)
{
ss
.
read
(
new
ArrayBuffer
(
4096
),{
offset
:
1
,
length
:
5
,
position
:
5
},
function
(
err
,
readOut
)
{
if
(
readOut
)
{
if
(
readOut
)
{
console
.
info
(
"
read data succeed
"
);
console
.
info
(
"
Read data successfully
"
);
console
.
log
(
String
.
fromCharCode
.
apply
(
null
,
new
Uint8Array
(
readOut
.
buffer
)));
console
.
log
(
String
.
fromCharCode
.
apply
(
null
,
new
Uint8Array
(
readOut
.
buffer
)));
}
}
});
});
...
@@ -2939,9 +2939,9 @@ Reads the next directory entry. This API uses a promise to return the result.
...
@@ -2939,9 +2939,9 @@ Reads the next directory entry. This API uses a promise to return the result.
```
js
```
js
let
dir
=
fileio
.
opendirSync
(
path
);
let
dir
=
fileio
.
opendirSync
(
path
);
dir
.
read
().
then
(
function
(
dirent
){
dir
.
read
().
then
(
function
(
dirent
){
console
.
log
(
"
read succeed
:
"
+
JSON
.
stringify
(
dirent
));
console
.
log
(
"
Read the next directory entry
:
"
+
JSON
.
stringify
(
dirent
));
}).
catch
(
function
(
err
){
}).
catch
(
function
(
err
){
console
.
info
(
"
read failed with e
rror:
"
+
err
);
console
.
info
(
"
Failed to read data. E
rror:
"
+
err
);
});
});
```
```
...
@@ -2965,7 +2965,7 @@ Reads the next directory entry. This API uses an asynchronous callback to return
...
@@ -2965,7 +2965,7 @@ Reads the next directory entry. This API uses an asynchronous callback to return
dir
.
read
(
function
(
err
,
dirent
)
{
dir
.
read
(
function
(
err
,
dirent
)
{
if
(
dirent
)
{
if
(
dirent
)
{
// Do something
// Do something
console
.
log
(
"
read succeed
:
"
+
JSON
.
stringify
(
dirent
));
console
.
log
(
"
Read the next directory entry
:
"
+
JSON
.
stringify
(
dirent
));
}
}
});
});
```
```
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录