🌳
pt0/serverF/libFs/mkdirpF.mts
1import fs, { promises } from 'fs'
2import { dirname } from 'path'
3import type { absFileDirPath } from '../../ptDirF.mts'
4import { fs1Promises as fsPromises } from './fsPromisesF.mts'
6export const fileSizeBytes = async (path : absFileDirPath) => (await fsPromises.stat(path)).size
8export const mkDirUnlessExist = async (path : absFileDirPath) => {
9 try {
10 await promises.mkdir(path)
11 } catch (err : unknown) {
12 if ((err as NodeJS.ErrnoException).code == 'EEXIST') return
13 throw err
14 }
17export const fileExists = async (path : absFileDirPath) => {
18 return !!(await promises.stat(path).catch(() => false))
21export const mkdirParentP = (path: string): void => {
22 const parDir: string = dirname(path)
23 if (!fs.existsSync(parDir)) {
24 mkdirParentP(parDir)
25 fs.mkdirSync(parDir)
26 }
29export const mkdirp = async (path: absFileDirPath) => {
30 await promises.mkdir(path, { recursive: true })