-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-index.ts
More file actions
41 lines (34 loc) · 1.16 KB
/
build-index.ts
File metadata and controls
41 lines (34 loc) · 1.16 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { MultiZipReader } from '@fparchive/multi-zip-reader';
import * as path from 'path';
import * as fs from 'fs';
async function run() {
const folderPath = process.argv[2];
const indexFilePath = path.join(folderPath, 'fp-index.dat');
if (fs.existsSync(indexFilePath)) {
fs.unlinkSync(indexFilePath);
}
if (!folderPath) {
console.error('Please provide a folder path as the first argument');
process.exit(1);
}
const reader = new MultiZipReader();
await reader.loadDirectory(folderPath);
const indexFileContent: IndexFileContent = {};
for (const source of reader.sources) {
const relPath = path.relative(folderPath, source.path);
indexFileContent[relPath] = {};
for (const file in source.data) {
const zipOffset = await reader.getZipDataOffset(file);
if (zipOffset) {
indexFileContent[relPath][file] = [zipOffset.compressedLength, zipOffset.offset];
}
}
}
// Save index to file
await fs.promises.writeFile(indexFilePath, JSON.stringify(indexFileContent));
}
type IndexFileContent = {
[k: string]: Record<string, FilePosition>
}
type FilePosition = [number, number]; // [length, offset]
run();