Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
cd94749f
D
Docs
项目概览
OpenHarmony
/
Docs
12 个月 前同步成功
通知
159
Star
292
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
cd94749f
编写于
1月 05, 2023
作者:
Z
zhuhongtao66
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
bugfix_fileio_fifo
Signed-off-by:
N
zhuhongtao66
<
zhuhongtao12@huawei.com
>
上级
61a95ba2
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
136 addition
and
136 deletion
+136
-136
zh-cn/application-dev/reference/apis/js-apis-fileio.md
zh-cn/application-dev/reference/apis/js-apis-fileio.md
+136
-136
未找到文件。
zh-cn/application-dev/reference/apis/js-apis-fileio.md
浏览文件 @
cd94749f
...
...
@@ -67,10 +67,10 @@ stat(path: string): Promise<Stat>
```
js
let
filePath
=
pathDir
+
"
test.txt
"
;
fileio
.
stat
(
filePath
).
then
(
function
(
stat
)
{
fileio
.
stat
(
filePath
).
then
(
function
(
stat
)
{
console
.
info
(
"
getFileInfo succeed, the size of file is
"
+
stat
.
size
);
}).
catch
(
function
(
err
)
{
console
.
info
(
"
getFileInfo failed with error:
"
+
err
);
}).
catch
(
function
(
err
)
{
console
.
info
(
"
getFileInfo failed with error:
"
+
err
);
});
```
...
...
@@ -152,10 +152,10 @@ opendir(path: string): Promise<Dir>
```
js
let
dirPath
=
pathDir
+
"
/testDir
"
;
fileio
.
opendir
(
dirPath
).
then
(
function
(
dir
)
{
fileio
.
opendir
(
dirPath
).
then
(
function
(
dir
)
{
console
.
info
(
"
opendir succeed
"
);
}).
catch
(
function
(
err
)
{
console
.
info
(
"
opendir failed with error:
"
+
err
);
}).
catch
(
function
(
err
)
{
console
.
info
(
"
opendir failed with error:
"
+
err
);
});
```
...
...
@@ -240,10 +240,10 @@ access(path: string, mode?: number): Promise<void>
```
js
let
filePath
=
pathDir
+
"
/test.txt
"
;
fileio
.
access
(
filePath
).
then
(
function
()
{
fileio
.
access
(
filePath
).
then
(
function
()
{
console
.
info
(
"
access succeed
"
);
}).
catch
(
function
(
err
)
{
console
.
info
(
"
access failed with error:
"
+
err
);
}).
catch
(
function
(
err
)
{
console
.
info
(
"
access failed with error:
"
+
err
);
});
```
...
...
@@ -296,7 +296,7 @@ accessSync(path: string, mode?: number): void
try
{
fileio
.
accessSync
(
filePath
);
}
catch
(
err
)
{
console
.
info
(
"
accessSync failed with error:
"
+
err
);
console
.
info
(
"
accessSync failed with error:
"
+
err
);
}
```
...
...
@@ -326,10 +326,10 @@ close(fd: number): Promise<void>
```
js
let
filePath
=
pathDir
+
"
/test.txt
"
;
let
fd
=
fileio
.
openSync
(
filePath
);
fileio
.
close
(
fd
).
then
(
function
()
{
fileio
.
close
(
fd
).
then
(
function
()
{
console
.
info
(
"
close file succeed
"
);
}).
catch
(
function
(
err
)
{
console
.
info
(
"
close file failed with error:
"
+
err
);
}).
catch
(
function
(
err
)
{
console
.
info
(
"
close file failed with error:
"
+
err
);
});
```
...
...
@@ -410,10 +410,10 @@ copyFile(src: string|number, dest: string|number, mode?: number): Promise<voi
```
js
let
srcPath
=
pathDir
+
"
srcDir/test.txt
"
;
let
dstPath
=
pathDir
+
"
dstDir/test.txt
"
;
fileio
.
copyFile
(
srcPath
,
dstPath
).
then
(
function
()
{
fileio
.
copyFile
(
srcPath
,
dstPath
).
then
(
function
()
{
console
.
info
(
"
copyFile succeed
"
);
}).
catch
(
function
(
err
)
{
console
.
info
(
"
copyFile failed with error:
"
+
err
);
}).
catch
(
function
(
err
)
{
console
.
info
(
"
copyFile failed with error:
"
+
err
);
});
```
...
...
@@ -496,10 +496,10 @@ mkdir(path: string, mode?: number): Promise<void>
```
js
let
dirPath
=
pathDir
+
'
/testDir
'
;
fileio
.
mkdir
(
dirPath
).
then
(
function
()
{
fileio
.
mkdir
(
dirPath
).
then
(
function
()
{
console
.
info
(
"
mkdir succeed
"
);
}).
catch
(
function
(
error
){
console
.
info
(
"
mkdir failed with error:
"
+
error
);
}).
catch
(
function
(
error
)
{
console
.
info
(
"
mkdir failed with error:
"
+
error
);
});
```
...
...
@@ -524,7 +524,7 @@ mkdir(path: string, mode: number, callback: AsyncCallback<void>): void
```
js
let
dirPath
=
pathDir
+
'
/testDir
'
;
fileio
.
mkdir
(
dirPath
,
function
(
err
)
{
fileio
.
mkdir
(
dirPath
,
function
(
err
)
{
console
.
info
(
"
mkdir succeed
"
);
});
```
...
...
@@ -579,10 +579,10 @@ open(path: string, flags?: number, mode?: number): Promise<number>
```
js
let
filePath
=
pathDir
+
"
/test.txt
"
;
fileio
.
open
(
filePath
,
0o1
,
0o0200
).
then
(
function
(
number
)
{
fileio
.
open
(
filePath
,
0o1
,
0o0200
).
then
(
function
(
number
)
{
console
.
info
(
"
open file succeed
"
);
}).
catch
(
function
(
err
)
{
console
.
info
(
"
open file failed with error:
"
+
err
);
}).
catch
(
function
(
err
)
{
console
.
info
(
"
open file failed with error:
"
+
err
);
});
```
...
...
@@ -608,7 +608,7 @@ open(path: string, flags: number, mode: number, callback: AsyncCallback<numbe
```
js
let
filePath
=
pathDir
+
"
/test.txt
"
;
fileio
.
open
(
filePath
,
0
,
function
(
err
,
fd
)
{
fileio
.
open
(
filePath
,
0
,
function
(
err
,
fd
)
{
// do something
});
```
...
...
@@ -681,11 +681,11 @@ read(fd: number, buffer: ArrayBuffer, options?: { offset?: number; length?: numb
let
filePath
=
pathDir
+
"
/test.txt
"
;
let
fd
=
fileio
.
openSync
(
filePath
,
0o2
);
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
.
log
(
String
.
fromCharCode
.
apply
(
null
,
new
Uint8Array
(
readOut
.
buffer
)));
}).
catch
(
function
(
err
)
{
console
.
info
(
"
read file data failed with error:
"
+
err
);
}).
catch
(
function
(
err
)
{
console
.
info
(
"
read file data failed with error:
"
+
err
);
});
```
...
...
@@ -778,10 +778,10 @@ rmdir(path: string): Promise<void>
```
js
let
dirPath
=
pathDir
+
'
/testDir
'
;
fileio
.
rmdir
(
dirPath
).
then
(
function
()
{
fileio
.
rmdir
(
dirPath
).
then
(
function
()
{
console
.
info
(
"
rmdir succeed
"
);
}).
catch
(
function
(
err
)
{
console
.
info
(
"
rmdir failed with error:
"
+
err
);
}).
catch
(
function
(
err
)
{
console
.
info
(
"
rmdir failed with error:
"
+
err
);
});
```
...
...
@@ -805,7 +805,7 @@ rmdir(path: string, callback: AsyncCallback<void>): void
```
js
let
dirPath
=
pathDir
+
'
/testDir
'
;
fileio
.
rmdir
(
dirPath
,
function
(
err
)
{
fileio
.
rmdir
(
dirPath
,
function
(
err
)
{
// do something
console
.
info
(
"
rmdir succeed
"
);
});
...
...
@@ -858,10 +858,10 @@ unlink(path: string): Promise<void>
```
js
let
filePath
=
pathDir
+
"
/test.txt
"
;
fileio
.
unlink
(
filePath
).
then
(
function
()
{
fileio
.
unlink
(
filePath
).
then
(
function
()
{
console
.
info
(
"
remove file succeed
"
);
}).
catch
(
function
(
error
)
{
console
.
info
(
"
remove file failed with error:
"
+
error
);
}).
catch
(
function
(
error
)
{
console
.
info
(
"
remove file failed with error:
"
+
error
);
});
```
...
...
@@ -885,7 +885,7 @@ unlink(path: string, callback: AsyncCallback<void>): void
```
js
let
filePath
=
pathDir
+
"
/test.txt
"
;
fileio
.
unlink
(
filePath
,
function
(
err
)
{
fileio
.
unlink
(
filePath
,
function
(
err
)
{
console
.
info
(
"
remove file succeed
"
);
});
```
...
...
@@ -940,10 +940,10 @@ write(fd: number, buffer: ArrayBuffer|string, options?: { offset?: number; lengt
```
js
let
filePath
=
pathDir
+
"
/test.txt
"
;
let
fd
=
fileio
.
openSync
(
filePath
,
0o100
|
0o2
,
0o666
);
fileio
.
write
(
fd
,
"
hello, world
"
).
then
(
function
(
number
)
{
console
.
info
(
"
write data to file succeed and size is:
"
+
number
);
}).
catch
(
function
(
err
)
{
console
.
info
(
"
write data to file failed with error:
"
+
err
);
fileio
.
write
(
fd
,
"
hello, world
"
).
then
(
function
(
number
)
{
console
.
info
(
"
write data to file succeed and size is:
"
+
number
);
}).
catch
(
function
(
err
)
{
console
.
info
(
"
write data to file failed with error:
"
+
err
);
});
```
...
...
@@ -972,7 +972,7 @@ write(fd: number, buffer: ArrayBuffer|string, options: { offset?: number; length
let
fd
=
fileio
.
openSync
(
filePath
,
0o100
|
0o2
,
0o666
);
fileio
.
write
(
fd
,
"
hello, world
"
,
function
(
err
,
bytesWritten
)
{
if
(
bytesWritten
)
{
console
.
info
(
"
write data to file succeed and size is:
"
+
bytesWritten
);
console
.
info
(
"
write data to file succeed and size is:
"
+
bytesWritten
);
}
});
```
...
...
@@ -1034,10 +1034,10 @@ hash(path: string, algorithm: string): Promise<string>
```
js
let
filePath
=
pathDir
+
"
/test.txt
"
;
fileio
.
hash
(
filePath
,
"
sha256
"
).
then
(
function
(
str
)
{
console
.
info
(
"
calculate file hash succeed:
"
+
str
);
}).
catch
(
function
(
err
)
{
console
.
info
(
"
calculate file hash failed with error:
"
+
err
);
fileio
.
hash
(
filePath
,
"
sha256
"
).
then
(
function
(
str
)
{
console
.
info
(
"
calculate file hash succeed:
"
+
str
);
}).
catch
(
function
(
err
)
{
console
.
info
(
"
calculate file hash failed with error:
"
+
err
);
});
```
...
...
@@ -1062,9 +1062,9 @@ hash(path: string, algorithm: string, callback: AsyncCallback<string>): vo
```
js
let
filePath
=
pathDir
+
"
/test.txt
"
;
fileio
.
hash
(
filePath
,
"
sha256
"
,
function
(
err
,
hashStr
)
{
fileio
.
hash
(
filePath
,
"
sha256
"
,
function
(
err
,
hashStr
)
{
if
(
hashStr
)
{
console
.
info
(
"
calculate file hash succeed:
"
+
hashStr
);
console
.
info
(
"
calculate file hash succeed:
"
+
hashStr
);
}
});
```
...
...
@@ -1095,10 +1095,10 @@ chmod(path: string, mode: number): Promise<void>
```
js
let
filePath
=
pathDir
+
"
/test.txt
"
;
fileio
.
chmod
(
filePath
,
0o700
).
then
(
function
()
{
fileio
.
chmod
(
filePath
,
0o700
).
then
(
function
()
{
console
.
info
(
"
chmod succeed
"
);
}).
catch
(
function
(
err
)
{
console
.
info
(
"
chmod failed with error:
"
+
err
);
}).
catch
(
function
(
err
)
{
console
.
info
(
"
chmod failed with error:
"
+
err
);
});
```
...
...
@@ -1177,10 +1177,10 @@ fstat(fd: number): Promise<Stat>
```
js
let
filePath
=
pathDir
+
"
/test.txt
"
;
let
fd
=
fileio
.
openSync
(
filePath
);
fileio
.
fstat
(
fd
).
then
(
function
(
stat
)
{
console
.
info
(
"
fstat succeed, the size of file is
"
+
stat
.
size
);
}).
catch
(
function
(
err
)
{
console
.
info
(
"
fstat failed with error:
"
+
err
);
fileio
.
fstat
(
fd
).
then
(
function
(
stat
)
{
console
.
info
(
"
fstat succeed, the size of file is
"
+
stat
.
size
);
}).
catch
(
function
(
err
)
{
console
.
info
(
"
fstat failed with error:
"
+
err
);
});
```
...
...
@@ -1266,10 +1266,10 @@ ftruncate(fd: number, len?: number): Promise<void>
```
js
let
filePath
=
pathDir
+
"
/test.txt
"
;
let
fd
=
fileio
.
openSync
(
filePath
);
fileio
.
ftruncate
(
fd
,
5
).
then
(
function
(
err
)
{
fileio
.
ftruncate
(
fd
,
5
).
then
(
function
(
err
)
{
console
.
info
(
"
truncate file succeed
"
);
}).
catch
(
function
(
err
)
{
console
.
info
(
"
truncate file failed with error:
"
+
err
);
}).
catch
(
function
(
err
)
{
console
.
info
(
"
truncate file failed with error:
"
+
err
);
});
```
...
...
@@ -1296,7 +1296,7 @@ ftruncate(fd: number, len?: number, callback: AsyncCallback<void>): void
let
filePath
=
pathDir
+
"
/test.txt
"
;
let
fd
=
fileio
.
openSync
(
filePath
);
let
len
=
5
;
fileio
.
ftruncate
(
fd
,
5
,
function
(
err
)
{
fileio
.
ftruncate
(
fd
,
5
,
function
(
err
)
{
// do something
});
```
...
...
@@ -1353,10 +1353,10 @@ truncate(path: string, len?: number): Promise<void>
```
js
let
filePath
=
pathDir
+
"
/test.txt
"
;
let
len
=
5
;
fileio
.
truncate
(
filePath
,
len
).
then
(
function
()
{
fileio
.
truncate
(
filePath
,
len
).
then
(
function
()
{
console
.
info
(
"
truncate file succeed
"
);
}).
catch
(
function
(
err
)
{
console
.
info
(
"
truncate file failed with error:
"
+
err
);
}).
catch
(
function
(
err
)
{
console
.
info
(
"
truncate file failed with error:
"
+
err
);
});
```
...
...
@@ -1382,7 +1382,7 @@ truncate(path: string, len?: number, callback: AsyncCallback<void>): void
```
js
let
filePath
=
pathDir
+
"
/test.txt
"
;
let
len
=
5
;
fileio
.
truncate
(
filePath
,
len
,
function
(
err
)
{
fileio
.
truncate
(
filePath
,
len
,
function
(
err
)
{
// do something
});
```
...
...
@@ -1437,10 +1437,10 @@ readText(filePath: string, options?: { position?: number; length?: number; encod
```
js
let
filePath
=
pathDir
+
"
/test.txt
"
;
fileio
.
readText
(
filePath
).
then
(
function
(
str
)
{
console
.
info
(
"
readText succeed:
"
+
str
);
}).
catch
(
function
(
err
)
{
console
.
info
(
"
readText failed with error:
"
+
err
);
fileio
.
readText
(
filePath
).
then
(
function
(
str
)
{
console
.
info
(
"
readText succeed:
"
+
str
);
}).
catch
(
function
(
err
)
{
console
.
info
(
"
readText failed with error:
"
+
err
);
});
```
...
...
@@ -1465,7 +1465,7 @@ readText(filePath: string, options: { position?: number; length?: number; encodi
```
js
let
filePath
=
pathDir
+
"
/test.txt
"
;
fileio
.
readText
(
filePath
,
{
position
:
1
,
encoding
:
'
UTF-8
'
},
function
(
err
,
str
)
{
fileio
.
readText
(
filePath
,
{
position
:
1
,
encoding
:
'
UTF-8
'
},
function
(
err
,
str
)
{
// do something
});
```
...
...
@@ -1524,10 +1524,10 @@ lstat(path: string): Promise<Stat>
```
js
let
filePath
=
pathDir
+
"
/test.txt
"
;
fileio
.
lstat
(
filePath
).
then
(
function
(
stat
)
{
fileio
.
lstat
(
filePath
).
then
(
function
(
stat
)
{
console
.
info
(
"
get link status succeed, the size of file is
"
+
stat
.
size
);
}).
catch
(
function
(
err
)
{
console
.
info
(
"
get link status failed with error:
"
+
err
);
}).
catch
(
function
(
err
)
{
console
.
info
(
"
get link status failed with error:
"
+
err
);
});
```
...
...
@@ -1611,10 +1611,10 @@ rename(oldPath: string, newPath: string): Promise<void>
```
js
let
srcFile
=
pathDir
+
"
/test.txt
"
;
let
dstFile
=
pathDir
+
'
/new.txt
'
;
fileio
.
rename
(
srcFile
,
dstFile
).
then
(
function
()
{
fileio
.
rename
(
srcFile
,
dstFile
).
then
(
function
()
{
console
.
info
(
"
rename succeed
"
);
}).
catch
(
function
(
err
)
{
console
.
info
(
"
rename failed with error:
"
+
err
);
}).
catch
(
function
(
err
)
{
console
.
info
(
"
rename failed with error:
"
+
err
);
});
```
...
...
@@ -1640,7 +1640,7 @@ rename(oldPath: string, newPath: string, callback: AsyncCallback<void>): v
```
js
let
srcFile
=
pathDir
+
"
/test.txt
"
;
let
dstFile
=
pathDir
+
'
/new.txt
'
;
fileio
.
rename
(
srcFile
,
dstFile
,
function
(
err
)
{
fileio
.
rename
(
srcFile
,
dstFile
,
function
(
err
)
{
});
```
...
...
@@ -1694,10 +1694,10 @@ fsync(fd: number): Promise<void>
```
js
let
filePath
=
pathDir
+
"
/test.txt
"
;
let
fd
=
fileio
.
openSync
(
filePath
);
fileio
.
fsync
(
fd
).
then
(
function
()
{
fileio
.
fsync
(
fd
).
then
(
function
()
{
console
.
info
(
"
sync data succeed
"
);
}).
catch
(
function
(
err
)
{
console
.
info
(
"
sync data failed with error:
"
+
err
);
}).
catch
(
function
(
err
)
{
console
.
info
(
"
sync data failed with error:
"
+
err
);
});
```
...
...
@@ -1722,7 +1722,7 @@ fsync(fd: number, callback: AsyncCallback<void>): void
```
js
let
filePath
=
pathDir
+
"
/test.txt
"
;
let
fd
=
fileio
.
openSync
(
filePath
);
fileio
.
fsync
(
fd
,
function
(
err
)
{
fileio
.
fsync
(
fd
,
function
(
err
)
{
// do something
});
```
...
...
@@ -1776,10 +1776,10 @@ fdatasync(fd: number): Promise<void>
```
js
let
filePath
=
pathDir
+
"
/test.txt
"
;
let
fd
=
fileio
.
openSync
(
filePath
);
fileio
.
fdatasync
(
fd
).
then
(
function
(
err
)
{
fileio
.
fdatasync
(
fd
).
then
(
function
(
err
)
{
console
.
info
(
"
sync data succeed
"
);
}).
catch
(
function
(
err
)
{
console
.
info
(
"
sync data failed with error:
"
+
err
);
}).
catch
(
function
(
err
)
{
console
.
info
(
"
sync data failed with error:
"
+
err
);
});
```
...
...
@@ -1859,10 +1859,10 @@ symlink(target: string, srcPath: string): Promise<void>
```
js
let
srcFile
=
pathDir
+
"
/test.txt
"
;
let
dstFile
=
pathDir
+
'
/test
'
;
fileio
.
symlink
(
srcFile
,
dstFile
).
then
(
function
()
{
fileio
.
symlink
(
srcFile
,
dstFile
).
then
(
function
()
{
console
.
info
(
"
symlink succeed
"
);
}).
catch
(
function
(
err
)
{
console
.
info
(
"
symlink failed with error:
"
+
err
);
}).
catch
(
function
(
err
)
{
console
.
info
(
"
symlink failed with error:
"
+
err
);
});
```
...
...
@@ -1945,10 +1945,10 @@ chown(path: string, uid: number, gid: number): Promise<void>
```
js
let
filePath
=
pathDir
+
"
/test.txt
"
;
let
stat
=
fileio
.
statSync
(
filePath
);
fileio
.
chown
(
filePath
,
stat
.
uid
,
stat
.
gid
).
then
(
function
()
{
fileio
.
chown
(
filePath
,
stat
.
uid
,
stat
.
gid
).
then
(
function
()
{
console
.
info
(
"
chown succeed
"
);
}).
catch
(
function
(
err
)
{
console
.
info
(
"
chown failed with error:
"
+
err
);
}).
catch
(
function
(
err
)
{
console
.
info
(
"
chown failed with error:
"
+
err
);
});
```
...
...
@@ -1975,7 +1975,7 @@ chown(path: string, uid: number, gid: number, callback: AsyncCallback<void>
```
js
let
filePath
=
pathDir
+
"
/test.txt
"
;
let
stat
=
fileio
.
statSync
(
filePath
)
fileio
.
chown
(
filePath
,
stat
.
uid
,
stat
.
gid
,
function
(
err
){
fileio
.
chown
(
filePath
,
stat
.
uid
,
stat
.
gid
,
function
(
err
)
{
// do something
});
```
...
...
@@ -2029,10 +2029,10 @@ mkdtemp(prefix: string): Promise<string>
**示例:**
```
js
fileio
.
mkdtemp
(
pathDir
+
"
/XXXXXX
"
).
then
(
function
(
pathDir
)
{
console
.
info
(
"
mkdtemp succeed:
"
+
pathDir
);
}).
catch
(
function
(
err
)
{
console
.
info
(
"
mkdtemp failed with error:
"
+
err
);
fileio
.
mkdtemp
(
pathDir
+
"
/XXXXXX
"
).
then
(
function
(
pathDir
)
{
console
.
info
(
"
mkdtemp succeed:
"
+
pathDir
);
}).
catch
(
function
(
err
)
{
console
.
info
(
"
mkdtemp failed with error:
"
+
err
);
});
```
...
...
@@ -2115,10 +2115,10 @@ fchmod(fd: number, mode: number): Promise<void>
let
filePath
=
pathDir
+
"
/test.txt
"
;
let
fd
=
fileio
.
openSync
(
filePath
);
let
mode
=
0o700
;
fileio
.
fchmod
(
fd
,
mode
).
then
(
function
()
{
fileio
.
fchmod
(
fd
,
mode
).
then
(
function
()
{
console
.
info
(
"
chmod succeed
"
);
}).
catch
(
function
(
err
)
{
console
.
info
(
"
chmod failed with error:
"
+
err
);
}).
catch
(
function
(
err
)
{
console
.
info
(
"
chmod failed with error:
"
+
err
);
});
```
...
...
@@ -2201,10 +2201,10 @@ createStream(path: string, mode: string): Promise<Stream>
```
js
let
filePath
=
pathDir
+
"
/test.txt
"
;
fileio
.
createStream
(
filePath
,
"
r+
"
).
then
(
function
(
stream
)
{
fileio
.
createStream
(
filePath
,
"
r+
"
).
then
(
function
(
stream
)
{
console
.
info
(
"
createStream succeed
"
);
}).
catch
(
function
(
err
)
{
console
.
info
(
"
createStream failed with error:
"
+
err
);
}).
catch
(
function
(
err
)
{
console
.
info
(
"
createStream failed with error:
"
+
err
);
});
```
...
...
@@ -2229,7 +2229,7 @@ createStream(path: string, mode: string, callback: AsyncCallback<Stream>):
```
js
let
filePath
=
pathDir
+
"
/test.txt
"
;
fileio
.
createStream
(
filePath
,
"
r+
"
,
function
(
err
,
stream
)
{
fileio
.
createStream
(
filePath
,
"
r+
"
,
function
(
err
,
stream
)
{
// do something
});
```
...
...
@@ -2290,10 +2290,10 @@ fdopenStream(fd: number, mode: string): Promise<Stream>
```
js
let
filePath
=
pathDir
+
"
/test.txt
"
;
let
fd
=
fileio
.
openSync
(
filePath
);
fileio
.
fdopenStream
(
fd
,
"
r+
"
).
then
(
function
(
stream
)
{
fileio
.
fdopenStream
(
fd
,
"
r+
"
).
then
(
function
(
stream
)
{
console
.
info
(
"
openStream succeed
"
);
}).
catch
(
function
(
err
)
{
console
.
info
(
"
openStream failed with error:
"
+
err
);
}).
catch
(
function
(
err
)
{
console
.
info
(
"
openStream failed with error:
"
+
err
);
});
```
...
...
@@ -2383,10 +2383,10 @@ fchown(fd: number, uid: number, gid: number): Promise<void>
let
filePath
=
pathDir
+
"
/test.txt
"
;
let
fd
=
fileio
.
openSync
(
filePath
);
let
stat
=
fileio
.
statSync
(
filePath
);
fileio
.
fchown
(
fd
,
stat
.
uid
,
stat
.
gid
).
then
(
function
()
{
fileio
.
fchown
(
fd
,
stat
.
uid
,
stat
.
gid
).
then
(
function
()
{
console
.
info
(
"
chown succeed
"
);
}).
catch
(
function
(
err
)
{
console
.
info
(
"
chown failed with error:
"
+
err
);
}).
catch
(
function
(
err
)
{
console
.
info
(
"
chown failed with error:
"
+
err
);
});
```
...
...
@@ -2414,7 +2414,7 @@ fchown(fd: number, uid: number, gid: number, callback: AsyncCallback<void>
let
filePath
=
pathDir
+
"
/test.txt
"
;
let
fd
=
fileio
.
openSync
(
filePath
);
let
stat
=
fileio
.
statSync
(
filePath
);
fileio
.
fchown
(
fd
,
stat
.
uid
,
stat
.
gid
,
function
(
err
){
fileio
.
fchown
(
fd
,
stat
.
uid
,
stat
.
gid
,
function
(
err
)
{
// do something
});
```
...
...
@@ -2473,10 +2473,10 @@ lchown(path: string, uid: number, gid: number): Promise<void>
```
js
let
filePath
=
pathDir
+
"
/test.txt
"
;
let
stat
=
fileio
.
statSync
(
filePath
);
fileio
.
lchown
(
filePath
,
stat
.
uid
,
stat
.
gid
).
then
(
function
()
{
fileio
.
lchown
(
filePath
,
stat
.
uid
,
stat
.
gid
).
then
(
function
()
{
console
.
info
(
"
chown succeed
"
);
}).
catch
(
function
(
err
)
{
console
.
info
(
"
chown failed with error:
"
+
err
);
}).
catch
(
function
(
err
)
{
console
.
info
(
"
chown failed with error:
"
+
err
);
});
```
...
...
@@ -2503,7 +2503,7 @@ lchown(path: string, uid: number, gid: number, callback: AsyncCallback<void&g
```
js
let
filePath
=
pathDir
+
"
/test.txt
"
;
let
stat
=
fileio
.
statSync
(
filePath
);
fileio
.
lchown
(
filePath
,
stat
.
uid
,
stat
.
gid
,
function
(
err
){
fileio
.
lchown
(
filePath
,
stat
.
uid
,
stat
.
gid
,
function
(
err
)
{
// do something
});
```
...
...
@@ -2560,8 +2560,8 @@ createWatcher(filename: string, events: number, callback: AsyncCallback<numbe
```
js
let
filePath
=
pathDir
+
"
/test.txt
"
;
fileio
.
createWatcher
(
filePath
,
1
,
function
(
number
)
{
console
.
info
(
"
Monitoring times:
"
+
number
);
fileio
.
createWatcher
(
filePath
,
1
,
function
(
number
)
{
console
.
info
(
"
Monitoring times:
"
+
number
);
});
```
...
...
@@ -2775,10 +2775,10 @@ stop(): Promise<void>
```
js
let
filePath
=
path
+
"
/test.txt
"
;
let
watcher
=
fileio
.
createWatcher
(
filePath
,
1
,
function
(
number
)
{
console
.
info
(
"
Monitoring times:
"
+
number
);
let
watcher
=
fileio
.
createWatcher
(
filePath
,
1
,
function
(
number
)
{
console
.
info
(
"
Monitoring times:
"
+
number
);
});
watcher
.
stop
().
then
(
function
()
{
watcher
.
stop
().
then
(
function
()
{
console
.
info
(
"
close watcher succeed
"
);
});
```
...
...
@@ -2802,10 +2802,10 @@ stop(callback: AsyncCallback<void>): void
```
js
let
filePath
=
path
+
"
/test.txt
"
;
let
watcher
=
fileio
.
createWatcher
(
filePath
,
1
,
function
(
number
)
{
console
.
info
(
"
Monitoring times:
"
+
number
);
let
watcher
=
fileio
.
createWatcher
(
filePath
,
1
,
function
(
number
)
{
console
.
info
(
"
Monitoring times:
"
+
number
);
});
watcher
.
stop
(
function
()
{
watcher
.
stop
(
function
()
{
console
.
info
(
"
close watcher succeed
"
);
})
```
...
...
@@ -2835,10 +2835,10 @@ close(): Promise<void>
```
js
let
filePath
=
pathDir
+
"
/test.txt
"
;
let
ss
=
fileio
.
createStreamSync
(
filePath
,
"
r+
"
);
ss
.
close
().
then
(
function
()
{
ss
.
close
().
then
(
function
()
{
console
.
info
(
"
close fileStream succeed
"
);
}).
catch
(
function
(
err
)
{
console
.
info
(
"
close fileStream failed with error:
"
+
err
);
}).
catch
(
function
(
err
)
{
console
.
info
(
"
close fileStream failed with error:
"
+
err
);
});
```
...
...
@@ -2904,10 +2904,10 @@ flush(): Promise<void>
```
js
let
filePath
=
pathDir
+
"
/test.txt
"
;
let
ss
=
fileio
.
createStreamSync
(
filePath
,
"
r+
"
);
ss
.
flush
().
then
(
function
(){
ss
.
flush
().
then
(
function
()
{
console
.
info
(
"
flush succeed
"
);
}).
catch
(
function
(
err
)
{
console
.
info
(
"
flush failed with error:
"
+
err
);
}).
catch
(
function
(
err
)
{
console
.
info
(
"
flush failed with error:
"
+
err
);
});
```
...
...
@@ -2980,10 +2980,10 @@ write(buffer: ArrayBuffer|string, options?: { offset?: number; length?: number;
```
js
let
filePath
=
pathDir
+
"
/test.txt
"
;
let
ss
=
fileio
.
createStreamSync
(
filePath
,
"
r+
"
);
ss
.
write
(
"
hello, world
"
,{
offset
:
1
,
length
:
5
,
position
:
5
,
encoding
:
'
utf-8
'
}).
then
(
function
(
number
){
console
.
info
(
"
write succeed and size is:
"
+
number
);
}).
catch
(
function
(
err
)
{
console
.
info
(
"
write failed with error:
"
+
err
);
ss
.
write
(
"
hello, world
"
,{
offset
:
1
,
length
:
5
,
position
:
5
,
encoding
:
'
utf-8
'
}).
then
(
function
(
number
)
{
console
.
info
(
"
write succeed and size is:
"
+
number
);
}).
catch
(
function
(
err
)
{
console
.
info
(
"
write failed with error:
"
+
err
);
});
```
...
...
@@ -3012,7 +3012,7 @@ write(buffer: ArrayBuffer|string, options: { offset?: number; length?: number; p
ss
.
write
(
"
hello, world
"
,
{
offset
:
1
,
length
:
5
,
position
:
5
,
encoding
:
'
utf-8
'
},
function
(
err
,
bytesWritten
)
{
if
(
bytesWritten
)
{
// do something
console
.
info
(
"
write succeed and size is:
"
+
bytesWritten
);
console
.
info
(
"
write succeed and size is:
"
+
bytesWritten
);
}
});
```
...
...
@@ -3074,11 +3074,11 @@ read(buffer: ArrayBuffer, options?: { position?: number; offset?: number; length
```
js
let
filePath
=
pathDir
+
"
/test.txt
"
;
let
ss
=
fileio
.
createStreamSync
(
filePath
,
"
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
)
{
console
.
info
(
"
read data failed with error:
"
+
err
);
}).
catch
(
function
(
err
)
{
console
.
info
(
"
read data failed with error:
"
+
err
);
});
```
...
...
@@ -3165,10 +3165,10 @@ read(): Promise<Dirent>
**示例:**
```
js
dir
.
read
().
then
(
function
(
dirent
){
dir
.
read
().
then
(
function
(
dirent
)
{
console
.
log
(
"
read succeed, the name of dirent is
"
+
dirent
.
name
);
}).
catch
(
function
(
err
)
{
console
.
info
(
"
read failed with error:
"
+
err
);
}).
catch
(
function
(
err
)
{
console
.
info
(
"
read failed with error:
"
+
err
);
});
```
...
...
@@ -3231,7 +3231,7 @@ close(): Promise<void>
**示例:**
```
js
dir
.
close
().
then
(
function
(
err
)
{
dir
.
close
().
then
(
function
(
err
)
{
console
.
info
(
"
close dir successfully
"
);
});
```
...
...
@@ -3248,7 +3248,7 @@ close(callback: AsyncCallback<void>): void
**示例:**
```
js
dir
.
close
(
function
(
err
)
{
dir
.
close
(
function
(
err
)
{
console
.
info
(
"
close dir successfully
"
);
});
```
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录