2021-05-10 15:53:05 +10:00
|
|
|
/**
|
|
|
|
|
* Various promisify of fs utilities.
|
|
|
|
|
*
|
|
|
|
|
* @hidden
|
|
|
|
|
* @module
|
|
|
|
|
*/
|
|
|
|
|
|
2022-02-04 14:12:00 +11:00
|
|
|
import fs, { promises as asyncFs } from "fs";
|
|
|
|
|
import { promisify } from "util";
|
2021-03-15 13:38:36 +11:00
|
|
|
|
2022-02-11 17:27:15 +11:00
|
|
|
import { delay } from "./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);
|
|
|
|
|
}
|