analogger 1.28.3 → 1.29.2
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 +48 -1
- package/ana-logger.d.cts +3 -1
- package/browser/ana-logger.mjs +18 -6
- package/demo.cjs +12 -2
- package/dist/analogger-browser.min.mjs +3 -3
- package/dist/html-to-image-plugin.min.mjs +3 -3
- package/esm/ana-logger.mjs +18 -6
- package/package.json +1 -1
- package/src/ana-logger.cjs +18 -6
- package/browser/imported/adm-zip/adm-zip.mjs +0 -959
- package/browser/imported/adm-zip/zipEntry.mjs +0 -414
- package/browser/imported/adm-zip/zipFile.mjs +0 -455
- package/esm/node_modules/adm-zip/adm-zip.mjs +0 -959
- package/esm/node_modules/adm-zip/zipEntry.mjs +0 -414
- package/esm/node_modules/adm-zip/zipFile.mjs +0 -455
|
@@ -1,455 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* DO NOT EDIT THIS FILE DIRECTLY.
|
|
3
|
-
* This file is generated following the conversion of
|
|
4
|
-
* @see [./node_modules/adm-zip/zipFile.js]{@link ./node_modules/adm-zip/zipFile.js}
|
|
5
|
-
*
|
|
6
|
-
**/
|
|
7
|
-
import ZipEntry from "./zipEntry.mjs";
|
|
8
|
-
import Headers from "./headers.mjs";
|
|
9
|
-
import Utils from "./util.mjs";
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
export default function (/*Buffer|null*/ inBuffer, /** object */ options) {
|
|
15
|
-
var entryList = [],
|
|
16
|
-
entryTable = {},
|
|
17
|
-
_comment = Buffer.alloc(0),
|
|
18
|
-
mainHeader = new Headers.MainHeader(),
|
|
19
|
-
loadedEntries = false;
|
|
20
|
-
var password = null;
|
|
21
|
-
const temporary = new Set();
|
|
22
|
-
|
|
23
|
-
// assign options
|
|
24
|
-
const opts = options;
|
|
25
|
-
|
|
26
|
-
const { noSort, decoder } = opts;
|
|
27
|
-
|
|
28
|
-
if (inBuffer) {
|
|
29
|
-
// is a memory buffer
|
|
30
|
-
readMainHeader(opts.readEntries);
|
|
31
|
-
} else {
|
|
32
|
-
// none. is a new file
|
|
33
|
-
loadedEntries = true;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function makeTemporaryFolders() {
|
|
37
|
-
const foldersList = new Set();
|
|
38
|
-
|
|
39
|
-
// Make list of all folders in file
|
|
40
|
-
for (const elem of Object.keys(entryTable)) {
|
|
41
|
-
const elements = elem.split("/");
|
|
42
|
-
elements.pop(); // filename
|
|
43
|
-
if (!elements.length) continue; // no folders
|
|
44
|
-
for (let i = 0; i < elements.length; i++) {
|
|
45
|
-
const sub = elements.slice(0, i + 1).join("/") + "/";
|
|
46
|
-
foldersList.add(sub);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// create missing folders as temporary
|
|
51
|
-
for (const elem of foldersList) {
|
|
52
|
-
if (!(elem in entryTable)) {
|
|
53
|
-
const tempfolder = new ZipEntry(opts);
|
|
54
|
-
tempfolder.entryName = elem;
|
|
55
|
-
tempfolder.attr = 0x10;
|
|
56
|
-
tempfolder.temporary = true;
|
|
57
|
-
entryList.push(tempfolder);
|
|
58
|
-
entryTable[tempfolder.entryName] = tempfolder;
|
|
59
|
-
temporary.add(tempfolder);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
function readEntries() {
|
|
65
|
-
loadedEntries = true;
|
|
66
|
-
entryTable = {};
|
|
67
|
-
if (mainHeader.diskEntries > (inBuffer.length - mainHeader.offset) / Utils.Constants.CENHDR) {
|
|
68
|
-
throw Utils.Errors.DISK_ENTRY_TOO_LARGE();
|
|
69
|
-
}
|
|
70
|
-
entryList = new Array(mainHeader.diskEntries); // total number of entries
|
|
71
|
-
var index = mainHeader.offset; // offset of first CEN header
|
|
72
|
-
for (var i = 0; i < entryList.length; i++) {
|
|
73
|
-
var tmp = index,
|
|
74
|
-
entry = new ZipEntry(opts, inBuffer);
|
|
75
|
-
entry.header = inBuffer.slice(tmp, (tmp += Utils.Constants.CENHDR));
|
|
76
|
-
|
|
77
|
-
entry.entryName = inBuffer.slice(tmp, (tmp += entry.header.fileNameLength));
|
|
78
|
-
|
|
79
|
-
if (entry.header.extraLength) {
|
|
80
|
-
entry.extra = inBuffer.slice(tmp, (tmp += entry.header.extraLength));
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
if (entry.header.commentLength) entry.comment = inBuffer.slice(tmp, tmp + entry.header.commentLength);
|
|
84
|
-
|
|
85
|
-
index += entry.header.centralHeaderSize;
|
|
86
|
-
|
|
87
|
-
entryList[i] = entry;
|
|
88
|
-
entryTable[entry.entryName] = entry;
|
|
89
|
-
}
|
|
90
|
-
temporary.clear();
|
|
91
|
-
makeTemporaryFolders();
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
function readMainHeader(/*Boolean*/ readNow) {
|
|
95
|
-
var i = inBuffer.length - Utils.Constants.ENDHDR, // END header size
|
|
96
|
-
max = Math.max(0, i - 0xffff), // 0xFFFF is the max zip file comment length
|
|
97
|
-
n = max,
|
|
98
|
-
endStart = inBuffer.length,
|
|
99
|
-
endOffset = -1, // Start offset of the END header
|
|
100
|
-
commentEnd = 0;
|
|
101
|
-
|
|
102
|
-
// option to search header form entire file
|
|
103
|
-
const trailingSpace = typeof opts.trailingSpace === "boolean" ? opts.trailingSpace : false;
|
|
104
|
-
if (trailingSpace) max = 0;
|
|
105
|
-
|
|
106
|
-
for (i; i >= n; i--) {
|
|
107
|
-
if (inBuffer[i] !== 0x50) continue; // quick check that the byte is 'P'
|
|
108
|
-
if (inBuffer.readUInt32LE(i) === Utils.Constants.ENDSIG) {
|
|
109
|
-
// "PK\005\006"
|
|
110
|
-
endOffset = i;
|
|
111
|
-
commentEnd = i;
|
|
112
|
-
endStart = i + Utils.Constants.ENDHDR;
|
|
113
|
-
// We already found a regular signature, let's look just a bit further to check if there's any zip64 signature
|
|
114
|
-
n = i - Utils.Constants.END64HDR;
|
|
115
|
-
continue;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
if (inBuffer.readUInt32LE(i) === Utils.Constants.END64SIG) {
|
|
119
|
-
// Found a zip64 signature, let's continue reading the whole zip64 record
|
|
120
|
-
n = max;
|
|
121
|
-
continue;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
if (inBuffer.readUInt32LE(i) === Utils.Constants.ZIP64SIG) {
|
|
125
|
-
// Found the zip64 record, let's determine it's size
|
|
126
|
-
endOffset = i;
|
|
127
|
-
endStart = i + Utils.readBigUInt64LE(inBuffer, i + Utils.Constants.ZIP64SIZE) + Utils.Constants.ZIP64LEAD;
|
|
128
|
-
break;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
if (endOffset == -1) throw Utils.Errors.INVALID_FORMAT();
|
|
133
|
-
|
|
134
|
-
mainHeader.loadFromBinary(inBuffer.slice(endOffset, endStart));
|
|
135
|
-
if (mainHeader.commentLength) {
|
|
136
|
-
_comment = inBuffer.slice(commentEnd + Utils.Constants.ENDHDR);
|
|
137
|
-
}
|
|
138
|
-
if (readNow) readEntries();
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
function sortEntries() {
|
|
142
|
-
if (entryList.length > 1 && !noSort) {
|
|
143
|
-
entryList.sort((a, b) => a.entryName.toLowerCase().localeCompare(b.entryName.toLowerCase()));
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
return {
|
|
148
|
-
/**
|
|
149
|
-
* Returns an array of ZipEntry objects existent in the current opened archive
|
|
150
|
-
* @return Array
|
|
151
|
-
*/
|
|
152
|
-
get entries() {
|
|
153
|
-
if (!loadedEntries) {
|
|
154
|
-
readEntries();
|
|
155
|
-
}
|
|
156
|
-
return entryList.filter((e) => !temporary.has(e));
|
|
157
|
-
},
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* Archive comment
|
|
161
|
-
* @return {String}
|
|
162
|
-
*/
|
|
163
|
-
get comment() {
|
|
164
|
-
return decoder.decode(_comment);
|
|
165
|
-
},
|
|
166
|
-
set comment(val) {
|
|
167
|
-
_comment = Utils.toBuffer(val, decoder.encode);
|
|
168
|
-
mainHeader.commentLength = _comment.length;
|
|
169
|
-
},
|
|
170
|
-
|
|
171
|
-
getEntryCount: function () {
|
|
172
|
-
if (!loadedEntries) {
|
|
173
|
-
return mainHeader.diskEntries;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
return entryList.length;
|
|
177
|
-
},
|
|
178
|
-
|
|
179
|
-
forEach: function (callback) {
|
|
180
|
-
this.entries.forEach(callback);
|
|
181
|
-
},
|
|
182
|
-
|
|
183
|
-
/**
|
|
184
|
-
* Returns a reference to the entry with the given name or null if entry is inexistent
|
|
185
|
-
*
|
|
186
|
-
* @param entryName
|
|
187
|
-
* @return ZipEntry
|
|
188
|
-
*/
|
|
189
|
-
getEntry: function (/*String*/ entryName) {
|
|
190
|
-
if (!loadedEntries) {
|
|
191
|
-
readEntries();
|
|
192
|
-
}
|
|
193
|
-
return entryTable[entryName] || null;
|
|
194
|
-
},
|
|
195
|
-
|
|
196
|
-
/**
|
|
197
|
-
* Adds the given entry to the entry list
|
|
198
|
-
*
|
|
199
|
-
* @param entry
|
|
200
|
-
*/
|
|
201
|
-
setEntry: function (/*ZipEntry*/ entry) {
|
|
202
|
-
if (!loadedEntries) {
|
|
203
|
-
readEntries();
|
|
204
|
-
}
|
|
205
|
-
entryList.push(entry);
|
|
206
|
-
entryTable[entry.entryName] = entry;
|
|
207
|
-
mainHeader.totalEntries = entryList.length;
|
|
208
|
-
},
|
|
209
|
-
|
|
210
|
-
/**
|
|
211
|
-
* Removes the file with the given name from the entry list.
|
|
212
|
-
*
|
|
213
|
-
* If the entry is a directory, then all nested files and directories will be removed
|
|
214
|
-
* @param entryName
|
|
215
|
-
* @returns {void}
|
|
216
|
-
*/
|
|
217
|
-
deleteFile: function (/*String*/ entryName, withsubfolders = true) {
|
|
218
|
-
if (!loadedEntries) {
|
|
219
|
-
readEntries();
|
|
220
|
-
}
|
|
221
|
-
const entry = entryTable[entryName];
|
|
222
|
-
const list = this.getEntryChildren(entry, withsubfolders).map((child) => child.entryName);
|
|
223
|
-
|
|
224
|
-
list.forEach(this.deleteEntry);
|
|
225
|
-
},
|
|
226
|
-
|
|
227
|
-
/**
|
|
228
|
-
* Removes the entry with the given name from the entry list.
|
|
229
|
-
*
|
|
230
|
-
* @param {string} entryName
|
|
231
|
-
* @returns {void}
|
|
232
|
-
*/
|
|
233
|
-
deleteEntry: function (/*String*/ entryName) {
|
|
234
|
-
if (!loadedEntries) {
|
|
235
|
-
readEntries();
|
|
236
|
-
}
|
|
237
|
-
const entry = entryTable[entryName];
|
|
238
|
-
const index = entryList.indexOf(entry);
|
|
239
|
-
if (index >= 0) {
|
|
240
|
-
entryList.splice(index, 1);
|
|
241
|
-
delete entryTable[entryName];
|
|
242
|
-
mainHeader.totalEntries = entryList.length;
|
|
243
|
-
}
|
|
244
|
-
},
|
|
245
|
-
|
|
246
|
-
/**
|
|
247
|
-
* Iterates and returns all nested files and directories of the given entry
|
|
248
|
-
*
|
|
249
|
-
* @param entry
|
|
250
|
-
* @return Array
|
|
251
|
-
*/
|
|
252
|
-
getEntryChildren: function (/*ZipEntry*/ entry, subfolders = true) {
|
|
253
|
-
if (!loadedEntries) {
|
|
254
|
-
readEntries();
|
|
255
|
-
}
|
|
256
|
-
if (typeof entry === "object") {
|
|
257
|
-
if (entry.isDirectory && subfolders) {
|
|
258
|
-
const list = [];
|
|
259
|
-
const name = entry.entryName;
|
|
260
|
-
|
|
261
|
-
for (const zipEntry of entryList) {
|
|
262
|
-
if (zipEntry.entryName.startsWith(name)) {
|
|
263
|
-
list.push(zipEntry);
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
return list;
|
|
267
|
-
} else {
|
|
268
|
-
return [entry];
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
return [];
|
|
272
|
-
},
|
|
273
|
-
|
|
274
|
-
/**
|
|
275
|
-
* How many child elements entry has
|
|
276
|
-
*
|
|
277
|
-
* @param {ZipEntry} entry
|
|
278
|
-
* @return {integer}
|
|
279
|
-
*/
|
|
280
|
-
getChildCount: function (entry) {
|
|
281
|
-
if (entry && entry.isDirectory) {
|
|
282
|
-
const list = this.getEntryChildren(entry);
|
|
283
|
-
return list.includes(entry) ? list.length - 1 : list.length;
|
|
284
|
-
}
|
|
285
|
-
return 0;
|
|
286
|
-
},
|
|
287
|
-
|
|
288
|
-
/**
|
|
289
|
-
* Returns the zip file
|
|
290
|
-
*
|
|
291
|
-
* @return Buffer
|
|
292
|
-
*/
|
|
293
|
-
compressToBuffer: function () {
|
|
294
|
-
if (!loadedEntries) {
|
|
295
|
-
readEntries();
|
|
296
|
-
}
|
|
297
|
-
sortEntries();
|
|
298
|
-
|
|
299
|
-
const dataBlock = [];
|
|
300
|
-
const headerBlocks = [];
|
|
301
|
-
let totalSize = 0;
|
|
302
|
-
let dindex = 0;
|
|
303
|
-
|
|
304
|
-
mainHeader.size = 0;
|
|
305
|
-
mainHeader.offset = 0;
|
|
306
|
-
let totalEntries = 0;
|
|
307
|
-
|
|
308
|
-
for (const entry of this.entries) {
|
|
309
|
-
// compress data and set local and entry header accordingly. Reason why is called first
|
|
310
|
-
const compressedData = entry.getCompressedData();
|
|
311
|
-
entry.header.offset = dindex;
|
|
312
|
-
|
|
313
|
-
// 1. construct local header
|
|
314
|
-
const localHeader = entry.packLocalHeader();
|
|
315
|
-
|
|
316
|
-
// 2. offsets
|
|
317
|
-
const dataLength = localHeader.length + compressedData.length;
|
|
318
|
-
dindex += dataLength;
|
|
319
|
-
|
|
320
|
-
// 3. store values in sequence
|
|
321
|
-
dataBlock.push(localHeader);
|
|
322
|
-
dataBlock.push(compressedData);
|
|
323
|
-
|
|
324
|
-
// 4. construct central header
|
|
325
|
-
const centralHeader = entry.packCentralHeader();
|
|
326
|
-
headerBlocks.push(centralHeader);
|
|
327
|
-
// 5. update main header
|
|
328
|
-
mainHeader.size += centralHeader.length;
|
|
329
|
-
totalSize += dataLength + centralHeader.length;
|
|
330
|
-
totalEntries++;
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
totalSize += mainHeader.mainHeaderSize; // also includes zip file comment length
|
|
334
|
-
// point to end of data and beginning of central directory first record
|
|
335
|
-
mainHeader.offset = dindex;
|
|
336
|
-
mainHeader.totalEntries = totalEntries;
|
|
337
|
-
|
|
338
|
-
dindex = 0;
|
|
339
|
-
const outBuffer = Buffer.alloc(totalSize);
|
|
340
|
-
// write data blocks
|
|
341
|
-
for (const content of dataBlock) {
|
|
342
|
-
content.copy(outBuffer, dindex);
|
|
343
|
-
dindex += content.length;
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
// write central directory entries
|
|
347
|
-
for (const content of headerBlocks) {
|
|
348
|
-
content.copy(outBuffer, dindex);
|
|
349
|
-
dindex += content.length;
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
// write main header
|
|
353
|
-
const mh = mainHeader.toBinary();
|
|
354
|
-
if (_comment) {
|
|
355
|
-
_comment.copy(mh, Utils.Constants.ENDHDR); // add zip file comment
|
|
356
|
-
}
|
|
357
|
-
mh.copy(outBuffer, dindex);
|
|
358
|
-
|
|
359
|
-
// Since we update entry and main header offsets,
|
|
360
|
-
// they are no longer valid and we have to reset content
|
|
361
|
-
// (Issue 64)
|
|
362
|
-
|
|
363
|
-
inBuffer = outBuffer;
|
|
364
|
-
loadedEntries = false;
|
|
365
|
-
|
|
366
|
-
return outBuffer;
|
|
367
|
-
},
|
|
368
|
-
|
|
369
|
-
toAsyncBuffer: function (/*Function*/ onSuccess, /*Function*/ onFail, /*Function*/ onItemStart, /*Function*/ onItemEnd) {
|
|
370
|
-
try {
|
|
371
|
-
if (!loadedEntries) {
|
|
372
|
-
readEntries();
|
|
373
|
-
}
|
|
374
|
-
sortEntries();
|
|
375
|
-
|
|
376
|
-
const dataBlock = [];
|
|
377
|
-
const centralHeaders = [];
|
|
378
|
-
let totalSize = 0;
|
|
379
|
-
let dindex = 0;
|
|
380
|
-
let totalEntries = 0;
|
|
381
|
-
|
|
382
|
-
mainHeader.size = 0;
|
|
383
|
-
mainHeader.offset = 0;
|
|
384
|
-
|
|
385
|
-
const compress2Buffer = function (entryLists) {
|
|
386
|
-
if (entryLists.length > 0) {
|
|
387
|
-
const entry = entryLists.shift();
|
|
388
|
-
const name = entry.entryName + entry.extra.toString();
|
|
389
|
-
if (onItemStart) onItemStart(name);
|
|
390
|
-
entry.getCompressedDataAsync(function (compressedData) {
|
|
391
|
-
if (onItemEnd) onItemEnd(name);
|
|
392
|
-
entry.header.offset = dindex;
|
|
393
|
-
|
|
394
|
-
// 1. construct local header
|
|
395
|
-
const localHeader = entry.packLocalHeader();
|
|
396
|
-
|
|
397
|
-
// 2. offsets
|
|
398
|
-
const dataLength = localHeader.length + compressedData.length;
|
|
399
|
-
dindex += dataLength;
|
|
400
|
-
|
|
401
|
-
// 3. store values in sequence
|
|
402
|
-
dataBlock.push(localHeader);
|
|
403
|
-
dataBlock.push(compressedData);
|
|
404
|
-
|
|
405
|
-
// central header
|
|
406
|
-
const centalHeader = entry.packCentralHeader();
|
|
407
|
-
centralHeaders.push(centalHeader);
|
|
408
|
-
mainHeader.size += centalHeader.length;
|
|
409
|
-
totalSize += dataLength + centalHeader.length;
|
|
410
|
-
totalEntries++;
|
|
411
|
-
|
|
412
|
-
compress2Buffer(entryLists);
|
|
413
|
-
});
|
|
414
|
-
} else {
|
|
415
|
-
totalSize += mainHeader.mainHeaderSize; // also includes zip file comment length
|
|
416
|
-
// point to end of data and beginning of central directory first record
|
|
417
|
-
mainHeader.offset = dindex;
|
|
418
|
-
mainHeader.totalEntries = totalEntries;
|
|
419
|
-
|
|
420
|
-
dindex = 0;
|
|
421
|
-
const outBuffer = Buffer.alloc(totalSize);
|
|
422
|
-
dataBlock.forEach(function (content) {
|
|
423
|
-
content.copy(outBuffer, dindex); // write data blocks
|
|
424
|
-
dindex += content.length;
|
|
425
|
-
});
|
|
426
|
-
centralHeaders.forEach(function (content) {
|
|
427
|
-
content.copy(outBuffer, dindex); // write central directory entries
|
|
428
|
-
dindex += content.length;
|
|
429
|
-
});
|
|
430
|
-
|
|
431
|
-
const mh = mainHeader.toBinary();
|
|
432
|
-
if (_comment) {
|
|
433
|
-
_comment.copy(mh, Utils.Constants.ENDHDR); // add zip file comment
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
mh.copy(outBuffer, dindex); // write main header
|
|
437
|
-
|
|
438
|
-
// Since we update entry and main header offsets, they are no
|
|
439
|
-
// longer valid and we have to reset content using our new buffer
|
|
440
|
-
// (Issue 64)
|
|
441
|
-
|
|
442
|
-
inBuffer = outBuffer;
|
|
443
|
-
loadedEntries = false;
|
|
444
|
-
|
|
445
|
-
onSuccess(outBuffer);
|
|
446
|
-
}
|
|
447
|
-
};
|
|
448
|
-
|
|
449
|
-
compress2Buffer(Array.from(this.entries));
|
|
450
|
-
} catch (e) {
|
|
451
|
-
onFail(e);
|
|
452
|
-
}
|
|
453
|
-
}
|
|
454
|
-
};
|
|
455
|
-
👈-1;
|