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;4BAED,IAAM,KAAK,GAAG,KAAI,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC,SAAS,CAAC,CAAC;4BAE5C,IAAM,eAAe,GAAqB;gCACtC,MAAM,EAAE,KAAK,CAAC,IAAI;gCAClB,KAAK,EAAE;;wCACH,WAAO,IAAI,CAAC,kBAAkB,CAAC,SAAS,CAAC,EAAC;;qCAC7C;gCACD,MAAM,QAAA;6BACT,CAAC;4BACF,OAAO,CAAC,eAAe,CAAC,CAAC;wBAC7B,CAAC,CAAC,CAAC;oBACP,CAAC,CAAC,EAAC;;;KACN;IACL,WAAC;AAAD,CAAC,AApHD,CAA0B,SAAG,GAoH5B;AApHY,oBAAI","sourcesContent":["// ==LICENSE-BEGIN==\n// Copyright 2017 European Digital Reading Lab. All rights reserved.\n// Licensed to the Readium Foundation under one or more contributor license agreements.\n// Use of this source code is governed by a BSD-style license\n// that can be found in the LICENSE file exposed on Github (readium) in the project repository.\n// ==LICENSE-END==\n\nimport * as debug_ from \"debug\";\nimport StreamZip = require(\"node-stream-zip\");\n\nimport { IStreamAndLength, IZip, Zip } from \"./zip\";\n\n// import { bufferToStream } from \"../stream/BufferUtils\";\n\nconst debug = debug_(\"r2:utils#zip/zip1\");\n\nexport class Zip1 extends Zip {\n\n public static async loadPromise(filePath: string): Promise<IZip> {\n\n return new Promise<IZip>((resolve, reject) => {\n\n const zip = new StreamZip({\n file: filePath,\n storeEntries: true,\n });\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n zip.on(\"error\", (err: any) => {\n debug(\"--ZIP error: \" + filePath);\n debug(err);\n\n reject(err);\n });\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n zip.on(\"entry\", (_entry: any) => {\n // console.log(\"--ZIP: entry\");\n // debug(entry.name);\n });\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n zip.on(\"extract\", (entry: any, file: any) => {\n debug(\"--ZIP extract:\");\n debug(entry.name);\n debug(file);\n });\n\n zip.on(\"ready\", () => {\n // console.log(\"--ZIP: ready\");\n // console.log(zip.entriesCount);\n\n // const entries = zip.entries();\n // console.log(entries);\n\n resolve(new Zip1(filePath, zip));\n });\n });\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n private constructor(readonly filePath: string, readonly zip: any) {\n super();\n }\n\n public freeDestroy(): void {\n debug(\"freeDestroy: Zip1 -- \" + this.filePath);\n if (this.zip) {\n this.zip.close();\n }\n }\n\n public entriesCount(): number {\n return this.zip.entriesCount;\n }\n\n public hasEntries(): boolean {\n return this.entriesCount() > 0;\n }\n\n public hasEntry(entryPath: string): boolean {\n return this.hasEntries()\n && this.zip.entries()[entryPath];\n }\n\n public async getEntries(): Promise<string[]> {\n\n if (!this.hasEntries()) {\n return Promise.resolve([]);\n }\n return Promise.resolve(Object.keys(this.zip.entries()));\n }\n\n public async entryStreamPromise(entryPath: string): Promise<IStreamAndLength> {\n\n // debug(`entryStreamPromise: ${entryPath}`);\n\n if (!this.hasEntries() || !this.hasEntry(entryPath)) {\n return Promise.reject(\"no such path in zip: \" + entryPath);\n }\n\n // return new Promise<IStreamAndLength>((resolve, _reject) => {\n // const buffer: Buffer = this.zip.entryDataSync(entryPath);\n // const streamAndLength: IStreamAndLength = {\n // length: buffer.length,\n // stream: bufferToStream(buffer),\n // };\n // resolve(streamAndLength);\n // });\n\n return new Promise<IStreamAndLength>((resolve, reject) => {\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n this.zip.stream(entryPath, (err: any, stream: NodeJS.ReadableStream) => {\n if (err) {\n reject(err);\n return;\n }\n\n const entry = this.zip.entries()[entryPath];\n\n const streamAndLength: IStreamAndLength = {\n length: entry.size,\n reset: async () => {\n return this.entryStreamPromise(entryPath);\n },\n stream,\n };\n resolve(streamAndLength);\n });\n });\n }\n}\n"]}
\No newline at end of file