1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | var tslib_1 = require("tslib");
|
4 | var fs = require("fs");
|
5 | var path = require("path");
|
6 | var BufferUtils_1 = require("./stream/BufferUtils");
|
7 | var zip_ex_1 = require("./zip/zip-ex");
|
8 | var zip1_1 = require("./zip/zip1");
|
9 | var zip2_1 = require("./zip/zip2");
|
10 | var zip3_1 = require("./zip/zip3");
|
11 | console.log("process.cwd():");
|
12 | console.log(process.cwd());
|
13 | console.log("__dirname:");
|
14 | console.log(__dirname);
|
15 | var args = process.argv.slice(2);
|
16 | console.log("args:");
|
17 | console.log(args);
|
18 | if (!args[0]) {
|
19 | console.log("FILEPATH ARGUMENT IS MISSING.");
|
20 | process.exit(1);
|
21 | }
|
22 | var argPath = args[0].trim();
|
23 | var filePath = argPath;
|
24 | console.log(filePath);
|
25 | if (!fs.existsSync(filePath)) {
|
26 | filePath = path.join(__dirname, argPath);
|
27 | console.log(filePath);
|
28 | if (!fs.existsSync(filePath)) {
|
29 | filePath = path.join(process.cwd(), argPath);
|
30 | console.log(filePath);
|
31 | if (!fs.existsSync(filePath)) {
|
32 | console.log("FILEPATH DOES NOT EXIST.");
|
33 | process.exit(1);
|
34 | }
|
35 | }
|
36 | }
|
37 | var stats = fs.lstatSync(filePath);
|
38 | if (!stats.isFile() && !stats.isDirectory()) {
|
39 | console.log("FILEPATH MUST BE FILE OR DIRECTORY.");
|
40 | process.exit(1);
|
41 | }
|
42 | var fileName = path.basename(filePath);
|
43 | var ext = path.extname(fileName);
|
44 | if (stats.isDirectory()) {
|
45 | (function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
46 | var zipExploded, entries, _i, entries_1, entryName, zipStream_, err_1, zipStream, zipData, err_2, str;
|
47 | return tslib_1.__generator(this, function (_a) {
|
48 | switch (_a.label) {
|
49 | case 0: return [4, zip_ex_1.ZipExploded.loadPromise(filePath)];
|
50 | case 1:
|
51 | zipExploded = _a.sent();
|
52 | return [4, zipExploded.getEntries()];
|
53 | case 2:
|
54 | entries = _a.sent();
|
55 | _i = 0, entries_1 = entries;
|
56 | _a.label = 3;
|
57 | case 3:
|
58 | if (!(_i < entries_1.length)) return [3, 13];
|
59 | entryName = entries_1[_i];
|
60 | console.log("############## " + entryName);
|
61 | zipStream_ = void 0;
|
62 | _a.label = 4;
|
63 | case 4:
|
64 | _a.trys.push([4, 6, , 7]);
|
65 | return [4, zipExploded.entryStreamPromise(entryName)];
|
66 | case 5:
|
67 | zipStream_ = _a.sent();
|
68 | return [3, 7];
|
69 | case 6:
|
70 | err_1 = _a.sent();
|
71 | console.log(err_1);
|
72 | return [2];
|
73 | case 7:
|
74 | zipStream = zipStream_.stream;
|
75 | zipData = void 0;
|
76 | _a.label = 8;
|
77 | case 8:
|
78 | _a.trys.push([8, 10, , 11]);
|
79 | return [4, (0, BufferUtils_1.streamToBufferPromise)(zipStream)];
|
80 | case 9:
|
81 | zipData = _a.sent();
|
82 | return [3, 11];
|
83 | case 10:
|
84 | err_2 = _a.sent();
|
85 | console.log(err_2);
|
86 | return [2];
|
87 | case 11:
|
88 | if (/\.css$/i.test(entryName)) {
|
89 | str = zipData.toString("utf8");
|
90 | console.log(str);
|
91 | }
|
92 | _a.label = 12;
|
93 | case 12:
|
94 | _i++;
|
95 | return [3, 3];
|
96 | case 13: return [2];
|
97 | }
|
98 | });
|
99 | }); })();
|
100 | }
|
101 | else if (/((\.epub3?)|(\.cbz)|(\.zip))$/i.test(ext)) {
|
102 | (function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
103 | var time3, zip3, diff3, time2, zip2, diff2, time1, zip1, diff1;
|
104 | return tslib_1.__generator(this, function (_a) {
|
105 | switch (_a.label) {
|
106 | case 0:
|
107 | time3 = process.hrtime();
|
108 | return [4, zip3_1.Zip3.loadPromise(filePath)];
|
109 | case 1:
|
110 | zip3 = _a.sent();
|
111 | diff3 = process.hrtime(time3);
|
112 | console.log("Zip 3 (".concat(zip3.entriesCount(), "): ").concat(diff3[0], " seconds + ").concat(diff3[1], " nanoseconds"));
|
113 | time2 = process.hrtime();
|
114 | return [4, zip2_1.Zip2.loadPromise(filePath)];
|
115 | case 2:
|
116 | zip2 = _a.sent();
|
117 | diff2 = process.hrtime(time2);
|
118 | console.log("Zip 2 (".concat(zip2.entriesCount(), "): ").concat(diff2[0], " seconds + ").concat(diff2[1], " nanoseconds"));
|
119 | time1 = process.hrtime();
|
120 | return [4, zip1_1.Zip1.loadPromise(filePath)];
|
121 | case 3:
|
122 | zip1 = _a.sent();
|
123 | diff1 = process.hrtime(time1);
|
124 | console.log("Zip 1 (".concat(zip1.entriesCount(), "): ").concat(diff1[0], " seconds + ").concat(diff1[1], " nanoseconds"));
|
125 | return [2];
|
126 | }
|
127 | });
|
128 | }); })();
|
129 | }
|
130 |
|
\ | No newline at end of file |