[bugfix] use YauzlZip class wrapper for extracting files

* fixed issue where yauzl just closes after reading all files
This commit is contained in:
silentrald
2024-11-14 14:24:45 +08:00
parent 8c6f3b0aa8
commit bfb6d28a34
6 changed files with 90 additions and 511 deletions
+9 -5
View File
@@ -6,7 +6,7 @@ import { inflate } from "pako"
import { EMPTY, Observable, ReplaySubject, Subscriber, catchError, filter, from, lastValueFrom, mergeMap, scan, share, tap } from "rxjs";
import { Progression, hashFile } from "../helpers/fs.helpers";
import { OculusDownloaderErrorCodes } from "../../shared/models/bs-version-download/oculus-download.model";
import { getFilesFromZip } from "main/helpers/zip.helpers";
import { YauzlZip } from "./yauzl-zip.class";
export class OculusDownloader {
@@ -35,14 +35,18 @@ export class OculusDownloader {
.catch(err => CustomError.throw(err, "DOWNLOAD_MANIFEST_FAILED"));
const manifestName = "manifest.json";
const buffers = await getFilesFromZip(buffer, [manifestName]);
const manifest = buffers[manifestName];
if(!manifest) {
const zip = await YauzlZip.fromBuffer(buffer);
const entry = await zip.findEntry((entry) => entry.fileName === manifestName);
if(!entry) {
throw new CustomError("Manifest file not found", "MANIFEST_FILE_NOT_FOUND");
}
const manifest = await entry.read();
return JSON.parse(manifest.toString())
.catch((err: Error) => CustomError.throw(err, "PARSE_MANIFEST_FILE_FAILED"));
.catch((err: Error) => CustomError.throw(err, "PARSE_MANIFEST_FILE_FAILED"))
.finally(() => {
zip.close();
});
}
private downloadManifestFile(file: OculusManifestFile, destination: string): Observable<Progression<OculusManifestFile>> {
+1 -1
View File
@@ -7,6 +7,7 @@ export class YauzlZip {
private static readonly YAUZL_OPEN_OPTIONS: Options = {
lazyEntries: true,
decodeStrings: true,
autoClose: false,
};
public static fromPath(path: string): Promise<YauzlZip> {
@@ -36,7 +37,6 @@ export class YauzlZip {
private async readEntry(): Promise<YauzlZipEntry> {
return new Promise((resolve, reject) => {
const onEntry = (entry: Entry) => {
cleanup();
resolve(new YauzlZipEntry({ entry, zip: this.zip }));