Spaces:
Configuration error
Configuration error
Download src/utils/fs.js from UUUZCX/video-optimizer-bot: direct link, hf CLI and curl.
- Browser
- Download file 1.16 kB
-
https://huggingface.co/spaces/UUUZCX/video-optimizer-bot/resolve/main/src/utils/fs.js
- Command line
-
hf download hf://spaces/UUUZCX/video-optimizer-bot/src/utils/fs.js
-
curl -L -o fs.js https://huggingface.co/spaces/UUUZCX/video-optimizer-bot/resolve/main/src/utils/fs.js
1.16 kB
| const fs = require("node:fs"); | |
| const fsp = require("node:fs/promises"); | |
| const path = require("node:path"); | |
| async function exists(filePath) { | |
| try { | |
| await fsp.access(filePath); | |
| return true; | |
| } catch { | |
| return false; | |
| } | |
| } | |
| async function ensureDir(dir) { | |
| await fsp.mkdir(dir, { recursive: true }); | |
| } | |
| async function safeUnlink(filePath) { | |
| try { | |
| await fsp.unlink(filePath); | |
| } catch (error) { | |
| if (error.code !== "ENOENT") throw error; | |
| } | |
| } | |
| async function listFilesRecursive(dir) { | |
| if (!fs.existsSync(dir)) return []; | |
| const entries = await fsp.readdir(dir, { withFileTypes: true }); | |
| const files = []; | |
| for (const entry of entries) { | |
| const full = path.join(dir, entry.name); | |
| if (entry.isDirectory()) files.push(...await listFilesRecursive(full)); | |
| if (entry.isFile()) files.push(full); | |
| } | |
| return files; | |
| } | |
| async function directorySize(dir) { | |
| const files = await listFilesRecursive(dir); | |
| let total = 0; | |
| for (const file of files) { | |
| const stat = await fsp.stat(file); | |
| total += stat.size; | |
| } | |
| return total; | |
| } | |
| module.exports = { exists, ensureDir, safeUnlink, listFilesRecursive, directorySize }; | |