调整closeSync方法,紧接着writeSync,readSync,防止打开的文件没有正确关闭
Signed-off-by: madixin <madixin@huawei.com>
This commit is contained in:
parent
303ff79be1
commit
5f548d1090
|
@ -58,8 +58,6 @@ export class FileUtils {
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
async deleteFile(path: string): Promise<void> {
|
async deleteFile(path: string): Promise<void> {
|
||||||
// const isExist: boolean = await fs.access(path)
|
|
||||||
// if (isExist) {
|
|
||||||
try {
|
try {
|
||||||
await fs.unlink(path)
|
await fs.unlink(path)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
@ -76,8 +74,7 @@ export class FileUtils {
|
||||||
writeDataSync(path: string, content: ArrayBuffer | string): boolean {
|
writeDataSync(path: string, content: ArrayBuffer | string): boolean {
|
||||||
try {
|
try {
|
||||||
let fd = fs.openSync(path, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE | fs.OpenMode.TRUNC).fd
|
let fd = fs.openSync(path, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE | fs.OpenMode.TRUNC).fd
|
||||||
let stat = fs.statSync(path)
|
fs.writeSync(fd, content)
|
||||||
fs.writeSync(fd, content, { offset: stat.size })
|
|
||||||
fs.closeSync(fd)
|
fs.closeSync(fd)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -150,9 +147,9 @@ export class FileUtils {
|
||||||
readFileSync(path: string): ArrayBuffer | undefined {
|
readFileSync(path: string): ArrayBuffer | undefined {
|
||||||
try {
|
try {
|
||||||
if (fs.accessSync(path)) {
|
if (fs.accessSync(path)) {
|
||||||
let fd = fs.openSync(path, fs.OpenMode.READ_ONLY).fd;
|
|
||||||
let length = fs.statSync(path).size
|
let length = fs.statSync(path).size
|
||||||
let buf = new ArrayBuffer(length);
|
let buf = new ArrayBuffer(length);
|
||||||
|
let fd = fs.openSync(path, fs.OpenMode.READ_ONLY).fd;
|
||||||
fs.readSync(fd, buf)
|
fs.readSync(fd, buf)
|
||||||
fs.closeSync(fd)
|
fs.closeSync(fd)
|
||||||
return buf
|
return buf
|
||||||
|
|
Loading…
Reference in New Issue