2021-03-15 13:38:36 +11:00
|
|
|
import fs, { promises as asyncFs } from 'fs';
|
|
|
|
|
import { promisify } from 'util';
|
|
|
|
|
|
2021-04-13 22:36:37 +10:00
|
|
|
import { delay } from '../lib/delay';
|
2021-05-03 15:52:38 +10:00
|
|
|
export const existsAsync = (filepath: string): Promise<void> =>
|
2021-03-15 13:38:36 +11:00
|
|
|
asyncFs.access(filepath, fs.constants.F_OK);
|
|
|
|
|
|
|
|
|
|
export const openAsync = promisify(fs.open);
|
|
|
|
|
|
|
|
|
|
export const mkdirAsync = asyncFs.mkdir;
|
|
|
|
|
|
2021-05-03 15:52:38 +10:00
|
|
|
export async function waitForFile(path: string): Promise<void> {
|
2021-03-15 13:38:36 +11:00
|
|
|
let found = false;
|
|
|
|
|
do {
|
|
|
|
|
try {
|
|
|
|
|
await existsAsync(path);
|
|
|
|
|
found = true;
|
|
|
|
|
} catch (e) {
|
|
|
|
|
await delay(500);
|
|
|
|
|
}
|
|
|
|
|
} while (!found);
|
|
|
|
|
}
|