支持大文件
Some checks failed
CI/CD / Code Check (push) Has been cancelled
CI/CD / Build Windows (push) Has been cancelled

This commit is contained in:
2026-03-15 09:02:02 +08:00
parent 4654f36202
commit 5c278e1925
12 changed files with 410 additions and 177 deletions

View File

@@ -22,23 +22,18 @@ export class FileExtractor {
const fullPath = path.join(this.modsPath, jarFilename);
try {
let fileData: Buffer | null = null;
try {
fileData = fs.readFileSync(fullPath);
const mixins = await JarParser.extractMixins(fileData);
const infos = await JarParser.extractModInfo(fileData);
const hash = await this.calculateFileHash(fullPath);
const mixins = await JarParser.extractMixinsFromFile(fullPath);
const infos = await JarParser.extractModInfoFromFile(fullPath);
files.push({
filename: fullPath,
hash: crypto.createHash('sha1').update(fileData).digest('hex'),
mixins,
infos,
});
files.push({
filename: fullPath,
hash,
mixins,
infos,
});
logger.debug("文件已处理", { 文件名: fullPath, 绝对路径: path.resolve(fullPath), Mixin数量: mixins.length });
} finally {
fileData = null;
}
logger.debug("文件已处理", { 文件名: fullPath, 绝对路径: path.resolve(fullPath), Mixin数量: mixins.length });
} catch (error: any) {
logger.error("处理文件时出错", { 文件名: fullPath, 错误: error.message });
}
@@ -48,6 +43,25 @@ export class FileExtractor {
return files;
}
private async calculateFileHash(filePath: string): Promise<string> {
return new Promise((resolve, reject) => {
const hash = crypto.createHash('sha1');
const stream = fs.createReadStream(filePath);
stream.on('data', (chunk) => {
hash.update(chunk);
});
stream.on('end', () => {
resolve(hash.digest('hex'));
});
stream.on('error', (error) => {
reject(error);
});
});
}
private getJarFiles(): string[] {
if (!fs.existsSync(this.modsPath)) {
fs.mkdirSync(this.modsPath, { recursive: true });