mirror of
https://github.com/waku-org/js-waku.git
synced 2025-01-25 19:59:11 +00:00
88c6ec6ef4
As per ESM standard.
31 lines
614 B
TypeScript
31 lines
614 B
TypeScript
/**
|
|
* Various promisify of fs utilities.
|
|
*
|
|
* @hidden
|
|
* @module
|
|
*/
|
|
|
|
import fs, { promises as asyncFs } from "fs";
|
|
import { promisify } from "util";
|
|
|
|
import { delay } from "./delay.js";
|
|
|
|
export const existsAsync = (filepath: string): Promise<void> =>
|
|
asyncFs.access(filepath, fs.constants.F_OK);
|
|
|
|
export const openAsync = promisify(fs.open);
|
|
|
|
export const mkdirAsync = asyncFs.mkdir;
|
|
|
|
export async function waitForFile(path: string): Promise<void> {
|
|
let found = false;
|
|
do {
|
|
try {
|
|
await existsAsync(path);
|
|
found = true;
|
|
} catch (e) {
|
|
await delay(500);
|
|
}
|
|
} while (!found);
|
|
}
|