stage-browser 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (172) hide show
  1. package/README.md +92 -45
  2. package/build/icon.icns +0 -0
  3. package/build/icon.png +0 -0
  4. package/dist/bin/stage.js +111 -0
  5. package/dist/main/cli-args.js +28 -0
  6. package/dist/main/context-menu.js +68 -0
  7. package/dist/main/context.js +2 -0
  8. package/dist/main/extensions.js +78 -0
  9. package/dist/main/ipc.js +73 -0
  10. package/dist/main/main.js +282 -0
  11. package/dist/main/menu.js +140 -0
  12. package/dist/main/reveal.js +170 -0
  13. package/dist/main/selftest.js +570 -0
  14. package/dist/main/store.js +85 -0
  15. package/dist/main/suggest.js +43 -0
  16. package/dist/main/tabs.js +324 -0
  17. package/dist/main/ui-window.js +133 -0
  18. package/dist/main/url.js +38 -0
  19. package/dist/main/window.js +133 -0
  20. package/dist/preload/extension-compat.js +163 -0
  21. package/dist/preload/ui-preload.js +34 -0
  22. package/dist/shared/contract.js +6 -0
  23. package/dist/ui/app.js +692 -0
  24. package/{src → dist}/ui/index.html +15 -5
  25. package/dist/ui/mock.js +500 -0
  26. package/{src → dist}/ui/styles.css +55 -14
  27. package/node_modules/@types/chrome/LICENSE +21 -0
  28. package/node_modules/@types/chrome/README.md +15 -0
  29. package/node_modules/@types/chrome/chrome-cast/index.d.ts +1156 -0
  30. package/node_modules/@types/chrome/har-format/index.d.ts +6 -0
  31. package/node_modules/@types/chrome/index.d.ts +13786 -0
  32. package/node_modules/@types/chrome/package.json +99 -0
  33. package/node_modules/@types/filesystem/LICENSE +21 -0
  34. package/node_modules/@types/filesystem/README.md +15 -0
  35. package/node_modules/@types/filesystem/index.d.ts +564 -0
  36. package/node_modules/@types/filesystem/package.json +26 -0
  37. package/node_modules/@types/filewriter/LICENSE +21 -0
  38. package/node_modules/@types/filewriter/README.md +15 -0
  39. package/node_modules/@types/filewriter/index.d.ts +166 -0
  40. package/node_modules/@types/filewriter/package.json +25 -0
  41. package/node_modules/@types/har-format/LICENSE +21 -0
  42. package/node_modules/@types/har-format/README.md +15 -0
  43. package/node_modules/@types/har-format/index.d.ts +938 -0
  44. package/node_modules/@types/har-format/package.json +31 -0
  45. package/node_modules/adm-zip/LICENSE +21 -0
  46. package/node_modules/adm-zip/README.md +90 -0
  47. package/node_modules/adm-zip/adm-zip.js +1020 -0
  48. package/node_modules/adm-zip/headers/entryHeader.js +396 -0
  49. package/node_modules/adm-zip/headers/index.js +2 -0
  50. package/node_modules/adm-zip/headers/mainHeader.js +177 -0
  51. package/node_modules/adm-zip/methods/deflater.js +33 -0
  52. package/node_modules/adm-zip/methods/index.js +3 -0
  53. package/node_modules/adm-zip/methods/inflater.js +64 -0
  54. package/node_modules/adm-zip/methods/zipcrypto.js +175 -0
  55. package/node_modules/adm-zip/package.json +56 -0
  56. package/node_modules/adm-zip/types.d.ts +223 -0
  57. package/node_modules/adm-zip/util/constants.js +142 -0
  58. package/node_modules/adm-zip/util/decoder.js +5 -0
  59. package/node_modules/adm-zip/util/errors.js +66 -0
  60. package/node_modules/adm-zip/util/fattr.js +76 -0
  61. package/node_modules/adm-zip/util/index.js +5 -0
  62. package/node_modules/adm-zip/util/utils.js +481 -0
  63. package/node_modules/adm-zip/zipEntry.js +415 -0
  64. package/node_modules/adm-zip/zipFile.js +466 -0
  65. package/node_modules/debug/LICENSE +20 -0
  66. package/node_modules/debug/README.md +481 -0
  67. package/node_modules/debug/package.json +64 -0
  68. package/node_modules/debug/src/browser.js +272 -0
  69. package/node_modules/debug/src/common.js +292 -0
  70. package/node_modules/debug/src/index.js +10 -0
  71. package/node_modules/debug/src/node.js +263 -0
  72. package/node_modules/electron-chrome-web-store/README.md +143 -0
  73. package/node_modules/electron-chrome-web-store/dist/chrome-web-store.preload.js +299 -0
  74. package/node_modules/electron-chrome-web-store/dist/cjs/browser/index.js +1674 -0
  75. package/node_modules/electron-chrome-web-store/dist/esm/browser/index.mjs +950 -0
  76. package/node_modules/electron-chrome-web-store/dist/types/browser/api.d.ts +2 -0
  77. package/node_modules/electron-chrome-web-store/dist/types/browser/crx3.d.ts +20 -0
  78. package/node_modules/electron-chrome-web-store/dist/types/browser/id.d.ts +9 -0
  79. package/node_modules/electron-chrome-web-store/dist/types/browser/index.d.ts +62 -0
  80. package/node_modules/electron-chrome-web-store/dist/types/browser/installer.d.ts +29 -0
  81. package/node_modules/electron-chrome-web-store/dist/types/browser/loader.d.ts +18 -0
  82. package/node_modules/electron-chrome-web-store/dist/types/browser/types.d.ts +21 -0
  83. package/node_modules/electron-chrome-web-store/dist/types/browser/updater.d.ts +6 -0
  84. package/node_modules/electron-chrome-web-store/dist/types/browser/utils.d.ts +4 -0
  85. package/node_modules/electron-chrome-web-store/dist/types/common/constants.d.ts +44 -0
  86. package/node_modules/electron-chrome-web-store/dist/types/renderer/chrome-web-store.preload.d.ts +1 -0
  87. package/node_modules/electron-chrome-web-store/package.json +43 -0
  88. package/node_modules/ms/index.js +162 -0
  89. package/node_modules/ms/license.md +21 -0
  90. package/node_modules/ms/package.json +38 -0
  91. package/node_modules/ms/readme.md +59 -0
  92. package/node_modules/pbf/LICENSE +27 -0
  93. package/node_modules/pbf/README.md +293 -0
  94. package/node_modules/pbf/bin/pbf +17 -0
  95. package/node_modules/pbf/compile.js +441 -0
  96. package/node_modules/pbf/dist/pbf-dev.js +838 -0
  97. package/node_modules/pbf/dist/pbf.js +1 -0
  98. package/node_modules/pbf/index.d.ts +206 -0
  99. package/node_modules/pbf/index.js +830 -0
  100. package/node_modules/pbf/package.json +63 -0
  101. package/node_modules/protocol-buffers-schema/.travis.yml +7 -0
  102. package/node_modules/protocol-buffers-schema/LICENSE +21 -0
  103. package/node_modules/protocol-buffers-schema/README.md +122 -0
  104. package/node_modules/protocol-buffers-schema/example.js +11 -0
  105. package/node_modules/protocol-buffers-schema/example.proto +13 -0
  106. package/node_modules/protocol-buffers-schema/index.js +6 -0
  107. package/node_modules/protocol-buffers-schema/package.json +31 -0
  108. package/node_modules/protocol-buffers-schema/parse.js +769 -0
  109. package/node_modules/protocol-buffers-schema/stringify.js +206 -0
  110. package/node_modules/protocol-buffers-schema/test/fixtures/basic.json +90 -0
  111. package/node_modules/protocol-buffers-schema/test/fixtures/basic.proto +11 -0
  112. package/node_modules/protocol-buffers-schema/test/fixtures/comments.json +99 -0
  113. package/node_modules/protocol-buffers-schema/test/fixtures/comments.proto +19 -0
  114. package/node_modules/protocol-buffers-schema/test/fixtures/complex.json +125 -0
  115. package/node_modules/protocol-buffers-schema/test/fixtures/complex.proto +30 -0
  116. package/node_modules/protocol-buffers-schema/test/fixtures/enum.json +42 -0
  117. package/node_modules/protocol-buffers-schema/test/fixtures/enum.proto +8 -0
  118. package/node_modules/protocol-buffers-schema/test/fixtures/escaped-quotes.json +32 -0
  119. package/node_modules/protocol-buffers-schema/test/fixtures/escaped-quotes.proto +3 -0
  120. package/node_modules/protocol-buffers-schema/test/fixtures/extend.json +167 -0
  121. package/node_modules/protocol-buffers-schema/test/fixtures/extend.proto +19 -0
  122. package/node_modules/protocol-buffers-schema/test/fixtures/import.json +30 -0
  123. package/node_modules/protocol-buffers-schema/test/fixtures/import.proto +6 -0
  124. package/node_modules/protocol-buffers-schema/test/fixtures/map.json +33 -0
  125. package/node_modules/protocol-buffers-schema/test/fixtures/map.proto +3 -0
  126. package/node_modules/protocol-buffers-schema/test/fixtures/no-tags.proto +8 -0
  127. package/node_modules/protocol-buffers-schema/test/fixtures/oneof.json +41 -0
  128. package/node_modules/protocol-buffers-schema/test/fixtures/oneof.proto +6 -0
  129. package/node_modules/protocol-buffers-schema/test/fixtures/option.json +364 -0
  130. package/node_modules/protocol-buffers-schema/test/fixtures/option.proto +72 -0
  131. package/node_modules/protocol-buffers-schema/test/fixtures/options.json +47 -0
  132. package/node_modules/protocol-buffers-schema/test/fixtures/options.proto +8 -0
  133. package/node_modules/protocol-buffers-schema/test/fixtures/pheromon-trajectories.proto +8 -0
  134. package/node_modules/protocol-buffers-schema/test/fixtures/reserved.json +55 -0
  135. package/node_modules/protocol-buffers-schema/test/fixtures/reserved.proto +17 -0
  136. package/node_modules/protocol-buffers-schema/test/fixtures/search.json +30 -0
  137. package/node_modules/protocol-buffers-schema/test/fixtures/search.proto +5 -0
  138. package/node_modules/protocol-buffers-schema/test/fixtures/service.json +108 -0
  139. package/node_modules/protocol-buffers-schema/test/fixtures/service.proto +30 -0
  140. package/node_modules/protocol-buffers-schema/test/fixtures/valid-packed.proto +35 -0
  141. package/node_modules/protocol-buffers-schema/test/fixtures/version.json +90 -0
  142. package/node_modules/protocol-buffers-schema/test/fixtures/version.proto +13 -0
  143. package/node_modules/protocol-buffers-schema/test/index.js +157 -0
  144. package/node_modules/protocol-buffers-schema/tokenize.js +56 -0
  145. package/node_modules/resolve-protobuf-schema/.travis.yml +3 -0
  146. package/node_modules/resolve-protobuf-schema/LICENSE +21 -0
  147. package/node_modules/resolve-protobuf-schema/README.md +49 -0
  148. package/node_modules/resolve-protobuf-schema/index.js +50 -0
  149. package/node_modules/resolve-protobuf-schema/package.json +25 -0
  150. package/node_modules/resolve-protobuf-schema/test/a.proto +5 -0
  151. package/node_modules/resolve-protobuf-schema/test/b.proto +5 -0
  152. package/node_modules/resolve-protobuf-schema/test/c.proto +3 -0
  153. package/node_modules/resolve-protobuf-schema/test/index.js +49 -0
  154. package/package.json +35 -11
  155. package/bin/stage.js +0 -52
  156. package/src/main/cli-args.js +0 -28
  157. package/src/main/context-menu.js +0 -64
  158. package/src/main/extensions.js +0 -61
  159. package/src/main/main.js +0 -310
  160. package/src/main/menu.js +0 -171
  161. package/src/main/reveal.js +0 -141
  162. package/src/main/selftest.js +0 -383
  163. package/src/main/store.js +0 -77
  164. package/src/main/suggest.js +0 -50
  165. package/src/main/tabs.js +0 -351
  166. package/src/main/url.js +0 -37
  167. package/src/main/window.js +0 -71
  168. package/src/preload/extension-compat.js +0 -34
  169. package/src/preload/ui-preload.js +0 -40
  170. package/src/ui/app.js +0 -588
  171. package/src/ui/mock.js +0 -455
  172. /package/{src → dist}/ui/newtab.html +0 -0
