(dir: string)
| 315 | } |
| 316 | |
| 317 | async function getDirectorySize(dir: string): Promise<number> { |
| 318 | let total = 0 |
| 319 | |
| 320 | const walk = async (current: string) => { |
| 321 | const entries = await fs.readdir(current, { withFileTypes: true }).catch(() => []) |
| 322 | |
| 323 | for (const entry of entries) { |
| 324 | const full = path.join(current, entry.name) |
| 325 | if (entry.isDirectory()) { |
| 326 | await walk(full) |
| 327 | continue |
| 328 | } |
| 329 | if (entry.isFile()) { |
| 330 | const stat = await fs.stat(full).catch(() => null) |
| 331 | if (stat) total += stat.size |
| 332 | } |
| 333 | } |
| 334 | } |
| 335 | |
| 336 | await walk(dir) |
| 337 | return total |
| 338 | } |
| 339 | |
| 340 | function formatSize(bytes: number): string { |
| 341 | if (bytes < 1024) return `${bytes} B` |
no test coverage detected