(
pack: Pack,
packReadingOptions: PackReadingOptions = { skipParsingTables: false },
)
| 2565 | }; |
| 2566 | let toRead: Mod[]; |
| 2567 | export const readFromExistingPack = async ( |
| 2568 | pack: Pack, |
| 2569 | packReadingOptions: PackReadingOptions = { skipParsingTables: false }, |
| 2570 | ): Promise<Pack> => { |
| 2571 | const pack_files = pack.packedFiles; |
| 2572 | let packHeader: PackHeader | undefined; |
| 2573 | const modPath = pack.path; |
| 2574 | console.log(`reading from existing pack ${modPath}`); |
| 2575 | let lastChangedLocal = -1; |
| 2576 | let size = 0; |
| 2577 | try { |
| 2578 | const stats = await fsExtra.stat(modPath); |
| 2579 | lastChangedLocal = stats.mtimeMs; |
| 2580 | size = stats.size; |
| 2581 | } catch (e) { |
| 2582 | console.log(e); |
| 2583 | } |
| 2584 | // let file: BinaryFile | undefined; |
| 2585 | // eslint-disable-next-line @typescript-eslint/no-inferrable-types |
| 2586 | let fileId: number = -1; |
| 2587 | try { |
| 2588 | // file = new BinaryFile(modPath, "r", true); |
| 2589 | fileId = fs.openSync(modPath, "r"); |
| 2590 | // await file.open(); |
| 2591 | console.log(`${modPath} file opened`); |
| 2592 | if (packReadingOptions.tablesToRead) |
| 2593 | console.log(`readFromExistingPack: TABLES TO READ:`, packReadingOptions.tablesToRead.join(", ")); |
| 2594 | if (packReadingOptions.filesToRead && packReadingOptions.filesToRead.length > 0) { |
| 2595 | for (const fileToRead of packReadingOptions.filesToRead) { |
| 2596 | // console.log("FIND", fileToRead); |
| 2597 | const indexOfFileToRead = bs(pack_files, fileToRead, (a: PackedFile, b: string) => |
| 2598 | collator.compare(a.name, b), |
| 2599 | ); |
| 2600 | if (indexOfFileToRead >= 0) { |
| 2601 | // console.log("FOUND", fileToRead); |
| 2602 | const packedFileToRead = pack_files[indexOfFileToRead]; |
| 2603 | let buffer = Buffer.allocUnsafe(packedFileToRead.file_size); |
| 2604 | fs.readSync(fileId, buffer, 0, buffer.length, packedFileToRead.start_pos); |
| 2605 | if (packedFileToRead.is_compressed) { |
| 2606 | buffer = Buffer.concat([ |
| 2607 | Buffer.from(await decompressPackedPayload(buffer, packedFileToRead.name)), |
| 2608 | ]); |
| 2609 | } |
| 2610 | packedFileToRead.buffer = buffer; |
| 2611 | } |
| 2612 | } |
| 2613 | } |
| 2614 | const dbPackFiles = packReadingOptions.skipParsingTables |
| 2615 | ? [] |
| 2616 | : pack_files.filter((packFile) => { |
| 2617 | const dbNameMatch = packFile.name.match(matchDBFileRegex); |
| 2618 | return dbNameMatch != null && dbNameMatch[1]; |
| 2619 | }); |
| 2620 | if (packReadingOptions.skipParsingTables || dbPackFiles.length < 1) { |
| 2621 | return { |
| 2622 | name: nodePath.basename(modPath), |
| 2623 | path: modPath, |
| 2624 | packedFiles: pack_files, |
no test coverage detected