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AAO,OAAO,CAAC,OAAO,CAAC,eAAe,CAAC,EAAC;;;KAC3C;IACL,kBAAC;AAAD,CAAC,AAjFD,CAAiC,SAAG,GAiFnC;AAjFY,kCAAW","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 * as fs from \"fs\";\nimport * as path from \"path\";\n\nimport { IStreamAndLength, IZip, Zip } from \"./zip\";\n\n// import * as filehound from \"filehound\";\n// import { bufferToStream } from \"../stream/BufferUtils\";\n\nconst debug = debug_(\"r2:utils#zip/zip-ex\");\n\nexport class ZipExploded extends Zip {\n\n public static async loadPromise(dirPath: string): Promise<IZip> {\n return Promise.resolve(new ZipExploded(dirPath));\n }\n\n private constructor(readonly dirPath: string) {\n super();\n }\n\n public freeDestroy(): void {\n debug(\"freeDestroy: ZipExploded -- \" + this.dirPath);\n }\n\n public entriesCount(): number {\n return 0; // TODO: hacky! (not really needed ... but still)\n }\n\n public hasEntries(): boolean {\n return true; // TODO: hacky\n }\n\n public hasEntry(entryPath: string): boolean {\n return this.hasEntries()\n && fs.existsSync(path.join(this.dirPath, entryPath));\n }\n\n public async getEntries(): Promise<string[]> {\n\n return new Promise<string[]>(async (resolve, _reject) => {\n\n const dirPathNormalized = fs.realpathSync(this.dirPath);\n\n // const files: string[] = await filehound.create()\n // // .discard(\"node_modules\")\n // // .depth(5)\n // .paths(this.dirPath)\n // // .ext([\".epub\", \".epub3\", \".cbz\"])\n // .find();\n const files = fs.readdirSync(this.dirPath, { withFileTypes: true }).\n filter((f) => f.isFile()).map((f) => path.join(this.dirPath, f.name));\n\n const adjustedFiles = files.map((file) => {\n const filePathNormalized = fs.realpathSync(file);\n\n let relativeFilePath = filePathNormalized.replace(dirPathNormalized, \"\");\n // debug(relativeFilePath);\n\n // TODO: is this necessary?\n if (relativeFilePath.indexOf(\"/\") === 0) {\n relativeFilePath = relativeFilePath.substr(1);\n }\n\n return relativeFilePath;\n });\n\n resolve(adjustedFiles);\n });\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 exploded: \" + entryPath);\n }\n\n const fullPath = path.join(this.dirPath, entryPath);\n const stats = fs.lstatSync(fullPath);\n\n const streamAndLength: IStreamAndLength = {\n length: stats.size,\n reset: async () => {\n return this.entryStreamPromise(entryPath);\n },\n stream: fs.createReadStream(fullPath, { autoClose: false }),\n };\n\n return Promise.resolve(streamAndLength);\n }\n}\n"]}
\No newline at end of file