stage-browser 0.0.0-stage → 0.1.1
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.
- package/README.md +136 -2
- package/build/icon.icns +0 -0
- package/build/icon.png +0 -0
- package/dist/bin/stage.js +111 -0
- package/dist/main/cli-args.js +28 -0
- package/dist/main/context-menu.js +68 -0
- package/dist/main/context.js +2 -0
- package/dist/main/extensions.js +78 -0
- package/dist/main/ipc.js +90 -0
- package/dist/main/main.js +279 -0
- package/dist/main/menu.js +140 -0
- package/dist/main/reveal.js +155 -0
- package/dist/main/selftest.js +490 -0
- package/dist/main/store.js +85 -0
- package/dist/main/suggest.js +43 -0
- package/dist/main/tabs.js +324 -0
- package/dist/main/url.js +38 -0
- package/dist/main/window.js +68 -0
- package/dist/preload/extension-compat.js +163 -0
- package/dist/preload/ui-preload.js +33 -0
- package/dist/shared/contract.js +6 -0
- package/dist/ui/app.js +653 -0
- package/dist/ui/index.html +41 -0
- package/dist/ui/mock.js +479 -0
- package/dist/ui/newtab.html +69 -0
- package/dist/ui/styles.css +410 -0
- package/node_modules/@types/chrome/LICENSE +21 -0
- package/node_modules/@types/chrome/README.md +15 -0
- package/node_modules/@types/chrome/chrome-cast/index.d.ts +1156 -0
- package/node_modules/@types/chrome/har-format/index.d.ts +6 -0
- package/node_modules/@types/chrome/index.d.ts +13786 -0
- package/node_modules/@types/chrome/package.json +99 -0
- package/node_modules/@types/filesystem/LICENSE +21 -0
- package/node_modules/@types/filesystem/README.md +15 -0
- package/node_modules/@types/filesystem/index.d.ts +564 -0
- package/node_modules/@types/filesystem/package.json +26 -0
- package/node_modules/@types/filewriter/LICENSE +21 -0
- package/node_modules/@types/filewriter/README.md +15 -0
- package/node_modules/@types/filewriter/index.d.ts +166 -0
- package/node_modules/@types/filewriter/package.json +25 -0
- package/node_modules/@types/har-format/LICENSE +21 -0
- package/node_modules/@types/har-format/README.md +15 -0
- package/node_modules/@types/har-format/index.d.ts +938 -0
- package/node_modules/@types/har-format/package.json +31 -0
- package/node_modules/adm-zip/LICENSE +21 -0
- package/node_modules/adm-zip/README.md +90 -0
- package/node_modules/adm-zip/adm-zip.js +1020 -0
- package/node_modules/adm-zip/headers/entryHeader.js +396 -0
- package/node_modules/adm-zip/headers/index.js +2 -0
- package/node_modules/adm-zip/headers/mainHeader.js +177 -0
- package/node_modules/adm-zip/methods/deflater.js +33 -0
- package/node_modules/adm-zip/methods/index.js +3 -0
- package/node_modules/adm-zip/methods/inflater.js +64 -0
- package/node_modules/adm-zip/methods/zipcrypto.js +175 -0
- package/node_modules/adm-zip/package.json +56 -0
- package/node_modules/adm-zip/types.d.ts +223 -0
- package/node_modules/adm-zip/util/constants.js +142 -0
- package/node_modules/adm-zip/util/decoder.js +5 -0
- package/node_modules/adm-zip/util/errors.js +66 -0
- package/node_modules/adm-zip/util/fattr.js +76 -0
- package/node_modules/adm-zip/util/index.js +5 -0
- package/node_modules/adm-zip/util/utils.js +481 -0
- package/node_modules/adm-zip/zipEntry.js +415 -0
- package/node_modules/adm-zip/zipFile.js +466 -0
- package/node_modules/debug/LICENSE +20 -0
- package/node_modules/debug/README.md +481 -0
- package/node_modules/debug/package.json +64 -0
- package/node_modules/debug/src/browser.js +272 -0
- package/node_modules/debug/src/common.js +292 -0
- package/node_modules/debug/src/index.js +10 -0
- package/node_modules/debug/src/node.js +263 -0
- package/node_modules/electron-chrome-web-store/README.md +143 -0
- package/node_modules/electron-chrome-web-store/dist/chrome-web-store.preload.js +299 -0
- package/node_modules/electron-chrome-web-store/dist/cjs/browser/index.js +1674 -0
- package/node_modules/electron-chrome-web-store/dist/esm/browser/index.mjs +950 -0
- package/node_modules/electron-chrome-web-store/dist/types/browser/api.d.ts +2 -0
- package/node_modules/electron-chrome-web-store/dist/types/browser/crx3.d.ts +20 -0
- package/node_modules/electron-chrome-web-store/dist/types/browser/id.d.ts +9 -0
- package/node_modules/electron-chrome-web-store/dist/types/browser/index.d.ts +62 -0
- package/node_modules/electron-chrome-web-store/dist/types/browser/installer.d.ts +29 -0
- package/node_modules/electron-chrome-web-store/dist/types/browser/loader.d.ts +18 -0
- package/node_modules/electron-chrome-web-store/dist/types/browser/types.d.ts +21 -0
- package/node_modules/electron-chrome-web-store/dist/types/browser/updater.d.ts +6 -0
- package/node_modules/electron-chrome-web-store/dist/types/browser/utils.d.ts +4 -0
- package/node_modules/electron-chrome-web-store/dist/types/common/constants.d.ts +44 -0
- package/node_modules/electron-chrome-web-store/dist/types/renderer/chrome-web-store.preload.d.ts +1 -0
- package/node_modules/electron-chrome-web-store/package.json +43 -0
- package/node_modules/ms/index.js +162 -0
- package/node_modules/ms/license.md +21 -0
- package/node_modules/ms/package.json +38 -0
- package/node_modules/ms/readme.md +59 -0
- package/node_modules/pbf/LICENSE +27 -0
- package/node_modules/pbf/README.md +293 -0
- package/node_modules/pbf/bin/pbf +17 -0
- package/node_modules/pbf/compile.js +441 -0
- package/node_modules/pbf/dist/pbf-dev.js +838 -0
- package/node_modules/pbf/dist/pbf.js +1 -0
- package/node_modules/pbf/index.d.ts +206 -0
- package/node_modules/pbf/index.js +830 -0
- package/node_modules/pbf/package.json +63 -0
- package/node_modules/protocol-buffers-schema/.travis.yml +7 -0
- package/node_modules/protocol-buffers-schema/LICENSE +21 -0
- package/node_modules/protocol-buffers-schema/README.md +122 -0
- package/node_modules/protocol-buffers-schema/example.js +11 -0
- package/node_modules/protocol-buffers-schema/example.proto +13 -0
- package/node_modules/protocol-buffers-schema/index.js +6 -0
- package/node_modules/protocol-buffers-schema/package.json +31 -0
- package/node_modules/protocol-buffers-schema/parse.js +769 -0
- package/node_modules/protocol-buffers-schema/stringify.js +206 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/basic.json +90 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/basic.proto +11 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/comments.json +99 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/comments.proto +19 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/complex.json +125 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/complex.proto +30 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/enum.json +42 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/enum.proto +8 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/escaped-quotes.json +32 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/escaped-quotes.proto +3 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/extend.json +167 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/extend.proto +19 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/import.json +30 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/import.proto +6 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/map.json +33 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/map.proto +3 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/no-tags.proto +8 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/oneof.json +41 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/oneof.proto +6 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/option.json +364 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/option.proto +72 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/options.json +47 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/options.proto +8 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/pheromon-trajectories.proto +8 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/reserved.json +55 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/reserved.proto +17 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/search.json +30 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/search.proto +5 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/service.json +108 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/service.proto +30 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/valid-packed.proto +35 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/version.json +90 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/version.proto +13 -0
- package/node_modules/protocol-buffers-schema/test/index.js +157 -0
- package/node_modules/protocol-buffers-schema/tokenize.js +56 -0
- package/node_modules/resolve-protobuf-schema/.travis.yml +3 -0
- package/node_modules/resolve-protobuf-schema/LICENSE +21 -0
- package/node_modules/resolve-protobuf-schema/README.md +49 -0
- package/node_modules/resolve-protobuf-schema/index.js +50 -0
- package/node_modules/resolve-protobuf-schema/package.json +25 -0
- package/node_modules/resolve-protobuf-schema/test/a.proto +5 -0
- package/node_modules/resolve-protobuf-schema/test/b.proto +5 -0
- package/node_modules/resolve-protobuf-schema/test/c.proto +3 -0
- package/node_modules/resolve-protobuf-schema/test/index.js +49 -0
- package/package.json +64 -4
|
@@ -0,0 +1,466 @@
|
|
|
1
|
+
const ZipEntry = require("./zipEntry");
|
|
2
|
+
const Headers = require("./headers");
|
|
3
|
+
const Utils = require("./util");
|
|
4
|
+
|
|
5
|
+
module.exports = function (/*Buffer|null*/ inBuffer, /** object */ options) {
|
|
6
|
+
var entryList = [],
|
|
7
|
+
// prototype-less: entry names come from untrusted input, so keys like
|
|
8
|
+
// "__proto__" or "constructor" must be plain data, not touch the prototype
|
|
9
|
+
// chain (which otherwise crashes addFile and hides such entries)
|
|
10
|
+
entryTable = Object.create(null),
|
|
11
|
+
_comment = Buffer.alloc(0),
|
|
12
|
+
mainHeader = new Headers.MainHeader(),
|
|
13
|
+
loadedEntries = false;
|
|
14
|
+
var password = null;
|
|
15
|
+
const temporary = new Set();
|
|
16
|
+
|
|
17
|
+
// assign options
|
|
18
|
+
const opts = options;
|
|
19
|
+
|
|
20
|
+
const { noSort, decoder } = opts;
|
|
21
|
+
|
|
22
|
+
if (inBuffer) {
|
|
23
|
+
// is a memory buffer
|
|
24
|
+
readMainHeader(opts.readEntries);
|
|
25
|
+
} else {
|
|
26
|
+
// none. is a new file
|
|
27
|
+
loadedEntries = true;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function makeTemporaryFolders() {
|
|
31
|
+
const foldersList = new Set();
|
|
32
|
+
|
|
33
|
+
// Make list of all folders in file
|
|
34
|
+
for (const elem of Object.keys(entryTable)) {
|
|
35
|
+
const elements = elem.split("/");
|
|
36
|
+
elements.pop(); // filename
|
|
37
|
+
if (!elements.length) continue; // no folders
|
|
38
|
+
for (let i = 0; i < elements.length; i++) {
|
|
39
|
+
const sub = elements.slice(0, i + 1).join("/") + "/";
|
|
40
|
+
foldersList.add(sub);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// create missing folders as temporary
|
|
45
|
+
for (const elem of foldersList) {
|
|
46
|
+
if (!(elem in entryTable)) {
|
|
47
|
+
const tempfolder = new ZipEntry(opts);
|
|
48
|
+
tempfolder.entryName = elem;
|
|
49
|
+
tempfolder.attr = 0x10;
|
|
50
|
+
tempfolder.temporary = true;
|
|
51
|
+
entryList.push(tempfolder);
|
|
52
|
+
entryTable[tempfolder.entryName] = tempfolder;
|
|
53
|
+
temporary.add(tempfolder);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function readEntries() {
|
|
59
|
+
loadedEntries = true;
|
|
60
|
+
entryTable = Object.create(null);
|
|
61
|
+
if (mainHeader.diskEntries > (inBuffer.length - mainHeader.offset) / Utils.Constants.CENHDR) {
|
|
62
|
+
throw Utils.Errors.DISK_ENTRY_TOO_LARGE();
|
|
63
|
+
}
|
|
64
|
+
entryList = new Array(mainHeader.diskEntries); // total number of entries
|
|
65
|
+
var index = mainHeader.offset; // offset of first CEN header
|
|
66
|
+
for (var i = 0; i < entryList.length; i++) {
|
|
67
|
+
var tmp = index,
|
|
68
|
+
entry = new ZipEntry(opts, inBuffer);
|
|
69
|
+
entry.header = inBuffer.slice(tmp, (tmp += Utils.Constants.CENHDR));
|
|
70
|
+
|
|
71
|
+
entry.entryName = inBuffer.slice(tmp, (tmp += entry.header.fileNameLength));
|
|
72
|
+
|
|
73
|
+
if (entry.header.extraLength) {
|
|
74
|
+
entry.extra = inBuffer.slice(tmp, (tmp += entry.header.extraLength));
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (entry.header.commentLength) entry.comment = inBuffer.slice(tmp, tmp + entry.header.commentLength);
|
|
78
|
+
|
|
79
|
+
index += entry.header.centralHeaderSize;
|
|
80
|
+
|
|
81
|
+
// Reject archives that declare the same entry name twice. adm-zip keeps
|
|
82
|
+
// every entry in entryList but only the last in entryTable, so getEntry()
|
|
83
|
+
// (table) and extractAllTo() (list) could resolve one name to different
|
|
84
|
+
// content: an app that validates entry bytes via getEntry() before
|
|
85
|
+
// extracting could approve one file while a different one lands on disk
|
|
86
|
+
// (GHSA-p634-w6r4-rjp2). Fail closed on the ambiguity.
|
|
87
|
+
if (entry.entryName in entryTable) {
|
|
88
|
+
throw Utils.Errors.DUPLICATE_ENTRY(`"${entry.entryName}"`);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
entryList[i] = entry;
|
|
92
|
+
entryTable[entry.entryName] = entry;
|
|
93
|
+
}
|
|
94
|
+
temporary.clear();
|
|
95
|
+
makeTemporaryFolders();
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function readMainHeader(/*Boolean*/ readNow) {
|
|
99
|
+
var i = inBuffer.length - Utils.Constants.ENDHDR, // END header size
|
|
100
|
+
max = Math.max(0, i - 0xffff), // 0xFFFF is the max zip file comment length
|
|
101
|
+
n = max,
|
|
102
|
+
endStart = inBuffer.length,
|
|
103
|
+
endOffset = -1, // Start offset of the END header
|
|
104
|
+
commentEnd = 0;
|
|
105
|
+
|
|
106
|
+
// option to search header form entire file
|
|
107
|
+
const trailingSpace = typeof opts.trailingSpace === "boolean" ? opts.trailingSpace : false;
|
|
108
|
+
if (trailingSpace) max = 0;
|
|
109
|
+
|
|
110
|
+
for (i; i >= n; i--) {
|
|
111
|
+
if (inBuffer[i] !== 0x50) continue; // quick check that the byte is 'P'
|
|
112
|
+
if (inBuffer.readUInt32LE(i) === Utils.Constants.ENDSIG) {
|
|
113
|
+
// "PK\005\006"
|
|
114
|
+
endOffset = i;
|
|
115
|
+
commentEnd = i;
|
|
116
|
+
endStart = i + Utils.Constants.ENDHDR;
|
|
117
|
+
// We already found a regular signature, let's look just a bit further to check if there's any zip64 signature
|
|
118
|
+
n = i - Utils.Constants.END64HDR;
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (inBuffer.readUInt32LE(i) === Utils.Constants.END64SIG) {
|
|
123
|
+
// Found a zip64 signature, let's continue reading the whole zip64 record
|
|
124
|
+
n = max;
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (inBuffer.readUInt32LE(i) === Utils.Constants.ZIP64SIG) {
|
|
129
|
+
// Found the zip64 record, let's determine it's size
|
|
130
|
+
endOffset = i;
|
|
131
|
+
endStart = i + Utils.readBigUInt64LE(inBuffer, i + Utils.Constants.ZIP64SIZE) + Utils.Constants.ZIP64LEAD;
|
|
132
|
+
break;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (endOffset == -1) throw Utils.Errors.INVALID_FORMAT();
|
|
137
|
+
|
|
138
|
+
mainHeader.loadFromBinary(inBuffer.slice(endOffset, endStart));
|
|
139
|
+
if (mainHeader.commentLength) {
|
|
140
|
+
_comment = inBuffer.slice(commentEnd + Utils.Constants.ENDHDR);
|
|
141
|
+
}
|
|
142
|
+
if (readNow) readEntries();
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function sortEntries() {
|
|
146
|
+
if (entryList.length > 1 && !noSort) {
|
|
147
|
+
// Decode + lowercase each name once rather than on every comparison:
|
|
148
|
+
// the entryName getter re-decodes the underlying buffer on each access,
|
|
149
|
+
// so the previous inline comparator did O(n log n) redundant decoding.
|
|
150
|
+
// Ordering is unchanged (same localeCompare on the same keys).
|
|
151
|
+
entryList = entryList
|
|
152
|
+
.map((entry) => ({ entry, key: entry.entryName.toLowerCase() }))
|
|
153
|
+
.sort((a, b) => a.key.localeCompare(b.key))
|
|
154
|
+
.map((pair) => pair.entry);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
return {
|
|
159
|
+
/**
|
|
160
|
+
* Returns an array of ZipEntry objects existent in the current opened archive
|
|
161
|
+
* @return Array
|
|
162
|
+
*/
|
|
163
|
+
get entries() {
|
|
164
|
+
if (!loadedEntries) {
|
|
165
|
+
readEntries();
|
|
166
|
+
}
|
|
167
|
+
return entryList.filter((e) => !temporary.has(e));
|
|
168
|
+
},
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Archive comment
|
|
172
|
+
* @return {String}
|
|
173
|
+
*/
|
|
174
|
+
get comment() {
|
|
175
|
+
return decoder.decode(_comment);
|
|
176
|
+
},
|
|
177
|
+
set comment(val) {
|
|
178
|
+
_comment = Utils.toBuffer(val, decoder.encode);
|
|
179
|
+
mainHeader.commentLength = _comment.length;
|
|
180
|
+
},
|
|
181
|
+
|
|
182
|
+
getEntryCount: function () {
|
|
183
|
+
if (!loadedEntries) {
|
|
184
|
+
return mainHeader.diskEntries;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
return entryList.length;
|
|
188
|
+
},
|
|
189
|
+
|
|
190
|
+
forEach: function (callback) {
|
|
191
|
+
this.entries.forEach(callback);
|
|
192
|
+
},
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Returns a reference to the entry with the given name or null if entry is inexistent
|
|
196
|
+
*
|
|
197
|
+
* @param entryName
|
|
198
|
+
* @return ZipEntry
|
|
199
|
+
*/
|
|
200
|
+
getEntry: function (/*String*/ entryName) {
|
|
201
|
+
if (!loadedEntries) {
|
|
202
|
+
readEntries();
|
|
203
|
+
}
|
|
204
|
+
return entryTable[entryName] || null;
|
|
205
|
+
},
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Adds the given entry to the entry list
|
|
209
|
+
*
|
|
210
|
+
* @param entry
|
|
211
|
+
*/
|
|
212
|
+
setEntry: function (/*ZipEntry*/ entry) {
|
|
213
|
+
if (!loadedEntries) {
|
|
214
|
+
readEntries();
|
|
215
|
+
}
|
|
216
|
+
entryList.push(entry);
|
|
217
|
+
entryTable[entry.entryName] = entry;
|
|
218
|
+
mainHeader.totalEntries = entryList.length;
|
|
219
|
+
},
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Removes the file with the given name from the entry list.
|
|
223
|
+
*
|
|
224
|
+
* If the entry is a directory, then all nested files and directories will be removed
|
|
225
|
+
* @param entryName
|
|
226
|
+
* @returns {void}
|
|
227
|
+
*/
|
|
228
|
+
deleteFile: function (/*String*/ entryName, withsubfolders = true) {
|
|
229
|
+
if (!loadedEntries) {
|
|
230
|
+
readEntries();
|
|
231
|
+
}
|
|
232
|
+
const entry = entryTable[entryName];
|
|
233
|
+
const list = this.getEntryChildren(entry, withsubfolders).map((child) => child.entryName);
|
|
234
|
+
|
|
235
|
+
list.forEach(this.deleteEntry);
|
|
236
|
+
},
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Removes the entry with the given name from the entry list.
|
|
240
|
+
*
|
|
241
|
+
* @param {string} entryName
|
|
242
|
+
* @returns {void}
|
|
243
|
+
*/
|
|
244
|
+
deleteEntry: function (/*String*/ entryName) {
|
|
245
|
+
if (!loadedEntries) {
|
|
246
|
+
readEntries();
|
|
247
|
+
}
|
|
248
|
+
const entry = entryTable[entryName];
|
|
249
|
+
const index = entryList.indexOf(entry);
|
|
250
|
+
if (index >= 0) {
|
|
251
|
+
entryList.splice(index, 1);
|
|
252
|
+
delete entryTable[entryName];
|
|
253
|
+
mainHeader.totalEntries = entryList.length;
|
|
254
|
+
}
|
|
255
|
+
},
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* Iterates and returns all nested files and directories of the given entry
|
|
259
|
+
*
|
|
260
|
+
* @param entry
|
|
261
|
+
* @return Array
|
|
262
|
+
*/
|
|
263
|
+
getEntryChildren: function (/*ZipEntry*/ entry, subfolders = true) {
|
|
264
|
+
if (!loadedEntries) {
|
|
265
|
+
readEntries();
|
|
266
|
+
}
|
|
267
|
+
if (typeof entry === "object") {
|
|
268
|
+
if (entry.isDirectory && subfolders) {
|
|
269
|
+
const list = [];
|
|
270
|
+
const name = entry.entryName;
|
|
271
|
+
|
|
272
|
+
for (const zipEntry of entryList) {
|
|
273
|
+
if (zipEntry.entryName.startsWith(name)) {
|
|
274
|
+
list.push(zipEntry);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
return list;
|
|
278
|
+
} else {
|
|
279
|
+
return [entry];
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
return [];
|
|
283
|
+
},
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* How many child elements entry has
|
|
287
|
+
*
|
|
288
|
+
* @param {ZipEntry} entry
|
|
289
|
+
* @return {integer}
|
|
290
|
+
*/
|
|
291
|
+
getChildCount: function (entry) {
|
|
292
|
+
if (entry && entry.isDirectory) {
|
|
293
|
+
const list = this.getEntryChildren(entry);
|
|
294
|
+
return list.includes(entry) ? list.length - 1 : list.length;
|
|
295
|
+
}
|
|
296
|
+
return 0;
|
|
297
|
+
},
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* Returns the zip file
|
|
301
|
+
*
|
|
302
|
+
* @return Buffer
|
|
303
|
+
*/
|
|
304
|
+
compressToBuffer: function () {
|
|
305
|
+
if (!loadedEntries) {
|
|
306
|
+
readEntries();
|
|
307
|
+
}
|
|
308
|
+
sortEntries();
|
|
309
|
+
|
|
310
|
+
const dataBlock = [];
|
|
311
|
+
const headerBlocks = [];
|
|
312
|
+
let totalSize = 0;
|
|
313
|
+
let dindex = 0;
|
|
314
|
+
|
|
315
|
+
mainHeader.size = 0;
|
|
316
|
+
mainHeader.offset = 0;
|
|
317
|
+
let totalEntries = 0;
|
|
318
|
+
|
|
319
|
+
for (const entry of this.entries) {
|
|
320
|
+
// compress data and set local and entry header accordingly. Reason why is called first
|
|
321
|
+
const compressedData = entry.getCompressedData();
|
|
322
|
+
entry.header.offset = dindex;
|
|
323
|
+
|
|
324
|
+
// 1. construct local header
|
|
325
|
+
const localHeader = entry.packLocalHeader();
|
|
326
|
+
|
|
327
|
+
// 2. offsets
|
|
328
|
+
const dataLength = localHeader.length + compressedData.length;
|
|
329
|
+
dindex += dataLength;
|
|
330
|
+
|
|
331
|
+
// 3. store values in sequence
|
|
332
|
+
dataBlock.push(localHeader);
|
|
333
|
+
dataBlock.push(compressedData);
|
|
334
|
+
|
|
335
|
+
// 4. construct central header
|
|
336
|
+
const centralHeader = entry.packCentralHeader();
|
|
337
|
+
headerBlocks.push(centralHeader);
|
|
338
|
+
// 5. update main header
|
|
339
|
+
mainHeader.size += centralHeader.length;
|
|
340
|
+
totalSize += dataLength + centralHeader.length;
|
|
341
|
+
totalEntries++;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
totalSize += mainHeader.mainHeaderSize; // also includes zip file comment length
|
|
345
|
+
// point to end of data and beginning of central directory first record
|
|
346
|
+
mainHeader.offset = dindex;
|
|
347
|
+
mainHeader.totalEntries = totalEntries;
|
|
348
|
+
|
|
349
|
+
dindex = 0;
|
|
350
|
+
const outBuffer = Buffer.alloc(totalSize);
|
|
351
|
+
// write data blocks
|
|
352
|
+
for (const content of dataBlock) {
|
|
353
|
+
content.copy(outBuffer, dindex);
|
|
354
|
+
dindex += content.length;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
// write central directory entries
|
|
358
|
+
for (const content of headerBlocks) {
|
|
359
|
+
content.copy(outBuffer, dindex);
|
|
360
|
+
dindex += content.length;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
// write main header
|
|
364
|
+
const mh = mainHeader.toBinary();
|
|
365
|
+
if (_comment) {
|
|
366
|
+
_comment.copy(mh, mh.length - _comment.length); // add zip file comment
|
|
367
|
+
}
|
|
368
|
+
mh.copy(outBuffer, dindex);
|
|
369
|
+
|
|
370
|
+
// Since we update entry and main header offsets,
|
|
371
|
+
// they are no longer valid and we have to reset content
|
|
372
|
+
// (Issue 64)
|
|
373
|
+
|
|
374
|
+
inBuffer = outBuffer;
|
|
375
|
+
loadedEntries = false;
|
|
376
|
+
|
|
377
|
+
return outBuffer;
|
|
378
|
+
},
|
|
379
|
+
|
|
380
|
+
toAsyncBuffer: function (/*Function*/ onSuccess, /*Function*/ onFail, /*Function*/ onItemStart, /*Function*/ onItemEnd) {
|
|
381
|
+
try {
|
|
382
|
+
if (!loadedEntries) {
|
|
383
|
+
readEntries();
|
|
384
|
+
}
|
|
385
|
+
sortEntries();
|
|
386
|
+
|
|
387
|
+
const dataBlock = [];
|
|
388
|
+
const centralHeaders = [];
|
|
389
|
+
let totalSize = 0;
|
|
390
|
+
let dindex = 0;
|
|
391
|
+
let totalEntries = 0;
|
|
392
|
+
|
|
393
|
+
mainHeader.size = 0;
|
|
394
|
+
mainHeader.offset = 0;
|
|
395
|
+
|
|
396
|
+
const compress2Buffer = function (entryLists) {
|
|
397
|
+
if (entryLists.length > 0) {
|
|
398
|
+
const entry = entryLists.shift();
|
|
399
|
+
const name = entry.entryName + entry.extra.toString();
|
|
400
|
+
if (onItemStart) onItemStart(name);
|
|
401
|
+
entry.getCompressedDataAsync(function (compressedData) {
|
|
402
|
+
if (onItemEnd) onItemEnd(name);
|
|
403
|
+
entry.header.offset = dindex;
|
|
404
|
+
|
|
405
|
+
// 1. construct local header
|
|
406
|
+
const localHeader = entry.packLocalHeader();
|
|
407
|
+
|
|
408
|
+
// 2. offsets
|
|
409
|
+
const dataLength = localHeader.length + compressedData.length;
|
|
410
|
+
dindex += dataLength;
|
|
411
|
+
|
|
412
|
+
// 3. store values in sequence
|
|
413
|
+
dataBlock.push(localHeader);
|
|
414
|
+
dataBlock.push(compressedData);
|
|
415
|
+
|
|
416
|
+
// central header
|
|
417
|
+
const centalHeader = entry.packCentralHeader();
|
|
418
|
+
centralHeaders.push(centalHeader);
|
|
419
|
+
mainHeader.size += centalHeader.length;
|
|
420
|
+
totalSize += dataLength + centalHeader.length;
|
|
421
|
+
totalEntries++;
|
|
422
|
+
|
|
423
|
+
compress2Buffer(entryLists);
|
|
424
|
+
});
|
|
425
|
+
} else {
|
|
426
|
+
totalSize += mainHeader.mainHeaderSize; // also includes zip file comment length
|
|
427
|
+
// point to end of data and beginning of central directory first record
|
|
428
|
+
mainHeader.offset = dindex;
|
|
429
|
+
mainHeader.totalEntries = totalEntries;
|
|
430
|
+
|
|
431
|
+
dindex = 0;
|
|
432
|
+
const outBuffer = Buffer.alloc(totalSize);
|
|
433
|
+
dataBlock.forEach(function (content) {
|
|
434
|
+
content.copy(outBuffer, dindex); // write data blocks
|
|
435
|
+
dindex += content.length;
|
|
436
|
+
});
|
|
437
|
+
centralHeaders.forEach(function (content) {
|
|
438
|
+
content.copy(outBuffer, dindex); // write central directory entries
|
|
439
|
+
dindex += content.length;
|
|
440
|
+
});
|
|
441
|
+
|
|
442
|
+
const mh = mainHeader.toBinary();
|
|
443
|
+
if (_comment) {
|
|
444
|
+
_comment.copy(mh, mh.length - _comment.length); // add zip file comment
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
mh.copy(outBuffer, dindex); // write main header
|
|
448
|
+
|
|
449
|
+
// Since we update entry and main header offsets, they are no
|
|
450
|
+
// longer valid and we have to reset content using our new buffer
|
|
451
|
+
// (Issue 64)
|
|
452
|
+
|
|
453
|
+
inBuffer = outBuffer;
|
|
454
|
+
loadedEntries = false;
|
|
455
|
+
|
|
456
|
+
onSuccess(outBuffer);
|
|
457
|
+
}
|
|
458
|
+
};
|
|
459
|
+
|
|
460
|
+
compress2Buffer(Array.from(this.entries));
|
|
461
|
+
} catch (e) {
|
|
462
|
+
onFail(e);
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
};
|
|
466
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
(The MIT License)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2014-2017 TJ Holowaychuk <tj@vision-media.ca>
|
|
4
|
+
Copyright (c) 2018-2021 Josh Junon
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
|
7
|
+
and associated documentation files (the 'Software'), to deal in the Software without restriction,
|
|
8
|
+
including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
9
|
+
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
|
|
10
|
+
subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial
|
|
13
|
+
portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
|
|
16
|
+
LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
17
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
18
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
19
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
20
|
+
|