Use async fileExists

This commit is contained in:
HaveAGitGat 2024-06-01 08:27:41 +01:00
parent 99160eadb3
commit 28192d7723
5 changed files with 21 additions and 15 deletions

View file

@ -4,6 +4,7 @@ import {
} from './cliParsers';
import { Ilog, IupdateWorker } from './interfaces/interfaces';
import { IFileObject, Istreams } from './interfaces/synced/IFileObject';
import { fileExists } from './fileUtils';
const fancyTimeFormat = (time: number) => {
// Hours, minutes and seconds
@ -92,7 +93,7 @@ class CLI {
this.config = config;
}
updateETA = (perc: number): void => {
updateETA = async (perc: number): Promise<void> => {
if (perc > 0) {
if (this.lastProgCheck === 0) {
this.lastProgCheck = new Date().getTime();
@ -124,7 +125,7 @@ class CLI {
let outputFileSizeInGbytes;
try {
if (fs.existsSync(this.config.outputFilePath)) {
if (await fileExists(this.config.outputFilePath)) {
let singleFileSize = fs.statSync(this.config.outputFilePath);
// @ts-expect-error type
singleFileSize = singleFileSize.size;
@ -180,7 +181,7 @@ class CLI {
});
if (percentage > 0) {
this.updateETA(percentage);
void this.updateETA(percentage);
this.config.updateWorker({
percentage,
});
@ -236,7 +237,7 @@ class CLI {
}
if (percentage > 0) {
this.updateETA(percentage);
void this.updateETA(percentage);
this.config.updateWorker({
percentage,
});
@ -246,7 +247,7 @@ class CLI {
str,
});
if (percentage > 0) {
this.updateETA(percentage);
void this.updateETA(percentage);
this.config.updateWorker({
percentage,
});

View file

@ -1,6 +1,8 @@
import { promises as fsp } from 'fs';
import { IpluginInputArgs } from './interfaces/interfaces';
export const fileExists = async (path:string): Promise<boolean> => !!(await fsp.stat(path).catch(() => false));
export const getContainer = (filePath: string): string => {
const parts = filePath.split('.');
return parts[parts.length - 1];