@dgac/nmb2b-client
Version:
EUROCONTROL Network Manager B2B SOAP client
28 lines (26 loc) • 811 B
JavaScript
import debug_default from "./debug.js";
import * as fs from "node:fs/promises";
//#region src/utils/fs.ts
const debug = debug_default("dir-exists");
async function dirExists(path, { readable, writable } = {
readable: true,
writable: false
}) {
debug(`Testing if directory ${path} is readable ${writable ? "and writable " : ""}...`);
try {
const stats = await fs.stat(path);
if (!stats.isDirectory()) return false;
await fs.access(path, (writable ? fs.constants.W_OK : 0) | (readable ? fs.constants.R_OK : 0));
debug(`Directory ${path} is accessible`);
return true;
} catch {
return false;
}
}
async function createDir(path) {
debug("Creating directory %s ...", path);
await fs.mkdir(path, { recursive: true });
}
//#endregion
export { createDir, dirExists };
//# sourceMappingURL=fs.js.map