@@ -0,0 +1,175 @@
1
+ "use strict";
2
+
3
+ // node crypt, we use it for generate salt
4
+ // eslint-disable-next-line node/no-unsupported-features/node-builtins
5
+ const { randomFillSync } = require("crypto");
6
+ const Errors = require("../util/errors");
7
+
8
+ // generate CRC32 lookup table
9
+ const crctable = new Uint32Array(256).map((t, crc) => {
10
+ for (let j = 0; j < 8; j++) {
11
+ if (0 !== (crc & 1)) {
12
+ crc = (crc >>> 1) ^ 0xedb88320;
13
+ } else {
14
+ crc >>>= 1;
15
+ }
16
+ }
17
+ return crc >>> 0;
18
+ });
19
+
20
+ // C-style uInt32 Multiply (discards higher bits, when JS multiply discards lower bits)
21
+ const uMul = (a, b) => Math.imul(a, b) >>> 0;
22
+
23
+ // crc32 byte single update (actually same function is part of utils.crc32 function :) )
24
+ const crc32update = (pCrc32, bval) => {
25
+ return crctable[(pCrc32 ^ bval) & 0xff] ^ (pCrc32 >>> 8);
26
+ };
27
+
28
+ // function for generating salt for encrytion header
29
+ const genSalt = () => {
30
+ if ("function" === typeof randomFillSync) {
31
+ return randomFillSync(Buffer.alloc(12));
32
+ } else {
33
+ // fallback if function is not defined
34
+ return genSalt.node();
35
+ }
36
+ };
37
+
38
+ // salt generation with node random function (mainly as fallback)
39
+ genSalt.node = () => {
40
+ const salt = Buffer.alloc(12);
41
+ const len = salt.length;
42
+ for (let i = 0; i < len; i++) salt[i] = (Math.random() * 256) & 0xff;
43
+ return salt;
44
+ };
45
+
46
+ // general config
47
+ const config = {
48
+ genSalt
49
+ };
50
+
51
+ // Class Initkeys handles same basic ops with keys
52
+ function Initkeys(pw) {
53
+ const pass = Buffer.isBuffer(pw) ? pw : Buffer.from(pw);
54
+ this.keys = new Uint32Array([0x12345678, 0x23456789, 0x34567890]);
55
+ for (let i = 0; i < pass.length; i++) {
56
+ this.updateKeys(pass[i]);
57
+ }
58
+ }
59
+
60
+ Initkeys.prototype.updateKeys = function (byteValue) {
61
+ const keys = this.keys;
62
+ keys[0] = crc32update(keys[0], byteValue);
63
+ keys[1] += keys[0] & 0xff;
64
+ keys[1] = uMul(keys[1], 134775813) + 1;
65
+ keys[2] = crc32update(keys[2], keys[1] >>> 24);
66
+ return byteValue;
67
+ };
68
+
69
+ Initkeys.prototype.next = function () {
70
+ const k = (this.keys[2] | 2) >>> 0; // key
71
+ return (uMul(k, k ^ 1) >> 8) & 0xff; // decode
72
+ };
73
+
74
+ function make_decrypter(/*Buffer*/ pwd) {
75
+ // 1. Stage initialize key
76
+ const keys = new Initkeys(pwd);
77
+
78
+ // return decrypter function
79
+ return function (/*Buffer*/ data) {
80
+ // result - we create new Buffer for results
81
+ const result = Buffer.alloc(data.length);
82
+ let pos = 0;
83
+ // process input data
84
+ for (let c of data) {
85
+ //c ^= keys.next();
86
+ //result[pos++] = c; // decode & Save Value
87
+ result[pos++] = keys.updateKeys(c ^ keys.next()); // update keys with decoded byte
88
+ }
89
+ return result;
90
+ };
91
+ }
92
+
93
+ function make_encrypter(/*Buffer*/ pwd) {
94
+ // 1. Stage initialize key
95
+ const keys = new Initkeys(pwd);
96
+
97
+ // return encrypting function, result and pos is here so we dont have to merge buffers later
98
+ return function (/*Buffer*/ data, /*Buffer*/ result, /* Number */ pos = 0) {
99
+ // result - we create new Buffer for results
100
+ if (!result) result = Buffer.alloc(data.length);
101
+ // process input data
102
+ for (let c of data) {
103
+ const k = keys.next(); // save key byte
104
+ result[pos++] = c ^ k; // save val
105
+ keys.updateKeys(c); // update keys with decoded byte
106
+ }
107
+ return result;
108
+ };
109
+ }
110
+
111
+ function decrypt(/*Buffer*/ data, /*Object*/ header, /*String, Buffer*/ pwd) {
112
+ if (!data || !Buffer.isBuffer(data) || data.length < 12) {
113
+ return Buffer.alloc(0);
114
+ }
115
+
116
+ // 1. We Initialize and generate decrypting function
117
+ const decrypter = make_decrypter(pwd);
118
+
119
+ // 2. decrypt salt what is always 12 bytes and is a part of file content
120
+ const salt = decrypter(data.slice(0, 12));
121
+
122
+ // if bit 3 (0x08) of the general-purpose flags field is set, check salt[11] with the high byte of the header time
123
+ // 2 byte data block (as per Info-Zip spec), otherwise check with the high byte of the header entry
124
+ const verifyByte = (header.flags & 0x8) === 0x8 ? header.timeHighByte : header.crc >>> 24;
125
+
126
+ //3. does password meet expectations
127
+ if (salt[11] !== verifyByte) {
128
+ throw Errors.WRONG_PASSWORD();
129
+ }
130
+
131
+ // 4. decode content
132
+ return decrypter(data.slice(12));
133
+ }
134
+
135
+ // lets add way to populate salt, NOT RECOMMENDED for production but maybe useful for testing general functionality
136
+ function _salter(data) {
137
+ if (Buffer.isBuffer(data) && data.length >= 12) {
138
+ // be aware - currently salting buffer data is modified
139
+ config.genSalt = function () {
140
+ return data.slice(0, 12);
141
+ };
142
+ } else if (data === "node") {
143
+ // test salt generation with node random function
144
+ config.genSalt = genSalt.node;
145
+ } else {
146
+ // if value is not acceptable config gets reset.
147
+ config.genSalt = genSalt;
148
+ }
149
+ }
150
+
151
+ function encrypt(/*Buffer*/ data, /*Object*/ header, /*String, Buffer*/ pwd, /*Boolean*/ oldlike = false) {
152
+ // 1. test data if data is not Buffer we make buffer from it
153
+ if (data == null) data = Buffer.alloc(0);
154
+ // if data is not buffer be make buffer from it
155
+ if (!Buffer.isBuffer(data)) data = Buffer.from(data.toString());
156
+
157
+ // 2. We Initialize and generate encrypting function
158
+ const encrypter = make_encrypter(pwd);
159
+
160
+ // 3. generate salt (12-bytes of random data)
161
+ const salt = config.genSalt();
162
+ salt[11] = (header.crc >>> 24) & 0xff;
163
+
164
+ // old implementations (before PKZip 2.04g) used two byte check
165
+ if (oldlike) salt[10] = (header.crc >>> 16) & 0xff;
166
+
167
+ // 4. create output
168
+ const result = Buffer.alloc(data.length + 12);
169
+ encrypter(salt, result);
170
+
171
+ // finally encode content
172
+ return encrypter(data, result, 12);
173
+ }
174
+
175
+ module.exports = { decrypt, encrypt, _salter };
@@ -0,0 +1,56 @@
1
+ {
2
+ "name": "adm-zip",
3
+ "version": "0.6.1",
4
+ "description": "Javascript implementation of zip for nodejs with support for electron original-fs. Allows user to create or extract zip files both in memory or to/from disk",
5
+ "scripts": {
6
+ "test": "mocha -R spec",
7
+ "test:format": "npm run format:prettier:raw -- --check",
8
+ "format": "npm run format:prettier",
9
+ "format:prettier": "npm run format:prettier:raw -- --write",
10
+ "format:prettier:raw": "prettier \"**/*.{js,yml,json}\""
11
+ },
12
+ "keywords": [
13
+ "zip",
14
+ "methods",
15
+ "archive",
16
+ "unzip"
17
+ ],
18
+ "homepage": "https://github.com/cthackers/adm-zip",
19
+ "author": "Nasca Iacob <adm-zip@pm.me> (https://github.com/cthackers)",
20
+ "bugs": {
21
+ "email": "adm-zip@pm.me",
22
+ "url": "https://github.com/cthackers/adm-zip/issues"
23
+ },
24
+ "license": "MIT",
25
+ "files": [
26
+ "adm-zip.js",
27
+ "headers",
28
+ "methods",
29
+ "util",
30
+ "zipEntry.js",
31
+ "zipFile.js",
32
+ "types.d.ts",
33
+ "LICENSE"
34
+ ],
35
+ "main": "adm-zip.js",
36
+ "types": "types.d.ts",
37
+ "repository": {
38
+ "type": "git",
39
+ "url": "https://github.com/cthackers/adm-zip.git"
40
+ },
41
+ "engines": {
42
+ "node": ">=14.0"
43
+ },
44
+ "overrides": {
45
+ "mocha": {
46
+ "chokidar": "^4.0.3"
47
+ }
48
+ },
49
+ "devDependencies": {
50
+ "chai": "^6.2.2",
51
+ "iconv-lite": "^0.7.2",
52
+ "mocha": "^12.0.0",
53
+ "prettier": "^3.8.1",
54
+ "rimraf": "^3.0.2"
55
+ }
56
+ }
@@ -0,0 +1,223 @@
1
+ /// <reference types="node" />
2
+
3
+ import type { Stats } from "fs";
4
+
5
+ declare namespace AdmZip {
6
+ /** Options accepted by the AdmZip constructor. */
7
+ interface InitOptions {
8
+ /** If true, disables sorting of the entries by name. */
9
+ noSort: boolean;
10
+ /** Read all entries during load (slower initial load, avoids lazy parsing later). */
11
+ readEntries: boolean;
12
+ /** Default compression method for new entries (see Constants: STORED = 0, DEFLATED = 8). */
13
+ method: number;
14
+ /** Custom filesystem implementation (e.g. Electron's `original-fs`). */
15
+ fs: unknown | null;
16
+ /** Filename used by `writeZip`/`writeZipPromise` when none is supplied. */
17
+ filename?: string;
18
+ /** Raw zip buffer to load (alternative to passing a Buffer as the first argument). */
19
+ input?: Buffer;
20
+ /** Custom text encoder/decoder for entry names (e.g. to support MBCS via iconv-lite). */
21
+ decoder?: ZipTextDecoder;
22
+ }
23
+
24
+ /** Encoder/decoder used for entry names and comments. */
25
+ interface ZipTextDecoder {
26
+ /** Whether names are encoded as UTF-8 (sets the EFS flag). May be a predicate per name. */
27
+ efs?: boolean | ((entryName: string) => boolean);
28
+ encode(data: string): Buffer;
29
+ decode(data: Buffer | Uint8Array): string;
30
+ }
31
+
32
+ /** Filter deciding whether an entry is included when adding a local folder. */
33
+ type EntryFilter = RegExp | ((entryPath: string) => boolean);
34
+
35
+ /** The central-directory / local file header of a single entry. */
36
+ interface IZipEntryHeader {
37
+ made: number;
38
+ version: number;
39
+ flags: number;
40
+ flags_efs: boolean;
41
+ flags_desc: boolean;
42
+ method: number;
43
+ time: Date;
44
+ timeval: number;
45
+ readonly timeHighByte: number;
46
+ crc: number;
47
+ compressedSize: number;
48
+ size: number;
49
+ fileNameLength: number;
50
+ extraLength: number;
51
+ extraLocalLength: number;
52
+ commentLength: number;
53
+ diskNumStart: number;
54
+ inAttr: number;
55
+ attr: number;
56
+ /** Unix permission bits (e.g. 0o755), derived from `attr`. */
57
+ readonly fileAttr: number;
58
+ offset: number;
59
+ readonly encrypted: boolean;
60
+ readonly centralHeaderSize: number;
61
+ readonly realDataOffset: number;
62
+ readonly localHeader: Record<string, number | boolean>;
63
+ loadLocalHeaderFromBinary(input: Buffer): Buffer;
64
+ loadFromBinary(data: Buffer): void;
65
+ localHeaderToBinary(): Buffer;
66
+ centralHeaderToBinary(): Buffer;
67
+ toJSON(): object;
68
+ toString(): string;
69
+ }
70
+
71
+ /** A single file or directory inside the archive. */
72
+ interface IZipEntry {
73
+ /** Full path of the entry within the archive. */
74
+ entryName: string;
75
+ /** Raw (un-decoded) entry name bytes. */
76
+ readonly rawEntryName: Buffer;
77
+ /** The base name of the entry (last path segment). */
78
+ readonly name: string;
79
+ /** Extra field bytes. */
80
+ extra: Buffer;
81
+ /** Entry comment. */
82
+ comment: string;
83
+ readonly isDirectory: boolean;
84
+ /** Whether the name uses UTF-8 (EFS) encoding. */
85
+ readonly efs: boolean;
86
+ header: IZipEntryHeader;
87
+ /** MS-DOS / unix packed attribute value. */
88
+ attr: number;
89
+ getCompressedData(): Buffer;
90
+ getCompressedDataAsync(callback: (data: Buffer) => void): void;
91
+ setData(value: string | Buffer): void;
92
+ /** Decompress and return the entry content. Throws on a bad CRC. */
93
+ getData(pass?: string | Buffer): Buffer;
94
+ getDataAsync(callback: (data: Buffer, err?: string) => void, pass?: string | Buffer): void;
95
+ packCentralHeader(): Buffer;
96
+ packLocalHeader(): Buffer;
97
+ toJSON(): object;
98
+ toString(): string;
99
+ }
100
+ }
101
+
102
+ declare class AdmZip {
103
+ /**
104
+ * @param fileNameOrRawData Path to a zip file, a Buffer with zip data, or an options object.
105
+ * @param options Additional options.
106
+ */
107
+ constructor(fileNameOrRawData?: string | Buffer, options?: Partial<AdmZip.InitOptions>);
108
+ constructor(options?: Partial<AdmZip.InitOptions>);
109
+
110
+ /** Extract an entry and return its content as a Buffer, or null if not found. */
111
+ readFile(entry: string | AdmZip.IZipEntry, pass?: string | Buffer): Buffer | null;
112
+
113
+ /** Number of child entries for a directory entry (0 for files). */
114
+ childCount(entry: string | AdmZip.IZipEntry): number;
115
+
116
+ /** Asynchronously extract an entry's content. */
117
+ readFileAsync(entry: string | AdmZip.IZipEntry, callback: (data: Buffer | null, err?: string) => void): void;
118
+
119
+ /** Extract an entry and return its content as text (default encoding utf8). */
120
+ readAsText(entry: string | AdmZip.IZipEntry, encoding?: string): string;
121
+
122
+ /** Asynchronously extract an entry's content as text. */
123
+ readAsTextAsync(entry: string | AdmZip.IZipEntry, callback: (data: string, err?: string) => void, encoding?: string): void;
124
+
125
+ /** Remove an entry (and, for a directory, optionally its children). */
126
+ deleteFile(entry: string | AdmZip.IZipEntry, withSubfolders?: boolean): void;
127
+
128
+ /** Remove a single entry. */
129
+ deleteEntry(entry: string | AdmZip.IZipEntry): void;
130
+
131
+ /** Set the archive-level comment. */
132
+ addZipComment(comment: string): void;
133
+
134
+ /** Get the archive-level comment. */
135
+ getZipComment(): string;
136
+
137
+ /** Set the comment of a single entry. */
138
+ addZipEntryComment(entry: string | AdmZip.IZipEntry, comment: string): void;
139
+
140
+ /** Get the comment of a single entry. */
141
+ getZipEntryComment(entry: string | AdmZip.IZipEntry): string;
142
+
143
+ /** Replace the content of an existing entry. */
144
+ updateFile(entry: string | AdmZip.IZipEntry, content: Buffer): void;
145
+
146
+ /** Add a file from disk to the archive. */
147
+ addLocalFile(localPath: string, zipPath?: string, zipName?: string, comment?: string): void;
148
+
149
+ /** Asynchronously add a file from disk to the archive. */
150
+ addLocalFileAsync(
151
+ options: string | { localPath: string; zipPath?: string; zipName?: string; comment?: string },
152
+ callback: (err: Error | undefined, done: boolean) => void
153
+ ): void;
154
+
155
+ /** Add a folder and all of its nested files/directories to the archive. */
156
+ addLocalFolder(localPath: string, zipPath?: string, filter?: AdmZip.EntryFilter): void;
157
+
158
+ /** Asynchronously add a folder and its contents to the archive. */
159
+ addLocalFolderAsync(localPath: string, callback: (success?: boolean, err?: string) => void, zipPath?: string, filter?: AdmZip.EntryFilter): void;
160
+
161
+ /** Asynchronously add a folder and its contents to the archive. */
162
+ addLocalFolderAsync2(
163
+ options: string | { localPath: string; zipPath?: string; filter?: AdmZip.EntryFilter; namefix?: "latin1" | ((name: string) => string) },
164
+ callback: (err: Error | undefined, done?: boolean) => void
165
+ ): void;
166
+
167
+ /** Promise-returning variant of `addLocalFolderAsync2`. */
168
+ addLocalFolderPromise(localPath: string, props?: { zipPath?: string; filter?: AdmZip.EntryFilter; namefix?: "latin1" | ((name: string) => string) }): Promise<void>;
169
+
170
+ /**
171
+ * Create an entry from in-memory content.
172
+ * For a directory, `entryName` must end in `/` and `content` should be an empty buffer.
173
+ * @param attr Unix permission bits as a number, or a filesystem `Stats` object.
174
+ */
175
+ addFile(entryName: string, content: Buffer | string, comment?: string, attr?: number | Stats): AdmZip.IZipEntry;
176
+
177
+ /** All entries in the archive. */
178
+ getEntries(password?: string): AdmZip.IZipEntry[];
179
+
180
+ /** Look up a single entry by name, or null if absent. */
181
+ getEntry(name: string): AdmZip.IZipEntry | null;
182
+
183
+ /** Number of entries in the archive. */
184
+ getEntryCount(): number;
185
+
186
+ /** Iterate every entry. */
187
+ forEach(callback: (entry: AdmZip.IZipEntry) => void): void;
188
+
189
+ /** Extract a single entry (or a directory subtree) to disk. Returns success. */
190
+ extractEntryTo(
191
+ entry: string | AdmZip.IZipEntry,
192
+ targetPath: string,
193
+ maintainEntryPath?: boolean,
194
+ overwrite?: boolean,
195
+ keepOriginalPermission?: boolean,
196
+ outFileName?: string
197
+ ): boolean;
198
+
199
+ /** Verify every entry decompresses with a valid CRC. */
200
+ test(pass?: string | Buffer): boolean;
201
+
202
+ /** Extract the entire archive to disk. */
203
+ extractAllTo(targetPath: string, overwrite?: boolean, keepOriginalPermission?: boolean, pass?: string | Buffer): void;
204
+
205
+ /** Asynchronously extract the entire archive to disk. Returns a Promise when no callback is given. */
206
+ extractAllToAsync(targetPath: string, overwrite?: boolean, keepOriginalPermission?: boolean): Promise<void>;
207
+ extractAllToAsync(targetPath: string, overwrite: boolean, keepOriginalPermission: boolean, callback: (error?: Error) => void): void;
208
+
209
+ /** Write the archive to disk (uses the constructor filename if none supplied). */
210
+ writeZip(targetFileName?: string, callback?: (error: Error | null) => void): void;
211
+
212
+ /** Promise-returning variant of `writeZip`. */
213
+ writeZipPromise(targetFileName?: string, props?: { overwrite?: boolean; perm?: number }): Promise<void>;
214
+
215
+ /** Serialize the archive to a Buffer asynchronously. */
216
+ toBufferPromise(): Promise<Buffer>;
217
+
218
+ /** Serialize the archive to a Buffer. With callbacks it runs asynchronously and returns null. */
219
+ toBuffer(): Buffer;
220
+ toBuffer(onSuccess: (buffer: Buffer) => void, onFail?: (error: unknown) => void, onItemStart?: (name: string) => void, onItemEnd?: (name: string) => void): null;
221
+ }
222
+
223
+ export = AdmZip;
@@ -0,0 +1,142 @@
1
+ module.exports = {
2
+ /* The local file header */
3
+ LOCHDR : 30, // LOC header size
4
+ LOCSIG : 0x04034b50, // "PK\003\004"
5
+ LOCVER : 4, // version needed to extract
6
+ LOCFLG : 6, // general purpose bit flag
7
+ LOCHOW : 8, // compression method
8
+ LOCTIM : 10, // modification time (2 bytes time, 2 bytes date)
9
+ LOCCRC : 14, // uncompressed file crc-32 value
10
+ LOCSIZ : 18, // compressed size
11
+ LOCLEN : 22, // uncompressed size
12
+ LOCNAM : 26, // filename length
13
+ LOCEXT : 28, // extra field length
14
+
15
+ /* The Data descriptor */
16
+ EXTSIG : 0x08074b50, // "PK\007\008"
17
+ EXTHDR : 16, // EXT header size
18
+ EXTCRC : 4, // uncompressed file crc-32 value
19
+ EXTSIZ : 8, // compressed size
20
+ EXTLEN : 12, // uncompressed size
21
+
22
+ /* The central directory file header */
23
+ CENHDR : 46, // CEN header size
24
+ CENSIG : 0x02014b50, // "PK\001\002"
25
+ CENVEM : 4, // version made by
26
+ CENVER : 6, // version needed to extract
27
+ CENFLG : 8, // encrypt, decrypt flags
28
+ CENHOW : 10, // compression method
29
+ CENTIM : 12, // modification time (2 bytes time, 2 bytes date)
30
+ CENCRC : 16, // uncompressed file crc-32 value
31
+ CENSIZ : 20, // compressed size
32
+ CENLEN : 24, // uncompressed size
33
+ CENNAM : 28, // filename length
34
+ CENEXT : 30, // extra field length
35
+ CENCOM : 32, // file comment length
36
+ CENDSK : 34, // volume number start
37
+ CENATT : 36, // internal file attributes
38
+ CENATX : 38, // external file attributes (host system dependent)
39
+ CENOFF : 42, // LOC header offset
40
+
41
+ /* The entries in the end of central directory */
42
+ ENDHDR : 22, // END header size
43
+ ENDSIG : 0x06054b50, // "PK\005\006"
44
+ ENDSUB : 8, // number of entries on this disk
45
+ ENDTOT : 10, // total number of entries
46
+ ENDSIZ : 12, // central directory size in bytes
47
+ ENDOFF : 16, // offset of first CEN header
48
+ ENDCOM : 20, // zip file comment length
49
+
50
+ END64HDR : 20, // zip64 END header size
51
+ END64SIG : 0x07064b50, // zip64 Locator signature, "PK\006\007"
52
+ END64START : 4, // number of the disk with the start of the zip64
53
+ END64OFF : 8, // relative offset of the zip64 end of central directory
54
+ END64NUMDISKS : 16, // total number of disks
55
+
56
+ ZIP64SIG : 0x06064b50, // zip64 signature, "PK\006\006"
57
+ ZIP64HDR : 56, // zip64 record minimum size
58
+ ZIP64LEAD : 12, // leading bytes at the start of the record, not counted by the value stored in ZIP64SIZE
59
+ ZIP64SIZE : 4, // zip64 size of the central directory record
60
+ ZIP64VEM : 12, // zip64 version made by
61
+ ZIP64VER : 14, // zip64 version needed to extract
62
+ ZIP64DSK : 16, // zip64 number of this disk
63
+ ZIP64DSKDIR : 20, // number of the disk with the start of the record directory
64
+ ZIP64SUB : 24, // number of entries on this disk
65
+ ZIP64TOT : 32, // total number of entries
66
+ ZIP64SIZB : 40, // zip64 central directory size in bytes
67
+ ZIP64OFF : 48, // offset of start of central directory with respect to the starting disk number
68
+ ZIP64EXTRA : 56, // extensible data sector
69
+
70
+ /* Compression methods */
71
+ STORED : 0, // no compression
72
+ SHRUNK : 1, // shrunk
73
+ REDUCED1 : 2, // reduced with compression factor 1
74
+ REDUCED2 : 3, // reduced with compression factor 2
75
+ REDUCED3 : 4, // reduced with compression factor 3
76
+ REDUCED4 : 5, // reduced with compression factor 4
77
+ IMPLODED : 6, // imploded
78
+ // 7 reserved for Tokenizing compression algorithm
79
+ DEFLATED : 8, // deflated
80
+ ENHANCED_DEFLATED: 9, // enhanced deflated
81
+ PKWARE : 10,// PKWare DCL imploded
82
+ // 11 reserved by PKWARE
83
+ BZIP2 : 12, // compressed using BZIP2
84
+ // 13 reserved by PKWARE
85
+ LZMA : 14, // LZMA
86
+ // 15-17 reserved by PKWARE
87
+ IBM_TERSE : 18, // compressed using IBM TERSE
88
+ IBM_LZ77 : 19, // IBM LZ77 z
89
+ AES_ENCRYPT : 99, // WinZIP AES encryption method
90
+
91
+ /* General purpose bit flag */
92
+ // values can obtained with expression 2**bitnr
93
+ FLG_ENC : 1, // Bit 0: encrypted file
94
+ FLG_COMP1 : 2, // Bit 1, compression option
95
+ FLG_COMP2 : 4, // Bit 2, compression option
96
+ FLG_DESC : 8, // Bit 3, data descriptor
97
+ FLG_ENH : 16, // Bit 4, enhanced deflating
98
+ FLG_PATCH : 32, // Bit 5, indicates that the file is compressed patched data.
99
+ FLG_STR : 64, // Bit 6, strong encryption (patented)
100
+ // Bits 7-10: Currently unused.
101
+ FLG_EFS : 2048, // Bit 11: Language encoding flag (EFS)
102
+ // Bit 12: Reserved by PKWARE for enhanced compression.
103
+ // Bit 13: encrypted the Central Directory (patented).
104
+ // Bits 14-15: Reserved by PKWARE.
105
+ FLG_MSK : 4096, // mask header values
106
+
107
+ /* Load type */
108
+ FILE : 2,
109
+ BUFFER : 1,
110
+ NONE : 0,
111
+
112
+ /* 4.5 Extensible data fields */
113
+ EF_ID : 0,
114
+ EF_SIZE : 2,
115
+
116
+ /* Header IDs */
117
+ ID_ZIP64 : 0x0001,
118
+ ID_AVINFO : 0x0007,
119
+ ID_PFS : 0x0008,
120
+ ID_OS2 : 0x0009,
121
+ ID_NTFS : 0x000a,
122
+ ID_OPENVMS : 0x000c,
123
+ ID_UNIX : 0x000d,
124
+ ID_FORK : 0x000e,
125
+ ID_PATCH : 0x000f,
126
+ ID_X509_PKCS7 : 0x0014,
127
+ ID_X509_CERTID_F : 0x0015,
128
+ ID_X509_CERTID_C : 0x0016,
129
+ ID_STRONGENC : 0x0017,
130
+ ID_RECORD_MGT : 0x0018,
131
+ ID_X509_PKCS7_RL : 0x0019,
132
+ ID_IBM1 : 0x0065,
133
+ ID_IBM2 : 0x0066,
134
+ ID_POSZIP : 0x4690,
135
+
136
+ EF_ZIP64_OR_32 : 0xffffffff,
137
+ EF_ZIP64_OR_16 : 0xffff,
138
+ EF_ZIP64_SUNCOMP : 0,
139
+ EF_ZIP64_SCOMP : 8,
140
+ EF_ZIP64_RHO : 16,
141
+ EF_ZIP64_DSN : 24
142
+ };
@@ -0,0 +1,5 @@
1
+ module.exports = {
2
+ efs: true,
3
+ encode: (data) => Buffer.from(data, "utf8"),
4
+ decode: (data) => data.toString("utf8")
5
+ };
@@ -0,0 +1,66 @@
1
+ const errors = {
2
+ /* Header error messages */
3
+ INVALID_LOC: "Invalid LOC header (bad signature)",
4
+ INVALID_CEN: "Invalid CEN header (bad signature)",
5
+ INVALID_END: "Invalid END header (bad signature)",
6
+
7
+ /* Descriptor */
8
+ DESCRIPTOR_NOT_EXIST: "No descriptor present",
9
+ DESCRIPTOR_UNKNOWN: "Unknown descriptor format",
10
+ DESCRIPTOR_FAULTY: "Descriptor data is malformed",
11
+
12
+ /* ZipEntry error messages*/
13
+ NO_DATA: "Nothing to decompress",
14
+ BAD_CRC: "CRC32 checksum failed {0}",
15
+ MAX_OUTPUT_EXCEEDED: "Decompressed data exceeds the declared uncompressed size",
16
+ FILE_IN_THE_WAY: "There is a file in the way: {0}",
17
+ UNKNOWN_METHOD: "Invalid/unsupported compression method",
18
+
19
+ /* Inflater error messages */
20
+ AVAIL_DATA: "inflate::Available inflate data did not terminate",
21
+ INVALID_DISTANCE: "inflate::Invalid literal/length or distance code in fixed or dynamic block",
22
+ TO_MANY_CODES: "inflate::Dynamic block code description: too many length or distance codes",
23
+ INVALID_REPEAT_LEN: "inflate::Dynamic block code description: repeat more than specified lengths",
24
+ INVALID_REPEAT_FIRST: "inflate::Dynamic block code description: repeat lengths with no first length",
25
+ INCOMPLETE_CODES: "inflate::Dynamic block code description: code lengths codes incomplete",
26
+ INVALID_DYN_DISTANCE: "inflate::Dynamic block code description: invalid distance code lengths",
27
+ INVALID_CODES_LEN: "inflate::Dynamic block code description: invalid literal/length code lengths",
28
+ INVALID_STORE_BLOCK: "inflate::Stored block length did not match one's complement",
29
+ INVALID_BLOCK_TYPE: "inflate::Invalid block type (type == 3)",
30
+
31
+ /* ADM-ZIP error messages */
32
+ CANT_EXTRACT_FILE: "Could not extract the file",
33
+ CANT_OVERRIDE: "Target file already exists",
34
+ DISK_ENTRY_TOO_LARGE: "Number of disk entries is too large",
35
+ NO_ZIP: "No zip file was loaded",
36
+ NO_ENTRY: "Entry doesn't exist",
37
+ DUPLICATE_ENTRY: "Duplicate entry name {0}",
38
+ DIRECTORY_CONTENT_ERROR: "A directory cannot have content",
39
+ FILE_NOT_FOUND: 'File not found: "{0}"',
40
+ NOT_IMPLEMENTED: "Not implemented",
41
+ INVALID_FILENAME: "Invalid filename",
42
+ INVALID_FORMAT: "Invalid or unsupported zip format. No END header found",
43
+ ZIP64_VALUE_TOO_LARGE: "Zip64 value exceeds the maximum safe integer",
44
+ INVALID_PASS_PARAM: "Incompatible password parameter",
45
+ WRONG_PASSWORD: "Wrong Password",
46
+
47
+ /* ADM-ZIP */
48
+ COMMENT_TOO_LONG: "Comment is too long", // Comment can be max 65535 bytes long (NOTE: some non-US characters may take more space)
49
+ EXTRA_FIELD_PARSE_ERROR: "Extra field parsing error"
50
+ };
51
+
52
+ // template
53
+ function E(message) {
54
+ return function (...args) {
55
+ if (args.length) { // Allow {0} .. {9} arguments in error message, based on argument number
56
+ message = message.replace(/\{(\d)\}/g, (_, n) => args[n] || '');
57
+ }
58
+
59
+ return new Error('ADM-ZIP: ' + message);
60
+ };
61
+ }
62
+
63
+ // Init errors with template
64
+ for (const msg of Object.keys(errors)) {
65
+ exports[msg] = E(errors[msg]);
66
+ }