1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import { open, readdir, stat, writeFile } from 'node:fs/promises'
import path from 'node:path'
const root = process.argv[2] || '/tmp/live/index'
const result = { files: 0, bytes: 0, sst: { legacy: 0, grouped: 0, unknown: 0 }, sstBytes: 0 }
async function walk(dir) {
for (const item of await readdir(dir, { withFileTypes: true })) {
const file = path.join(dir, item.name)
if (item.isDirectory()) { await walk(file); continue }
if (!item.isFile()) continue
const info = await stat(file)
result.files++
result.bytes += info.size
if (path.basename(dir) !== 'sst') continue
result.sstBytes += info.size
const handle = await open(file, 'r')
try {
const footer = Buffer.alloc(4)
const { bytesRead } = info.size < 4 ? { bytesRead: 0 } : await handle.read(footer, 0, 4, info.size - 4)
const magic = bytesRead === 4 ? footer.readUInt32LE() : 0
result.sst[magic === 0x7a6b7674 ? 'legacy' : magic === 0x7a6b7633 ? 'grouped' : 'unknown']++
} finally { await handle.close() }
}
}
await walk(root)
await writeFile(process.argv[3] || '/tmp/live/output/index-snapshot.json', JSON.stringify(result, null, 2) + '\n')