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