ghc-proxy 0.3.0 → 0.3.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 +8 -8
- package/dist/GptEncoding-DuDWxow_.mjs +1134 -0
- package/dist/GptEncoding-DuDWxow_.mjs.map +1 -0
- package/dist/cl100k_base-YsziDpoU.mjs +101373 -0
- package/dist/cl100k_base-YsziDpoU.mjs.map +1 -0
- package/dist/file-type-BNd4XJK1.mjs +4527 -0
- package/dist/file-type-BNd4XJK1.mjs.map +1 -0
- package/dist/main.mjs +46895 -1323
- package/dist/main.mjs.map +1 -1
- package/dist/o200k_base-C_Bgi80R.mjs +204724 -0
- package/dist/o200k_base-C_Bgi80R.mjs.map +1 -0
- package/dist/p50k_base-DRo0AxsG.mjs +50482 -0
- package/dist/p50k_base-DRo0AxsG.mjs.map +1 -0
- package/dist/p50k_base-teVr-d1Y.mjs +10 -0
- package/dist/p50k_base-teVr-d1Y.mjs.map +1 -0
- package/dist/p50k_edit-nucqZWIv.mjs +10 -0
- package/dist/p50k_edit-nucqZWIv.mjs.map +1 -0
- package/dist/prompt-mE5xxWUf.mjs +848 -0
- package/dist/prompt-mE5xxWUf.mjs.map +1 -0
- package/dist/r50k_base-B2MFjxES.mjs +50464 -0
- package/dist/r50k_base-B2MFjxES.mjs.map +1 -0
- package/package.json +7 -7
|
@@ -0,0 +1,4527 @@
|
|
|
1
|
+
import { i as __toESM, r as __require, t as __commonJSMin } from "./main.mjs";
|
|
2
|
+
import { open } from "node:fs/promises";
|
|
3
|
+
import { PassThrough, Readable } from "node:stream";
|
|
4
|
+
|
|
5
|
+
//#region node_modules/strtok3/lib/stream/Errors.js
|
|
6
|
+
const defaultMessages = "End-Of-Stream";
|
|
7
|
+
/**
|
|
8
|
+
* Thrown on read operation of the end of file or stream has been reached
|
|
9
|
+
*/
|
|
10
|
+
var EndOfStreamError = class extends Error {
|
|
11
|
+
constructor() {
|
|
12
|
+
super(defaultMessages);
|
|
13
|
+
this.name = "EndOfStreamError";
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
var AbortError = class extends Error {
|
|
17
|
+
constructor(message = "The operation was aborted") {
|
|
18
|
+
super(message);
|
|
19
|
+
this.name = "AbortError";
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
//#region node_modules/strtok3/lib/stream/AbstractStreamReader.js
|
|
25
|
+
var AbstractStreamReader = class {
|
|
26
|
+
constructor() {
|
|
27
|
+
this.endOfStream = false;
|
|
28
|
+
this.interrupted = false;
|
|
29
|
+
/**
|
|
30
|
+
* Store peeked data
|
|
31
|
+
* @type {Array}
|
|
32
|
+
*/
|
|
33
|
+
this.peekQueue = [];
|
|
34
|
+
}
|
|
35
|
+
async peek(uint8Array, mayBeLess = false) {
|
|
36
|
+
const bytesRead = await this.read(uint8Array, mayBeLess);
|
|
37
|
+
this.peekQueue.push(uint8Array.subarray(0, bytesRead));
|
|
38
|
+
return bytesRead;
|
|
39
|
+
}
|
|
40
|
+
async read(buffer, mayBeLess = false) {
|
|
41
|
+
if (buffer.length === 0) return 0;
|
|
42
|
+
let bytesRead = this.readFromPeekBuffer(buffer);
|
|
43
|
+
if (!this.endOfStream) bytesRead += await this.readRemainderFromStream(buffer.subarray(bytesRead), mayBeLess);
|
|
44
|
+
if (bytesRead === 0 && !mayBeLess) throw new EndOfStreamError();
|
|
45
|
+
return bytesRead;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Read chunk from stream
|
|
49
|
+
* @param buffer - Target Uint8Array (or Buffer) to store data read from stream in
|
|
50
|
+
* @returns Number of bytes read
|
|
51
|
+
*/
|
|
52
|
+
readFromPeekBuffer(buffer) {
|
|
53
|
+
let remaining = buffer.length;
|
|
54
|
+
let bytesRead = 0;
|
|
55
|
+
while (this.peekQueue.length > 0 && remaining > 0) {
|
|
56
|
+
const peekData = this.peekQueue.pop();
|
|
57
|
+
if (!peekData) throw new Error("peekData should be defined");
|
|
58
|
+
const lenCopy = Math.min(peekData.length, remaining);
|
|
59
|
+
buffer.set(peekData.subarray(0, lenCopy), bytesRead);
|
|
60
|
+
bytesRead += lenCopy;
|
|
61
|
+
remaining -= lenCopy;
|
|
62
|
+
if (lenCopy < peekData.length) this.peekQueue.push(peekData.subarray(lenCopy));
|
|
63
|
+
}
|
|
64
|
+
return bytesRead;
|
|
65
|
+
}
|
|
66
|
+
async readRemainderFromStream(buffer, mayBeLess) {
|
|
67
|
+
let bytesRead = 0;
|
|
68
|
+
while (bytesRead < buffer.length && !this.endOfStream) {
|
|
69
|
+
if (this.interrupted) throw new AbortError();
|
|
70
|
+
const chunkLen = await this.readFromStream(buffer.subarray(bytesRead), mayBeLess);
|
|
71
|
+
if (chunkLen === 0) break;
|
|
72
|
+
bytesRead += chunkLen;
|
|
73
|
+
}
|
|
74
|
+
if (!mayBeLess && bytesRead < buffer.length) throw new EndOfStreamError();
|
|
75
|
+
return bytesRead;
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
//#endregion
|
|
80
|
+
//#region node_modules/strtok3/lib/stream/WebStreamReader.js
|
|
81
|
+
var WebStreamReader = class extends AbstractStreamReader {
|
|
82
|
+
constructor(reader) {
|
|
83
|
+
super();
|
|
84
|
+
this.reader = reader;
|
|
85
|
+
}
|
|
86
|
+
async abort() {
|
|
87
|
+
return this.close();
|
|
88
|
+
}
|
|
89
|
+
async close() {
|
|
90
|
+
this.reader.releaseLock();
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
//#endregion
|
|
95
|
+
//#region node_modules/strtok3/lib/stream/WebStreamByobReader.js
|
|
96
|
+
/**
|
|
97
|
+
* Read from a WebStream using a BYOB reader
|
|
98
|
+
* Reference: https://nodejs.org/api/webstreams.html#class-readablestreambyobreader
|
|
99
|
+
*/
|
|
100
|
+
var WebStreamByobReader = class extends WebStreamReader {
|
|
101
|
+
/**
|
|
102
|
+
* Read from stream
|
|
103
|
+
* @param buffer - Target Uint8Array (or Buffer) to store data read from stream in
|
|
104
|
+
* @param mayBeLess - If true, may fill the buffer partially
|
|
105
|
+
* @protected Bytes read
|
|
106
|
+
*/
|
|
107
|
+
async readFromStream(buffer, mayBeLess) {
|
|
108
|
+
if (buffer.length === 0) return 0;
|
|
109
|
+
const result = await this.reader.read(new Uint8Array(buffer.length), { min: mayBeLess ? void 0 : buffer.length });
|
|
110
|
+
if (result.done) this.endOfStream = result.done;
|
|
111
|
+
if (result.value) {
|
|
112
|
+
buffer.set(result.value);
|
|
113
|
+
return result.value.length;
|
|
114
|
+
}
|
|
115
|
+
return 0;
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
//#endregion
|
|
120
|
+
//#region node_modules/strtok3/lib/stream/WebStreamDefaultReader.js
|
|
121
|
+
var WebStreamDefaultReader = class extends AbstractStreamReader {
|
|
122
|
+
constructor(reader) {
|
|
123
|
+
super();
|
|
124
|
+
this.reader = reader;
|
|
125
|
+
this.buffer = null;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Copy chunk to target, and store the remainder in this.buffer
|
|
129
|
+
*/
|
|
130
|
+
writeChunk(target, chunk) {
|
|
131
|
+
const written = Math.min(chunk.length, target.length);
|
|
132
|
+
target.set(chunk.subarray(0, written));
|
|
133
|
+
if (written < chunk.length) this.buffer = chunk.subarray(written);
|
|
134
|
+
else this.buffer = null;
|
|
135
|
+
return written;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Read from stream
|
|
139
|
+
* @param buffer - Target Uint8Array (or Buffer) to store data read from stream in
|
|
140
|
+
* @param mayBeLess - If true, may fill the buffer partially
|
|
141
|
+
* @protected Bytes read
|
|
142
|
+
*/
|
|
143
|
+
async readFromStream(buffer, mayBeLess) {
|
|
144
|
+
if (buffer.length === 0) return 0;
|
|
145
|
+
let totalBytesRead = 0;
|
|
146
|
+
if (this.buffer) totalBytesRead += this.writeChunk(buffer, this.buffer);
|
|
147
|
+
while (totalBytesRead < buffer.length && !this.endOfStream) {
|
|
148
|
+
const result = await this.reader.read();
|
|
149
|
+
if (result.done) {
|
|
150
|
+
this.endOfStream = true;
|
|
151
|
+
break;
|
|
152
|
+
}
|
|
153
|
+
if (result.value) totalBytesRead += this.writeChunk(buffer.subarray(totalBytesRead), result.value);
|
|
154
|
+
}
|
|
155
|
+
if (!mayBeLess && totalBytesRead === 0 && this.endOfStream) throw new EndOfStreamError();
|
|
156
|
+
return totalBytesRead;
|
|
157
|
+
}
|
|
158
|
+
abort() {
|
|
159
|
+
this.interrupted = true;
|
|
160
|
+
return this.reader.cancel();
|
|
161
|
+
}
|
|
162
|
+
async close() {
|
|
163
|
+
await this.abort();
|
|
164
|
+
this.reader.releaseLock();
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
//#endregion
|
|
169
|
+
//#region node_modules/strtok3/lib/stream/WebStreamReaderFactory.js
|
|
170
|
+
function makeWebStreamReader(stream) {
|
|
171
|
+
try {
|
|
172
|
+
const reader = stream.getReader({ mode: "byob" });
|
|
173
|
+
if (reader instanceof ReadableStreamDefaultReader) return new WebStreamDefaultReader(reader);
|
|
174
|
+
return new WebStreamByobReader(reader);
|
|
175
|
+
} catch (error) {
|
|
176
|
+
if (error instanceof TypeError) return new WebStreamDefaultReader(stream.getReader());
|
|
177
|
+
throw error;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
//#endregion
|
|
182
|
+
//#region node_modules/strtok3/lib/AbstractTokenizer.js
|
|
183
|
+
/**
|
|
184
|
+
* Core tokenizer
|
|
185
|
+
*/
|
|
186
|
+
var AbstractTokenizer = class {
|
|
187
|
+
/**
|
|
188
|
+
* Constructor
|
|
189
|
+
* @param options Tokenizer options
|
|
190
|
+
* @protected
|
|
191
|
+
*/
|
|
192
|
+
constructor(options) {
|
|
193
|
+
this.numBuffer = new Uint8Array(8);
|
|
194
|
+
/**
|
|
195
|
+
* Tokenizer-stream position
|
|
196
|
+
*/
|
|
197
|
+
this.position = 0;
|
|
198
|
+
this.onClose = options?.onClose;
|
|
199
|
+
if (options?.abortSignal) options.abortSignal.addEventListener("abort", () => {
|
|
200
|
+
this.abort();
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Read a token from the tokenizer-stream
|
|
205
|
+
* @param token - The token to read
|
|
206
|
+
* @param position - If provided, the desired position in the tokenizer-stream
|
|
207
|
+
* @returns Promise with token data
|
|
208
|
+
*/
|
|
209
|
+
async readToken(token, position = this.position) {
|
|
210
|
+
const uint8Array = new Uint8Array(token.len);
|
|
211
|
+
if (await this.readBuffer(uint8Array, { position }) < token.len) throw new EndOfStreamError();
|
|
212
|
+
return token.get(uint8Array, 0);
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Peek a token from the tokenizer-stream.
|
|
216
|
+
* @param token - Token to peek from the tokenizer-stream.
|
|
217
|
+
* @param position - Offset where to begin reading within the file. If position is null, data will be read from the current file position.
|
|
218
|
+
* @returns Promise with token data
|
|
219
|
+
*/
|
|
220
|
+
async peekToken(token, position = this.position) {
|
|
221
|
+
const uint8Array = new Uint8Array(token.len);
|
|
222
|
+
if (await this.peekBuffer(uint8Array, { position }) < token.len) throw new EndOfStreamError();
|
|
223
|
+
return token.get(uint8Array, 0);
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Read a numeric token from the stream
|
|
227
|
+
* @param token - Numeric token
|
|
228
|
+
* @returns Promise with number
|
|
229
|
+
*/
|
|
230
|
+
async readNumber(token) {
|
|
231
|
+
if (await this.readBuffer(this.numBuffer, { length: token.len }) < token.len) throw new EndOfStreamError();
|
|
232
|
+
return token.get(this.numBuffer, 0);
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Read a numeric token from the stream
|
|
236
|
+
* @param token - Numeric token
|
|
237
|
+
* @returns Promise with number
|
|
238
|
+
*/
|
|
239
|
+
async peekNumber(token) {
|
|
240
|
+
if (await this.peekBuffer(this.numBuffer, { length: token.len }) < token.len) throw new EndOfStreamError();
|
|
241
|
+
return token.get(this.numBuffer, 0);
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Ignore number of bytes, advances the pointer in under tokenizer-stream.
|
|
245
|
+
* @param length - Number of bytes to ignore
|
|
246
|
+
* @return resolves the number of bytes ignored, equals length if this available, otherwise the number of bytes available
|
|
247
|
+
*/
|
|
248
|
+
async ignore(length) {
|
|
249
|
+
if (this.fileInfo.size !== void 0) {
|
|
250
|
+
const bytesLeft = this.fileInfo.size - this.position;
|
|
251
|
+
if (length > bytesLeft) {
|
|
252
|
+
this.position += bytesLeft;
|
|
253
|
+
return bytesLeft;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
this.position += length;
|
|
257
|
+
return length;
|
|
258
|
+
}
|
|
259
|
+
async close() {
|
|
260
|
+
await this.abort();
|
|
261
|
+
await this.onClose?.();
|
|
262
|
+
}
|
|
263
|
+
normalizeOptions(uint8Array, options) {
|
|
264
|
+
if (!this.supportsRandomAccess() && options && options.position !== void 0 && options.position < this.position) throw new Error("`options.position` must be equal or greater than `tokenizer.position`");
|
|
265
|
+
return {
|
|
266
|
+
mayBeLess: false,
|
|
267
|
+
offset: 0,
|
|
268
|
+
length: uint8Array.length,
|
|
269
|
+
position: this.position,
|
|
270
|
+
...options
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
abort() {
|
|
274
|
+
return Promise.resolve();
|
|
275
|
+
}
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
//#endregion
|
|
279
|
+
//#region node_modules/strtok3/lib/ReadStreamTokenizer.js
|
|
280
|
+
const maxBufferSize = 256e3;
|
|
281
|
+
var ReadStreamTokenizer = class extends AbstractTokenizer {
|
|
282
|
+
/**
|
|
283
|
+
* Constructor
|
|
284
|
+
* @param streamReader stream-reader to read from
|
|
285
|
+
* @param options Tokenizer options
|
|
286
|
+
*/
|
|
287
|
+
constructor(streamReader, options) {
|
|
288
|
+
super(options);
|
|
289
|
+
this.streamReader = streamReader;
|
|
290
|
+
this.fileInfo = options?.fileInfo ?? {};
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Read buffer from tokenizer
|
|
294
|
+
* @param uint8Array - Target Uint8Array to fill with data read from the tokenizer-stream
|
|
295
|
+
* @param options - Read behaviour options
|
|
296
|
+
* @returns Promise with number of bytes read
|
|
297
|
+
*/
|
|
298
|
+
async readBuffer(uint8Array, options) {
|
|
299
|
+
const normOptions = this.normalizeOptions(uint8Array, options);
|
|
300
|
+
const skipBytes = normOptions.position - this.position;
|
|
301
|
+
if (skipBytes > 0) {
|
|
302
|
+
await this.ignore(skipBytes);
|
|
303
|
+
return this.readBuffer(uint8Array, options);
|
|
304
|
+
}
|
|
305
|
+
if (skipBytes < 0) throw new Error("`options.position` must be equal or greater than `tokenizer.position`");
|
|
306
|
+
if (normOptions.length === 0) return 0;
|
|
307
|
+
const bytesRead = await this.streamReader.read(uint8Array.subarray(0, normOptions.length), normOptions.mayBeLess);
|
|
308
|
+
this.position += bytesRead;
|
|
309
|
+
if ((!options || !options.mayBeLess) && bytesRead < normOptions.length) throw new EndOfStreamError();
|
|
310
|
+
return bytesRead;
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Peek (read ahead) buffer from tokenizer
|
|
314
|
+
* @param uint8Array - Uint8Array (or Buffer) to write data to
|
|
315
|
+
* @param options - Read behaviour options
|
|
316
|
+
* @returns Promise with number of bytes peeked
|
|
317
|
+
*/
|
|
318
|
+
async peekBuffer(uint8Array, options) {
|
|
319
|
+
const normOptions = this.normalizeOptions(uint8Array, options);
|
|
320
|
+
let bytesRead = 0;
|
|
321
|
+
if (normOptions.position) {
|
|
322
|
+
const skipBytes = normOptions.position - this.position;
|
|
323
|
+
if (skipBytes > 0) {
|
|
324
|
+
const skipBuffer = new Uint8Array(normOptions.length + skipBytes);
|
|
325
|
+
bytesRead = await this.peekBuffer(skipBuffer, { mayBeLess: normOptions.mayBeLess });
|
|
326
|
+
uint8Array.set(skipBuffer.subarray(skipBytes));
|
|
327
|
+
return bytesRead - skipBytes;
|
|
328
|
+
}
|
|
329
|
+
if (skipBytes < 0) throw new Error("Cannot peek from a negative offset in a stream");
|
|
330
|
+
}
|
|
331
|
+
if (normOptions.length > 0) {
|
|
332
|
+
try {
|
|
333
|
+
bytesRead = await this.streamReader.peek(uint8Array.subarray(0, normOptions.length), normOptions.mayBeLess);
|
|
334
|
+
} catch (err) {
|
|
335
|
+
if (options?.mayBeLess && err instanceof EndOfStreamError) return 0;
|
|
336
|
+
throw err;
|
|
337
|
+
}
|
|
338
|
+
if (!normOptions.mayBeLess && bytesRead < normOptions.length) throw new EndOfStreamError();
|
|
339
|
+
}
|
|
340
|
+
return bytesRead;
|
|
341
|
+
}
|
|
342
|
+
async ignore(length) {
|
|
343
|
+
const bufSize = Math.min(maxBufferSize, length);
|
|
344
|
+
const buf = new Uint8Array(bufSize);
|
|
345
|
+
let totBytesRead = 0;
|
|
346
|
+
while (totBytesRead < length) {
|
|
347
|
+
const remaining = length - totBytesRead;
|
|
348
|
+
const bytesRead = await this.readBuffer(buf, { length: Math.min(bufSize, remaining) });
|
|
349
|
+
if (bytesRead < 0) return bytesRead;
|
|
350
|
+
totBytesRead += bytesRead;
|
|
351
|
+
}
|
|
352
|
+
return totBytesRead;
|
|
353
|
+
}
|
|
354
|
+
abort() {
|
|
355
|
+
return this.streamReader.abort();
|
|
356
|
+
}
|
|
357
|
+
async close() {
|
|
358
|
+
return this.streamReader.close();
|
|
359
|
+
}
|
|
360
|
+
supportsRandomAccess() {
|
|
361
|
+
return false;
|
|
362
|
+
}
|
|
363
|
+
};
|
|
364
|
+
|
|
365
|
+
//#endregion
|
|
366
|
+
//#region node_modules/strtok3/lib/BufferTokenizer.js
|
|
367
|
+
var BufferTokenizer = class extends AbstractTokenizer {
|
|
368
|
+
/**
|
|
369
|
+
* Construct BufferTokenizer
|
|
370
|
+
* @param uint8Array - Uint8Array to tokenize
|
|
371
|
+
* @param options Tokenizer options
|
|
372
|
+
*/
|
|
373
|
+
constructor(uint8Array, options) {
|
|
374
|
+
super(options);
|
|
375
|
+
this.uint8Array = uint8Array;
|
|
376
|
+
this.fileInfo = {
|
|
377
|
+
...options?.fileInfo ?? {},
|
|
378
|
+
size: uint8Array.length
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* Read buffer from tokenizer
|
|
383
|
+
* @param uint8Array - Uint8Array to tokenize
|
|
384
|
+
* @param options - Read behaviour options
|
|
385
|
+
* @returns {Promise<number>}
|
|
386
|
+
*/
|
|
387
|
+
async readBuffer(uint8Array, options) {
|
|
388
|
+
if (options?.position) this.position = options.position;
|
|
389
|
+
const bytesRead = await this.peekBuffer(uint8Array, options);
|
|
390
|
+
this.position += bytesRead;
|
|
391
|
+
return bytesRead;
|
|
392
|
+
}
|
|
393
|
+
/**
|
|
394
|
+
* Peek (read ahead) buffer from tokenizer
|
|
395
|
+
* @param uint8Array
|
|
396
|
+
* @param options - Read behaviour options
|
|
397
|
+
* @returns {Promise<number>}
|
|
398
|
+
*/
|
|
399
|
+
async peekBuffer(uint8Array, options) {
|
|
400
|
+
const normOptions = this.normalizeOptions(uint8Array, options);
|
|
401
|
+
const bytes2read = Math.min(this.uint8Array.length - normOptions.position, normOptions.length);
|
|
402
|
+
if (!normOptions.mayBeLess && bytes2read < normOptions.length) throw new EndOfStreamError();
|
|
403
|
+
uint8Array.set(this.uint8Array.subarray(normOptions.position, normOptions.position + bytes2read));
|
|
404
|
+
return bytes2read;
|
|
405
|
+
}
|
|
406
|
+
close() {
|
|
407
|
+
return super.close();
|
|
408
|
+
}
|
|
409
|
+
supportsRandomAccess() {
|
|
410
|
+
return true;
|
|
411
|
+
}
|
|
412
|
+
setPosition(position) {
|
|
413
|
+
this.position = position;
|
|
414
|
+
}
|
|
415
|
+
};
|
|
416
|
+
|
|
417
|
+
//#endregion
|
|
418
|
+
//#region node_modules/strtok3/lib/BlobTokenizer.js
|
|
419
|
+
var BlobTokenizer = class extends AbstractTokenizer {
|
|
420
|
+
/**
|
|
421
|
+
* Construct BufferTokenizer
|
|
422
|
+
* @param blob - Uint8Array to tokenize
|
|
423
|
+
* @param options Tokenizer options
|
|
424
|
+
*/
|
|
425
|
+
constructor(blob, options) {
|
|
426
|
+
super(options);
|
|
427
|
+
this.blob = blob;
|
|
428
|
+
this.fileInfo = {
|
|
429
|
+
...options?.fileInfo ?? {},
|
|
430
|
+
size: blob.size,
|
|
431
|
+
mimeType: blob.type
|
|
432
|
+
};
|
|
433
|
+
}
|
|
434
|
+
/**
|
|
435
|
+
* Read buffer from tokenizer
|
|
436
|
+
* @param uint8Array - Uint8Array to tokenize
|
|
437
|
+
* @param options - Read behaviour options
|
|
438
|
+
* @returns {Promise<number>}
|
|
439
|
+
*/
|
|
440
|
+
async readBuffer(uint8Array, options) {
|
|
441
|
+
if (options?.position) this.position = options.position;
|
|
442
|
+
const bytesRead = await this.peekBuffer(uint8Array, options);
|
|
443
|
+
this.position += bytesRead;
|
|
444
|
+
return bytesRead;
|
|
445
|
+
}
|
|
446
|
+
/**
|
|
447
|
+
* Peek (read ahead) buffer from tokenizer
|
|
448
|
+
* @param buffer
|
|
449
|
+
* @param options - Read behaviour options
|
|
450
|
+
* @returns {Promise<number>}
|
|
451
|
+
*/
|
|
452
|
+
async peekBuffer(buffer, options) {
|
|
453
|
+
const normOptions = this.normalizeOptions(buffer, options);
|
|
454
|
+
const bytes2read = Math.min(this.blob.size - normOptions.position, normOptions.length);
|
|
455
|
+
if (!normOptions.mayBeLess && bytes2read < normOptions.length) throw new EndOfStreamError();
|
|
456
|
+
const arrayBuffer = await this.blob.slice(normOptions.position, normOptions.position + bytes2read).arrayBuffer();
|
|
457
|
+
buffer.set(new Uint8Array(arrayBuffer));
|
|
458
|
+
return bytes2read;
|
|
459
|
+
}
|
|
460
|
+
close() {
|
|
461
|
+
return super.close();
|
|
462
|
+
}
|
|
463
|
+
supportsRandomAccess() {
|
|
464
|
+
return true;
|
|
465
|
+
}
|
|
466
|
+
setPosition(position) {
|
|
467
|
+
this.position = position;
|
|
468
|
+
}
|
|
469
|
+
};
|
|
470
|
+
|
|
471
|
+
//#endregion
|
|
472
|
+
//#region node_modules/strtok3/lib/core.js
|
|
473
|
+
/**
|
|
474
|
+
* Construct ReadStreamTokenizer from given ReadableStream (WebStream API).
|
|
475
|
+
* Will set fileSize, if provided given Stream has set the .path property/
|
|
476
|
+
* @param webStream - Read from Node.js Stream.Readable (must be a byte stream)
|
|
477
|
+
* @param options - Tokenizer options
|
|
478
|
+
* @returns ReadStreamTokenizer
|
|
479
|
+
*/
|
|
480
|
+
function fromWebStream(webStream, options) {
|
|
481
|
+
const webStreamReader = makeWebStreamReader(webStream);
|
|
482
|
+
const _options = options ?? {};
|
|
483
|
+
const chainedClose = _options.onClose;
|
|
484
|
+
_options.onClose = async () => {
|
|
485
|
+
await webStreamReader.close();
|
|
486
|
+
if (chainedClose) return chainedClose();
|
|
487
|
+
};
|
|
488
|
+
return new ReadStreamTokenizer(webStreamReader, _options);
|
|
489
|
+
}
|
|
490
|
+
/**
|
|
491
|
+
* Construct ReadStreamTokenizer from given Buffer.
|
|
492
|
+
* @param uint8Array - Uint8Array to tokenize
|
|
493
|
+
* @param options - Tokenizer options
|
|
494
|
+
* @returns BufferTokenizer
|
|
495
|
+
*/
|
|
496
|
+
function fromBuffer(uint8Array, options) {
|
|
497
|
+
return new BufferTokenizer(uint8Array, options);
|
|
498
|
+
}
|
|
499
|
+
/**
|
|
500
|
+
* Construct ReadStreamTokenizer from given Blob.
|
|
501
|
+
* @param blob - Uint8Array to tokenize
|
|
502
|
+
* @param options - Tokenizer options
|
|
503
|
+
* @returns BufferTokenizer
|
|
504
|
+
*/
|
|
505
|
+
function fromBlob(blob, options) {
|
|
506
|
+
return new BlobTokenizer(blob, options);
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
//#endregion
|
|
510
|
+
//#region node_modules/strtok3/lib/FileTokenizer.js
|
|
511
|
+
var FileTokenizer = class FileTokenizer extends AbstractTokenizer {
|
|
512
|
+
/**
|
|
513
|
+
* Create tokenizer from provided file path
|
|
514
|
+
* @param sourceFilePath File path
|
|
515
|
+
*/
|
|
516
|
+
static async fromFile(sourceFilePath) {
|
|
517
|
+
const fileHandle = await open(sourceFilePath, "r");
|
|
518
|
+
return new FileTokenizer(fileHandle, { fileInfo: {
|
|
519
|
+
path: sourceFilePath,
|
|
520
|
+
size: (await fileHandle.stat()).size
|
|
521
|
+
} });
|
|
522
|
+
}
|
|
523
|
+
constructor(fileHandle, options) {
|
|
524
|
+
super(options);
|
|
525
|
+
this.fileHandle = fileHandle;
|
|
526
|
+
this.fileInfo = options.fileInfo;
|
|
527
|
+
}
|
|
528
|
+
/**
|
|
529
|
+
* Read buffer from file
|
|
530
|
+
* @param uint8Array - Uint8Array to write result to
|
|
531
|
+
* @param options - Read behaviour options
|
|
532
|
+
* @returns Promise number of bytes read
|
|
533
|
+
*/
|
|
534
|
+
async readBuffer(uint8Array, options) {
|
|
535
|
+
const normOptions = this.normalizeOptions(uint8Array, options);
|
|
536
|
+
this.position = normOptions.position;
|
|
537
|
+
if (normOptions.length === 0) return 0;
|
|
538
|
+
const res = await this.fileHandle.read(uint8Array, 0, normOptions.length, normOptions.position);
|
|
539
|
+
this.position += res.bytesRead;
|
|
540
|
+
if (res.bytesRead < normOptions.length && (!options || !options.mayBeLess)) throw new EndOfStreamError();
|
|
541
|
+
return res.bytesRead;
|
|
542
|
+
}
|
|
543
|
+
/**
|
|
544
|
+
* Peek buffer from file
|
|
545
|
+
* @param uint8Array - Uint8Array (or Buffer) to write data to
|
|
546
|
+
* @param options - Read behaviour options
|
|
547
|
+
* @returns Promise number of bytes read
|
|
548
|
+
*/
|
|
549
|
+
async peekBuffer(uint8Array, options) {
|
|
550
|
+
const normOptions = this.normalizeOptions(uint8Array, options);
|
|
551
|
+
const res = await this.fileHandle.read(uint8Array, 0, normOptions.length, normOptions.position);
|
|
552
|
+
if (!normOptions.mayBeLess && res.bytesRead < normOptions.length) throw new EndOfStreamError();
|
|
553
|
+
return res.bytesRead;
|
|
554
|
+
}
|
|
555
|
+
async close() {
|
|
556
|
+
await this.fileHandle.close();
|
|
557
|
+
return super.close();
|
|
558
|
+
}
|
|
559
|
+
setPosition(position) {
|
|
560
|
+
this.position = position;
|
|
561
|
+
}
|
|
562
|
+
supportsRandomAccess() {
|
|
563
|
+
return true;
|
|
564
|
+
}
|
|
565
|
+
};
|
|
566
|
+
|
|
567
|
+
//#endregion
|
|
568
|
+
//#region node_modules/strtok3/lib/index.js
|
|
569
|
+
const fromFile = FileTokenizer.fromFile;
|
|
570
|
+
|
|
571
|
+
//#endregion
|
|
572
|
+
//#region node_modules/@borewit/text-codec/lib/index.js
|
|
573
|
+
const WINDOWS_1252_EXTRA = {
|
|
574
|
+
128: "€",
|
|
575
|
+
130: "‚",
|
|
576
|
+
131: "ƒ",
|
|
577
|
+
132: "„",
|
|
578
|
+
133: "…",
|
|
579
|
+
134: "†",
|
|
580
|
+
135: "‡",
|
|
581
|
+
136: "ˆ",
|
|
582
|
+
137: "‰",
|
|
583
|
+
138: "Š",
|
|
584
|
+
139: "‹",
|
|
585
|
+
140: "Œ",
|
|
586
|
+
142: "Ž",
|
|
587
|
+
145: "‘",
|
|
588
|
+
146: "’",
|
|
589
|
+
147: "“",
|
|
590
|
+
148: "”",
|
|
591
|
+
149: "•",
|
|
592
|
+
150: "–",
|
|
593
|
+
151: "—",
|
|
594
|
+
152: "˜",
|
|
595
|
+
153: "™",
|
|
596
|
+
154: "š",
|
|
597
|
+
155: "›",
|
|
598
|
+
156: "œ",
|
|
599
|
+
158: "ž",
|
|
600
|
+
159: "Ÿ"
|
|
601
|
+
};
|
|
602
|
+
const WINDOWS_1252_REVERSE = {};
|
|
603
|
+
for (const [code, char] of Object.entries(WINDOWS_1252_EXTRA)) WINDOWS_1252_REVERSE[char] = Number.parseInt(code, 10);
|
|
604
|
+
let _utf8Decoder;
|
|
605
|
+
function utf8Decoder() {
|
|
606
|
+
if (typeof globalThis.TextDecoder === "undefined") return void 0;
|
|
607
|
+
return _utf8Decoder !== null && _utf8Decoder !== void 0 ? _utf8Decoder : _utf8Decoder = new globalThis.TextDecoder("utf-8");
|
|
608
|
+
}
|
|
609
|
+
const CHUNK = 32 * 1024;
|
|
610
|
+
const REPLACEMENT = 65533;
|
|
611
|
+
/**
|
|
612
|
+
* Decode text from binary data
|
|
613
|
+
*/
|
|
614
|
+
function textDecode(bytes, encoding = "utf-8") {
|
|
615
|
+
switch (encoding.toLowerCase()) {
|
|
616
|
+
case "utf-8":
|
|
617
|
+
case "utf8": {
|
|
618
|
+
const dec = utf8Decoder();
|
|
619
|
+
return dec ? dec.decode(bytes) : decodeUTF8(bytes);
|
|
620
|
+
}
|
|
621
|
+
case "utf-16le": return decodeUTF16LE(bytes);
|
|
622
|
+
case "us-ascii":
|
|
623
|
+
case "ascii": return decodeASCII(bytes);
|
|
624
|
+
case "latin1":
|
|
625
|
+
case "iso-8859-1": return decodeLatin1(bytes);
|
|
626
|
+
case "windows-1252": return decodeWindows1252(bytes);
|
|
627
|
+
default: throw new RangeError(`Encoding '${encoding}' not supported`);
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
function flushChunk(parts, chunk) {
|
|
631
|
+
if (chunk.length === 0) return;
|
|
632
|
+
parts.push(String.fromCharCode.apply(null, chunk));
|
|
633
|
+
chunk.length = 0;
|
|
634
|
+
}
|
|
635
|
+
function pushCodeUnit(parts, chunk, codeUnit) {
|
|
636
|
+
chunk.push(codeUnit);
|
|
637
|
+
if (chunk.length >= CHUNK) flushChunk(parts, chunk);
|
|
638
|
+
}
|
|
639
|
+
function pushCodePoint(parts, chunk, cp) {
|
|
640
|
+
if (cp <= 65535) {
|
|
641
|
+
pushCodeUnit(parts, chunk, cp);
|
|
642
|
+
return;
|
|
643
|
+
}
|
|
644
|
+
cp -= 65536;
|
|
645
|
+
pushCodeUnit(parts, chunk, 55296 + (cp >> 10));
|
|
646
|
+
pushCodeUnit(parts, chunk, 56320 + (cp & 1023));
|
|
647
|
+
}
|
|
648
|
+
function decodeUTF8(bytes) {
|
|
649
|
+
const parts = [];
|
|
650
|
+
const chunk = [];
|
|
651
|
+
let i = 0;
|
|
652
|
+
if (bytes.length >= 3 && bytes[0] === 239 && bytes[1] === 187 && bytes[2] === 191) i = 3;
|
|
653
|
+
while (i < bytes.length) {
|
|
654
|
+
const b1 = bytes[i];
|
|
655
|
+
if (b1 <= 127) {
|
|
656
|
+
pushCodeUnit(parts, chunk, b1);
|
|
657
|
+
i++;
|
|
658
|
+
continue;
|
|
659
|
+
}
|
|
660
|
+
if (b1 < 194 || b1 > 244) {
|
|
661
|
+
pushCodeUnit(parts, chunk, REPLACEMENT);
|
|
662
|
+
i++;
|
|
663
|
+
continue;
|
|
664
|
+
}
|
|
665
|
+
if (b1 <= 223) {
|
|
666
|
+
if (i + 1 >= bytes.length) {
|
|
667
|
+
pushCodeUnit(parts, chunk, REPLACEMENT);
|
|
668
|
+
i++;
|
|
669
|
+
continue;
|
|
670
|
+
}
|
|
671
|
+
const b2 = bytes[i + 1];
|
|
672
|
+
if ((b2 & 192) !== 128) {
|
|
673
|
+
pushCodeUnit(parts, chunk, REPLACEMENT);
|
|
674
|
+
i++;
|
|
675
|
+
continue;
|
|
676
|
+
}
|
|
677
|
+
pushCodeUnit(parts, chunk, (b1 & 31) << 6 | b2 & 63);
|
|
678
|
+
i += 2;
|
|
679
|
+
continue;
|
|
680
|
+
}
|
|
681
|
+
if (b1 <= 239) {
|
|
682
|
+
if (i + 2 >= bytes.length) {
|
|
683
|
+
pushCodeUnit(parts, chunk, REPLACEMENT);
|
|
684
|
+
i++;
|
|
685
|
+
continue;
|
|
686
|
+
}
|
|
687
|
+
const b2 = bytes[i + 1];
|
|
688
|
+
const b3 = bytes[i + 2];
|
|
689
|
+
if (!((b2 & 192) === 128 && (b3 & 192) === 128 && !(b1 === 224 && b2 < 160) && !(b1 === 237 && b2 >= 160))) {
|
|
690
|
+
pushCodeUnit(parts, chunk, REPLACEMENT);
|
|
691
|
+
i++;
|
|
692
|
+
continue;
|
|
693
|
+
}
|
|
694
|
+
pushCodeUnit(parts, chunk, (b1 & 15) << 12 | (b2 & 63) << 6 | b3 & 63);
|
|
695
|
+
i += 3;
|
|
696
|
+
continue;
|
|
697
|
+
}
|
|
698
|
+
if (i + 3 >= bytes.length) {
|
|
699
|
+
pushCodeUnit(parts, chunk, REPLACEMENT);
|
|
700
|
+
i++;
|
|
701
|
+
continue;
|
|
702
|
+
}
|
|
703
|
+
const b2 = bytes[i + 1];
|
|
704
|
+
const b3 = bytes[i + 2];
|
|
705
|
+
const b4 = bytes[i + 3];
|
|
706
|
+
if (!((b2 & 192) === 128 && (b3 & 192) === 128 && (b4 & 192) === 128 && !(b1 === 240 && b2 < 144) && !(b1 === 244 && b2 > 143))) {
|
|
707
|
+
pushCodeUnit(parts, chunk, REPLACEMENT);
|
|
708
|
+
i++;
|
|
709
|
+
continue;
|
|
710
|
+
}
|
|
711
|
+
pushCodePoint(parts, chunk, (b1 & 7) << 18 | (b2 & 63) << 12 | (b3 & 63) << 6 | b4 & 63);
|
|
712
|
+
i += 4;
|
|
713
|
+
}
|
|
714
|
+
flushChunk(parts, chunk);
|
|
715
|
+
return parts.join("");
|
|
716
|
+
}
|
|
717
|
+
function decodeUTF16LE(bytes) {
|
|
718
|
+
const parts = [];
|
|
719
|
+
const chunk = [];
|
|
720
|
+
const len = bytes.length;
|
|
721
|
+
let i = 0;
|
|
722
|
+
while (i + 1 < len) {
|
|
723
|
+
const u1 = bytes[i] | bytes[i + 1] << 8;
|
|
724
|
+
i += 2;
|
|
725
|
+
if (u1 >= 55296 && u1 <= 56319) {
|
|
726
|
+
if (i + 1 < len) {
|
|
727
|
+
const u2 = bytes[i] | bytes[i + 1] << 8;
|
|
728
|
+
if (u2 >= 56320 && u2 <= 57343) {
|
|
729
|
+
pushCodeUnit(parts, chunk, u1);
|
|
730
|
+
pushCodeUnit(parts, chunk, u2);
|
|
731
|
+
i += 2;
|
|
732
|
+
} else pushCodeUnit(parts, chunk, REPLACEMENT);
|
|
733
|
+
} else pushCodeUnit(parts, chunk, REPLACEMENT);
|
|
734
|
+
continue;
|
|
735
|
+
}
|
|
736
|
+
if (u1 >= 56320 && u1 <= 57343) {
|
|
737
|
+
pushCodeUnit(parts, chunk, REPLACEMENT);
|
|
738
|
+
continue;
|
|
739
|
+
}
|
|
740
|
+
pushCodeUnit(parts, chunk, u1);
|
|
741
|
+
}
|
|
742
|
+
if (i < len) pushCodeUnit(parts, chunk, REPLACEMENT);
|
|
743
|
+
flushChunk(parts, chunk);
|
|
744
|
+
return parts.join("");
|
|
745
|
+
}
|
|
746
|
+
function decodeASCII(bytes) {
|
|
747
|
+
const parts = [];
|
|
748
|
+
for (let i = 0; i < bytes.length; i += CHUNK) {
|
|
749
|
+
const end = Math.min(bytes.length, i + CHUNK);
|
|
750
|
+
const codes = new Array(end - i);
|
|
751
|
+
for (let j = i, k = 0; j < end; j++, k++) codes[k] = bytes[j] & 127;
|
|
752
|
+
parts.push(String.fromCharCode.apply(null, codes));
|
|
753
|
+
}
|
|
754
|
+
return parts.join("");
|
|
755
|
+
}
|
|
756
|
+
function decodeLatin1(bytes) {
|
|
757
|
+
const parts = [];
|
|
758
|
+
for (let i = 0; i < bytes.length; i += CHUNK) {
|
|
759
|
+
const end = Math.min(bytes.length, i + CHUNK);
|
|
760
|
+
const codes = new Array(end - i);
|
|
761
|
+
for (let j = i, k = 0; j < end; j++, k++) codes[k] = bytes[j];
|
|
762
|
+
parts.push(String.fromCharCode.apply(null, codes));
|
|
763
|
+
}
|
|
764
|
+
return parts.join("");
|
|
765
|
+
}
|
|
766
|
+
function decodeWindows1252(bytes) {
|
|
767
|
+
const parts = [];
|
|
768
|
+
let out = "";
|
|
769
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
770
|
+
const b = bytes[i];
|
|
771
|
+
const extra = b >= 128 && b <= 159 ? WINDOWS_1252_EXTRA[b] : void 0;
|
|
772
|
+
out += extra !== null && extra !== void 0 ? extra : String.fromCharCode(b);
|
|
773
|
+
if (out.length >= CHUNK) {
|
|
774
|
+
parts.push(out);
|
|
775
|
+
out = "";
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
if (out) parts.push(out);
|
|
779
|
+
return parts.join("");
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
//#endregion
|
|
783
|
+
//#region node_modules/token-types/lib/index.js
|
|
784
|
+
function dv(array) {
|
|
785
|
+
return new DataView(array.buffer, array.byteOffset);
|
|
786
|
+
}
|
|
787
|
+
const UINT8 = {
|
|
788
|
+
len: 1,
|
|
789
|
+
get(array, offset) {
|
|
790
|
+
return dv(array).getUint8(offset);
|
|
791
|
+
},
|
|
792
|
+
put(array, offset, value) {
|
|
793
|
+
dv(array).setUint8(offset, value);
|
|
794
|
+
return offset + 1;
|
|
795
|
+
}
|
|
796
|
+
};
|
|
797
|
+
/**
|
|
798
|
+
* 16-bit unsigned integer, Little Endian byte order
|
|
799
|
+
*/
|
|
800
|
+
const UINT16_LE = {
|
|
801
|
+
len: 2,
|
|
802
|
+
get(array, offset) {
|
|
803
|
+
return dv(array).getUint16(offset, true);
|
|
804
|
+
},
|
|
805
|
+
put(array, offset, value) {
|
|
806
|
+
dv(array).setUint16(offset, value, true);
|
|
807
|
+
return offset + 2;
|
|
808
|
+
}
|
|
809
|
+
};
|
|
810
|
+
/**
|
|
811
|
+
* 16-bit unsigned integer, Big Endian byte order
|
|
812
|
+
*/
|
|
813
|
+
const UINT16_BE = {
|
|
814
|
+
len: 2,
|
|
815
|
+
get(array, offset) {
|
|
816
|
+
return dv(array).getUint16(offset);
|
|
817
|
+
},
|
|
818
|
+
put(array, offset, value) {
|
|
819
|
+
dv(array).setUint16(offset, value);
|
|
820
|
+
return offset + 2;
|
|
821
|
+
}
|
|
822
|
+
};
|
|
823
|
+
/**
|
|
824
|
+
* 32-bit unsigned integer, Little Endian byte order
|
|
825
|
+
*/
|
|
826
|
+
const UINT32_LE = {
|
|
827
|
+
len: 4,
|
|
828
|
+
get(array, offset) {
|
|
829
|
+
return dv(array).getUint32(offset, true);
|
|
830
|
+
},
|
|
831
|
+
put(array, offset, value) {
|
|
832
|
+
dv(array).setUint32(offset, value, true);
|
|
833
|
+
return offset + 4;
|
|
834
|
+
}
|
|
835
|
+
};
|
|
836
|
+
/**
|
|
837
|
+
* 32-bit unsigned integer, Big Endian byte order
|
|
838
|
+
*/
|
|
839
|
+
const UINT32_BE = {
|
|
840
|
+
len: 4,
|
|
841
|
+
get(array, offset) {
|
|
842
|
+
return dv(array).getUint32(offset);
|
|
843
|
+
},
|
|
844
|
+
put(array, offset, value) {
|
|
845
|
+
dv(array).setUint32(offset, value);
|
|
846
|
+
return offset + 4;
|
|
847
|
+
}
|
|
848
|
+
};
|
|
849
|
+
/**
|
|
850
|
+
* 32-bit signed integer, Big Endian byte order
|
|
851
|
+
*/
|
|
852
|
+
const INT32_BE = {
|
|
853
|
+
len: 4,
|
|
854
|
+
get(array, offset) {
|
|
855
|
+
return dv(array).getInt32(offset);
|
|
856
|
+
},
|
|
857
|
+
put(array, offset, value) {
|
|
858
|
+
dv(array).setInt32(offset, value);
|
|
859
|
+
return offset + 4;
|
|
860
|
+
}
|
|
861
|
+
};
|
|
862
|
+
/**
|
|
863
|
+
* 64-bit unsigned integer, Little Endian byte order
|
|
864
|
+
*/
|
|
865
|
+
const UINT64_LE = {
|
|
866
|
+
len: 8,
|
|
867
|
+
get(array, offset) {
|
|
868
|
+
return dv(array).getBigUint64(offset, true);
|
|
869
|
+
},
|
|
870
|
+
put(array, offset, value) {
|
|
871
|
+
dv(array).setBigUint64(offset, value, true);
|
|
872
|
+
return offset + 8;
|
|
873
|
+
}
|
|
874
|
+
};
|
|
875
|
+
/**
|
|
876
|
+
* Consume a fixed number of bytes from the stream and return a string with a specified encoding.
|
|
877
|
+
* Supports all encodings supported by TextDecoder, plus 'windows-1252'.
|
|
878
|
+
*/
|
|
879
|
+
var StringType = class {
|
|
880
|
+
constructor(len, encoding) {
|
|
881
|
+
this.len = len;
|
|
882
|
+
this.encoding = encoding;
|
|
883
|
+
}
|
|
884
|
+
get(data, offset = 0) {
|
|
885
|
+
return textDecode(data.subarray(offset, offset + this.len), this.encoding);
|
|
886
|
+
}
|
|
887
|
+
};
|
|
888
|
+
|
|
889
|
+
//#endregion
|
|
890
|
+
//#region node_modules/ms/index.js
|
|
891
|
+
var require_ms = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
892
|
+
/**
|
|
893
|
+
* Helpers.
|
|
894
|
+
*/
|
|
895
|
+
var s = 1e3;
|
|
896
|
+
var m = s * 60;
|
|
897
|
+
var h = m * 60;
|
|
898
|
+
var d = h * 24;
|
|
899
|
+
var w = d * 7;
|
|
900
|
+
var y = d * 365.25;
|
|
901
|
+
/**
|
|
902
|
+
* Parse or format the given `val`.
|
|
903
|
+
*
|
|
904
|
+
* Options:
|
|
905
|
+
*
|
|
906
|
+
* - `long` verbose formatting [false]
|
|
907
|
+
*
|
|
908
|
+
* @param {String|Number} val
|
|
909
|
+
* @param {Object} [options]
|
|
910
|
+
* @throws {Error} throw an error if val is not a non-empty string or a number
|
|
911
|
+
* @return {String|Number}
|
|
912
|
+
* @api public
|
|
913
|
+
*/
|
|
914
|
+
module.exports = function(val, options) {
|
|
915
|
+
options = options || {};
|
|
916
|
+
var type = typeof val;
|
|
917
|
+
if (type === "string" && val.length > 0) return parse(val);
|
|
918
|
+
else if (type === "number" && isFinite(val)) return options.long ? fmtLong(val) : fmtShort(val);
|
|
919
|
+
throw new Error("val is not a non-empty string or a valid number. val=" + JSON.stringify(val));
|
|
920
|
+
};
|
|
921
|
+
/**
|
|
922
|
+
* Parse the given `str` and return milliseconds.
|
|
923
|
+
*
|
|
924
|
+
* @param {String} str
|
|
925
|
+
* @return {Number}
|
|
926
|
+
* @api private
|
|
927
|
+
*/
|
|
928
|
+
function parse(str) {
|
|
929
|
+
str = String(str);
|
|
930
|
+
if (str.length > 100) return;
|
|
931
|
+
var match = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(str);
|
|
932
|
+
if (!match) return;
|
|
933
|
+
var n = parseFloat(match[1]);
|
|
934
|
+
switch ((match[2] || "ms").toLowerCase()) {
|
|
935
|
+
case "years":
|
|
936
|
+
case "year":
|
|
937
|
+
case "yrs":
|
|
938
|
+
case "yr":
|
|
939
|
+
case "y": return n * y;
|
|
940
|
+
case "weeks":
|
|
941
|
+
case "week":
|
|
942
|
+
case "w": return n * w;
|
|
943
|
+
case "days":
|
|
944
|
+
case "day":
|
|
945
|
+
case "d": return n * d;
|
|
946
|
+
case "hours":
|
|
947
|
+
case "hour":
|
|
948
|
+
case "hrs":
|
|
949
|
+
case "hr":
|
|
950
|
+
case "h": return n * h;
|
|
951
|
+
case "minutes":
|
|
952
|
+
case "minute":
|
|
953
|
+
case "mins":
|
|
954
|
+
case "min":
|
|
955
|
+
case "m": return n * m;
|
|
956
|
+
case "seconds":
|
|
957
|
+
case "second":
|
|
958
|
+
case "secs":
|
|
959
|
+
case "sec":
|
|
960
|
+
case "s": return n * s;
|
|
961
|
+
case "milliseconds":
|
|
962
|
+
case "millisecond":
|
|
963
|
+
case "msecs":
|
|
964
|
+
case "msec":
|
|
965
|
+
case "ms": return n;
|
|
966
|
+
default: return;
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
/**
|
|
970
|
+
* Short format for `ms`.
|
|
971
|
+
*
|
|
972
|
+
* @param {Number} ms
|
|
973
|
+
* @return {String}
|
|
974
|
+
* @api private
|
|
975
|
+
*/
|
|
976
|
+
function fmtShort(ms) {
|
|
977
|
+
var msAbs = Math.abs(ms);
|
|
978
|
+
if (msAbs >= d) return Math.round(ms / d) + "d";
|
|
979
|
+
if (msAbs >= h) return Math.round(ms / h) + "h";
|
|
980
|
+
if (msAbs >= m) return Math.round(ms / m) + "m";
|
|
981
|
+
if (msAbs >= s) return Math.round(ms / s) + "s";
|
|
982
|
+
return ms + "ms";
|
|
983
|
+
}
|
|
984
|
+
/**
|
|
985
|
+
* Long format for `ms`.
|
|
986
|
+
*
|
|
987
|
+
* @param {Number} ms
|
|
988
|
+
* @return {String}
|
|
989
|
+
* @api private
|
|
990
|
+
*/
|
|
991
|
+
function fmtLong(ms) {
|
|
992
|
+
var msAbs = Math.abs(ms);
|
|
993
|
+
if (msAbs >= d) return plural(ms, msAbs, d, "day");
|
|
994
|
+
if (msAbs >= h) return plural(ms, msAbs, h, "hour");
|
|
995
|
+
if (msAbs >= m) return plural(ms, msAbs, m, "minute");
|
|
996
|
+
if (msAbs >= s) return plural(ms, msAbs, s, "second");
|
|
997
|
+
return ms + " ms";
|
|
998
|
+
}
|
|
999
|
+
/**
|
|
1000
|
+
* Pluralization helper.
|
|
1001
|
+
*/
|
|
1002
|
+
function plural(ms, msAbs, n, name) {
|
|
1003
|
+
var isPlural = msAbs >= n * 1.5;
|
|
1004
|
+
return Math.round(ms / n) + " " + name + (isPlural ? "s" : "");
|
|
1005
|
+
}
|
|
1006
|
+
}));
|
|
1007
|
+
|
|
1008
|
+
//#endregion
|
|
1009
|
+
//#region node_modules/debug/src/common.js
|
|
1010
|
+
var require_common = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1011
|
+
/**
|
|
1012
|
+
* This is the common logic for both the Node.js and web browser
|
|
1013
|
+
* implementations of `debug()`.
|
|
1014
|
+
*/
|
|
1015
|
+
function setup(env) {
|
|
1016
|
+
createDebug.debug = createDebug;
|
|
1017
|
+
createDebug.default = createDebug;
|
|
1018
|
+
createDebug.coerce = coerce;
|
|
1019
|
+
createDebug.disable = disable;
|
|
1020
|
+
createDebug.enable = enable;
|
|
1021
|
+
createDebug.enabled = enabled;
|
|
1022
|
+
createDebug.humanize = require_ms();
|
|
1023
|
+
createDebug.destroy = destroy;
|
|
1024
|
+
Object.keys(env).forEach((key) => {
|
|
1025
|
+
createDebug[key] = env[key];
|
|
1026
|
+
});
|
|
1027
|
+
/**
|
|
1028
|
+
* The currently active debug mode names, and names to skip.
|
|
1029
|
+
*/
|
|
1030
|
+
createDebug.names = [];
|
|
1031
|
+
createDebug.skips = [];
|
|
1032
|
+
/**
|
|
1033
|
+
* Map of special "%n" handling functions, for the debug "format" argument.
|
|
1034
|
+
*
|
|
1035
|
+
* Valid key names are a single, lower or upper-case letter, i.e. "n" and "N".
|
|
1036
|
+
*/
|
|
1037
|
+
createDebug.formatters = {};
|
|
1038
|
+
/**
|
|
1039
|
+
* Selects a color for a debug namespace
|
|
1040
|
+
* @param {String} namespace The namespace string for the debug instance to be colored
|
|
1041
|
+
* @return {Number|String} An ANSI color code for the given namespace
|
|
1042
|
+
* @api private
|
|
1043
|
+
*/
|
|
1044
|
+
function selectColor(namespace) {
|
|
1045
|
+
let hash = 0;
|
|
1046
|
+
for (let i = 0; i < namespace.length; i++) {
|
|
1047
|
+
hash = (hash << 5) - hash + namespace.charCodeAt(i);
|
|
1048
|
+
hash |= 0;
|
|
1049
|
+
}
|
|
1050
|
+
return createDebug.colors[Math.abs(hash) % createDebug.colors.length];
|
|
1051
|
+
}
|
|
1052
|
+
createDebug.selectColor = selectColor;
|
|
1053
|
+
/**
|
|
1054
|
+
* Create a debugger with the given `namespace`.
|
|
1055
|
+
*
|
|
1056
|
+
* @param {String} namespace
|
|
1057
|
+
* @return {Function}
|
|
1058
|
+
* @api public
|
|
1059
|
+
*/
|
|
1060
|
+
function createDebug(namespace) {
|
|
1061
|
+
let prevTime;
|
|
1062
|
+
let enableOverride = null;
|
|
1063
|
+
let namespacesCache;
|
|
1064
|
+
let enabledCache;
|
|
1065
|
+
function debug(...args) {
|
|
1066
|
+
if (!debug.enabled) return;
|
|
1067
|
+
const self = debug;
|
|
1068
|
+
const curr = Number(/* @__PURE__ */ new Date());
|
|
1069
|
+
self.diff = curr - (prevTime || curr);
|
|
1070
|
+
self.prev = prevTime;
|
|
1071
|
+
self.curr = curr;
|
|
1072
|
+
prevTime = curr;
|
|
1073
|
+
args[0] = createDebug.coerce(args[0]);
|
|
1074
|
+
if (typeof args[0] !== "string") args.unshift("%O");
|
|
1075
|
+
let index = 0;
|
|
1076
|
+
args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => {
|
|
1077
|
+
if (match === "%%") return "%";
|
|
1078
|
+
index++;
|
|
1079
|
+
const formatter = createDebug.formatters[format];
|
|
1080
|
+
if (typeof formatter === "function") {
|
|
1081
|
+
const val = args[index];
|
|
1082
|
+
match = formatter.call(self, val);
|
|
1083
|
+
args.splice(index, 1);
|
|
1084
|
+
index--;
|
|
1085
|
+
}
|
|
1086
|
+
return match;
|
|
1087
|
+
});
|
|
1088
|
+
createDebug.formatArgs.call(self, args);
|
|
1089
|
+
(self.log || createDebug.log).apply(self, args);
|
|
1090
|
+
}
|
|
1091
|
+
debug.namespace = namespace;
|
|
1092
|
+
debug.useColors = createDebug.useColors();
|
|
1093
|
+
debug.color = createDebug.selectColor(namespace);
|
|
1094
|
+
debug.extend = extend;
|
|
1095
|
+
debug.destroy = createDebug.destroy;
|
|
1096
|
+
Object.defineProperty(debug, "enabled", {
|
|
1097
|
+
enumerable: true,
|
|
1098
|
+
configurable: false,
|
|
1099
|
+
get: () => {
|
|
1100
|
+
if (enableOverride !== null) return enableOverride;
|
|
1101
|
+
if (namespacesCache !== createDebug.namespaces) {
|
|
1102
|
+
namespacesCache = createDebug.namespaces;
|
|
1103
|
+
enabledCache = createDebug.enabled(namespace);
|
|
1104
|
+
}
|
|
1105
|
+
return enabledCache;
|
|
1106
|
+
},
|
|
1107
|
+
set: (v) => {
|
|
1108
|
+
enableOverride = v;
|
|
1109
|
+
}
|
|
1110
|
+
});
|
|
1111
|
+
if (typeof createDebug.init === "function") createDebug.init(debug);
|
|
1112
|
+
return debug;
|
|
1113
|
+
}
|
|
1114
|
+
function extend(namespace, delimiter) {
|
|
1115
|
+
const newDebug = createDebug(this.namespace + (typeof delimiter === "undefined" ? ":" : delimiter) + namespace);
|
|
1116
|
+
newDebug.log = this.log;
|
|
1117
|
+
return newDebug;
|
|
1118
|
+
}
|
|
1119
|
+
/**
|
|
1120
|
+
* Enables a debug mode by namespaces. This can include modes
|
|
1121
|
+
* separated by a colon and wildcards.
|
|
1122
|
+
*
|
|
1123
|
+
* @param {String} namespaces
|
|
1124
|
+
* @api public
|
|
1125
|
+
*/
|
|
1126
|
+
function enable(namespaces) {
|
|
1127
|
+
createDebug.save(namespaces);
|
|
1128
|
+
createDebug.namespaces = namespaces;
|
|
1129
|
+
createDebug.names = [];
|
|
1130
|
+
createDebug.skips = [];
|
|
1131
|
+
const split = (typeof namespaces === "string" ? namespaces : "").trim().replace(/\s+/g, ",").split(",").filter(Boolean);
|
|
1132
|
+
for (const ns of split) if (ns[0] === "-") createDebug.skips.push(ns.slice(1));
|
|
1133
|
+
else createDebug.names.push(ns);
|
|
1134
|
+
}
|
|
1135
|
+
/**
|
|
1136
|
+
* Checks if the given string matches a namespace template, honoring
|
|
1137
|
+
* asterisks as wildcards.
|
|
1138
|
+
*
|
|
1139
|
+
* @param {String} search
|
|
1140
|
+
* @param {String} template
|
|
1141
|
+
* @return {Boolean}
|
|
1142
|
+
*/
|
|
1143
|
+
function matchesTemplate(search, template) {
|
|
1144
|
+
let searchIndex = 0;
|
|
1145
|
+
let templateIndex = 0;
|
|
1146
|
+
let starIndex = -1;
|
|
1147
|
+
let matchIndex = 0;
|
|
1148
|
+
while (searchIndex < search.length) if (templateIndex < template.length && (template[templateIndex] === search[searchIndex] || template[templateIndex] === "*")) if (template[templateIndex] === "*") {
|
|
1149
|
+
starIndex = templateIndex;
|
|
1150
|
+
matchIndex = searchIndex;
|
|
1151
|
+
templateIndex++;
|
|
1152
|
+
} else {
|
|
1153
|
+
searchIndex++;
|
|
1154
|
+
templateIndex++;
|
|
1155
|
+
}
|
|
1156
|
+
else if (starIndex !== -1) {
|
|
1157
|
+
templateIndex = starIndex + 1;
|
|
1158
|
+
matchIndex++;
|
|
1159
|
+
searchIndex = matchIndex;
|
|
1160
|
+
} else return false;
|
|
1161
|
+
while (templateIndex < template.length && template[templateIndex] === "*") templateIndex++;
|
|
1162
|
+
return templateIndex === template.length;
|
|
1163
|
+
}
|
|
1164
|
+
/**
|
|
1165
|
+
* Disable debug output.
|
|
1166
|
+
*
|
|
1167
|
+
* @return {String} namespaces
|
|
1168
|
+
* @api public
|
|
1169
|
+
*/
|
|
1170
|
+
function disable() {
|
|
1171
|
+
const namespaces = [...createDebug.names, ...createDebug.skips.map((namespace) => "-" + namespace)].join(",");
|
|
1172
|
+
createDebug.enable("");
|
|
1173
|
+
return namespaces;
|
|
1174
|
+
}
|
|
1175
|
+
/**
|
|
1176
|
+
* Returns true if the given mode name is enabled, false otherwise.
|
|
1177
|
+
*
|
|
1178
|
+
* @param {String} name
|
|
1179
|
+
* @return {Boolean}
|
|
1180
|
+
* @api public
|
|
1181
|
+
*/
|
|
1182
|
+
function enabled(name) {
|
|
1183
|
+
for (const skip of createDebug.skips) if (matchesTemplate(name, skip)) return false;
|
|
1184
|
+
for (const ns of createDebug.names) if (matchesTemplate(name, ns)) return true;
|
|
1185
|
+
return false;
|
|
1186
|
+
}
|
|
1187
|
+
/**
|
|
1188
|
+
* Coerce `val`.
|
|
1189
|
+
*
|
|
1190
|
+
* @param {Mixed} val
|
|
1191
|
+
* @return {Mixed}
|
|
1192
|
+
* @api private
|
|
1193
|
+
*/
|
|
1194
|
+
function coerce(val) {
|
|
1195
|
+
if (val instanceof Error) return val.stack || val.message;
|
|
1196
|
+
return val;
|
|
1197
|
+
}
|
|
1198
|
+
/**
|
|
1199
|
+
* XXX DO NOT USE. This is a temporary stub function.
|
|
1200
|
+
* XXX It WILL be removed in the next major release.
|
|
1201
|
+
*/
|
|
1202
|
+
function destroy() {
|
|
1203
|
+
console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.");
|
|
1204
|
+
}
|
|
1205
|
+
createDebug.enable(createDebug.load());
|
|
1206
|
+
return createDebug;
|
|
1207
|
+
}
|
|
1208
|
+
module.exports = setup;
|
|
1209
|
+
}));
|
|
1210
|
+
|
|
1211
|
+
//#endregion
|
|
1212
|
+
//#region node_modules/debug/src/browser.js
|
|
1213
|
+
var require_browser = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1214
|
+
/**
|
|
1215
|
+
* This is the web browser implementation of `debug()`.
|
|
1216
|
+
*/
|
|
1217
|
+
exports.formatArgs = formatArgs;
|
|
1218
|
+
exports.save = save;
|
|
1219
|
+
exports.load = load;
|
|
1220
|
+
exports.useColors = useColors;
|
|
1221
|
+
exports.storage = localstorage();
|
|
1222
|
+
exports.destroy = (() => {
|
|
1223
|
+
let warned = false;
|
|
1224
|
+
return () => {
|
|
1225
|
+
if (!warned) {
|
|
1226
|
+
warned = true;
|
|
1227
|
+
console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.");
|
|
1228
|
+
}
|
|
1229
|
+
};
|
|
1230
|
+
})();
|
|
1231
|
+
/**
|
|
1232
|
+
* Colors.
|
|
1233
|
+
*/
|
|
1234
|
+
exports.colors = [
|
|
1235
|
+
"#0000CC",
|
|
1236
|
+
"#0000FF",
|
|
1237
|
+
"#0033CC",
|
|
1238
|
+
"#0033FF",
|
|
1239
|
+
"#0066CC",
|
|
1240
|
+
"#0066FF",
|
|
1241
|
+
"#0099CC",
|
|
1242
|
+
"#0099FF",
|
|
1243
|
+
"#00CC00",
|
|
1244
|
+
"#00CC33",
|
|
1245
|
+
"#00CC66",
|
|
1246
|
+
"#00CC99",
|
|
1247
|
+
"#00CCCC",
|
|
1248
|
+
"#00CCFF",
|
|
1249
|
+
"#3300CC",
|
|
1250
|
+
"#3300FF",
|
|
1251
|
+
"#3333CC",
|
|
1252
|
+
"#3333FF",
|
|
1253
|
+
"#3366CC",
|
|
1254
|
+
"#3366FF",
|
|
1255
|
+
"#3399CC",
|
|
1256
|
+
"#3399FF",
|
|
1257
|
+
"#33CC00",
|
|
1258
|
+
"#33CC33",
|
|
1259
|
+
"#33CC66",
|
|
1260
|
+
"#33CC99",
|
|
1261
|
+
"#33CCCC",
|
|
1262
|
+
"#33CCFF",
|
|
1263
|
+
"#6600CC",
|
|
1264
|
+
"#6600FF",
|
|
1265
|
+
"#6633CC",
|
|
1266
|
+
"#6633FF",
|
|
1267
|
+
"#66CC00",
|
|
1268
|
+
"#66CC33",
|
|
1269
|
+
"#9900CC",
|
|
1270
|
+
"#9900FF",
|
|
1271
|
+
"#9933CC",
|
|
1272
|
+
"#9933FF",
|
|
1273
|
+
"#99CC00",
|
|
1274
|
+
"#99CC33",
|
|
1275
|
+
"#CC0000",
|
|
1276
|
+
"#CC0033",
|
|
1277
|
+
"#CC0066",
|
|
1278
|
+
"#CC0099",
|
|
1279
|
+
"#CC00CC",
|
|
1280
|
+
"#CC00FF",
|
|
1281
|
+
"#CC3300",
|
|
1282
|
+
"#CC3333",
|
|
1283
|
+
"#CC3366",
|
|
1284
|
+
"#CC3399",
|
|
1285
|
+
"#CC33CC",
|
|
1286
|
+
"#CC33FF",
|
|
1287
|
+
"#CC6600",
|
|
1288
|
+
"#CC6633",
|
|
1289
|
+
"#CC9900",
|
|
1290
|
+
"#CC9933",
|
|
1291
|
+
"#CCCC00",
|
|
1292
|
+
"#CCCC33",
|
|
1293
|
+
"#FF0000",
|
|
1294
|
+
"#FF0033",
|
|
1295
|
+
"#FF0066",
|
|
1296
|
+
"#FF0099",
|
|
1297
|
+
"#FF00CC",
|
|
1298
|
+
"#FF00FF",
|
|
1299
|
+
"#FF3300",
|
|
1300
|
+
"#FF3333",
|
|
1301
|
+
"#FF3366",
|
|
1302
|
+
"#FF3399",
|
|
1303
|
+
"#FF33CC",
|
|
1304
|
+
"#FF33FF",
|
|
1305
|
+
"#FF6600",
|
|
1306
|
+
"#FF6633",
|
|
1307
|
+
"#FF9900",
|
|
1308
|
+
"#FF9933",
|
|
1309
|
+
"#FFCC00",
|
|
1310
|
+
"#FFCC33"
|
|
1311
|
+
];
|
|
1312
|
+
/**
|
|
1313
|
+
* Currently only WebKit-based Web Inspectors, Firefox >= v31,
|
|
1314
|
+
* and the Firebug extension (any Firefox version) are known
|
|
1315
|
+
* to support "%c" CSS customizations.
|
|
1316
|
+
*
|
|
1317
|
+
* TODO: add a `localStorage` variable to explicitly enable/disable colors
|
|
1318
|
+
*/
|
|
1319
|
+
function useColors() {
|
|
1320
|
+
if (typeof window !== "undefined" && window.process && (window.process.type === "renderer" || window.process.__nwjs)) return true;
|
|
1321
|
+
if (typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) return false;
|
|
1322
|
+
let m;
|
|
1323
|
+
return typeof document !== "undefined" && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance || typeof window !== "undefined" && window.console && (window.console.firebug || window.console.exception && window.console.table) || typeof navigator !== "undefined" && navigator.userAgent && (m = navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)) && parseInt(m[1], 10) >= 31 || typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/);
|
|
1324
|
+
}
|
|
1325
|
+
/**
|
|
1326
|
+
* Colorize log arguments if enabled.
|
|
1327
|
+
*
|
|
1328
|
+
* @api public
|
|
1329
|
+
*/
|
|
1330
|
+
function formatArgs(args) {
|
|
1331
|
+
args[0] = (this.useColors ? "%c" : "") + this.namespace + (this.useColors ? " %c" : " ") + args[0] + (this.useColors ? "%c " : " ") + "+" + module.exports.humanize(this.diff);
|
|
1332
|
+
if (!this.useColors) return;
|
|
1333
|
+
const c = "color: " + this.color;
|
|
1334
|
+
args.splice(1, 0, c, "color: inherit");
|
|
1335
|
+
let index = 0;
|
|
1336
|
+
let lastC = 0;
|
|
1337
|
+
args[0].replace(/%[a-zA-Z%]/g, (match) => {
|
|
1338
|
+
if (match === "%%") return;
|
|
1339
|
+
index++;
|
|
1340
|
+
if (match === "%c") lastC = index;
|
|
1341
|
+
});
|
|
1342
|
+
args.splice(lastC, 0, c);
|
|
1343
|
+
}
|
|
1344
|
+
/**
|
|
1345
|
+
* Invokes `console.debug()` when available.
|
|
1346
|
+
* No-op when `console.debug` is not a "function".
|
|
1347
|
+
* If `console.debug` is not available, falls back
|
|
1348
|
+
* to `console.log`.
|
|
1349
|
+
*
|
|
1350
|
+
* @api public
|
|
1351
|
+
*/
|
|
1352
|
+
exports.log = console.debug || console.log || (() => {});
|
|
1353
|
+
/**
|
|
1354
|
+
* Save `namespaces`.
|
|
1355
|
+
*
|
|
1356
|
+
* @param {String} namespaces
|
|
1357
|
+
* @api private
|
|
1358
|
+
*/
|
|
1359
|
+
function save(namespaces) {
|
|
1360
|
+
try {
|
|
1361
|
+
if (namespaces) exports.storage.setItem("debug", namespaces);
|
|
1362
|
+
else exports.storage.removeItem("debug");
|
|
1363
|
+
} catch (error) {}
|
|
1364
|
+
}
|
|
1365
|
+
/**
|
|
1366
|
+
* Load `namespaces`.
|
|
1367
|
+
*
|
|
1368
|
+
* @return {String} returns the previously persisted debug modes
|
|
1369
|
+
* @api private
|
|
1370
|
+
*/
|
|
1371
|
+
function load() {
|
|
1372
|
+
let r;
|
|
1373
|
+
try {
|
|
1374
|
+
r = exports.storage.getItem("debug") || exports.storage.getItem("DEBUG");
|
|
1375
|
+
} catch (error) {}
|
|
1376
|
+
if (!r && typeof process !== "undefined" && "env" in process) r = process.env.DEBUG;
|
|
1377
|
+
return r;
|
|
1378
|
+
}
|
|
1379
|
+
/**
|
|
1380
|
+
* Localstorage attempts to return the localstorage.
|
|
1381
|
+
*
|
|
1382
|
+
* This is necessary because safari throws
|
|
1383
|
+
* when a user disables cookies/localstorage
|
|
1384
|
+
* and you attempt to access it.
|
|
1385
|
+
*
|
|
1386
|
+
* @return {LocalStorage}
|
|
1387
|
+
* @api private
|
|
1388
|
+
*/
|
|
1389
|
+
function localstorage() {
|
|
1390
|
+
try {
|
|
1391
|
+
return localStorage;
|
|
1392
|
+
} catch (error) {}
|
|
1393
|
+
}
|
|
1394
|
+
module.exports = require_common()(exports);
|
|
1395
|
+
const { formatters } = module.exports;
|
|
1396
|
+
/**
|
|
1397
|
+
* Map %j to `JSON.stringify()`, since no Web Inspectors do that by default.
|
|
1398
|
+
*/
|
|
1399
|
+
formatters.j = function(v) {
|
|
1400
|
+
try {
|
|
1401
|
+
return JSON.stringify(v);
|
|
1402
|
+
} catch (error) {
|
|
1403
|
+
return "[UnexpectedJSONParseError]: " + error.message;
|
|
1404
|
+
}
|
|
1405
|
+
};
|
|
1406
|
+
}));
|
|
1407
|
+
|
|
1408
|
+
//#endregion
|
|
1409
|
+
//#region node_modules/debug/src/node.js
|
|
1410
|
+
var require_node = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1411
|
+
/**
|
|
1412
|
+
* Module dependencies.
|
|
1413
|
+
*/
|
|
1414
|
+
const tty = __require("tty");
|
|
1415
|
+
const util = __require("util");
|
|
1416
|
+
/**
|
|
1417
|
+
* This is the Node.js implementation of `debug()`.
|
|
1418
|
+
*/
|
|
1419
|
+
exports.init = init;
|
|
1420
|
+
exports.log = log;
|
|
1421
|
+
exports.formatArgs = formatArgs;
|
|
1422
|
+
exports.save = save;
|
|
1423
|
+
exports.load = load;
|
|
1424
|
+
exports.useColors = useColors;
|
|
1425
|
+
exports.destroy = util.deprecate(() => {}, "Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.");
|
|
1426
|
+
/**
|
|
1427
|
+
* Colors.
|
|
1428
|
+
*/
|
|
1429
|
+
exports.colors = [
|
|
1430
|
+
6,
|
|
1431
|
+
2,
|
|
1432
|
+
3,
|
|
1433
|
+
4,
|
|
1434
|
+
5,
|
|
1435
|
+
1
|
|
1436
|
+
];
|
|
1437
|
+
try {
|
|
1438
|
+
const supportsColor = __require("supports-color");
|
|
1439
|
+
if (supportsColor && (supportsColor.stderr || supportsColor).level >= 2) exports.colors = [
|
|
1440
|
+
20,
|
|
1441
|
+
21,
|
|
1442
|
+
26,
|
|
1443
|
+
27,
|
|
1444
|
+
32,
|
|
1445
|
+
33,
|
|
1446
|
+
38,
|
|
1447
|
+
39,
|
|
1448
|
+
40,
|
|
1449
|
+
41,
|
|
1450
|
+
42,
|
|
1451
|
+
43,
|
|
1452
|
+
44,
|
|
1453
|
+
45,
|
|
1454
|
+
56,
|
|
1455
|
+
57,
|
|
1456
|
+
62,
|
|
1457
|
+
63,
|
|
1458
|
+
68,
|
|
1459
|
+
69,
|
|
1460
|
+
74,
|
|
1461
|
+
75,
|
|
1462
|
+
76,
|
|
1463
|
+
77,
|
|
1464
|
+
78,
|
|
1465
|
+
79,
|
|
1466
|
+
80,
|
|
1467
|
+
81,
|
|
1468
|
+
92,
|
|
1469
|
+
93,
|
|
1470
|
+
98,
|
|
1471
|
+
99,
|
|
1472
|
+
112,
|
|
1473
|
+
113,
|
|
1474
|
+
128,
|
|
1475
|
+
129,
|
|
1476
|
+
134,
|
|
1477
|
+
135,
|
|
1478
|
+
148,
|
|
1479
|
+
149,
|
|
1480
|
+
160,
|
|
1481
|
+
161,
|
|
1482
|
+
162,
|
|
1483
|
+
163,
|
|
1484
|
+
164,
|
|
1485
|
+
165,
|
|
1486
|
+
166,
|
|
1487
|
+
167,
|
|
1488
|
+
168,
|
|
1489
|
+
169,
|
|
1490
|
+
170,
|
|
1491
|
+
171,
|
|
1492
|
+
172,
|
|
1493
|
+
173,
|
|
1494
|
+
178,
|
|
1495
|
+
179,
|
|
1496
|
+
184,
|
|
1497
|
+
185,
|
|
1498
|
+
196,
|
|
1499
|
+
197,
|
|
1500
|
+
198,
|
|
1501
|
+
199,
|
|
1502
|
+
200,
|
|
1503
|
+
201,
|
|
1504
|
+
202,
|
|
1505
|
+
203,
|
|
1506
|
+
204,
|
|
1507
|
+
205,
|
|
1508
|
+
206,
|
|
1509
|
+
207,
|
|
1510
|
+
208,
|
|
1511
|
+
209,
|
|
1512
|
+
214,
|
|
1513
|
+
215,
|
|
1514
|
+
220,
|
|
1515
|
+
221
|
|
1516
|
+
];
|
|
1517
|
+
} catch (error) {}
|
|
1518
|
+
/**
|
|
1519
|
+
* Build up the default `inspectOpts` object from the environment variables.
|
|
1520
|
+
*
|
|
1521
|
+
* $ DEBUG_COLORS=no DEBUG_DEPTH=10 DEBUG_SHOW_HIDDEN=enabled node script.js
|
|
1522
|
+
*/
|
|
1523
|
+
exports.inspectOpts = Object.keys(process.env).filter((key) => {
|
|
1524
|
+
return /^debug_/i.test(key);
|
|
1525
|
+
}).reduce((obj, key) => {
|
|
1526
|
+
const prop = key.substring(6).toLowerCase().replace(/_([a-z])/g, (_, k) => {
|
|
1527
|
+
return k.toUpperCase();
|
|
1528
|
+
});
|
|
1529
|
+
let val = process.env[key];
|
|
1530
|
+
if (/^(yes|on|true|enabled)$/i.test(val)) val = true;
|
|
1531
|
+
else if (/^(no|off|false|disabled)$/i.test(val)) val = false;
|
|
1532
|
+
else if (val === "null") val = null;
|
|
1533
|
+
else val = Number(val);
|
|
1534
|
+
obj[prop] = val;
|
|
1535
|
+
return obj;
|
|
1536
|
+
}, {});
|
|
1537
|
+
/**
|
|
1538
|
+
* Is stdout a TTY? Colored output is enabled when `true`.
|
|
1539
|
+
*/
|
|
1540
|
+
function useColors() {
|
|
1541
|
+
return "colors" in exports.inspectOpts ? Boolean(exports.inspectOpts.colors) : tty.isatty(process.stderr.fd);
|
|
1542
|
+
}
|
|
1543
|
+
/**
|
|
1544
|
+
* Adds ANSI color escape codes if enabled.
|
|
1545
|
+
*
|
|
1546
|
+
* @api public
|
|
1547
|
+
*/
|
|
1548
|
+
function formatArgs(args) {
|
|
1549
|
+
const { namespace: name, useColors } = this;
|
|
1550
|
+
if (useColors) {
|
|
1551
|
+
const c = this.color;
|
|
1552
|
+
const colorCode = "\x1B[3" + (c < 8 ? c : "8;5;" + c);
|
|
1553
|
+
const prefix = ` ${colorCode};1m${name} \u001B[0m`;
|
|
1554
|
+
args[0] = prefix + args[0].split("\n").join("\n" + prefix);
|
|
1555
|
+
args.push(colorCode + "m+" + module.exports.humanize(this.diff) + "\x1B[0m");
|
|
1556
|
+
} else args[0] = getDate() + name + " " + args[0];
|
|
1557
|
+
}
|
|
1558
|
+
function getDate() {
|
|
1559
|
+
if (exports.inspectOpts.hideDate) return "";
|
|
1560
|
+
return (/* @__PURE__ */ new Date()).toISOString() + " ";
|
|
1561
|
+
}
|
|
1562
|
+
/**
|
|
1563
|
+
* Invokes `util.formatWithOptions()` with the specified arguments and writes to stderr.
|
|
1564
|
+
*/
|
|
1565
|
+
function log(...args) {
|
|
1566
|
+
return process.stderr.write(util.formatWithOptions(exports.inspectOpts, ...args) + "\n");
|
|
1567
|
+
}
|
|
1568
|
+
/**
|
|
1569
|
+
* Save `namespaces`.
|
|
1570
|
+
*
|
|
1571
|
+
* @param {String} namespaces
|
|
1572
|
+
* @api private
|
|
1573
|
+
*/
|
|
1574
|
+
function save(namespaces) {
|
|
1575
|
+
if (namespaces) process.env.DEBUG = namespaces;
|
|
1576
|
+
else delete process.env.DEBUG;
|
|
1577
|
+
}
|
|
1578
|
+
/**
|
|
1579
|
+
* Load `namespaces`.
|
|
1580
|
+
*
|
|
1581
|
+
* @return {String} returns the previously persisted debug modes
|
|
1582
|
+
* @api private
|
|
1583
|
+
*/
|
|
1584
|
+
function load() {
|
|
1585
|
+
return process.env.DEBUG;
|
|
1586
|
+
}
|
|
1587
|
+
/**
|
|
1588
|
+
* Init logic for `debug` instances.
|
|
1589
|
+
*
|
|
1590
|
+
* Create a new `inspectOpts` object in case `useColors` is set
|
|
1591
|
+
* differently for a particular `debug` instance.
|
|
1592
|
+
*/
|
|
1593
|
+
function init(debug) {
|
|
1594
|
+
debug.inspectOpts = {};
|
|
1595
|
+
const keys = Object.keys(exports.inspectOpts);
|
|
1596
|
+
for (let i = 0; i < keys.length; i++) debug.inspectOpts[keys[i]] = exports.inspectOpts[keys[i]];
|
|
1597
|
+
}
|
|
1598
|
+
module.exports = require_common()(exports);
|
|
1599
|
+
const { formatters } = module.exports;
|
|
1600
|
+
/**
|
|
1601
|
+
* Map %o to `util.inspect()`, all on a single line.
|
|
1602
|
+
*/
|
|
1603
|
+
formatters.o = function(v) {
|
|
1604
|
+
this.inspectOpts.colors = this.useColors;
|
|
1605
|
+
return util.inspect(v, this.inspectOpts).split("\n").map((str) => str.trim()).join(" ");
|
|
1606
|
+
};
|
|
1607
|
+
/**
|
|
1608
|
+
* Map %O to `util.inspect()`, allowing multiple lines if needed.
|
|
1609
|
+
*/
|
|
1610
|
+
formatters.O = function(v) {
|
|
1611
|
+
this.inspectOpts.colors = this.useColors;
|
|
1612
|
+
return util.inspect(v, this.inspectOpts);
|
|
1613
|
+
};
|
|
1614
|
+
}));
|
|
1615
|
+
|
|
1616
|
+
//#endregion
|
|
1617
|
+
//#region node_modules/debug/src/index.js
|
|
1618
|
+
var require_src = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1619
|
+
/**
|
|
1620
|
+
* Detect Electron renderer / nwjs process, which is node, but we should
|
|
1621
|
+
* treat as a browser.
|
|
1622
|
+
*/
|
|
1623
|
+
if (typeof process === "undefined" || process.type === "renderer" || process.browser === true || process.__nwjs) module.exports = require_browser();
|
|
1624
|
+
else module.exports = require_node();
|
|
1625
|
+
}));
|
|
1626
|
+
|
|
1627
|
+
//#endregion
|
|
1628
|
+
//#region node_modules/@tokenizer/inflate/lib/ZipToken.js
|
|
1629
|
+
var import_src = /* @__PURE__ */ __toESM(require_src(), 1);
|
|
1630
|
+
/**
|
|
1631
|
+
* Ref https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT
|
|
1632
|
+
*/
|
|
1633
|
+
const Signature = {
|
|
1634
|
+
LocalFileHeader: 67324752,
|
|
1635
|
+
DataDescriptor: 134695760,
|
|
1636
|
+
CentralFileHeader: 33639248,
|
|
1637
|
+
EndOfCentralDirectory: 101010256
|
|
1638
|
+
};
|
|
1639
|
+
const DataDescriptor = {
|
|
1640
|
+
get(array) {
|
|
1641
|
+
return {
|
|
1642
|
+
signature: UINT32_LE.get(array, 0),
|
|
1643
|
+
compressedSize: UINT32_LE.get(array, 8),
|
|
1644
|
+
uncompressedSize: UINT32_LE.get(array, 12)
|
|
1645
|
+
};
|
|
1646
|
+
},
|
|
1647
|
+
len: 16
|
|
1648
|
+
};
|
|
1649
|
+
/**
|
|
1650
|
+
* First part of the ZIP Local File Header
|
|
1651
|
+
* Offset | Bytes| Description
|
|
1652
|
+
* -------|------+-------------------------------------------------------------------
|
|
1653
|
+
* 0 | 4 | Signature (0x04034b50)
|
|
1654
|
+
* 4 | 2 | Minimum version needed to extract
|
|
1655
|
+
* 6 | 2 | Bit flag
|
|
1656
|
+
* 8 | 2 | Compression method
|
|
1657
|
+
* 10 | 2 | File last modification time (MS-DOS format)
|
|
1658
|
+
* 12 | 2 | File last modification date (MS-DOS format)
|
|
1659
|
+
* 14 | 4 | CRC-32 of uncompressed data
|
|
1660
|
+
* 18 | 4 | Compressed size
|
|
1661
|
+
* 22 | 4 | Uncompressed size
|
|
1662
|
+
* 26 | 2 | File name length (n)
|
|
1663
|
+
* 28 | 2 | Extra field length (m)
|
|
1664
|
+
* 30 | n | File name
|
|
1665
|
+
* 30 + n | m | Extra field
|
|
1666
|
+
*/
|
|
1667
|
+
const LocalFileHeaderToken = {
|
|
1668
|
+
get(array) {
|
|
1669
|
+
const flags = UINT16_LE.get(array, 6);
|
|
1670
|
+
return {
|
|
1671
|
+
signature: UINT32_LE.get(array, 0),
|
|
1672
|
+
minVersion: UINT16_LE.get(array, 4),
|
|
1673
|
+
dataDescriptor: !!(flags & 8),
|
|
1674
|
+
compressedMethod: UINT16_LE.get(array, 8),
|
|
1675
|
+
compressedSize: UINT32_LE.get(array, 18),
|
|
1676
|
+
uncompressedSize: UINT32_LE.get(array, 22),
|
|
1677
|
+
filenameLength: UINT16_LE.get(array, 26),
|
|
1678
|
+
extraFieldLength: UINT16_LE.get(array, 28),
|
|
1679
|
+
filename: null
|
|
1680
|
+
};
|
|
1681
|
+
},
|
|
1682
|
+
len: 30
|
|
1683
|
+
};
|
|
1684
|
+
/**
|
|
1685
|
+
* 4.3.16 End of central directory record:
|
|
1686
|
+
* end of central dir signature (0x06064b50) 4 bytes
|
|
1687
|
+
* number of this disk 2 bytes
|
|
1688
|
+
* number of the disk with the start of the central directory 2 bytes
|
|
1689
|
+
* total number of entries in the central directory on this disk 2 bytes
|
|
1690
|
+
* total number of entries in the size of the central directory 2 bytes
|
|
1691
|
+
* sizeOfTheCentralDirectory 4 bytes
|
|
1692
|
+
* offset of start of central directory with respect to the starting disk number 4 bytes
|
|
1693
|
+
* .ZIP file comment length 2 bytes
|
|
1694
|
+
* .ZIP file comment (variable size)
|
|
1695
|
+
*/
|
|
1696
|
+
const EndOfCentralDirectoryRecordToken = {
|
|
1697
|
+
get(array) {
|
|
1698
|
+
return {
|
|
1699
|
+
signature: UINT32_LE.get(array, 0),
|
|
1700
|
+
nrOfThisDisk: UINT16_LE.get(array, 4),
|
|
1701
|
+
nrOfThisDiskWithTheStart: UINT16_LE.get(array, 6),
|
|
1702
|
+
nrOfEntriesOnThisDisk: UINT16_LE.get(array, 8),
|
|
1703
|
+
nrOfEntriesOfSize: UINT16_LE.get(array, 10),
|
|
1704
|
+
sizeOfCd: UINT32_LE.get(array, 12),
|
|
1705
|
+
offsetOfStartOfCd: UINT32_LE.get(array, 16),
|
|
1706
|
+
zipFileCommentLength: UINT16_LE.get(array, 20)
|
|
1707
|
+
};
|
|
1708
|
+
},
|
|
1709
|
+
len: 22
|
|
1710
|
+
};
|
|
1711
|
+
/**
|
|
1712
|
+
* File header:
|
|
1713
|
+
* central file header signature 4 bytes 0 (0x02014b50)
|
|
1714
|
+
* version made by 2 bytes 4
|
|
1715
|
+
* version needed to extract 2 bytes 6
|
|
1716
|
+
* general purpose bit flag 2 bytes 8
|
|
1717
|
+
* compression method 2 bytes 10
|
|
1718
|
+
* last mod file time 2 bytes 12
|
|
1719
|
+
* last mod file date 2 bytes 14
|
|
1720
|
+
* crc-32 4 bytes 16
|
|
1721
|
+
* compressed size 4 bytes 20
|
|
1722
|
+
* uncompressed size 4 bytes 24
|
|
1723
|
+
* file name length 2 bytes 28
|
|
1724
|
+
* extra field length 2 bytes 30
|
|
1725
|
+
* file comment length 2 bytes 32
|
|
1726
|
+
* disk number start 2 bytes 34
|
|
1727
|
+
* internal file attributes 2 bytes 36
|
|
1728
|
+
* external file attributes 4 bytes 38
|
|
1729
|
+
* relative offset of local header 4 bytes 42
|
|
1730
|
+
*/
|
|
1731
|
+
const FileHeader = {
|
|
1732
|
+
get(array) {
|
|
1733
|
+
const flags = UINT16_LE.get(array, 8);
|
|
1734
|
+
return {
|
|
1735
|
+
signature: UINT32_LE.get(array, 0),
|
|
1736
|
+
minVersion: UINT16_LE.get(array, 6),
|
|
1737
|
+
dataDescriptor: !!(flags & 8),
|
|
1738
|
+
compressedMethod: UINT16_LE.get(array, 10),
|
|
1739
|
+
compressedSize: UINT32_LE.get(array, 20),
|
|
1740
|
+
uncompressedSize: UINT32_LE.get(array, 24),
|
|
1741
|
+
filenameLength: UINT16_LE.get(array, 28),
|
|
1742
|
+
extraFieldLength: UINT16_LE.get(array, 30),
|
|
1743
|
+
fileCommentLength: UINT16_LE.get(array, 32),
|
|
1744
|
+
relativeOffsetOfLocalHeader: UINT32_LE.get(array, 42),
|
|
1745
|
+
filename: null
|
|
1746
|
+
};
|
|
1747
|
+
},
|
|
1748
|
+
len: 46
|
|
1749
|
+
};
|
|
1750
|
+
|
|
1751
|
+
//#endregion
|
|
1752
|
+
//#region node_modules/@tokenizer/inflate/lib/ZipHandler.js
|
|
1753
|
+
function signatureToArray(signature) {
|
|
1754
|
+
const signatureBytes = new Uint8Array(UINT32_LE.len);
|
|
1755
|
+
UINT32_LE.put(signatureBytes, 0, signature);
|
|
1756
|
+
return signatureBytes;
|
|
1757
|
+
}
|
|
1758
|
+
const debug = (0, import_src.default)("tokenizer:inflate");
|
|
1759
|
+
const syncBufferSize = 256 * 1024;
|
|
1760
|
+
const ddSignatureArray = signatureToArray(Signature.DataDescriptor);
|
|
1761
|
+
const eocdSignatureBytes = signatureToArray(Signature.EndOfCentralDirectory);
|
|
1762
|
+
var ZipHandler = class ZipHandler {
|
|
1763
|
+
constructor(tokenizer) {
|
|
1764
|
+
this.tokenizer = tokenizer;
|
|
1765
|
+
this.syncBuffer = new Uint8Array(syncBufferSize);
|
|
1766
|
+
}
|
|
1767
|
+
async isZip() {
|
|
1768
|
+
return await this.peekSignature() === Signature.LocalFileHeader;
|
|
1769
|
+
}
|
|
1770
|
+
peekSignature() {
|
|
1771
|
+
return this.tokenizer.peekToken(UINT32_LE);
|
|
1772
|
+
}
|
|
1773
|
+
async findEndOfCentralDirectoryLocator() {
|
|
1774
|
+
const randomReadTokenizer = this.tokenizer;
|
|
1775
|
+
const chunkLength = Math.min(16 * 1024, randomReadTokenizer.fileInfo.size);
|
|
1776
|
+
const buffer = this.syncBuffer.subarray(0, chunkLength);
|
|
1777
|
+
await this.tokenizer.readBuffer(buffer, { position: randomReadTokenizer.fileInfo.size - chunkLength });
|
|
1778
|
+
for (let i = buffer.length - 4; i >= 0; i--) if (buffer[i] === eocdSignatureBytes[0] && buffer[i + 1] === eocdSignatureBytes[1] && buffer[i + 2] === eocdSignatureBytes[2] && buffer[i + 3] === eocdSignatureBytes[3]) return randomReadTokenizer.fileInfo.size - chunkLength + i;
|
|
1779
|
+
return -1;
|
|
1780
|
+
}
|
|
1781
|
+
async readCentralDirectory() {
|
|
1782
|
+
if (!this.tokenizer.supportsRandomAccess()) {
|
|
1783
|
+
debug("Cannot reading central-directory without random-read support");
|
|
1784
|
+
return;
|
|
1785
|
+
}
|
|
1786
|
+
debug("Reading central-directory...");
|
|
1787
|
+
const pos = this.tokenizer.position;
|
|
1788
|
+
const offset = await this.findEndOfCentralDirectoryLocator();
|
|
1789
|
+
if (offset > 0) {
|
|
1790
|
+
debug("Central-directory 32-bit signature found");
|
|
1791
|
+
const eocdHeader = await this.tokenizer.readToken(EndOfCentralDirectoryRecordToken, offset);
|
|
1792
|
+
const files = [];
|
|
1793
|
+
this.tokenizer.setPosition(eocdHeader.offsetOfStartOfCd);
|
|
1794
|
+
for (let n = 0; n < eocdHeader.nrOfEntriesOfSize; ++n) {
|
|
1795
|
+
const entry = await this.tokenizer.readToken(FileHeader);
|
|
1796
|
+
if (entry.signature !== Signature.CentralFileHeader) throw new Error("Expected Central-File-Header signature");
|
|
1797
|
+
entry.filename = await this.tokenizer.readToken(new StringType(entry.filenameLength, "utf-8"));
|
|
1798
|
+
await this.tokenizer.ignore(entry.extraFieldLength);
|
|
1799
|
+
await this.tokenizer.ignore(entry.fileCommentLength);
|
|
1800
|
+
files.push(entry);
|
|
1801
|
+
debug(`Add central-directory file-entry: n=${n + 1}/${files.length}: filename=${files[n].filename}`);
|
|
1802
|
+
}
|
|
1803
|
+
this.tokenizer.setPosition(pos);
|
|
1804
|
+
return files;
|
|
1805
|
+
}
|
|
1806
|
+
this.tokenizer.setPosition(pos);
|
|
1807
|
+
}
|
|
1808
|
+
async unzip(fileCb) {
|
|
1809
|
+
const entries = await this.readCentralDirectory();
|
|
1810
|
+
if (entries) return this.iterateOverCentralDirectory(entries, fileCb);
|
|
1811
|
+
let stop = false;
|
|
1812
|
+
do {
|
|
1813
|
+
const zipHeader = await this.readLocalFileHeader();
|
|
1814
|
+
if (!zipHeader) break;
|
|
1815
|
+
const next = fileCb(zipHeader);
|
|
1816
|
+
stop = !!next.stop;
|
|
1817
|
+
let fileData;
|
|
1818
|
+
await this.tokenizer.ignore(zipHeader.extraFieldLength);
|
|
1819
|
+
if (zipHeader.dataDescriptor && zipHeader.compressedSize === 0) {
|
|
1820
|
+
const chunks = [];
|
|
1821
|
+
let len = syncBufferSize;
|
|
1822
|
+
debug("Compressed-file-size unknown, scanning for next data-descriptor-signature....");
|
|
1823
|
+
let nextHeaderIndex = -1;
|
|
1824
|
+
while (nextHeaderIndex < 0 && len === syncBufferSize) {
|
|
1825
|
+
len = await this.tokenizer.peekBuffer(this.syncBuffer, { mayBeLess: true });
|
|
1826
|
+
nextHeaderIndex = indexOf(this.syncBuffer.subarray(0, len), ddSignatureArray);
|
|
1827
|
+
const size = nextHeaderIndex >= 0 ? nextHeaderIndex : len;
|
|
1828
|
+
if (next.handler) {
|
|
1829
|
+
const data = new Uint8Array(size);
|
|
1830
|
+
await this.tokenizer.readBuffer(data);
|
|
1831
|
+
chunks.push(data);
|
|
1832
|
+
} else await this.tokenizer.ignore(size);
|
|
1833
|
+
}
|
|
1834
|
+
debug(`Found data-descriptor-signature at pos=${this.tokenizer.position}`);
|
|
1835
|
+
if (next.handler) await this.inflate(zipHeader, mergeArrays(chunks), next.handler);
|
|
1836
|
+
} else if (next.handler) {
|
|
1837
|
+
debug(`Reading compressed-file-data: ${zipHeader.compressedSize} bytes`);
|
|
1838
|
+
fileData = new Uint8Array(zipHeader.compressedSize);
|
|
1839
|
+
await this.tokenizer.readBuffer(fileData);
|
|
1840
|
+
await this.inflate(zipHeader, fileData, next.handler);
|
|
1841
|
+
} else {
|
|
1842
|
+
debug(`Ignoring compressed-file-data: ${zipHeader.compressedSize} bytes`);
|
|
1843
|
+
await this.tokenizer.ignore(zipHeader.compressedSize);
|
|
1844
|
+
}
|
|
1845
|
+
debug(`Reading data-descriptor at pos=${this.tokenizer.position}`);
|
|
1846
|
+
if (zipHeader.dataDescriptor) {
|
|
1847
|
+
if ((await this.tokenizer.readToken(DataDescriptor)).signature !== 134695760) throw new Error(`Expected data-descriptor-signature at position ${this.tokenizer.position - DataDescriptor.len}`);
|
|
1848
|
+
}
|
|
1849
|
+
} while (!stop);
|
|
1850
|
+
}
|
|
1851
|
+
async iterateOverCentralDirectory(entries, fileCb) {
|
|
1852
|
+
for (const fileHeader of entries) {
|
|
1853
|
+
const next = fileCb(fileHeader);
|
|
1854
|
+
if (next.handler) {
|
|
1855
|
+
this.tokenizer.setPosition(fileHeader.relativeOffsetOfLocalHeader);
|
|
1856
|
+
const zipHeader = await this.readLocalFileHeader();
|
|
1857
|
+
if (zipHeader) {
|
|
1858
|
+
await this.tokenizer.ignore(zipHeader.extraFieldLength);
|
|
1859
|
+
const fileData = new Uint8Array(fileHeader.compressedSize);
|
|
1860
|
+
await this.tokenizer.readBuffer(fileData);
|
|
1861
|
+
await this.inflate(zipHeader, fileData, next.handler);
|
|
1862
|
+
}
|
|
1863
|
+
}
|
|
1864
|
+
if (next.stop) break;
|
|
1865
|
+
}
|
|
1866
|
+
}
|
|
1867
|
+
async inflate(zipHeader, fileData, cb) {
|
|
1868
|
+
if (zipHeader.compressedMethod === 0) return cb(fileData);
|
|
1869
|
+
if (zipHeader.compressedMethod !== 8) throw new Error(`Unsupported ZIP compression method: ${zipHeader.compressedMethod}`);
|
|
1870
|
+
debug(`Decompress filename=${zipHeader.filename}, compressed-size=${fileData.length}`);
|
|
1871
|
+
return cb(await ZipHandler.decompressDeflateRaw(fileData));
|
|
1872
|
+
}
|
|
1873
|
+
static async decompressDeflateRaw(data) {
|
|
1874
|
+
const input = new ReadableStream({ start(controller) {
|
|
1875
|
+
controller.enqueue(data);
|
|
1876
|
+
controller.close();
|
|
1877
|
+
} });
|
|
1878
|
+
const ds = new DecompressionStream("deflate-raw");
|
|
1879
|
+
const output = input.pipeThrough(ds);
|
|
1880
|
+
try {
|
|
1881
|
+
const buffer = await new Response(output).arrayBuffer();
|
|
1882
|
+
return new Uint8Array(buffer);
|
|
1883
|
+
} catch (err) {
|
|
1884
|
+
const message = err instanceof Error ? `Failed to deflate ZIP entry: ${err.message}` : "Unknown decompression error in ZIP entry";
|
|
1885
|
+
throw new TypeError(message);
|
|
1886
|
+
}
|
|
1887
|
+
}
|
|
1888
|
+
async readLocalFileHeader() {
|
|
1889
|
+
const signature = await this.tokenizer.peekToken(UINT32_LE);
|
|
1890
|
+
if (signature === Signature.LocalFileHeader) {
|
|
1891
|
+
const header = await this.tokenizer.readToken(LocalFileHeaderToken);
|
|
1892
|
+
header.filename = await this.tokenizer.readToken(new StringType(header.filenameLength, "utf-8"));
|
|
1893
|
+
return header;
|
|
1894
|
+
}
|
|
1895
|
+
if (signature === Signature.CentralFileHeader) return false;
|
|
1896
|
+
if (signature === 3759263696) throw new Error("Encrypted ZIP");
|
|
1897
|
+
throw new Error("Unexpected signature");
|
|
1898
|
+
}
|
|
1899
|
+
};
|
|
1900
|
+
function indexOf(buffer, portion) {
|
|
1901
|
+
const bufferLength = buffer.length;
|
|
1902
|
+
const portionLength = portion.length;
|
|
1903
|
+
if (portionLength > bufferLength) return -1;
|
|
1904
|
+
for (let i = 0; i <= bufferLength - portionLength; i++) {
|
|
1905
|
+
let found = true;
|
|
1906
|
+
for (let j = 0; j < portionLength; j++) if (buffer[i + j] !== portion[j]) {
|
|
1907
|
+
found = false;
|
|
1908
|
+
break;
|
|
1909
|
+
}
|
|
1910
|
+
if (found) return i;
|
|
1911
|
+
}
|
|
1912
|
+
return -1;
|
|
1913
|
+
}
|
|
1914
|
+
function mergeArrays(chunks) {
|
|
1915
|
+
const totalLength = chunks.reduce((acc, curr) => acc + curr.length, 0);
|
|
1916
|
+
const mergedArray = new Uint8Array(totalLength);
|
|
1917
|
+
let offset = 0;
|
|
1918
|
+
for (const chunk of chunks) {
|
|
1919
|
+
mergedArray.set(chunk, offset);
|
|
1920
|
+
offset += chunk.length;
|
|
1921
|
+
}
|
|
1922
|
+
return mergedArray;
|
|
1923
|
+
}
|
|
1924
|
+
|
|
1925
|
+
//#endregion
|
|
1926
|
+
//#region node_modules/@tokenizer/inflate/lib/GzipHandler.js
|
|
1927
|
+
var GzipHandler = class {
|
|
1928
|
+
constructor(tokenizer) {
|
|
1929
|
+
this.tokenizer = tokenizer;
|
|
1930
|
+
}
|
|
1931
|
+
inflate() {
|
|
1932
|
+
const tokenizer = this.tokenizer;
|
|
1933
|
+
return new ReadableStream({ async pull(controller) {
|
|
1934
|
+
const buffer = new Uint8Array(1024);
|
|
1935
|
+
const size = await tokenizer.readBuffer(buffer, { mayBeLess: true });
|
|
1936
|
+
if (size === 0) {
|
|
1937
|
+
controller.close();
|
|
1938
|
+
return;
|
|
1939
|
+
}
|
|
1940
|
+
controller.enqueue(buffer.subarray(0, size));
|
|
1941
|
+
} }).pipeThrough(new DecompressionStream("gzip"));
|
|
1942
|
+
}
|
|
1943
|
+
};
|
|
1944
|
+
|
|
1945
|
+
//#endregion
|
|
1946
|
+
//#region node_modules/uint8array-extras/index.js
|
|
1947
|
+
const cachedDecoders = { utf8: new globalThis.TextDecoder("utf8") };
|
|
1948
|
+
const cachedEncoder = new globalThis.TextEncoder();
|
|
1949
|
+
const byteToHexLookupTable = Array.from({ length: 256 }, (_, index) => index.toString(16).padStart(2, "0"));
|
|
1950
|
+
/**
|
|
1951
|
+
@param {DataView} view
|
|
1952
|
+
@returns {number}
|
|
1953
|
+
*/
|
|
1954
|
+
function getUintBE(view) {
|
|
1955
|
+
const { byteLength } = view;
|
|
1956
|
+
if (byteLength === 6) return view.getUint16(0) * 2 ** 32 + view.getUint32(2);
|
|
1957
|
+
if (byteLength === 5) return view.getUint8(0) * 2 ** 32 + view.getUint32(1);
|
|
1958
|
+
if (byteLength === 4) return view.getUint32(0);
|
|
1959
|
+
if (byteLength === 3) return view.getUint8(0) * 2 ** 16 + view.getUint16(1);
|
|
1960
|
+
if (byteLength === 2) return view.getUint16(0);
|
|
1961
|
+
if (byteLength === 1) return view.getUint8(0);
|
|
1962
|
+
}
|
|
1963
|
+
|
|
1964
|
+
//#endregion
|
|
1965
|
+
//#region node_modules/file-type/util.js
|
|
1966
|
+
function stringToBytes(string, encoding) {
|
|
1967
|
+
if (encoding === "utf-16le") {
|
|
1968
|
+
const bytes = [];
|
|
1969
|
+
for (let index = 0; index < string.length; index++) {
|
|
1970
|
+
const code = string.charCodeAt(index);
|
|
1971
|
+
bytes.push(code & 255, code >> 8 & 255);
|
|
1972
|
+
}
|
|
1973
|
+
return bytes;
|
|
1974
|
+
}
|
|
1975
|
+
if (encoding === "utf-16be") {
|
|
1976
|
+
const bytes = [];
|
|
1977
|
+
for (let index = 0; index < string.length; index++) {
|
|
1978
|
+
const code = string.charCodeAt(index);
|
|
1979
|
+
bytes.push(code >> 8 & 255, code & 255);
|
|
1980
|
+
}
|
|
1981
|
+
return bytes;
|
|
1982
|
+
}
|
|
1983
|
+
return [...string].map((character) => character.charCodeAt(0));
|
|
1984
|
+
}
|
|
1985
|
+
/**
|
|
1986
|
+
Checks whether the TAR checksum is valid.
|
|
1987
|
+
|
|
1988
|
+
@param {Uint8Array} arrayBuffer - The TAR header `[offset ... offset + 512]`.
|
|
1989
|
+
@param {number} offset - TAR header offset.
|
|
1990
|
+
@returns {boolean} `true` if the TAR checksum is valid, otherwise `false`.
|
|
1991
|
+
*/
|
|
1992
|
+
function tarHeaderChecksumMatches(arrayBuffer, offset = 0) {
|
|
1993
|
+
const readSum = Number.parseInt(new StringType(6).get(arrayBuffer, 148).replace(/\0.*$/, "").trim(), 8);
|
|
1994
|
+
if (Number.isNaN(readSum)) return false;
|
|
1995
|
+
let sum = 256;
|
|
1996
|
+
for (let index = offset; index < offset + 148; index++) sum += arrayBuffer[index];
|
|
1997
|
+
for (let index = offset + 156; index < offset + 512; index++) sum += arrayBuffer[index];
|
|
1998
|
+
return readSum === sum;
|
|
1999
|
+
}
|
|
2000
|
+
/**
|
|
2001
|
+
ID3 UINT32 sync-safe tokenizer token.
|
|
2002
|
+
28 bits (representing up to 256MB) integer, the msb is 0 to avoid "false syncsignals".
|
|
2003
|
+
*/
|
|
2004
|
+
const uint32SyncSafeToken = {
|
|
2005
|
+
get: (buffer, offset) => buffer[offset + 3] & 127 | buffer[offset + 2] << 7 | buffer[offset + 1] << 14 | buffer[offset] << 21,
|
|
2006
|
+
len: 4
|
|
2007
|
+
};
|
|
2008
|
+
|
|
2009
|
+
//#endregion
|
|
2010
|
+
//#region node_modules/file-type/supported.js
|
|
2011
|
+
const extensions = [
|
|
2012
|
+
"jpg",
|
|
2013
|
+
"png",
|
|
2014
|
+
"apng",
|
|
2015
|
+
"gif",
|
|
2016
|
+
"webp",
|
|
2017
|
+
"flif",
|
|
2018
|
+
"xcf",
|
|
2019
|
+
"cr2",
|
|
2020
|
+
"cr3",
|
|
2021
|
+
"orf",
|
|
2022
|
+
"arw",
|
|
2023
|
+
"dng",
|
|
2024
|
+
"nef",
|
|
2025
|
+
"rw2",
|
|
2026
|
+
"raf",
|
|
2027
|
+
"tif",
|
|
2028
|
+
"bmp",
|
|
2029
|
+
"icns",
|
|
2030
|
+
"jxr",
|
|
2031
|
+
"psd",
|
|
2032
|
+
"indd",
|
|
2033
|
+
"zip",
|
|
2034
|
+
"tar",
|
|
2035
|
+
"rar",
|
|
2036
|
+
"gz",
|
|
2037
|
+
"bz2",
|
|
2038
|
+
"7z",
|
|
2039
|
+
"dmg",
|
|
2040
|
+
"mp4",
|
|
2041
|
+
"mid",
|
|
2042
|
+
"mkv",
|
|
2043
|
+
"webm",
|
|
2044
|
+
"mov",
|
|
2045
|
+
"avi",
|
|
2046
|
+
"mpg",
|
|
2047
|
+
"mp2",
|
|
2048
|
+
"mp3",
|
|
2049
|
+
"m4a",
|
|
2050
|
+
"oga",
|
|
2051
|
+
"ogg",
|
|
2052
|
+
"ogv",
|
|
2053
|
+
"opus",
|
|
2054
|
+
"flac",
|
|
2055
|
+
"wav",
|
|
2056
|
+
"spx",
|
|
2057
|
+
"amr",
|
|
2058
|
+
"pdf",
|
|
2059
|
+
"epub",
|
|
2060
|
+
"elf",
|
|
2061
|
+
"macho",
|
|
2062
|
+
"exe",
|
|
2063
|
+
"swf",
|
|
2064
|
+
"rtf",
|
|
2065
|
+
"wasm",
|
|
2066
|
+
"woff",
|
|
2067
|
+
"woff2",
|
|
2068
|
+
"eot",
|
|
2069
|
+
"ttf",
|
|
2070
|
+
"otf",
|
|
2071
|
+
"ttc",
|
|
2072
|
+
"ico",
|
|
2073
|
+
"flv",
|
|
2074
|
+
"ps",
|
|
2075
|
+
"xz",
|
|
2076
|
+
"sqlite",
|
|
2077
|
+
"nes",
|
|
2078
|
+
"crx",
|
|
2079
|
+
"xpi",
|
|
2080
|
+
"cab",
|
|
2081
|
+
"deb",
|
|
2082
|
+
"ar",
|
|
2083
|
+
"rpm",
|
|
2084
|
+
"Z",
|
|
2085
|
+
"lz",
|
|
2086
|
+
"cfb",
|
|
2087
|
+
"mxf",
|
|
2088
|
+
"mts",
|
|
2089
|
+
"blend",
|
|
2090
|
+
"bpg",
|
|
2091
|
+
"docx",
|
|
2092
|
+
"pptx",
|
|
2093
|
+
"xlsx",
|
|
2094
|
+
"3gp",
|
|
2095
|
+
"3g2",
|
|
2096
|
+
"j2c",
|
|
2097
|
+
"jp2",
|
|
2098
|
+
"jpm",
|
|
2099
|
+
"jpx",
|
|
2100
|
+
"mj2",
|
|
2101
|
+
"aif",
|
|
2102
|
+
"qcp",
|
|
2103
|
+
"odt",
|
|
2104
|
+
"ods",
|
|
2105
|
+
"odp",
|
|
2106
|
+
"xml",
|
|
2107
|
+
"mobi",
|
|
2108
|
+
"heic",
|
|
2109
|
+
"cur",
|
|
2110
|
+
"ktx",
|
|
2111
|
+
"ape",
|
|
2112
|
+
"wv",
|
|
2113
|
+
"dcm",
|
|
2114
|
+
"ics",
|
|
2115
|
+
"glb",
|
|
2116
|
+
"pcap",
|
|
2117
|
+
"dsf",
|
|
2118
|
+
"lnk",
|
|
2119
|
+
"alias",
|
|
2120
|
+
"voc",
|
|
2121
|
+
"ac3",
|
|
2122
|
+
"m4v",
|
|
2123
|
+
"m4p",
|
|
2124
|
+
"m4b",
|
|
2125
|
+
"f4v",
|
|
2126
|
+
"f4p",
|
|
2127
|
+
"f4b",
|
|
2128
|
+
"f4a",
|
|
2129
|
+
"mie",
|
|
2130
|
+
"asf",
|
|
2131
|
+
"ogm",
|
|
2132
|
+
"ogx",
|
|
2133
|
+
"mpc",
|
|
2134
|
+
"arrow",
|
|
2135
|
+
"shp",
|
|
2136
|
+
"aac",
|
|
2137
|
+
"mp1",
|
|
2138
|
+
"it",
|
|
2139
|
+
"s3m",
|
|
2140
|
+
"xm",
|
|
2141
|
+
"skp",
|
|
2142
|
+
"avif",
|
|
2143
|
+
"eps",
|
|
2144
|
+
"lzh",
|
|
2145
|
+
"pgp",
|
|
2146
|
+
"asar",
|
|
2147
|
+
"stl",
|
|
2148
|
+
"chm",
|
|
2149
|
+
"3mf",
|
|
2150
|
+
"zst",
|
|
2151
|
+
"jxl",
|
|
2152
|
+
"vcf",
|
|
2153
|
+
"jls",
|
|
2154
|
+
"pst",
|
|
2155
|
+
"dwg",
|
|
2156
|
+
"parquet",
|
|
2157
|
+
"class",
|
|
2158
|
+
"arj",
|
|
2159
|
+
"cpio",
|
|
2160
|
+
"ace",
|
|
2161
|
+
"avro",
|
|
2162
|
+
"icc",
|
|
2163
|
+
"fbx",
|
|
2164
|
+
"vsdx",
|
|
2165
|
+
"vtt",
|
|
2166
|
+
"apk",
|
|
2167
|
+
"drc",
|
|
2168
|
+
"lz4",
|
|
2169
|
+
"potx",
|
|
2170
|
+
"xltx",
|
|
2171
|
+
"dotx",
|
|
2172
|
+
"xltm",
|
|
2173
|
+
"ott",
|
|
2174
|
+
"ots",
|
|
2175
|
+
"otp",
|
|
2176
|
+
"odg",
|
|
2177
|
+
"otg",
|
|
2178
|
+
"xlsm",
|
|
2179
|
+
"docm",
|
|
2180
|
+
"dotm",
|
|
2181
|
+
"potm",
|
|
2182
|
+
"pptm",
|
|
2183
|
+
"jar",
|
|
2184
|
+
"jmp",
|
|
2185
|
+
"rm",
|
|
2186
|
+
"sav",
|
|
2187
|
+
"ppsm",
|
|
2188
|
+
"ppsx",
|
|
2189
|
+
"tar.gz",
|
|
2190
|
+
"reg",
|
|
2191
|
+
"dat"
|
|
2192
|
+
];
|
|
2193
|
+
const mimeTypes = [
|
|
2194
|
+
"image/jpeg",
|
|
2195
|
+
"image/png",
|
|
2196
|
+
"image/gif",
|
|
2197
|
+
"image/webp",
|
|
2198
|
+
"image/flif",
|
|
2199
|
+
"image/x-xcf",
|
|
2200
|
+
"image/x-canon-cr2",
|
|
2201
|
+
"image/x-canon-cr3",
|
|
2202
|
+
"image/tiff",
|
|
2203
|
+
"image/bmp",
|
|
2204
|
+
"image/vnd.ms-photo",
|
|
2205
|
+
"image/vnd.adobe.photoshop",
|
|
2206
|
+
"application/x-indesign",
|
|
2207
|
+
"application/epub+zip",
|
|
2208
|
+
"application/x-xpinstall",
|
|
2209
|
+
"application/vnd.ms-powerpoint.slideshow.macroenabled.12",
|
|
2210
|
+
"application/vnd.oasis.opendocument.text",
|
|
2211
|
+
"application/vnd.oasis.opendocument.spreadsheet",
|
|
2212
|
+
"application/vnd.oasis.opendocument.presentation",
|
|
2213
|
+
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
2214
|
+
"application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
|
2215
|
+
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
2216
|
+
"application/vnd.openxmlformats-officedocument.presentationml.slideshow",
|
|
2217
|
+
"application/zip",
|
|
2218
|
+
"application/x-tar",
|
|
2219
|
+
"application/x-rar-compressed",
|
|
2220
|
+
"application/gzip",
|
|
2221
|
+
"application/x-bzip2",
|
|
2222
|
+
"application/x-7z-compressed",
|
|
2223
|
+
"application/x-apple-diskimage",
|
|
2224
|
+
"application/vnd.apache.arrow.file",
|
|
2225
|
+
"video/mp4",
|
|
2226
|
+
"audio/midi",
|
|
2227
|
+
"video/matroska",
|
|
2228
|
+
"video/webm",
|
|
2229
|
+
"video/quicktime",
|
|
2230
|
+
"video/vnd.avi",
|
|
2231
|
+
"audio/wav",
|
|
2232
|
+
"audio/qcelp",
|
|
2233
|
+
"audio/x-ms-asf",
|
|
2234
|
+
"video/x-ms-asf",
|
|
2235
|
+
"application/vnd.ms-asf",
|
|
2236
|
+
"video/mpeg",
|
|
2237
|
+
"video/3gpp",
|
|
2238
|
+
"audio/mpeg",
|
|
2239
|
+
"audio/mp4",
|
|
2240
|
+
"video/ogg",
|
|
2241
|
+
"audio/ogg",
|
|
2242
|
+
"audio/ogg; codecs=opus",
|
|
2243
|
+
"application/ogg",
|
|
2244
|
+
"audio/flac",
|
|
2245
|
+
"audio/ape",
|
|
2246
|
+
"audio/wavpack",
|
|
2247
|
+
"audio/amr",
|
|
2248
|
+
"application/pdf",
|
|
2249
|
+
"application/x-elf",
|
|
2250
|
+
"application/x-mach-binary",
|
|
2251
|
+
"application/x-msdownload",
|
|
2252
|
+
"application/x-shockwave-flash",
|
|
2253
|
+
"application/rtf",
|
|
2254
|
+
"application/wasm",
|
|
2255
|
+
"font/woff",
|
|
2256
|
+
"font/woff2",
|
|
2257
|
+
"application/vnd.ms-fontobject",
|
|
2258
|
+
"font/ttf",
|
|
2259
|
+
"font/otf",
|
|
2260
|
+
"font/collection",
|
|
2261
|
+
"image/x-icon",
|
|
2262
|
+
"video/x-flv",
|
|
2263
|
+
"application/postscript",
|
|
2264
|
+
"application/eps",
|
|
2265
|
+
"application/x-xz",
|
|
2266
|
+
"application/x-sqlite3",
|
|
2267
|
+
"application/x-nintendo-nes-rom",
|
|
2268
|
+
"application/x-google-chrome-extension",
|
|
2269
|
+
"application/vnd.ms-cab-compressed",
|
|
2270
|
+
"application/x-deb",
|
|
2271
|
+
"application/x-unix-archive",
|
|
2272
|
+
"application/x-rpm",
|
|
2273
|
+
"application/x-compress",
|
|
2274
|
+
"application/x-lzip",
|
|
2275
|
+
"application/x-cfb",
|
|
2276
|
+
"application/x-mie",
|
|
2277
|
+
"application/mxf",
|
|
2278
|
+
"video/mp2t",
|
|
2279
|
+
"application/x-blender",
|
|
2280
|
+
"image/bpg",
|
|
2281
|
+
"image/j2c",
|
|
2282
|
+
"image/jp2",
|
|
2283
|
+
"image/jpx",
|
|
2284
|
+
"image/jpm",
|
|
2285
|
+
"image/mj2",
|
|
2286
|
+
"audio/aiff",
|
|
2287
|
+
"application/xml",
|
|
2288
|
+
"application/x-mobipocket-ebook",
|
|
2289
|
+
"image/heif",
|
|
2290
|
+
"image/heif-sequence",
|
|
2291
|
+
"image/heic",
|
|
2292
|
+
"image/heic-sequence",
|
|
2293
|
+
"image/icns",
|
|
2294
|
+
"image/ktx",
|
|
2295
|
+
"application/dicom",
|
|
2296
|
+
"audio/x-musepack",
|
|
2297
|
+
"text/calendar",
|
|
2298
|
+
"text/vcard",
|
|
2299
|
+
"text/vtt",
|
|
2300
|
+
"model/gltf-binary",
|
|
2301
|
+
"application/vnd.tcpdump.pcap",
|
|
2302
|
+
"audio/x-dsf",
|
|
2303
|
+
"application/x.ms.shortcut",
|
|
2304
|
+
"application/x.apple.alias",
|
|
2305
|
+
"audio/x-voc",
|
|
2306
|
+
"audio/vnd.dolby.dd-raw",
|
|
2307
|
+
"audio/x-m4a",
|
|
2308
|
+
"image/apng",
|
|
2309
|
+
"image/x-olympus-orf",
|
|
2310
|
+
"image/x-sony-arw",
|
|
2311
|
+
"image/x-adobe-dng",
|
|
2312
|
+
"image/x-nikon-nef",
|
|
2313
|
+
"image/x-panasonic-rw2",
|
|
2314
|
+
"image/x-fujifilm-raf",
|
|
2315
|
+
"video/x-m4v",
|
|
2316
|
+
"video/3gpp2",
|
|
2317
|
+
"application/x-esri-shape",
|
|
2318
|
+
"audio/aac",
|
|
2319
|
+
"audio/x-it",
|
|
2320
|
+
"audio/x-s3m",
|
|
2321
|
+
"audio/x-xm",
|
|
2322
|
+
"video/MP1S",
|
|
2323
|
+
"video/MP2P",
|
|
2324
|
+
"application/vnd.sketchup.skp",
|
|
2325
|
+
"image/avif",
|
|
2326
|
+
"application/x-lzh-compressed",
|
|
2327
|
+
"application/pgp-encrypted",
|
|
2328
|
+
"application/x-asar",
|
|
2329
|
+
"model/stl",
|
|
2330
|
+
"application/vnd.ms-htmlhelp",
|
|
2331
|
+
"model/3mf",
|
|
2332
|
+
"image/jxl",
|
|
2333
|
+
"application/zstd",
|
|
2334
|
+
"image/jls",
|
|
2335
|
+
"application/vnd.ms-outlook",
|
|
2336
|
+
"image/vnd.dwg",
|
|
2337
|
+
"application/vnd.apache.parquet",
|
|
2338
|
+
"application/java-vm",
|
|
2339
|
+
"application/x-arj",
|
|
2340
|
+
"application/x-cpio",
|
|
2341
|
+
"application/x-ace-compressed",
|
|
2342
|
+
"application/avro",
|
|
2343
|
+
"application/vnd.iccprofile",
|
|
2344
|
+
"application/x.autodesk.fbx",
|
|
2345
|
+
"application/vnd.visio",
|
|
2346
|
+
"application/vnd.android.package-archive",
|
|
2347
|
+
"application/vnd.google.draco",
|
|
2348
|
+
"application/x-lz4",
|
|
2349
|
+
"application/vnd.openxmlformats-officedocument.presentationml.template",
|
|
2350
|
+
"application/vnd.openxmlformats-officedocument.spreadsheetml.template",
|
|
2351
|
+
"application/vnd.openxmlformats-officedocument.wordprocessingml.template",
|
|
2352
|
+
"application/vnd.ms-excel.template.macroenabled.12",
|
|
2353
|
+
"application/vnd.oasis.opendocument.text-template",
|
|
2354
|
+
"application/vnd.oasis.opendocument.spreadsheet-template",
|
|
2355
|
+
"application/vnd.oasis.opendocument.presentation-template",
|
|
2356
|
+
"application/vnd.oasis.opendocument.graphics",
|
|
2357
|
+
"application/vnd.oasis.opendocument.graphics-template",
|
|
2358
|
+
"application/vnd.ms-excel.sheet.macroenabled.12",
|
|
2359
|
+
"application/vnd.ms-word.document.macroenabled.12",
|
|
2360
|
+
"application/vnd.ms-word.template.macroenabled.12",
|
|
2361
|
+
"application/vnd.ms-powerpoint.template.macroenabled.12",
|
|
2362
|
+
"application/vnd.ms-powerpoint.presentation.macroenabled.12",
|
|
2363
|
+
"application/java-archive",
|
|
2364
|
+
"application/vnd.rn-realmedia",
|
|
2365
|
+
"application/x-spss-sav",
|
|
2366
|
+
"application/x-ms-regedit",
|
|
2367
|
+
"application/x-ft-windows-registry-hive",
|
|
2368
|
+
"application/x-jmp-data"
|
|
2369
|
+
];
|
|
2370
|
+
|
|
2371
|
+
//#endregion
|
|
2372
|
+
//#region node_modules/file-type/core.js
|
|
2373
|
+
/**
|
|
2374
|
+
Primary entry point, Node.js specific entry point is index.js
|
|
2375
|
+
*/
|
|
2376
|
+
const reasonableDetectionSizeInBytes = 4100;
|
|
2377
|
+
const maximumMpegOffsetTolerance = reasonableDetectionSizeInBytes - 2;
|
|
2378
|
+
const maximumZipEntrySizeInBytes = 1024 * 1024;
|
|
2379
|
+
const maximumUntrustedSkipSizeInBytes = 16 * 1024 * 1024;
|
|
2380
|
+
const maximumNestedGzipDetectionSizeInBytes = maximumUntrustedSkipSizeInBytes;
|
|
2381
|
+
const maximumId3HeaderSizeInBytes = maximumUntrustedSkipSizeInBytes;
|
|
2382
|
+
const maximumEbmlDocumentTypeSizeInBytes = 64;
|
|
2383
|
+
const maximumEbmlElementPayloadSizeInBytes = maximumUntrustedSkipSizeInBytes;
|
|
2384
|
+
const maximumEbmlElementCount = 256;
|
|
2385
|
+
const maximumPngChunkSizeInBytes = maximumUntrustedSkipSizeInBytes;
|
|
2386
|
+
const maximumTiffIfdOffsetInBytes = maximumUntrustedSkipSizeInBytes;
|
|
2387
|
+
const recoverableZipErrorMessages = new Set([
|
|
2388
|
+
"Unexpected signature",
|
|
2389
|
+
"Encrypted ZIP",
|
|
2390
|
+
"Expected Central-File-Header signature"
|
|
2391
|
+
]);
|
|
2392
|
+
const recoverableZipErrorMessagePrefixes = ["Unsupported ZIP compression method:", "ZIP entry decompressed data exceeds "];
|
|
2393
|
+
const recoverableZipErrorCodes = new Set([
|
|
2394
|
+
"Z_BUF_ERROR",
|
|
2395
|
+
"Z_DATA_ERROR",
|
|
2396
|
+
"ERR_INVALID_STATE"
|
|
2397
|
+
]);
|
|
2398
|
+
var ParserHardLimitError = class extends Error {};
|
|
2399
|
+
function getSafeBound(value, maximum, reason) {
|
|
2400
|
+
if (!Number.isFinite(value) || value < 0 || value > maximum) throw new ParserHardLimitError(`${reason} has invalid size ${value} (maximum ${maximum} bytes)`);
|
|
2401
|
+
return value;
|
|
2402
|
+
}
|
|
2403
|
+
async function safeIgnore(tokenizer, length, { maximumLength = maximumUntrustedSkipSizeInBytes, reason = "skip" } = {}) {
|
|
2404
|
+
const safeLength = getSafeBound(length, maximumLength, reason);
|
|
2405
|
+
await tokenizer.ignore(safeLength);
|
|
2406
|
+
}
|
|
2407
|
+
async function safeReadBuffer(tokenizer, buffer, options, { maximumLength = buffer.length, reason = "read" } = {}) {
|
|
2408
|
+
const safeLength = getSafeBound(options?.length ?? buffer.length, maximumLength, reason);
|
|
2409
|
+
return tokenizer.readBuffer(buffer, {
|
|
2410
|
+
...options,
|
|
2411
|
+
length: safeLength
|
|
2412
|
+
});
|
|
2413
|
+
}
|
|
2414
|
+
async function decompressDeflateRawWithLimit(data, { maximumLength = maximumZipEntrySizeInBytes } = {}) {
|
|
2415
|
+
const reader = new ReadableStream({ start(controller) {
|
|
2416
|
+
controller.enqueue(data);
|
|
2417
|
+
controller.close();
|
|
2418
|
+
} }).pipeThrough(new DecompressionStream("deflate-raw")).getReader();
|
|
2419
|
+
const chunks = [];
|
|
2420
|
+
let totalLength = 0;
|
|
2421
|
+
try {
|
|
2422
|
+
for (;;) {
|
|
2423
|
+
const { done, value } = await reader.read();
|
|
2424
|
+
if (done) break;
|
|
2425
|
+
totalLength += value.length;
|
|
2426
|
+
if (totalLength > maximumLength) {
|
|
2427
|
+
await reader.cancel();
|
|
2428
|
+
throw new Error(`ZIP entry decompressed data exceeds ${maximumLength} bytes`);
|
|
2429
|
+
}
|
|
2430
|
+
chunks.push(value);
|
|
2431
|
+
}
|
|
2432
|
+
} finally {
|
|
2433
|
+
reader.releaseLock();
|
|
2434
|
+
}
|
|
2435
|
+
const uncompressedData = new Uint8Array(totalLength);
|
|
2436
|
+
let offset = 0;
|
|
2437
|
+
for (const chunk of chunks) {
|
|
2438
|
+
uncompressedData.set(chunk, offset);
|
|
2439
|
+
offset += chunk.length;
|
|
2440
|
+
}
|
|
2441
|
+
return uncompressedData;
|
|
2442
|
+
}
|
|
2443
|
+
ZipHandler.prototype.inflate = async function(zipHeader, fileData, callback) {
|
|
2444
|
+
if (zipHeader.compressedMethod === 0) return callback(fileData);
|
|
2445
|
+
if (zipHeader.compressedMethod !== 8) throw new Error(`Unsupported ZIP compression method: ${zipHeader.compressedMethod}`);
|
|
2446
|
+
return callback(await decompressDeflateRawWithLimit(fileData, { maximumLength: hasUnknownFileSize(this.tokenizer) ? maximumZipEntrySizeInBytes : Number.MAX_SAFE_INTEGER }));
|
|
2447
|
+
};
|
|
2448
|
+
function createByteLimitedReadableStream(stream, maximumBytes) {
|
|
2449
|
+
const reader = stream.getReader();
|
|
2450
|
+
let emittedBytes = 0;
|
|
2451
|
+
let sourceDone = false;
|
|
2452
|
+
let sourceCanceled = false;
|
|
2453
|
+
const cancelSource = async (reason) => {
|
|
2454
|
+
if (sourceDone || sourceCanceled) return;
|
|
2455
|
+
sourceCanceled = true;
|
|
2456
|
+
await reader.cancel(reason);
|
|
2457
|
+
};
|
|
2458
|
+
return new ReadableStream({
|
|
2459
|
+
async pull(controller) {
|
|
2460
|
+
if (emittedBytes >= maximumBytes) {
|
|
2461
|
+
controller.close();
|
|
2462
|
+
await cancelSource();
|
|
2463
|
+
return;
|
|
2464
|
+
}
|
|
2465
|
+
const { done, value } = await reader.read();
|
|
2466
|
+
if (done || !value) {
|
|
2467
|
+
sourceDone = true;
|
|
2468
|
+
controller.close();
|
|
2469
|
+
return;
|
|
2470
|
+
}
|
|
2471
|
+
const remainingBytes = maximumBytes - emittedBytes;
|
|
2472
|
+
if (value.length > remainingBytes) {
|
|
2473
|
+
controller.enqueue(value.subarray(0, remainingBytes));
|
|
2474
|
+
emittedBytes += remainingBytes;
|
|
2475
|
+
controller.close();
|
|
2476
|
+
await cancelSource();
|
|
2477
|
+
return;
|
|
2478
|
+
}
|
|
2479
|
+
controller.enqueue(value);
|
|
2480
|
+
emittedBytes += value.length;
|
|
2481
|
+
},
|
|
2482
|
+
async cancel(reason) {
|
|
2483
|
+
await cancelSource(reason);
|
|
2484
|
+
}
|
|
2485
|
+
});
|
|
2486
|
+
}
|
|
2487
|
+
async function fileTypeFromBlob(blob, options) {
|
|
2488
|
+
return new FileTypeParser(options).fromBlob(blob);
|
|
2489
|
+
}
|
|
2490
|
+
function getFileTypeFromMimeType(mimeType) {
|
|
2491
|
+
mimeType = mimeType.toLowerCase();
|
|
2492
|
+
switch (mimeType) {
|
|
2493
|
+
case "application/epub+zip": return {
|
|
2494
|
+
ext: "epub",
|
|
2495
|
+
mime: mimeType
|
|
2496
|
+
};
|
|
2497
|
+
case "application/vnd.oasis.opendocument.text": return {
|
|
2498
|
+
ext: "odt",
|
|
2499
|
+
mime: mimeType
|
|
2500
|
+
};
|
|
2501
|
+
case "application/vnd.oasis.opendocument.text-template": return {
|
|
2502
|
+
ext: "ott",
|
|
2503
|
+
mime: mimeType
|
|
2504
|
+
};
|
|
2505
|
+
case "application/vnd.oasis.opendocument.spreadsheet": return {
|
|
2506
|
+
ext: "ods",
|
|
2507
|
+
mime: mimeType
|
|
2508
|
+
};
|
|
2509
|
+
case "application/vnd.oasis.opendocument.spreadsheet-template": return {
|
|
2510
|
+
ext: "ots",
|
|
2511
|
+
mime: mimeType
|
|
2512
|
+
};
|
|
2513
|
+
case "application/vnd.oasis.opendocument.presentation": return {
|
|
2514
|
+
ext: "odp",
|
|
2515
|
+
mime: mimeType
|
|
2516
|
+
};
|
|
2517
|
+
case "application/vnd.oasis.opendocument.presentation-template": return {
|
|
2518
|
+
ext: "otp",
|
|
2519
|
+
mime: mimeType
|
|
2520
|
+
};
|
|
2521
|
+
case "application/vnd.oasis.opendocument.graphics": return {
|
|
2522
|
+
ext: "odg",
|
|
2523
|
+
mime: mimeType
|
|
2524
|
+
};
|
|
2525
|
+
case "application/vnd.oasis.opendocument.graphics-template": return {
|
|
2526
|
+
ext: "otg",
|
|
2527
|
+
mime: mimeType
|
|
2528
|
+
};
|
|
2529
|
+
case "application/vnd.openxmlformats-officedocument.presentationml.slideshow": return {
|
|
2530
|
+
ext: "ppsx",
|
|
2531
|
+
mime: mimeType
|
|
2532
|
+
};
|
|
2533
|
+
case "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": return {
|
|
2534
|
+
ext: "xlsx",
|
|
2535
|
+
mime: mimeType
|
|
2536
|
+
};
|
|
2537
|
+
case "application/vnd.ms-excel.sheet.macroenabled": return {
|
|
2538
|
+
ext: "xlsm",
|
|
2539
|
+
mime: "application/vnd.ms-excel.sheet.macroenabled.12"
|
|
2540
|
+
};
|
|
2541
|
+
case "application/vnd.openxmlformats-officedocument.spreadsheetml.template": return {
|
|
2542
|
+
ext: "xltx",
|
|
2543
|
+
mime: mimeType
|
|
2544
|
+
};
|
|
2545
|
+
case "application/vnd.ms-excel.template.macroenabled": return {
|
|
2546
|
+
ext: "xltm",
|
|
2547
|
+
mime: "application/vnd.ms-excel.template.macroenabled.12"
|
|
2548
|
+
};
|
|
2549
|
+
case "application/vnd.ms-powerpoint.slideshow.macroenabled": return {
|
|
2550
|
+
ext: "ppsm",
|
|
2551
|
+
mime: "application/vnd.ms-powerpoint.slideshow.macroenabled.12"
|
|
2552
|
+
};
|
|
2553
|
+
case "application/vnd.openxmlformats-officedocument.wordprocessingml.document": return {
|
|
2554
|
+
ext: "docx",
|
|
2555
|
+
mime: mimeType
|
|
2556
|
+
};
|
|
2557
|
+
case "application/vnd.ms-word.document.macroenabled": return {
|
|
2558
|
+
ext: "docm",
|
|
2559
|
+
mime: "application/vnd.ms-word.document.macroenabled.12"
|
|
2560
|
+
};
|
|
2561
|
+
case "application/vnd.openxmlformats-officedocument.wordprocessingml.template": return {
|
|
2562
|
+
ext: "dotx",
|
|
2563
|
+
mime: mimeType
|
|
2564
|
+
};
|
|
2565
|
+
case "application/vnd.ms-word.template.macroenabledtemplate": return {
|
|
2566
|
+
ext: "dotm",
|
|
2567
|
+
mime: "application/vnd.ms-word.template.macroenabled.12"
|
|
2568
|
+
};
|
|
2569
|
+
case "application/vnd.openxmlformats-officedocument.presentationml.template": return {
|
|
2570
|
+
ext: "potx",
|
|
2571
|
+
mime: mimeType
|
|
2572
|
+
};
|
|
2573
|
+
case "application/vnd.ms-powerpoint.template.macroenabled": return {
|
|
2574
|
+
ext: "potm",
|
|
2575
|
+
mime: "application/vnd.ms-powerpoint.template.macroenabled.12"
|
|
2576
|
+
};
|
|
2577
|
+
case "application/vnd.openxmlformats-officedocument.presentationml.presentation": return {
|
|
2578
|
+
ext: "pptx",
|
|
2579
|
+
mime: mimeType
|
|
2580
|
+
};
|
|
2581
|
+
case "application/vnd.ms-powerpoint.presentation.macroenabled": return {
|
|
2582
|
+
ext: "pptm",
|
|
2583
|
+
mime: "application/vnd.ms-powerpoint.presentation.macroenabled.12"
|
|
2584
|
+
};
|
|
2585
|
+
case "application/vnd.ms-visio.drawing": return {
|
|
2586
|
+
ext: "vsdx",
|
|
2587
|
+
mime: "application/vnd.visio"
|
|
2588
|
+
};
|
|
2589
|
+
case "application/vnd.ms-package.3dmanufacturing-3dmodel+xml": return {
|
|
2590
|
+
ext: "3mf",
|
|
2591
|
+
mime: "model/3mf"
|
|
2592
|
+
};
|
|
2593
|
+
default:
|
|
2594
|
+
}
|
|
2595
|
+
}
|
|
2596
|
+
function _check(buffer, headers, options) {
|
|
2597
|
+
options = {
|
|
2598
|
+
offset: 0,
|
|
2599
|
+
...options
|
|
2600
|
+
};
|
|
2601
|
+
for (const [index, header] of headers.entries()) if (options.mask) {
|
|
2602
|
+
if (header !== (options.mask[index] & buffer[index + options.offset])) return false;
|
|
2603
|
+
} else if (header !== buffer[index + options.offset]) return false;
|
|
2604
|
+
return true;
|
|
2605
|
+
}
|
|
2606
|
+
function normalizeSampleSize(sampleSize) {
|
|
2607
|
+
if (!Number.isFinite(sampleSize)) return reasonableDetectionSizeInBytes;
|
|
2608
|
+
return Math.max(1, Math.trunc(sampleSize));
|
|
2609
|
+
}
|
|
2610
|
+
function normalizeMpegOffsetTolerance(mpegOffsetTolerance) {
|
|
2611
|
+
if (!Number.isFinite(mpegOffsetTolerance)) return 0;
|
|
2612
|
+
return Math.max(0, Math.min(maximumMpegOffsetTolerance, Math.trunc(mpegOffsetTolerance)));
|
|
2613
|
+
}
|
|
2614
|
+
function getKnownFileSizeOrMaximum(fileSize) {
|
|
2615
|
+
if (!Number.isFinite(fileSize)) return Number.MAX_SAFE_INTEGER;
|
|
2616
|
+
return Math.max(0, fileSize);
|
|
2617
|
+
}
|
|
2618
|
+
function hasUnknownFileSize(tokenizer) {
|
|
2619
|
+
const fileSize = tokenizer.fileInfo.size;
|
|
2620
|
+
return !Number.isFinite(fileSize) || fileSize === Number.MAX_SAFE_INTEGER;
|
|
2621
|
+
}
|
|
2622
|
+
function hasExceededUnknownSizeScanBudget(tokenizer, startOffset, maximumBytes) {
|
|
2623
|
+
return hasUnknownFileSize(tokenizer) && tokenizer.position - startOffset > maximumBytes;
|
|
2624
|
+
}
|
|
2625
|
+
function isRecoverableZipError(error) {
|
|
2626
|
+
if (error instanceof EndOfStreamError) return true;
|
|
2627
|
+
if (error instanceof ParserHardLimitError) return true;
|
|
2628
|
+
if (!(error instanceof Error)) return false;
|
|
2629
|
+
if (recoverableZipErrorMessages.has(error.message)) return true;
|
|
2630
|
+
if (error instanceof TypeError && recoverableZipErrorCodes.has(error.code)) return true;
|
|
2631
|
+
for (const prefix of recoverableZipErrorMessagePrefixes) if (error.message.startsWith(prefix)) return true;
|
|
2632
|
+
return false;
|
|
2633
|
+
}
|
|
2634
|
+
function canReadZipEntryForDetection(zipHeader, maximumSize = maximumZipEntrySizeInBytes) {
|
|
2635
|
+
const sizes = [zipHeader.compressedSize, zipHeader.uncompressedSize];
|
|
2636
|
+
for (const size of sizes) if (!Number.isFinite(size) || size < 0 || size > maximumSize) return false;
|
|
2637
|
+
return true;
|
|
2638
|
+
}
|
|
2639
|
+
function createOpenXmlZipDetectionState() {
|
|
2640
|
+
return {
|
|
2641
|
+
hasContentTypesEntry: false,
|
|
2642
|
+
hasParsedContentTypesEntry: false,
|
|
2643
|
+
isParsingContentTypes: false,
|
|
2644
|
+
hasUnparseableContentTypes: false,
|
|
2645
|
+
hasWordDirectory: false,
|
|
2646
|
+
hasPresentationDirectory: false,
|
|
2647
|
+
hasSpreadsheetDirectory: false,
|
|
2648
|
+
hasThreeDimensionalModelEntry: false
|
|
2649
|
+
};
|
|
2650
|
+
}
|
|
2651
|
+
function updateOpenXmlZipDetectionStateFromFilename(openXmlState, filename) {
|
|
2652
|
+
if (filename.startsWith("word/")) openXmlState.hasWordDirectory = true;
|
|
2653
|
+
if (filename.startsWith("ppt/")) openXmlState.hasPresentationDirectory = true;
|
|
2654
|
+
if (filename.startsWith("xl/")) openXmlState.hasSpreadsheetDirectory = true;
|
|
2655
|
+
if (filename.startsWith("3D/") && filename.endsWith(".model")) openXmlState.hasThreeDimensionalModelEntry = true;
|
|
2656
|
+
}
|
|
2657
|
+
function getOpenXmlFileTypeFromZipEntries(openXmlState) {
|
|
2658
|
+
if (!openXmlState.hasContentTypesEntry || openXmlState.hasUnparseableContentTypes || openXmlState.isParsingContentTypes || openXmlState.hasParsedContentTypesEntry) return;
|
|
2659
|
+
if (openXmlState.hasWordDirectory) return {
|
|
2660
|
+
ext: "docx",
|
|
2661
|
+
mime: "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
|
|
2662
|
+
};
|
|
2663
|
+
if (openXmlState.hasPresentationDirectory) return {
|
|
2664
|
+
ext: "pptx",
|
|
2665
|
+
mime: "application/vnd.openxmlformats-officedocument.presentationml.presentation"
|
|
2666
|
+
};
|
|
2667
|
+
if (openXmlState.hasSpreadsheetDirectory) return {
|
|
2668
|
+
ext: "xlsx",
|
|
2669
|
+
mime: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
|
2670
|
+
};
|
|
2671
|
+
if (openXmlState.hasThreeDimensionalModelEntry) return {
|
|
2672
|
+
ext: "3mf",
|
|
2673
|
+
mime: "model/3mf"
|
|
2674
|
+
};
|
|
2675
|
+
}
|
|
2676
|
+
function getOpenXmlMimeTypeFromContentTypesXml(xmlContent) {
|
|
2677
|
+
const endPosition = xmlContent.indexOf(".main+xml\"");
|
|
2678
|
+
if (endPosition === -1) {
|
|
2679
|
+
const mimeType = "application/vnd.ms-package.3dmanufacturing-3dmodel+xml";
|
|
2680
|
+
if (xmlContent.includes(`ContentType="${mimeType}"`)) return mimeType;
|
|
2681
|
+
return;
|
|
2682
|
+
}
|
|
2683
|
+
const truncatedContent = xmlContent.slice(0, endPosition);
|
|
2684
|
+
const firstQuotePosition = truncatedContent.lastIndexOf("\"");
|
|
2685
|
+
return truncatedContent.slice(firstQuotePosition + 1);
|
|
2686
|
+
}
|
|
2687
|
+
var FileTypeParser = class {
|
|
2688
|
+
constructor(options) {
|
|
2689
|
+
const normalizedMpegOffsetTolerance = normalizeMpegOffsetTolerance(options?.mpegOffsetTolerance);
|
|
2690
|
+
this.options = {
|
|
2691
|
+
...options,
|
|
2692
|
+
mpegOffsetTolerance: normalizedMpegOffsetTolerance
|
|
2693
|
+
};
|
|
2694
|
+
this.detectors = [
|
|
2695
|
+
...this.options.customDetectors ?? [],
|
|
2696
|
+
{
|
|
2697
|
+
id: "core",
|
|
2698
|
+
detect: this.detectConfident
|
|
2699
|
+
},
|
|
2700
|
+
{
|
|
2701
|
+
id: "core.imprecise",
|
|
2702
|
+
detect: this.detectImprecise
|
|
2703
|
+
}
|
|
2704
|
+
];
|
|
2705
|
+
this.tokenizerOptions = { abortSignal: this.options.signal };
|
|
2706
|
+
}
|
|
2707
|
+
async fromTokenizer(tokenizer) {
|
|
2708
|
+
const initialPosition = tokenizer.position;
|
|
2709
|
+
for (const detector of this.detectors) {
|
|
2710
|
+
let fileType;
|
|
2711
|
+
try {
|
|
2712
|
+
fileType = await detector.detect(tokenizer);
|
|
2713
|
+
} catch (error) {
|
|
2714
|
+
if (error instanceof EndOfStreamError) return;
|
|
2715
|
+
if (error instanceof ParserHardLimitError) return;
|
|
2716
|
+
throw error;
|
|
2717
|
+
}
|
|
2718
|
+
if (fileType) return fileType;
|
|
2719
|
+
if (initialPosition !== tokenizer.position) return;
|
|
2720
|
+
}
|
|
2721
|
+
}
|
|
2722
|
+
async fromBuffer(input) {
|
|
2723
|
+
if (!(input instanceof Uint8Array || input instanceof ArrayBuffer)) throw new TypeError(`Expected the \`input\` argument to be of type \`Uint8Array\` or \`ArrayBuffer\`, got \`${typeof input}\``);
|
|
2724
|
+
const buffer = input instanceof Uint8Array ? input : new Uint8Array(input);
|
|
2725
|
+
if (!(buffer?.length > 1)) return;
|
|
2726
|
+
return this.fromTokenizer(fromBuffer(buffer, this.tokenizerOptions));
|
|
2727
|
+
}
|
|
2728
|
+
async fromBlob(blob) {
|
|
2729
|
+
const tokenizer = fromBlob(blob, this.tokenizerOptions);
|
|
2730
|
+
try {
|
|
2731
|
+
return await this.fromTokenizer(tokenizer);
|
|
2732
|
+
} finally {
|
|
2733
|
+
await tokenizer.close();
|
|
2734
|
+
}
|
|
2735
|
+
}
|
|
2736
|
+
async fromStream(stream) {
|
|
2737
|
+
const tokenizer = fromWebStream(stream, this.tokenizerOptions);
|
|
2738
|
+
try {
|
|
2739
|
+
return await this.fromTokenizer(tokenizer);
|
|
2740
|
+
} finally {
|
|
2741
|
+
await tokenizer.close();
|
|
2742
|
+
}
|
|
2743
|
+
}
|
|
2744
|
+
async toDetectionStream(stream, options) {
|
|
2745
|
+
const sampleSize = normalizeSampleSize(options?.sampleSize ?? reasonableDetectionSizeInBytes);
|
|
2746
|
+
let detectedFileType;
|
|
2747
|
+
let firstChunk;
|
|
2748
|
+
const reader = stream.getReader({ mode: "byob" });
|
|
2749
|
+
try {
|
|
2750
|
+
const { value: chunk, done } = await reader.read(new Uint8Array(sampleSize));
|
|
2751
|
+
firstChunk = chunk;
|
|
2752
|
+
if (!done && chunk) try {
|
|
2753
|
+
detectedFileType = await this.fromBuffer(chunk.subarray(0, sampleSize));
|
|
2754
|
+
} catch (error) {
|
|
2755
|
+
if (!(error instanceof EndOfStreamError)) throw error;
|
|
2756
|
+
detectedFileType = void 0;
|
|
2757
|
+
}
|
|
2758
|
+
firstChunk = chunk;
|
|
2759
|
+
} finally {
|
|
2760
|
+
reader.releaseLock();
|
|
2761
|
+
}
|
|
2762
|
+
const transformStream = new TransformStream({
|
|
2763
|
+
async start(controller) {
|
|
2764
|
+
controller.enqueue(firstChunk);
|
|
2765
|
+
},
|
|
2766
|
+
transform(chunk, controller) {
|
|
2767
|
+
controller.enqueue(chunk);
|
|
2768
|
+
}
|
|
2769
|
+
});
|
|
2770
|
+
const newStream = stream.pipeThrough(transformStream);
|
|
2771
|
+
newStream.fileType = detectedFileType;
|
|
2772
|
+
return newStream;
|
|
2773
|
+
}
|
|
2774
|
+
check(header, options) {
|
|
2775
|
+
return _check(this.buffer, header, options);
|
|
2776
|
+
}
|
|
2777
|
+
checkString(header, options) {
|
|
2778
|
+
return this.check(stringToBytes(header, options?.encoding), options);
|
|
2779
|
+
}
|
|
2780
|
+
detectConfident = async (tokenizer) => {
|
|
2781
|
+
this.buffer = new Uint8Array(reasonableDetectionSizeInBytes);
|
|
2782
|
+
if (tokenizer.fileInfo.size === void 0) tokenizer.fileInfo.size = Number.MAX_SAFE_INTEGER;
|
|
2783
|
+
this.tokenizer = tokenizer;
|
|
2784
|
+
await tokenizer.peekBuffer(this.buffer, {
|
|
2785
|
+
length: 32,
|
|
2786
|
+
mayBeLess: true
|
|
2787
|
+
});
|
|
2788
|
+
if (this.check([66, 77])) return {
|
|
2789
|
+
ext: "bmp",
|
|
2790
|
+
mime: "image/bmp"
|
|
2791
|
+
};
|
|
2792
|
+
if (this.check([11, 119])) return {
|
|
2793
|
+
ext: "ac3",
|
|
2794
|
+
mime: "audio/vnd.dolby.dd-raw"
|
|
2795
|
+
};
|
|
2796
|
+
if (this.check([120, 1])) return {
|
|
2797
|
+
ext: "dmg",
|
|
2798
|
+
mime: "application/x-apple-diskimage"
|
|
2799
|
+
};
|
|
2800
|
+
if (this.check([77, 90])) return {
|
|
2801
|
+
ext: "exe",
|
|
2802
|
+
mime: "application/x-msdownload"
|
|
2803
|
+
};
|
|
2804
|
+
if (this.check([37, 33])) {
|
|
2805
|
+
await tokenizer.peekBuffer(this.buffer, {
|
|
2806
|
+
length: 24,
|
|
2807
|
+
mayBeLess: true
|
|
2808
|
+
});
|
|
2809
|
+
if (this.checkString("PS-Adobe-", { offset: 2 }) && this.checkString(" EPSF-", { offset: 14 })) return {
|
|
2810
|
+
ext: "eps",
|
|
2811
|
+
mime: "application/eps"
|
|
2812
|
+
};
|
|
2813
|
+
return {
|
|
2814
|
+
ext: "ps",
|
|
2815
|
+
mime: "application/postscript"
|
|
2816
|
+
};
|
|
2817
|
+
}
|
|
2818
|
+
if (this.check([31, 160]) || this.check([31, 157])) return {
|
|
2819
|
+
ext: "Z",
|
|
2820
|
+
mime: "application/x-compress"
|
|
2821
|
+
};
|
|
2822
|
+
if (this.check([199, 113])) return {
|
|
2823
|
+
ext: "cpio",
|
|
2824
|
+
mime: "application/x-cpio"
|
|
2825
|
+
};
|
|
2826
|
+
if (this.check([96, 234])) return {
|
|
2827
|
+
ext: "arj",
|
|
2828
|
+
mime: "application/x-arj"
|
|
2829
|
+
};
|
|
2830
|
+
if (this.check([
|
|
2831
|
+
239,
|
|
2832
|
+
187,
|
|
2833
|
+
191
|
|
2834
|
+
])) {
|
|
2835
|
+
await this.tokenizer.ignore(3);
|
|
2836
|
+
return this.detectConfident(tokenizer);
|
|
2837
|
+
}
|
|
2838
|
+
if (this.check([
|
|
2839
|
+
71,
|
|
2840
|
+
73,
|
|
2841
|
+
70
|
|
2842
|
+
])) return {
|
|
2843
|
+
ext: "gif",
|
|
2844
|
+
mime: "image/gif"
|
|
2845
|
+
};
|
|
2846
|
+
if (this.check([
|
|
2847
|
+
73,
|
|
2848
|
+
73,
|
|
2849
|
+
188
|
|
2850
|
+
])) return {
|
|
2851
|
+
ext: "jxr",
|
|
2852
|
+
mime: "image/vnd.ms-photo"
|
|
2853
|
+
};
|
|
2854
|
+
if (this.check([
|
|
2855
|
+
31,
|
|
2856
|
+
139,
|
|
2857
|
+
8
|
|
2858
|
+
])) {
|
|
2859
|
+
const limitedInflatedStream = createByteLimitedReadableStream(new GzipHandler(tokenizer).inflate(), maximumNestedGzipDetectionSizeInBytes);
|
|
2860
|
+
let compressedFileType;
|
|
2861
|
+
try {
|
|
2862
|
+
compressedFileType = await this.fromStream(limitedInflatedStream);
|
|
2863
|
+
} catch (error) {
|
|
2864
|
+
if (error?.name === "AbortError") throw error;
|
|
2865
|
+
}
|
|
2866
|
+
if (compressedFileType?.ext === "tar") return {
|
|
2867
|
+
ext: "tar.gz",
|
|
2868
|
+
mime: "application/gzip"
|
|
2869
|
+
};
|
|
2870
|
+
return {
|
|
2871
|
+
ext: "gz",
|
|
2872
|
+
mime: "application/gzip"
|
|
2873
|
+
};
|
|
2874
|
+
}
|
|
2875
|
+
if (this.check([
|
|
2876
|
+
66,
|
|
2877
|
+
90,
|
|
2878
|
+
104
|
|
2879
|
+
])) return {
|
|
2880
|
+
ext: "bz2",
|
|
2881
|
+
mime: "application/x-bzip2"
|
|
2882
|
+
};
|
|
2883
|
+
if (this.checkString("ID3")) {
|
|
2884
|
+
await safeIgnore(tokenizer, 6, {
|
|
2885
|
+
maximumLength: 6,
|
|
2886
|
+
reason: "ID3 header prefix"
|
|
2887
|
+
});
|
|
2888
|
+
const id3HeaderLength = await tokenizer.readToken(uint32SyncSafeToken);
|
|
2889
|
+
const isUnknownFileSize = hasUnknownFileSize(tokenizer);
|
|
2890
|
+
if (!Number.isFinite(id3HeaderLength) || id3HeaderLength < 0 || isUnknownFileSize && id3HeaderLength > maximumId3HeaderSizeInBytes) return;
|
|
2891
|
+
if (tokenizer.position + id3HeaderLength > tokenizer.fileInfo.size) {
|
|
2892
|
+
if (isUnknownFileSize) return;
|
|
2893
|
+
return {
|
|
2894
|
+
ext: "mp3",
|
|
2895
|
+
mime: "audio/mpeg"
|
|
2896
|
+
};
|
|
2897
|
+
}
|
|
2898
|
+
try {
|
|
2899
|
+
await safeIgnore(tokenizer, id3HeaderLength, {
|
|
2900
|
+
maximumLength: isUnknownFileSize ? maximumId3HeaderSizeInBytes : tokenizer.fileInfo.size,
|
|
2901
|
+
reason: "ID3 payload"
|
|
2902
|
+
});
|
|
2903
|
+
} catch (error) {
|
|
2904
|
+
if (error instanceof EndOfStreamError) return;
|
|
2905
|
+
throw error;
|
|
2906
|
+
}
|
|
2907
|
+
return this.fromTokenizer(tokenizer);
|
|
2908
|
+
}
|
|
2909
|
+
if (this.checkString("MP+")) return {
|
|
2910
|
+
ext: "mpc",
|
|
2911
|
+
mime: "audio/x-musepack"
|
|
2912
|
+
};
|
|
2913
|
+
if ((this.buffer[0] === 67 || this.buffer[0] === 70) && this.check([87, 83], { offset: 1 })) return {
|
|
2914
|
+
ext: "swf",
|
|
2915
|
+
mime: "application/x-shockwave-flash"
|
|
2916
|
+
};
|
|
2917
|
+
if (this.check([
|
|
2918
|
+
255,
|
|
2919
|
+
216,
|
|
2920
|
+
255
|
|
2921
|
+
])) {
|
|
2922
|
+
if (this.check([247], { offset: 3 })) return {
|
|
2923
|
+
ext: "jls",
|
|
2924
|
+
mime: "image/jls"
|
|
2925
|
+
};
|
|
2926
|
+
return {
|
|
2927
|
+
ext: "jpg",
|
|
2928
|
+
mime: "image/jpeg"
|
|
2929
|
+
};
|
|
2930
|
+
}
|
|
2931
|
+
if (this.check([
|
|
2932
|
+
79,
|
|
2933
|
+
98,
|
|
2934
|
+
106,
|
|
2935
|
+
1
|
|
2936
|
+
])) return {
|
|
2937
|
+
ext: "avro",
|
|
2938
|
+
mime: "application/avro"
|
|
2939
|
+
};
|
|
2940
|
+
if (this.checkString("FLIF")) return {
|
|
2941
|
+
ext: "flif",
|
|
2942
|
+
mime: "image/flif"
|
|
2943
|
+
};
|
|
2944
|
+
if (this.checkString("8BPS")) return {
|
|
2945
|
+
ext: "psd",
|
|
2946
|
+
mime: "image/vnd.adobe.photoshop"
|
|
2947
|
+
};
|
|
2948
|
+
if (this.checkString("MPCK")) return {
|
|
2949
|
+
ext: "mpc",
|
|
2950
|
+
mime: "audio/x-musepack"
|
|
2951
|
+
};
|
|
2952
|
+
if (this.checkString("FORM")) return {
|
|
2953
|
+
ext: "aif",
|
|
2954
|
+
mime: "audio/aiff"
|
|
2955
|
+
};
|
|
2956
|
+
if (this.checkString("icns", { offset: 0 })) return {
|
|
2957
|
+
ext: "icns",
|
|
2958
|
+
mime: "image/icns"
|
|
2959
|
+
};
|
|
2960
|
+
if (this.check([
|
|
2961
|
+
80,
|
|
2962
|
+
75,
|
|
2963
|
+
3,
|
|
2964
|
+
4
|
|
2965
|
+
])) {
|
|
2966
|
+
let fileType;
|
|
2967
|
+
const openXmlState = createOpenXmlZipDetectionState();
|
|
2968
|
+
try {
|
|
2969
|
+
await new ZipHandler(tokenizer).unzip((zipHeader) => {
|
|
2970
|
+
updateOpenXmlZipDetectionStateFromFilename(openXmlState, zipHeader.filename);
|
|
2971
|
+
const isOpenXmlContentTypesEntry = zipHeader.filename === "[Content_Types].xml";
|
|
2972
|
+
const openXmlFileTypeFromEntries = getOpenXmlFileTypeFromZipEntries(openXmlState);
|
|
2973
|
+
if (!isOpenXmlContentTypesEntry && openXmlFileTypeFromEntries) {
|
|
2974
|
+
fileType = openXmlFileTypeFromEntries;
|
|
2975
|
+
return { stop: true };
|
|
2976
|
+
}
|
|
2977
|
+
switch (zipHeader.filename) {
|
|
2978
|
+
case "META-INF/mozilla.rsa":
|
|
2979
|
+
fileType = {
|
|
2980
|
+
ext: "xpi",
|
|
2981
|
+
mime: "application/x-xpinstall"
|
|
2982
|
+
};
|
|
2983
|
+
return { stop: true };
|
|
2984
|
+
case "META-INF/MANIFEST.MF":
|
|
2985
|
+
fileType = {
|
|
2986
|
+
ext: "jar",
|
|
2987
|
+
mime: "application/java-archive"
|
|
2988
|
+
};
|
|
2989
|
+
return { stop: true };
|
|
2990
|
+
case "mimetype":
|
|
2991
|
+
if (!canReadZipEntryForDetection(zipHeader)) return {};
|
|
2992
|
+
return {
|
|
2993
|
+
async handler(fileData) {
|
|
2994
|
+
fileType = getFileTypeFromMimeType(new TextDecoder("utf-8").decode(fileData).trim());
|
|
2995
|
+
},
|
|
2996
|
+
stop: true
|
|
2997
|
+
};
|
|
2998
|
+
case "[Content_Types].xml":
|
|
2999
|
+
openXmlState.hasContentTypesEntry = true;
|
|
3000
|
+
if (!canReadZipEntryForDetection(zipHeader, hasUnknownFileSize(tokenizer) ? maximumZipEntrySizeInBytes : Number.MAX_SAFE_INTEGER)) {
|
|
3001
|
+
openXmlState.hasUnparseableContentTypes = true;
|
|
3002
|
+
return {};
|
|
3003
|
+
}
|
|
3004
|
+
openXmlState.isParsingContentTypes = true;
|
|
3005
|
+
return {
|
|
3006
|
+
async handler(fileData) {
|
|
3007
|
+
const mimeType = getOpenXmlMimeTypeFromContentTypesXml(new TextDecoder("utf-8").decode(fileData));
|
|
3008
|
+
if (mimeType) fileType = getFileTypeFromMimeType(mimeType);
|
|
3009
|
+
openXmlState.hasParsedContentTypesEntry = true;
|
|
3010
|
+
openXmlState.isParsingContentTypes = false;
|
|
3011
|
+
},
|
|
3012
|
+
stop: true
|
|
3013
|
+
};
|
|
3014
|
+
default:
|
|
3015
|
+
if (/classes\d*\.dex/.test(zipHeader.filename)) {
|
|
3016
|
+
fileType = {
|
|
3017
|
+
ext: "apk",
|
|
3018
|
+
mime: "application/vnd.android.package-archive"
|
|
3019
|
+
};
|
|
3020
|
+
return { stop: true };
|
|
3021
|
+
}
|
|
3022
|
+
return {};
|
|
3023
|
+
}
|
|
3024
|
+
});
|
|
3025
|
+
} catch (error) {
|
|
3026
|
+
if (!isRecoverableZipError(error)) throw error;
|
|
3027
|
+
if (openXmlState.isParsingContentTypes) {
|
|
3028
|
+
openXmlState.isParsingContentTypes = false;
|
|
3029
|
+
openXmlState.hasUnparseableContentTypes = true;
|
|
3030
|
+
}
|
|
3031
|
+
}
|
|
3032
|
+
return fileType ?? getOpenXmlFileTypeFromZipEntries(openXmlState) ?? {
|
|
3033
|
+
ext: "zip",
|
|
3034
|
+
mime: "application/zip"
|
|
3035
|
+
};
|
|
3036
|
+
}
|
|
3037
|
+
if (this.checkString("OggS")) {
|
|
3038
|
+
await tokenizer.ignore(28);
|
|
3039
|
+
const type = new Uint8Array(8);
|
|
3040
|
+
await tokenizer.readBuffer(type);
|
|
3041
|
+
if (_check(type, [
|
|
3042
|
+
79,
|
|
3043
|
+
112,
|
|
3044
|
+
117,
|
|
3045
|
+
115,
|
|
3046
|
+
72,
|
|
3047
|
+
101,
|
|
3048
|
+
97,
|
|
3049
|
+
100
|
|
3050
|
+
])) return {
|
|
3051
|
+
ext: "opus",
|
|
3052
|
+
mime: "audio/ogg; codecs=opus"
|
|
3053
|
+
};
|
|
3054
|
+
if (_check(type, [
|
|
3055
|
+
128,
|
|
3056
|
+
116,
|
|
3057
|
+
104,
|
|
3058
|
+
101,
|
|
3059
|
+
111,
|
|
3060
|
+
114,
|
|
3061
|
+
97
|
|
3062
|
+
])) return {
|
|
3063
|
+
ext: "ogv",
|
|
3064
|
+
mime: "video/ogg"
|
|
3065
|
+
};
|
|
3066
|
+
if (_check(type, [
|
|
3067
|
+
1,
|
|
3068
|
+
118,
|
|
3069
|
+
105,
|
|
3070
|
+
100,
|
|
3071
|
+
101,
|
|
3072
|
+
111,
|
|
3073
|
+
0
|
|
3074
|
+
])) return {
|
|
3075
|
+
ext: "ogm",
|
|
3076
|
+
mime: "video/ogg"
|
|
3077
|
+
};
|
|
3078
|
+
if (_check(type, [
|
|
3079
|
+
127,
|
|
3080
|
+
70,
|
|
3081
|
+
76,
|
|
3082
|
+
65,
|
|
3083
|
+
67
|
|
3084
|
+
])) return {
|
|
3085
|
+
ext: "oga",
|
|
3086
|
+
mime: "audio/ogg"
|
|
3087
|
+
};
|
|
3088
|
+
if (_check(type, [
|
|
3089
|
+
83,
|
|
3090
|
+
112,
|
|
3091
|
+
101,
|
|
3092
|
+
101,
|
|
3093
|
+
120,
|
|
3094
|
+
32,
|
|
3095
|
+
32
|
|
3096
|
+
])) return {
|
|
3097
|
+
ext: "spx",
|
|
3098
|
+
mime: "audio/ogg"
|
|
3099
|
+
};
|
|
3100
|
+
if (_check(type, [
|
|
3101
|
+
1,
|
|
3102
|
+
118,
|
|
3103
|
+
111,
|
|
3104
|
+
114,
|
|
3105
|
+
98,
|
|
3106
|
+
105,
|
|
3107
|
+
115
|
|
3108
|
+
])) return {
|
|
3109
|
+
ext: "ogg",
|
|
3110
|
+
mime: "audio/ogg"
|
|
3111
|
+
};
|
|
3112
|
+
return {
|
|
3113
|
+
ext: "ogx",
|
|
3114
|
+
mime: "application/ogg"
|
|
3115
|
+
};
|
|
3116
|
+
}
|
|
3117
|
+
if (this.check([80, 75]) && (this.buffer[2] === 3 || this.buffer[2] === 5 || this.buffer[2] === 7) && (this.buffer[3] === 4 || this.buffer[3] === 6 || this.buffer[3] === 8)) return {
|
|
3118
|
+
ext: "zip",
|
|
3119
|
+
mime: "application/zip"
|
|
3120
|
+
};
|
|
3121
|
+
if (this.checkString("MThd")) return {
|
|
3122
|
+
ext: "mid",
|
|
3123
|
+
mime: "audio/midi"
|
|
3124
|
+
};
|
|
3125
|
+
if (this.checkString("wOFF") && (this.check([
|
|
3126
|
+
0,
|
|
3127
|
+
1,
|
|
3128
|
+
0,
|
|
3129
|
+
0
|
|
3130
|
+
], { offset: 4 }) || this.checkString("OTTO", { offset: 4 }))) return {
|
|
3131
|
+
ext: "woff",
|
|
3132
|
+
mime: "font/woff"
|
|
3133
|
+
};
|
|
3134
|
+
if (this.checkString("wOF2") && (this.check([
|
|
3135
|
+
0,
|
|
3136
|
+
1,
|
|
3137
|
+
0,
|
|
3138
|
+
0
|
|
3139
|
+
], { offset: 4 }) || this.checkString("OTTO", { offset: 4 }))) return {
|
|
3140
|
+
ext: "woff2",
|
|
3141
|
+
mime: "font/woff2"
|
|
3142
|
+
};
|
|
3143
|
+
if (this.check([
|
|
3144
|
+
212,
|
|
3145
|
+
195,
|
|
3146
|
+
178,
|
|
3147
|
+
161
|
|
3148
|
+
]) || this.check([
|
|
3149
|
+
161,
|
|
3150
|
+
178,
|
|
3151
|
+
195,
|
|
3152
|
+
212
|
|
3153
|
+
])) return {
|
|
3154
|
+
ext: "pcap",
|
|
3155
|
+
mime: "application/vnd.tcpdump.pcap"
|
|
3156
|
+
};
|
|
3157
|
+
if (this.checkString("DSD ")) return {
|
|
3158
|
+
ext: "dsf",
|
|
3159
|
+
mime: "audio/x-dsf"
|
|
3160
|
+
};
|
|
3161
|
+
if (this.checkString("LZIP")) return {
|
|
3162
|
+
ext: "lz",
|
|
3163
|
+
mime: "application/x-lzip"
|
|
3164
|
+
};
|
|
3165
|
+
if (this.checkString("fLaC")) return {
|
|
3166
|
+
ext: "flac",
|
|
3167
|
+
mime: "audio/flac"
|
|
3168
|
+
};
|
|
3169
|
+
if (this.check([
|
|
3170
|
+
66,
|
|
3171
|
+
80,
|
|
3172
|
+
71,
|
|
3173
|
+
251
|
|
3174
|
+
])) return {
|
|
3175
|
+
ext: "bpg",
|
|
3176
|
+
mime: "image/bpg"
|
|
3177
|
+
};
|
|
3178
|
+
if (this.checkString("wvpk")) return {
|
|
3179
|
+
ext: "wv",
|
|
3180
|
+
mime: "audio/wavpack"
|
|
3181
|
+
};
|
|
3182
|
+
if (this.checkString("%PDF")) return {
|
|
3183
|
+
ext: "pdf",
|
|
3184
|
+
mime: "application/pdf"
|
|
3185
|
+
};
|
|
3186
|
+
if (this.check([
|
|
3187
|
+
0,
|
|
3188
|
+
97,
|
|
3189
|
+
115,
|
|
3190
|
+
109
|
|
3191
|
+
])) return {
|
|
3192
|
+
ext: "wasm",
|
|
3193
|
+
mime: "application/wasm"
|
|
3194
|
+
};
|
|
3195
|
+
if (this.check([73, 73])) {
|
|
3196
|
+
const fileType = await this.readTiffHeader(false);
|
|
3197
|
+
if (fileType) return fileType;
|
|
3198
|
+
}
|
|
3199
|
+
if (this.check([77, 77])) {
|
|
3200
|
+
const fileType = await this.readTiffHeader(true);
|
|
3201
|
+
if (fileType) return fileType;
|
|
3202
|
+
}
|
|
3203
|
+
if (this.checkString("MAC ")) return {
|
|
3204
|
+
ext: "ape",
|
|
3205
|
+
mime: "audio/ape"
|
|
3206
|
+
};
|
|
3207
|
+
if (this.check([
|
|
3208
|
+
26,
|
|
3209
|
+
69,
|
|
3210
|
+
223,
|
|
3211
|
+
163
|
|
3212
|
+
])) {
|
|
3213
|
+
async function readField() {
|
|
3214
|
+
const msb = await tokenizer.peekNumber(UINT8);
|
|
3215
|
+
let mask = 128;
|
|
3216
|
+
let ic = 0;
|
|
3217
|
+
while ((msb & mask) === 0 && mask !== 0) {
|
|
3218
|
+
++ic;
|
|
3219
|
+
mask >>= 1;
|
|
3220
|
+
}
|
|
3221
|
+
const id = new Uint8Array(ic + 1);
|
|
3222
|
+
await safeReadBuffer(tokenizer, id, void 0, {
|
|
3223
|
+
maximumLength: id.length,
|
|
3224
|
+
reason: "EBML field"
|
|
3225
|
+
});
|
|
3226
|
+
return id;
|
|
3227
|
+
}
|
|
3228
|
+
async function readElement() {
|
|
3229
|
+
const idField = await readField();
|
|
3230
|
+
const lengthField = await readField();
|
|
3231
|
+
lengthField[0] ^= 128 >> lengthField.length - 1;
|
|
3232
|
+
const nrLength = Math.min(6, lengthField.length);
|
|
3233
|
+
const idView = new DataView(idField.buffer);
|
|
3234
|
+
const lengthView = new DataView(lengthField.buffer, lengthField.length - nrLength, nrLength);
|
|
3235
|
+
return {
|
|
3236
|
+
id: getUintBE(idView),
|
|
3237
|
+
len: getUintBE(lengthView)
|
|
3238
|
+
};
|
|
3239
|
+
}
|
|
3240
|
+
async function readChildren(children) {
|
|
3241
|
+
let ebmlElementCount = 0;
|
|
3242
|
+
while (children > 0) {
|
|
3243
|
+
ebmlElementCount++;
|
|
3244
|
+
if (ebmlElementCount > maximumEbmlElementCount) return;
|
|
3245
|
+
const element = await readElement();
|
|
3246
|
+
if (element.id === 17026) {
|
|
3247
|
+
if (element.len > maximumEbmlDocumentTypeSizeInBytes) return;
|
|
3248
|
+
const documentTypeLength = getSafeBound(element.len, maximumEbmlDocumentTypeSizeInBytes, "EBML DocType");
|
|
3249
|
+
return (await tokenizer.readToken(new StringType(documentTypeLength))).replaceAll(/\00.*$/g, "");
|
|
3250
|
+
}
|
|
3251
|
+
if (hasUnknownFileSize(tokenizer) && (!Number.isFinite(element.len) || element.len < 0 || element.len > maximumEbmlElementPayloadSizeInBytes)) return;
|
|
3252
|
+
await safeIgnore(tokenizer, element.len, {
|
|
3253
|
+
maximumLength: hasUnknownFileSize(tokenizer) ? maximumEbmlElementPayloadSizeInBytes : tokenizer.fileInfo.size,
|
|
3254
|
+
reason: "EBML payload"
|
|
3255
|
+
});
|
|
3256
|
+
--children;
|
|
3257
|
+
}
|
|
3258
|
+
}
|
|
3259
|
+
switch (await readChildren((await readElement()).len)) {
|
|
3260
|
+
case "webm": return {
|
|
3261
|
+
ext: "webm",
|
|
3262
|
+
mime: "video/webm"
|
|
3263
|
+
};
|
|
3264
|
+
case "matroska": return {
|
|
3265
|
+
ext: "mkv",
|
|
3266
|
+
mime: "video/matroska"
|
|
3267
|
+
};
|
|
3268
|
+
default: return;
|
|
3269
|
+
}
|
|
3270
|
+
}
|
|
3271
|
+
if (this.checkString("SQLi")) return {
|
|
3272
|
+
ext: "sqlite",
|
|
3273
|
+
mime: "application/x-sqlite3"
|
|
3274
|
+
};
|
|
3275
|
+
if (this.check([
|
|
3276
|
+
78,
|
|
3277
|
+
69,
|
|
3278
|
+
83,
|
|
3279
|
+
26
|
|
3280
|
+
])) return {
|
|
3281
|
+
ext: "nes",
|
|
3282
|
+
mime: "application/x-nintendo-nes-rom"
|
|
3283
|
+
};
|
|
3284
|
+
if (this.checkString("Cr24")) return {
|
|
3285
|
+
ext: "crx",
|
|
3286
|
+
mime: "application/x-google-chrome-extension"
|
|
3287
|
+
};
|
|
3288
|
+
if (this.checkString("MSCF") || this.checkString("ISc(")) return {
|
|
3289
|
+
ext: "cab",
|
|
3290
|
+
mime: "application/vnd.ms-cab-compressed"
|
|
3291
|
+
};
|
|
3292
|
+
if (this.check([
|
|
3293
|
+
237,
|
|
3294
|
+
171,
|
|
3295
|
+
238,
|
|
3296
|
+
219
|
|
3297
|
+
])) return {
|
|
3298
|
+
ext: "rpm",
|
|
3299
|
+
mime: "application/x-rpm"
|
|
3300
|
+
};
|
|
3301
|
+
if (this.check([
|
|
3302
|
+
197,
|
|
3303
|
+
208,
|
|
3304
|
+
211,
|
|
3305
|
+
198
|
|
3306
|
+
])) return {
|
|
3307
|
+
ext: "eps",
|
|
3308
|
+
mime: "application/eps"
|
|
3309
|
+
};
|
|
3310
|
+
if (this.check([
|
|
3311
|
+
40,
|
|
3312
|
+
181,
|
|
3313
|
+
47,
|
|
3314
|
+
253
|
|
3315
|
+
])) return {
|
|
3316
|
+
ext: "zst",
|
|
3317
|
+
mime: "application/zstd"
|
|
3318
|
+
};
|
|
3319
|
+
if (this.check([
|
|
3320
|
+
127,
|
|
3321
|
+
69,
|
|
3322
|
+
76,
|
|
3323
|
+
70
|
|
3324
|
+
])) return {
|
|
3325
|
+
ext: "elf",
|
|
3326
|
+
mime: "application/x-elf"
|
|
3327
|
+
};
|
|
3328
|
+
if (this.check([
|
|
3329
|
+
33,
|
|
3330
|
+
66,
|
|
3331
|
+
68,
|
|
3332
|
+
78
|
|
3333
|
+
])) return {
|
|
3334
|
+
ext: "pst",
|
|
3335
|
+
mime: "application/vnd.ms-outlook"
|
|
3336
|
+
};
|
|
3337
|
+
if (this.checkString("PAR1") || this.checkString("PARE")) return {
|
|
3338
|
+
ext: "parquet",
|
|
3339
|
+
mime: "application/vnd.apache.parquet"
|
|
3340
|
+
};
|
|
3341
|
+
if (this.checkString("ttcf")) return {
|
|
3342
|
+
ext: "ttc",
|
|
3343
|
+
mime: "font/collection"
|
|
3344
|
+
};
|
|
3345
|
+
if (this.check([
|
|
3346
|
+
254,
|
|
3347
|
+
237,
|
|
3348
|
+
250,
|
|
3349
|
+
206
|
|
3350
|
+
]) || this.check([
|
|
3351
|
+
254,
|
|
3352
|
+
237,
|
|
3353
|
+
250,
|
|
3354
|
+
207
|
|
3355
|
+
]) || this.check([
|
|
3356
|
+
206,
|
|
3357
|
+
250,
|
|
3358
|
+
237,
|
|
3359
|
+
254
|
|
3360
|
+
]) || this.check([
|
|
3361
|
+
207,
|
|
3362
|
+
250,
|
|
3363
|
+
237,
|
|
3364
|
+
254
|
|
3365
|
+
])) return {
|
|
3366
|
+
ext: "macho",
|
|
3367
|
+
mime: "application/x-mach-binary"
|
|
3368
|
+
};
|
|
3369
|
+
if (this.check([
|
|
3370
|
+
4,
|
|
3371
|
+
34,
|
|
3372
|
+
77,
|
|
3373
|
+
24
|
|
3374
|
+
])) return {
|
|
3375
|
+
ext: "lz4",
|
|
3376
|
+
mime: "application/x-lz4"
|
|
3377
|
+
};
|
|
3378
|
+
if (this.checkString("regf")) return {
|
|
3379
|
+
ext: "dat",
|
|
3380
|
+
mime: "application/x-ft-windows-registry-hive"
|
|
3381
|
+
};
|
|
3382
|
+
if (this.checkString("$FL2") || this.checkString("$FL3")) return {
|
|
3383
|
+
ext: "sav",
|
|
3384
|
+
mime: "application/x-spss-sav"
|
|
3385
|
+
};
|
|
3386
|
+
if (this.check([
|
|
3387
|
+
79,
|
|
3388
|
+
84,
|
|
3389
|
+
84,
|
|
3390
|
+
79,
|
|
3391
|
+
0
|
|
3392
|
+
])) return {
|
|
3393
|
+
ext: "otf",
|
|
3394
|
+
mime: "font/otf"
|
|
3395
|
+
};
|
|
3396
|
+
if (this.checkString("#!AMR")) return {
|
|
3397
|
+
ext: "amr",
|
|
3398
|
+
mime: "audio/amr"
|
|
3399
|
+
};
|
|
3400
|
+
if (this.checkString("{\\rtf")) return {
|
|
3401
|
+
ext: "rtf",
|
|
3402
|
+
mime: "application/rtf"
|
|
3403
|
+
};
|
|
3404
|
+
if (this.check([
|
|
3405
|
+
70,
|
|
3406
|
+
76,
|
|
3407
|
+
86,
|
|
3408
|
+
1
|
|
3409
|
+
])) return {
|
|
3410
|
+
ext: "flv",
|
|
3411
|
+
mime: "video/x-flv"
|
|
3412
|
+
};
|
|
3413
|
+
if (this.checkString("IMPM")) return {
|
|
3414
|
+
ext: "it",
|
|
3415
|
+
mime: "audio/x-it"
|
|
3416
|
+
};
|
|
3417
|
+
if (this.checkString("-lh0-", { offset: 2 }) || this.checkString("-lh1-", { offset: 2 }) || this.checkString("-lh2-", { offset: 2 }) || this.checkString("-lh3-", { offset: 2 }) || this.checkString("-lh4-", { offset: 2 }) || this.checkString("-lh5-", { offset: 2 }) || this.checkString("-lh6-", { offset: 2 }) || this.checkString("-lh7-", { offset: 2 }) || this.checkString("-lzs-", { offset: 2 }) || this.checkString("-lz4-", { offset: 2 }) || this.checkString("-lz5-", { offset: 2 }) || this.checkString("-lhd-", { offset: 2 })) return {
|
|
3418
|
+
ext: "lzh",
|
|
3419
|
+
mime: "application/x-lzh-compressed"
|
|
3420
|
+
};
|
|
3421
|
+
if (this.check([
|
|
3422
|
+
0,
|
|
3423
|
+
0,
|
|
3424
|
+
1,
|
|
3425
|
+
186
|
|
3426
|
+
])) {
|
|
3427
|
+
if (this.check([33], {
|
|
3428
|
+
offset: 4,
|
|
3429
|
+
mask: [241]
|
|
3430
|
+
})) return {
|
|
3431
|
+
ext: "mpg",
|
|
3432
|
+
mime: "video/MP1S"
|
|
3433
|
+
};
|
|
3434
|
+
if (this.check([68], {
|
|
3435
|
+
offset: 4,
|
|
3436
|
+
mask: [196]
|
|
3437
|
+
})) return {
|
|
3438
|
+
ext: "mpg",
|
|
3439
|
+
mime: "video/MP2P"
|
|
3440
|
+
};
|
|
3441
|
+
}
|
|
3442
|
+
if (this.checkString("ITSF")) return {
|
|
3443
|
+
ext: "chm",
|
|
3444
|
+
mime: "application/vnd.ms-htmlhelp"
|
|
3445
|
+
};
|
|
3446
|
+
if (this.check([
|
|
3447
|
+
202,
|
|
3448
|
+
254,
|
|
3449
|
+
186,
|
|
3450
|
+
190
|
|
3451
|
+
])) {
|
|
3452
|
+
const machOArchitectureCount = UINT32_BE.get(this.buffer, 4);
|
|
3453
|
+
const javaClassFileMajorVersion = UINT16_BE.get(this.buffer, 6);
|
|
3454
|
+
if (machOArchitectureCount > 0 && machOArchitectureCount <= 30) return {
|
|
3455
|
+
ext: "macho",
|
|
3456
|
+
mime: "application/x-mach-binary"
|
|
3457
|
+
};
|
|
3458
|
+
if (javaClassFileMajorVersion > 30) return {
|
|
3459
|
+
ext: "class",
|
|
3460
|
+
mime: "application/java-vm"
|
|
3461
|
+
};
|
|
3462
|
+
}
|
|
3463
|
+
if (this.checkString(".RMF")) return {
|
|
3464
|
+
ext: "rm",
|
|
3465
|
+
mime: "application/vnd.rn-realmedia"
|
|
3466
|
+
};
|
|
3467
|
+
if (this.checkString("DRACO")) return {
|
|
3468
|
+
ext: "drc",
|
|
3469
|
+
mime: "application/vnd.google.draco"
|
|
3470
|
+
};
|
|
3471
|
+
if (this.check([
|
|
3472
|
+
253,
|
|
3473
|
+
55,
|
|
3474
|
+
122,
|
|
3475
|
+
88,
|
|
3476
|
+
90,
|
|
3477
|
+
0
|
|
3478
|
+
])) return {
|
|
3479
|
+
ext: "xz",
|
|
3480
|
+
mime: "application/x-xz"
|
|
3481
|
+
};
|
|
3482
|
+
if (this.checkString("<?xml ")) return {
|
|
3483
|
+
ext: "xml",
|
|
3484
|
+
mime: "application/xml"
|
|
3485
|
+
};
|
|
3486
|
+
if (this.check([
|
|
3487
|
+
55,
|
|
3488
|
+
122,
|
|
3489
|
+
188,
|
|
3490
|
+
175,
|
|
3491
|
+
39,
|
|
3492
|
+
28
|
|
3493
|
+
])) return {
|
|
3494
|
+
ext: "7z",
|
|
3495
|
+
mime: "application/x-7z-compressed"
|
|
3496
|
+
};
|
|
3497
|
+
if (this.check([
|
|
3498
|
+
82,
|
|
3499
|
+
97,
|
|
3500
|
+
114,
|
|
3501
|
+
33,
|
|
3502
|
+
26,
|
|
3503
|
+
7
|
|
3504
|
+
]) && (this.buffer[6] === 0 || this.buffer[6] === 1)) return {
|
|
3505
|
+
ext: "rar",
|
|
3506
|
+
mime: "application/x-rar-compressed"
|
|
3507
|
+
};
|
|
3508
|
+
if (this.checkString("solid ")) return {
|
|
3509
|
+
ext: "stl",
|
|
3510
|
+
mime: "model/stl"
|
|
3511
|
+
};
|
|
3512
|
+
if (this.checkString("AC")) {
|
|
3513
|
+
const version = new StringType(4, "latin1").get(this.buffer, 2);
|
|
3514
|
+
if (version.match("^d*") && version >= 1e3 && version <= 1050) return {
|
|
3515
|
+
ext: "dwg",
|
|
3516
|
+
mime: "image/vnd.dwg"
|
|
3517
|
+
};
|
|
3518
|
+
}
|
|
3519
|
+
if (this.checkString("070707")) return {
|
|
3520
|
+
ext: "cpio",
|
|
3521
|
+
mime: "application/x-cpio"
|
|
3522
|
+
};
|
|
3523
|
+
if (this.checkString("BLENDER")) return {
|
|
3524
|
+
ext: "blend",
|
|
3525
|
+
mime: "application/x-blender"
|
|
3526
|
+
};
|
|
3527
|
+
if (this.checkString("!<arch>")) {
|
|
3528
|
+
await tokenizer.ignore(8);
|
|
3529
|
+
if (await tokenizer.readToken(new StringType(13, "ascii")) === "debian-binary") return {
|
|
3530
|
+
ext: "deb",
|
|
3531
|
+
mime: "application/x-deb"
|
|
3532
|
+
};
|
|
3533
|
+
return {
|
|
3534
|
+
ext: "ar",
|
|
3535
|
+
mime: "application/x-unix-archive"
|
|
3536
|
+
};
|
|
3537
|
+
}
|
|
3538
|
+
if (this.checkString("WEBVTT") && [
|
|
3539
|
+
"\n",
|
|
3540
|
+
"\r",
|
|
3541
|
+
" ",
|
|
3542
|
+
" ",
|
|
3543
|
+
"\0"
|
|
3544
|
+
].some((char7) => this.checkString(char7, { offset: 6 }))) return {
|
|
3545
|
+
ext: "vtt",
|
|
3546
|
+
mime: "text/vtt"
|
|
3547
|
+
};
|
|
3548
|
+
if (this.check([
|
|
3549
|
+
137,
|
|
3550
|
+
80,
|
|
3551
|
+
78,
|
|
3552
|
+
71,
|
|
3553
|
+
13,
|
|
3554
|
+
10,
|
|
3555
|
+
26,
|
|
3556
|
+
10
|
|
3557
|
+
])) {
|
|
3558
|
+
const pngFileType = {
|
|
3559
|
+
ext: "png",
|
|
3560
|
+
mime: "image/png"
|
|
3561
|
+
};
|
|
3562
|
+
const apngFileType = {
|
|
3563
|
+
ext: "apng",
|
|
3564
|
+
mime: "image/apng"
|
|
3565
|
+
};
|
|
3566
|
+
await tokenizer.ignore(8);
|
|
3567
|
+
async function readChunkHeader() {
|
|
3568
|
+
return {
|
|
3569
|
+
length: await tokenizer.readToken(INT32_BE),
|
|
3570
|
+
type: await tokenizer.readToken(new StringType(4, "latin1"))
|
|
3571
|
+
};
|
|
3572
|
+
}
|
|
3573
|
+
const isUnknownPngStream = hasUnknownFileSize(tokenizer);
|
|
3574
|
+
const pngScanStart = tokenizer.position;
|
|
3575
|
+
do {
|
|
3576
|
+
if (hasExceededUnknownSizeScanBudget(tokenizer, pngScanStart, maximumPngChunkSizeInBytes)) break;
|
|
3577
|
+
const chunk = await readChunkHeader();
|
|
3578
|
+
if (chunk.length < 0) return;
|
|
3579
|
+
switch (chunk.type) {
|
|
3580
|
+
case "IDAT": return pngFileType;
|
|
3581
|
+
case "acTL": return apngFileType;
|
|
3582
|
+
default:
|
|
3583
|
+
if (isUnknownPngStream && chunk.length > maximumPngChunkSizeInBytes) return;
|
|
3584
|
+
try {
|
|
3585
|
+
await safeIgnore(tokenizer, chunk.length + 4, {
|
|
3586
|
+
maximumLength: isUnknownPngStream ? maximumPngChunkSizeInBytes + 4 : tokenizer.fileInfo.size,
|
|
3587
|
+
reason: "PNG chunk payload"
|
|
3588
|
+
});
|
|
3589
|
+
} catch (error) {
|
|
3590
|
+
if (!isUnknownPngStream && (error instanceof ParserHardLimitError || error instanceof EndOfStreamError)) return pngFileType;
|
|
3591
|
+
throw error;
|
|
3592
|
+
}
|
|
3593
|
+
}
|
|
3594
|
+
} while (tokenizer.position + 8 < tokenizer.fileInfo.size);
|
|
3595
|
+
return pngFileType;
|
|
3596
|
+
}
|
|
3597
|
+
if (this.check([
|
|
3598
|
+
65,
|
|
3599
|
+
82,
|
|
3600
|
+
82,
|
|
3601
|
+
79,
|
|
3602
|
+
87,
|
|
3603
|
+
49,
|
|
3604
|
+
0,
|
|
3605
|
+
0
|
|
3606
|
+
])) return {
|
|
3607
|
+
ext: "arrow",
|
|
3608
|
+
mime: "application/vnd.apache.arrow.file"
|
|
3609
|
+
};
|
|
3610
|
+
if (this.check([
|
|
3611
|
+
103,
|
|
3612
|
+
108,
|
|
3613
|
+
84,
|
|
3614
|
+
70,
|
|
3615
|
+
2,
|
|
3616
|
+
0,
|
|
3617
|
+
0,
|
|
3618
|
+
0
|
|
3619
|
+
])) return {
|
|
3620
|
+
ext: "glb",
|
|
3621
|
+
mime: "model/gltf-binary"
|
|
3622
|
+
};
|
|
3623
|
+
if (this.check([
|
|
3624
|
+
102,
|
|
3625
|
+
114,
|
|
3626
|
+
101,
|
|
3627
|
+
101
|
|
3628
|
+
], { offset: 4 }) || this.check([
|
|
3629
|
+
109,
|
|
3630
|
+
100,
|
|
3631
|
+
97,
|
|
3632
|
+
116
|
|
3633
|
+
], { offset: 4 }) || this.check([
|
|
3634
|
+
109,
|
|
3635
|
+
111,
|
|
3636
|
+
111,
|
|
3637
|
+
118
|
|
3638
|
+
], { offset: 4 }) || this.check([
|
|
3639
|
+
119,
|
|
3640
|
+
105,
|
|
3641
|
+
100,
|
|
3642
|
+
101
|
|
3643
|
+
], { offset: 4 })) return {
|
|
3644
|
+
ext: "mov",
|
|
3645
|
+
mime: "video/quicktime"
|
|
3646
|
+
};
|
|
3647
|
+
if (this.check([
|
|
3648
|
+
73,
|
|
3649
|
+
73,
|
|
3650
|
+
82,
|
|
3651
|
+
79,
|
|
3652
|
+
8,
|
|
3653
|
+
0,
|
|
3654
|
+
0,
|
|
3655
|
+
0,
|
|
3656
|
+
24
|
|
3657
|
+
])) return {
|
|
3658
|
+
ext: "orf",
|
|
3659
|
+
mime: "image/x-olympus-orf"
|
|
3660
|
+
};
|
|
3661
|
+
if (this.checkString("gimp xcf ")) return {
|
|
3662
|
+
ext: "xcf",
|
|
3663
|
+
mime: "image/x-xcf"
|
|
3664
|
+
};
|
|
3665
|
+
if (this.checkString("ftyp", { offset: 4 }) && (this.buffer[8] & 96) !== 0) {
|
|
3666
|
+
const brandMajor = new StringType(4, "latin1").get(this.buffer, 8).replace("\0", " ").trim();
|
|
3667
|
+
switch (brandMajor) {
|
|
3668
|
+
case "avif":
|
|
3669
|
+
case "avis": return {
|
|
3670
|
+
ext: "avif",
|
|
3671
|
+
mime: "image/avif"
|
|
3672
|
+
};
|
|
3673
|
+
case "mif1": return {
|
|
3674
|
+
ext: "heic",
|
|
3675
|
+
mime: "image/heif"
|
|
3676
|
+
};
|
|
3677
|
+
case "msf1": return {
|
|
3678
|
+
ext: "heic",
|
|
3679
|
+
mime: "image/heif-sequence"
|
|
3680
|
+
};
|
|
3681
|
+
case "heic":
|
|
3682
|
+
case "heix": return {
|
|
3683
|
+
ext: "heic",
|
|
3684
|
+
mime: "image/heic"
|
|
3685
|
+
};
|
|
3686
|
+
case "hevc":
|
|
3687
|
+
case "hevx": return {
|
|
3688
|
+
ext: "heic",
|
|
3689
|
+
mime: "image/heic-sequence"
|
|
3690
|
+
};
|
|
3691
|
+
case "qt": return {
|
|
3692
|
+
ext: "mov",
|
|
3693
|
+
mime: "video/quicktime"
|
|
3694
|
+
};
|
|
3695
|
+
case "M4V":
|
|
3696
|
+
case "M4VH":
|
|
3697
|
+
case "M4VP": return {
|
|
3698
|
+
ext: "m4v",
|
|
3699
|
+
mime: "video/x-m4v"
|
|
3700
|
+
};
|
|
3701
|
+
case "M4P": return {
|
|
3702
|
+
ext: "m4p",
|
|
3703
|
+
mime: "video/mp4"
|
|
3704
|
+
};
|
|
3705
|
+
case "M4B": return {
|
|
3706
|
+
ext: "m4b",
|
|
3707
|
+
mime: "audio/mp4"
|
|
3708
|
+
};
|
|
3709
|
+
case "M4A": return {
|
|
3710
|
+
ext: "m4a",
|
|
3711
|
+
mime: "audio/x-m4a"
|
|
3712
|
+
};
|
|
3713
|
+
case "F4V": return {
|
|
3714
|
+
ext: "f4v",
|
|
3715
|
+
mime: "video/mp4"
|
|
3716
|
+
};
|
|
3717
|
+
case "F4P": return {
|
|
3718
|
+
ext: "f4p",
|
|
3719
|
+
mime: "video/mp4"
|
|
3720
|
+
};
|
|
3721
|
+
case "F4A": return {
|
|
3722
|
+
ext: "f4a",
|
|
3723
|
+
mime: "audio/mp4"
|
|
3724
|
+
};
|
|
3725
|
+
case "F4B": return {
|
|
3726
|
+
ext: "f4b",
|
|
3727
|
+
mime: "audio/mp4"
|
|
3728
|
+
};
|
|
3729
|
+
case "crx": return {
|
|
3730
|
+
ext: "cr3",
|
|
3731
|
+
mime: "image/x-canon-cr3"
|
|
3732
|
+
};
|
|
3733
|
+
default:
|
|
3734
|
+
if (brandMajor.startsWith("3g")) {
|
|
3735
|
+
if (brandMajor.startsWith("3g2")) return {
|
|
3736
|
+
ext: "3g2",
|
|
3737
|
+
mime: "video/3gpp2"
|
|
3738
|
+
};
|
|
3739
|
+
return {
|
|
3740
|
+
ext: "3gp",
|
|
3741
|
+
mime: "video/3gpp"
|
|
3742
|
+
};
|
|
3743
|
+
}
|
|
3744
|
+
return {
|
|
3745
|
+
ext: "mp4",
|
|
3746
|
+
mime: "video/mp4"
|
|
3747
|
+
};
|
|
3748
|
+
}
|
|
3749
|
+
}
|
|
3750
|
+
if (this.checkString("REGEDIT4\r\n")) return {
|
|
3751
|
+
ext: "reg",
|
|
3752
|
+
mime: "application/x-ms-regedit"
|
|
3753
|
+
};
|
|
3754
|
+
if (this.check([
|
|
3755
|
+
82,
|
|
3756
|
+
73,
|
|
3757
|
+
70,
|
|
3758
|
+
70
|
|
3759
|
+
])) {
|
|
3760
|
+
if (this.checkString("WEBP", { offset: 8 })) return {
|
|
3761
|
+
ext: "webp",
|
|
3762
|
+
mime: "image/webp"
|
|
3763
|
+
};
|
|
3764
|
+
if (this.check([
|
|
3765
|
+
65,
|
|
3766
|
+
86,
|
|
3767
|
+
73
|
|
3768
|
+
], { offset: 8 })) return {
|
|
3769
|
+
ext: "avi",
|
|
3770
|
+
mime: "video/vnd.avi"
|
|
3771
|
+
};
|
|
3772
|
+
if (this.check([
|
|
3773
|
+
87,
|
|
3774
|
+
65,
|
|
3775
|
+
86,
|
|
3776
|
+
69
|
|
3777
|
+
], { offset: 8 })) return {
|
|
3778
|
+
ext: "wav",
|
|
3779
|
+
mime: "audio/wav"
|
|
3780
|
+
};
|
|
3781
|
+
if (this.check([
|
|
3782
|
+
81,
|
|
3783
|
+
76,
|
|
3784
|
+
67,
|
|
3785
|
+
77
|
|
3786
|
+
], { offset: 8 })) return {
|
|
3787
|
+
ext: "qcp",
|
|
3788
|
+
mime: "audio/qcelp"
|
|
3789
|
+
};
|
|
3790
|
+
}
|
|
3791
|
+
if (this.check([
|
|
3792
|
+
73,
|
|
3793
|
+
73,
|
|
3794
|
+
85,
|
|
3795
|
+
0,
|
|
3796
|
+
24,
|
|
3797
|
+
0,
|
|
3798
|
+
0,
|
|
3799
|
+
0,
|
|
3800
|
+
136,
|
|
3801
|
+
231,
|
|
3802
|
+
116,
|
|
3803
|
+
216
|
|
3804
|
+
])) return {
|
|
3805
|
+
ext: "rw2",
|
|
3806
|
+
mime: "image/x-panasonic-rw2"
|
|
3807
|
+
};
|
|
3808
|
+
if (this.check([
|
|
3809
|
+
48,
|
|
3810
|
+
38,
|
|
3811
|
+
178,
|
|
3812
|
+
117,
|
|
3813
|
+
142,
|
|
3814
|
+
102,
|
|
3815
|
+
207,
|
|
3816
|
+
17,
|
|
3817
|
+
166,
|
|
3818
|
+
217
|
|
3819
|
+
])) {
|
|
3820
|
+
let isMalformedAsf = false;
|
|
3821
|
+
try {
|
|
3822
|
+
async function readHeader() {
|
|
3823
|
+
const guid = new Uint8Array(16);
|
|
3824
|
+
await safeReadBuffer(tokenizer, guid, void 0, {
|
|
3825
|
+
maximumLength: guid.length,
|
|
3826
|
+
reason: "ASF header GUID"
|
|
3827
|
+
});
|
|
3828
|
+
return {
|
|
3829
|
+
id: guid,
|
|
3830
|
+
size: Number(await tokenizer.readToken(UINT64_LE))
|
|
3831
|
+
};
|
|
3832
|
+
}
|
|
3833
|
+
await safeIgnore(tokenizer, 30, {
|
|
3834
|
+
maximumLength: 30,
|
|
3835
|
+
reason: "ASF header prelude"
|
|
3836
|
+
});
|
|
3837
|
+
const isUnknownFileSize = hasUnknownFileSize(tokenizer);
|
|
3838
|
+
const asfHeaderScanStart = tokenizer.position;
|
|
3839
|
+
while (tokenizer.position + 24 < tokenizer.fileInfo.size) {
|
|
3840
|
+
if (hasExceededUnknownSizeScanBudget(tokenizer, asfHeaderScanStart, maximumUntrustedSkipSizeInBytes)) break;
|
|
3841
|
+
const previousPosition = tokenizer.position;
|
|
3842
|
+
const header = await readHeader();
|
|
3843
|
+
let payload = header.size - 24;
|
|
3844
|
+
if (!Number.isFinite(payload) || payload < 0) {
|
|
3845
|
+
isMalformedAsf = true;
|
|
3846
|
+
break;
|
|
3847
|
+
}
|
|
3848
|
+
if (_check(header.id, [
|
|
3849
|
+
145,
|
|
3850
|
+
7,
|
|
3851
|
+
220,
|
|
3852
|
+
183,
|
|
3853
|
+
183,
|
|
3854
|
+
169,
|
|
3855
|
+
207,
|
|
3856
|
+
17,
|
|
3857
|
+
142,
|
|
3858
|
+
230,
|
|
3859
|
+
0,
|
|
3860
|
+
192,
|
|
3861
|
+
12,
|
|
3862
|
+
32,
|
|
3863
|
+
83,
|
|
3864
|
+
101
|
|
3865
|
+
])) {
|
|
3866
|
+
const typeId = new Uint8Array(16);
|
|
3867
|
+
payload -= await safeReadBuffer(tokenizer, typeId, void 0, {
|
|
3868
|
+
maximumLength: typeId.length,
|
|
3869
|
+
reason: "ASF stream type GUID"
|
|
3870
|
+
});
|
|
3871
|
+
if (_check(typeId, [
|
|
3872
|
+
64,
|
|
3873
|
+
158,
|
|
3874
|
+
105,
|
|
3875
|
+
248,
|
|
3876
|
+
77,
|
|
3877
|
+
91,
|
|
3878
|
+
207,
|
|
3879
|
+
17,
|
|
3880
|
+
168,
|
|
3881
|
+
253,
|
|
3882
|
+
0,
|
|
3883
|
+
128,
|
|
3884
|
+
95,
|
|
3885
|
+
92,
|
|
3886
|
+
68,
|
|
3887
|
+
43
|
|
3888
|
+
])) return {
|
|
3889
|
+
ext: "asf",
|
|
3890
|
+
mime: "audio/x-ms-asf"
|
|
3891
|
+
};
|
|
3892
|
+
if (_check(typeId, [
|
|
3893
|
+
192,
|
|
3894
|
+
239,
|
|
3895
|
+
25,
|
|
3896
|
+
188,
|
|
3897
|
+
77,
|
|
3898
|
+
91,
|
|
3899
|
+
207,
|
|
3900
|
+
17,
|
|
3901
|
+
168,
|
|
3902
|
+
253,
|
|
3903
|
+
0,
|
|
3904
|
+
128,
|
|
3905
|
+
95,
|
|
3906
|
+
92,
|
|
3907
|
+
68,
|
|
3908
|
+
43
|
|
3909
|
+
])) return {
|
|
3910
|
+
ext: "asf",
|
|
3911
|
+
mime: "video/x-ms-asf"
|
|
3912
|
+
};
|
|
3913
|
+
break;
|
|
3914
|
+
}
|
|
3915
|
+
await safeIgnore(tokenizer, payload, {
|
|
3916
|
+
maximumLength: isUnknownFileSize ? maximumUntrustedSkipSizeInBytes : tokenizer.fileInfo.size,
|
|
3917
|
+
reason: "ASF header payload"
|
|
3918
|
+
});
|
|
3919
|
+
if (tokenizer.position <= previousPosition) {
|
|
3920
|
+
isMalformedAsf = true;
|
|
3921
|
+
break;
|
|
3922
|
+
}
|
|
3923
|
+
}
|
|
3924
|
+
} catch (error) {
|
|
3925
|
+
if (error instanceof EndOfStreamError || error instanceof ParserHardLimitError) {
|
|
3926
|
+
if (hasUnknownFileSize(tokenizer)) isMalformedAsf = true;
|
|
3927
|
+
} else throw error;
|
|
3928
|
+
}
|
|
3929
|
+
if (isMalformedAsf) return;
|
|
3930
|
+
return {
|
|
3931
|
+
ext: "asf",
|
|
3932
|
+
mime: "application/vnd.ms-asf"
|
|
3933
|
+
};
|
|
3934
|
+
}
|
|
3935
|
+
if (this.check([
|
|
3936
|
+
171,
|
|
3937
|
+
75,
|
|
3938
|
+
84,
|
|
3939
|
+
88,
|
|
3940
|
+
32,
|
|
3941
|
+
49,
|
|
3942
|
+
49,
|
|
3943
|
+
187,
|
|
3944
|
+
13,
|
|
3945
|
+
10,
|
|
3946
|
+
26,
|
|
3947
|
+
10
|
|
3948
|
+
])) return {
|
|
3949
|
+
ext: "ktx",
|
|
3950
|
+
mime: "image/ktx"
|
|
3951
|
+
};
|
|
3952
|
+
if ((this.check([
|
|
3953
|
+
126,
|
|
3954
|
+
16,
|
|
3955
|
+
4
|
|
3956
|
+
]) || this.check([
|
|
3957
|
+
126,
|
|
3958
|
+
24,
|
|
3959
|
+
4
|
|
3960
|
+
])) && this.check([
|
|
3961
|
+
48,
|
|
3962
|
+
77,
|
|
3963
|
+
73,
|
|
3964
|
+
69
|
|
3965
|
+
], { offset: 4 })) return {
|
|
3966
|
+
ext: "mie",
|
|
3967
|
+
mime: "application/x-mie"
|
|
3968
|
+
};
|
|
3969
|
+
if (this.check([
|
|
3970
|
+
39,
|
|
3971
|
+
10,
|
|
3972
|
+
0,
|
|
3973
|
+
0,
|
|
3974
|
+
0,
|
|
3975
|
+
0,
|
|
3976
|
+
0,
|
|
3977
|
+
0,
|
|
3978
|
+
0,
|
|
3979
|
+
0,
|
|
3980
|
+
0,
|
|
3981
|
+
0
|
|
3982
|
+
], { offset: 2 })) return {
|
|
3983
|
+
ext: "shp",
|
|
3984
|
+
mime: "application/x-esri-shape"
|
|
3985
|
+
};
|
|
3986
|
+
if (this.check([
|
|
3987
|
+
255,
|
|
3988
|
+
79,
|
|
3989
|
+
255,
|
|
3990
|
+
81
|
|
3991
|
+
])) return {
|
|
3992
|
+
ext: "j2c",
|
|
3993
|
+
mime: "image/j2c"
|
|
3994
|
+
};
|
|
3995
|
+
if (this.check([
|
|
3996
|
+
0,
|
|
3997
|
+
0,
|
|
3998
|
+
0,
|
|
3999
|
+
12,
|
|
4000
|
+
106,
|
|
4001
|
+
80,
|
|
4002
|
+
32,
|
|
4003
|
+
32,
|
|
4004
|
+
13,
|
|
4005
|
+
10,
|
|
4006
|
+
135,
|
|
4007
|
+
10
|
|
4008
|
+
])) {
|
|
4009
|
+
await tokenizer.ignore(20);
|
|
4010
|
+
switch (await tokenizer.readToken(new StringType(4, "ascii"))) {
|
|
4011
|
+
case "jp2 ": return {
|
|
4012
|
+
ext: "jp2",
|
|
4013
|
+
mime: "image/jp2"
|
|
4014
|
+
};
|
|
4015
|
+
case "jpx ": return {
|
|
4016
|
+
ext: "jpx",
|
|
4017
|
+
mime: "image/jpx"
|
|
4018
|
+
};
|
|
4019
|
+
case "jpm ": return {
|
|
4020
|
+
ext: "jpm",
|
|
4021
|
+
mime: "image/jpm"
|
|
4022
|
+
};
|
|
4023
|
+
case "mjp2": return {
|
|
4024
|
+
ext: "mj2",
|
|
4025
|
+
mime: "image/mj2"
|
|
4026
|
+
};
|
|
4027
|
+
default: return;
|
|
4028
|
+
}
|
|
4029
|
+
}
|
|
4030
|
+
if (this.check([255, 10]) || this.check([
|
|
4031
|
+
0,
|
|
4032
|
+
0,
|
|
4033
|
+
0,
|
|
4034
|
+
12,
|
|
4035
|
+
74,
|
|
4036
|
+
88,
|
|
4037
|
+
76,
|
|
4038
|
+
32,
|
|
4039
|
+
13,
|
|
4040
|
+
10,
|
|
4041
|
+
135,
|
|
4042
|
+
10
|
|
4043
|
+
])) return {
|
|
4044
|
+
ext: "jxl",
|
|
4045
|
+
mime: "image/jxl"
|
|
4046
|
+
};
|
|
4047
|
+
if (this.check([254, 255])) {
|
|
4048
|
+
if (this.checkString("<?xml ", {
|
|
4049
|
+
offset: 2,
|
|
4050
|
+
encoding: "utf-16be"
|
|
4051
|
+
})) return {
|
|
4052
|
+
ext: "xml",
|
|
4053
|
+
mime: "application/xml"
|
|
4054
|
+
};
|
|
4055
|
+
return;
|
|
4056
|
+
}
|
|
4057
|
+
if (this.check([
|
|
4058
|
+
208,
|
|
4059
|
+
207,
|
|
4060
|
+
17,
|
|
4061
|
+
224,
|
|
4062
|
+
161,
|
|
4063
|
+
177,
|
|
4064
|
+
26,
|
|
4065
|
+
225
|
|
4066
|
+
])) return {
|
|
4067
|
+
ext: "cfb",
|
|
4068
|
+
mime: "application/x-cfb"
|
|
4069
|
+
};
|
|
4070
|
+
await tokenizer.peekBuffer(this.buffer, {
|
|
4071
|
+
length: Math.min(256, tokenizer.fileInfo.size),
|
|
4072
|
+
mayBeLess: true
|
|
4073
|
+
});
|
|
4074
|
+
if (this.check([
|
|
4075
|
+
97,
|
|
4076
|
+
99,
|
|
4077
|
+
115,
|
|
4078
|
+
112
|
|
4079
|
+
], { offset: 36 })) return {
|
|
4080
|
+
ext: "icc",
|
|
4081
|
+
mime: "application/vnd.iccprofile"
|
|
4082
|
+
};
|
|
4083
|
+
if (this.checkString("**ACE", { offset: 7 }) && this.checkString("**", { offset: 12 })) return {
|
|
4084
|
+
ext: "ace",
|
|
4085
|
+
mime: "application/x-ace-compressed"
|
|
4086
|
+
};
|
|
4087
|
+
if (this.checkString("BEGIN:")) {
|
|
4088
|
+
if (this.checkString("VCARD", { offset: 6 })) return {
|
|
4089
|
+
ext: "vcf",
|
|
4090
|
+
mime: "text/vcard"
|
|
4091
|
+
};
|
|
4092
|
+
if (this.checkString("VCALENDAR", { offset: 6 })) return {
|
|
4093
|
+
ext: "ics",
|
|
4094
|
+
mime: "text/calendar"
|
|
4095
|
+
};
|
|
4096
|
+
}
|
|
4097
|
+
if (this.checkString("FUJIFILMCCD-RAW")) return {
|
|
4098
|
+
ext: "raf",
|
|
4099
|
+
mime: "image/x-fujifilm-raf"
|
|
4100
|
+
};
|
|
4101
|
+
if (this.checkString("Extended Module:")) return {
|
|
4102
|
+
ext: "xm",
|
|
4103
|
+
mime: "audio/x-xm"
|
|
4104
|
+
};
|
|
4105
|
+
if (this.checkString("Creative Voice File")) return {
|
|
4106
|
+
ext: "voc",
|
|
4107
|
+
mime: "audio/x-voc"
|
|
4108
|
+
};
|
|
4109
|
+
if (this.check([
|
|
4110
|
+
4,
|
|
4111
|
+
0,
|
|
4112
|
+
0,
|
|
4113
|
+
0
|
|
4114
|
+
]) && this.buffer.length >= 16) {
|
|
4115
|
+
const jsonSize = new DataView(this.buffer.buffer).getUint32(12, true);
|
|
4116
|
+
if (jsonSize > 12 && this.buffer.length >= jsonSize + 16) try {
|
|
4117
|
+
const header = new TextDecoder().decode(this.buffer.subarray(16, jsonSize + 16));
|
|
4118
|
+
if (JSON.parse(header).files) return {
|
|
4119
|
+
ext: "asar",
|
|
4120
|
+
mime: "application/x-asar"
|
|
4121
|
+
};
|
|
4122
|
+
} catch {}
|
|
4123
|
+
}
|
|
4124
|
+
if (this.check([
|
|
4125
|
+
6,
|
|
4126
|
+
14,
|
|
4127
|
+
43,
|
|
4128
|
+
52,
|
|
4129
|
+
2,
|
|
4130
|
+
5,
|
|
4131
|
+
1,
|
|
4132
|
+
1,
|
|
4133
|
+
13,
|
|
4134
|
+
1,
|
|
4135
|
+
2,
|
|
4136
|
+
1,
|
|
4137
|
+
1,
|
|
4138
|
+
2
|
|
4139
|
+
])) return {
|
|
4140
|
+
ext: "mxf",
|
|
4141
|
+
mime: "application/mxf"
|
|
4142
|
+
};
|
|
4143
|
+
if (this.checkString("SCRM", { offset: 44 })) return {
|
|
4144
|
+
ext: "s3m",
|
|
4145
|
+
mime: "audio/x-s3m"
|
|
4146
|
+
};
|
|
4147
|
+
if (this.check([71]) && this.check([71], { offset: 188 })) return {
|
|
4148
|
+
ext: "mts",
|
|
4149
|
+
mime: "video/mp2t"
|
|
4150
|
+
};
|
|
4151
|
+
if (this.check([71], { offset: 4 }) && this.check([71], { offset: 196 })) return {
|
|
4152
|
+
ext: "mts",
|
|
4153
|
+
mime: "video/mp2t"
|
|
4154
|
+
};
|
|
4155
|
+
if (this.check([
|
|
4156
|
+
66,
|
|
4157
|
+
79,
|
|
4158
|
+
79,
|
|
4159
|
+
75,
|
|
4160
|
+
77,
|
|
4161
|
+
79,
|
|
4162
|
+
66,
|
|
4163
|
+
73
|
|
4164
|
+
], { offset: 60 })) return {
|
|
4165
|
+
ext: "mobi",
|
|
4166
|
+
mime: "application/x-mobipocket-ebook"
|
|
4167
|
+
};
|
|
4168
|
+
if (this.check([
|
|
4169
|
+
68,
|
|
4170
|
+
73,
|
|
4171
|
+
67,
|
|
4172
|
+
77
|
|
4173
|
+
], { offset: 128 })) return {
|
|
4174
|
+
ext: "dcm",
|
|
4175
|
+
mime: "application/dicom"
|
|
4176
|
+
};
|
|
4177
|
+
if (this.check([
|
|
4178
|
+
76,
|
|
4179
|
+
0,
|
|
4180
|
+
0,
|
|
4181
|
+
0,
|
|
4182
|
+
1,
|
|
4183
|
+
20,
|
|
4184
|
+
2,
|
|
4185
|
+
0,
|
|
4186
|
+
0,
|
|
4187
|
+
0,
|
|
4188
|
+
0,
|
|
4189
|
+
0,
|
|
4190
|
+
192,
|
|
4191
|
+
0,
|
|
4192
|
+
0,
|
|
4193
|
+
0,
|
|
4194
|
+
0,
|
|
4195
|
+
0,
|
|
4196
|
+
0,
|
|
4197
|
+
70
|
|
4198
|
+
])) return {
|
|
4199
|
+
ext: "lnk",
|
|
4200
|
+
mime: "application/x.ms.shortcut"
|
|
4201
|
+
};
|
|
4202
|
+
if (this.check([
|
|
4203
|
+
98,
|
|
4204
|
+
111,
|
|
4205
|
+
111,
|
|
4206
|
+
107,
|
|
4207
|
+
0,
|
|
4208
|
+
0,
|
|
4209
|
+
0,
|
|
4210
|
+
0,
|
|
4211
|
+
109,
|
|
4212
|
+
97,
|
|
4213
|
+
114,
|
|
4214
|
+
107,
|
|
4215
|
+
0,
|
|
4216
|
+
0,
|
|
4217
|
+
0,
|
|
4218
|
+
0
|
|
4219
|
+
])) return {
|
|
4220
|
+
ext: "alias",
|
|
4221
|
+
mime: "application/x.apple.alias"
|
|
4222
|
+
};
|
|
4223
|
+
if (this.checkString("Kaydara FBX Binary \0")) return {
|
|
4224
|
+
ext: "fbx",
|
|
4225
|
+
mime: "application/x.autodesk.fbx"
|
|
4226
|
+
};
|
|
4227
|
+
if (this.check([76, 80], { offset: 34 }) && (this.check([
|
|
4228
|
+
0,
|
|
4229
|
+
0,
|
|
4230
|
+
1
|
|
4231
|
+
], { offset: 8 }) || this.check([
|
|
4232
|
+
1,
|
|
4233
|
+
0,
|
|
4234
|
+
2
|
|
4235
|
+
], { offset: 8 }) || this.check([
|
|
4236
|
+
2,
|
|
4237
|
+
0,
|
|
4238
|
+
2
|
|
4239
|
+
], { offset: 8 }))) return {
|
|
4240
|
+
ext: "eot",
|
|
4241
|
+
mime: "application/vnd.ms-fontobject"
|
|
4242
|
+
};
|
|
4243
|
+
if (this.check([
|
|
4244
|
+
6,
|
|
4245
|
+
6,
|
|
4246
|
+
237,
|
|
4247
|
+
245,
|
|
4248
|
+
216,
|
|
4249
|
+
29,
|
|
4250
|
+
70,
|
|
4251
|
+
229,
|
|
4252
|
+
189,
|
|
4253
|
+
49,
|
|
4254
|
+
239,
|
|
4255
|
+
231,
|
|
4256
|
+
254,
|
|
4257
|
+
116,
|
|
4258
|
+
183,
|
|
4259
|
+
29
|
|
4260
|
+
])) return {
|
|
4261
|
+
ext: "indd",
|
|
4262
|
+
mime: "application/x-indesign"
|
|
4263
|
+
};
|
|
4264
|
+
if (this.check([
|
|
4265
|
+
255,
|
|
4266
|
+
255,
|
|
4267
|
+
0,
|
|
4268
|
+
0,
|
|
4269
|
+
7,
|
|
4270
|
+
0,
|
|
4271
|
+
0,
|
|
4272
|
+
0,
|
|
4273
|
+
4,
|
|
4274
|
+
0,
|
|
4275
|
+
0,
|
|
4276
|
+
0,
|
|
4277
|
+
1,
|
|
4278
|
+
0,
|
|
4279
|
+
1,
|
|
4280
|
+
0
|
|
4281
|
+
]) || this.check([
|
|
4282
|
+
0,
|
|
4283
|
+
0,
|
|
4284
|
+
255,
|
|
4285
|
+
255,
|
|
4286
|
+
0,
|
|
4287
|
+
0,
|
|
4288
|
+
0,
|
|
4289
|
+
7,
|
|
4290
|
+
0,
|
|
4291
|
+
0,
|
|
4292
|
+
0,
|
|
4293
|
+
4,
|
|
4294
|
+
0,
|
|
4295
|
+
1,
|
|
4296
|
+
0,
|
|
4297
|
+
1
|
|
4298
|
+
])) return {
|
|
4299
|
+
ext: "jmp",
|
|
4300
|
+
mime: "application/x-jmp-data"
|
|
4301
|
+
};
|
|
4302
|
+
await tokenizer.peekBuffer(this.buffer, {
|
|
4303
|
+
length: Math.min(512, tokenizer.fileInfo.size),
|
|
4304
|
+
mayBeLess: true
|
|
4305
|
+
});
|
|
4306
|
+
if (this.checkString("ustar", { offset: 257 }) && (this.checkString("\0", { offset: 262 }) || this.checkString(" ", { offset: 262 })) || this.check([
|
|
4307
|
+
0,
|
|
4308
|
+
0,
|
|
4309
|
+
0,
|
|
4310
|
+
0,
|
|
4311
|
+
0,
|
|
4312
|
+
0
|
|
4313
|
+
], { offset: 257 }) && tarHeaderChecksumMatches(this.buffer)) return {
|
|
4314
|
+
ext: "tar",
|
|
4315
|
+
mime: "application/x-tar"
|
|
4316
|
+
};
|
|
4317
|
+
if (this.check([255, 254])) {
|
|
4318
|
+
const encoding = "utf-16le";
|
|
4319
|
+
if (this.checkString("<?xml ", {
|
|
4320
|
+
offset: 2,
|
|
4321
|
+
encoding
|
|
4322
|
+
})) return {
|
|
4323
|
+
ext: "xml",
|
|
4324
|
+
mime: "application/xml"
|
|
4325
|
+
};
|
|
4326
|
+
if (this.check([255, 14], { offset: 2 }) && this.checkString("SketchUp Model", {
|
|
4327
|
+
offset: 4,
|
|
4328
|
+
encoding
|
|
4329
|
+
})) return {
|
|
4330
|
+
ext: "skp",
|
|
4331
|
+
mime: "application/vnd.sketchup.skp"
|
|
4332
|
+
};
|
|
4333
|
+
if (this.checkString("Windows Registry Editor Version 5.00\r\n", {
|
|
4334
|
+
offset: 2,
|
|
4335
|
+
encoding
|
|
4336
|
+
})) return {
|
|
4337
|
+
ext: "reg",
|
|
4338
|
+
mime: "application/x-ms-regedit"
|
|
4339
|
+
};
|
|
4340
|
+
return;
|
|
4341
|
+
}
|
|
4342
|
+
if (this.checkString("-----BEGIN PGP MESSAGE-----")) return {
|
|
4343
|
+
ext: "pgp",
|
|
4344
|
+
mime: "application/pgp-encrypted"
|
|
4345
|
+
};
|
|
4346
|
+
};
|
|
4347
|
+
detectImprecise = async (tokenizer) => {
|
|
4348
|
+
this.buffer = new Uint8Array(reasonableDetectionSizeInBytes);
|
|
4349
|
+
const fileSize = getKnownFileSizeOrMaximum(tokenizer.fileInfo.size);
|
|
4350
|
+
await tokenizer.peekBuffer(this.buffer, {
|
|
4351
|
+
length: Math.min(8, fileSize),
|
|
4352
|
+
mayBeLess: true
|
|
4353
|
+
});
|
|
4354
|
+
if (this.check([
|
|
4355
|
+
0,
|
|
4356
|
+
0,
|
|
4357
|
+
1,
|
|
4358
|
+
186
|
|
4359
|
+
]) || this.check([
|
|
4360
|
+
0,
|
|
4361
|
+
0,
|
|
4362
|
+
1,
|
|
4363
|
+
179
|
|
4364
|
+
])) return {
|
|
4365
|
+
ext: "mpg",
|
|
4366
|
+
mime: "video/mpeg"
|
|
4367
|
+
};
|
|
4368
|
+
if (this.check([
|
|
4369
|
+
0,
|
|
4370
|
+
1,
|
|
4371
|
+
0,
|
|
4372
|
+
0,
|
|
4373
|
+
0
|
|
4374
|
+
])) return {
|
|
4375
|
+
ext: "ttf",
|
|
4376
|
+
mime: "font/ttf"
|
|
4377
|
+
};
|
|
4378
|
+
if (this.check([
|
|
4379
|
+
0,
|
|
4380
|
+
0,
|
|
4381
|
+
1,
|
|
4382
|
+
0
|
|
4383
|
+
])) return {
|
|
4384
|
+
ext: "ico",
|
|
4385
|
+
mime: "image/x-icon"
|
|
4386
|
+
};
|
|
4387
|
+
if (this.check([
|
|
4388
|
+
0,
|
|
4389
|
+
0,
|
|
4390
|
+
2,
|
|
4391
|
+
0
|
|
4392
|
+
])) return {
|
|
4393
|
+
ext: "cur",
|
|
4394
|
+
mime: "image/x-icon"
|
|
4395
|
+
};
|
|
4396
|
+
await tokenizer.peekBuffer(this.buffer, {
|
|
4397
|
+
length: Math.min(2 + this.options.mpegOffsetTolerance, fileSize),
|
|
4398
|
+
mayBeLess: true
|
|
4399
|
+
});
|
|
4400
|
+
if (this.buffer.length >= 2 + this.options.mpegOffsetTolerance) for (let depth = 0; depth <= this.options.mpegOffsetTolerance; ++depth) {
|
|
4401
|
+
const type = this.scanMpeg(depth);
|
|
4402
|
+
if (type) return type;
|
|
4403
|
+
}
|
|
4404
|
+
};
|
|
4405
|
+
async readTiffTag(bigEndian) {
|
|
4406
|
+
const tagId = await this.tokenizer.readToken(bigEndian ? UINT16_BE : UINT16_LE);
|
|
4407
|
+
await this.tokenizer.ignore(10);
|
|
4408
|
+
switch (tagId) {
|
|
4409
|
+
case 50341: return {
|
|
4410
|
+
ext: "arw",
|
|
4411
|
+
mime: "image/x-sony-arw"
|
|
4412
|
+
};
|
|
4413
|
+
case 50706: return {
|
|
4414
|
+
ext: "dng",
|
|
4415
|
+
mime: "image/x-adobe-dng"
|
|
4416
|
+
};
|
|
4417
|
+
default:
|
|
4418
|
+
}
|
|
4419
|
+
}
|
|
4420
|
+
async readTiffIFD(bigEndian) {
|
|
4421
|
+
const numberOfTags = await this.tokenizer.readToken(bigEndian ? UINT16_BE : UINT16_LE);
|
|
4422
|
+
if (hasUnknownFileSize(this.tokenizer) && 2 + numberOfTags * 12 > maximumTiffIfdOffsetInBytes) return;
|
|
4423
|
+
for (let n = 0; n < numberOfTags; ++n) {
|
|
4424
|
+
const fileType = await this.readTiffTag(bigEndian);
|
|
4425
|
+
if (fileType) return fileType;
|
|
4426
|
+
}
|
|
4427
|
+
}
|
|
4428
|
+
async readTiffHeader(bigEndian) {
|
|
4429
|
+
const tiffFileType = {
|
|
4430
|
+
ext: "tif",
|
|
4431
|
+
mime: "image/tiff"
|
|
4432
|
+
};
|
|
4433
|
+
const version = (bigEndian ? UINT16_BE : UINT16_LE).get(this.buffer, 2);
|
|
4434
|
+
const ifdOffset = (bigEndian ? UINT32_BE : UINT32_LE).get(this.buffer, 4);
|
|
4435
|
+
if (version === 42) {
|
|
4436
|
+
if (ifdOffset >= 6) {
|
|
4437
|
+
if (this.checkString("CR", { offset: 8 })) return {
|
|
4438
|
+
ext: "cr2",
|
|
4439
|
+
mime: "image/x-canon-cr2"
|
|
4440
|
+
};
|
|
4441
|
+
if (ifdOffset >= 8) {
|
|
4442
|
+
const someId1 = (bigEndian ? UINT16_BE : UINT16_LE).get(this.buffer, 8);
|
|
4443
|
+
const someId2 = (bigEndian ? UINT16_BE : UINT16_LE).get(this.buffer, 10);
|
|
4444
|
+
if (someId1 === 28 && someId2 === 254 || someId1 === 31 && someId2 === 11) return {
|
|
4445
|
+
ext: "nef",
|
|
4446
|
+
mime: "image/x-nikon-nef"
|
|
4447
|
+
};
|
|
4448
|
+
}
|
|
4449
|
+
}
|
|
4450
|
+
const maximumTiffOffset = hasUnknownFileSize(this.tokenizer) ? maximumTiffIfdOffsetInBytes : this.tokenizer.fileInfo.size;
|
|
4451
|
+
try {
|
|
4452
|
+
await safeIgnore(this.tokenizer, ifdOffset, {
|
|
4453
|
+
maximumLength: maximumTiffOffset,
|
|
4454
|
+
reason: "TIFF IFD offset"
|
|
4455
|
+
});
|
|
4456
|
+
} catch (error) {
|
|
4457
|
+
if (error instanceof EndOfStreamError) return;
|
|
4458
|
+
throw error;
|
|
4459
|
+
}
|
|
4460
|
+
let fileType;
|
|
4461
|
+
try {
|
|
4462
|
+
fileType = await this.readTiffIFD(bigEndian);
|
|
4463
|
+
} catch (error) {
|
|
4464
|
+
if (error instanceof EndOfStreamError) return;
|
|
4465
|
+
throw error;
|
|
4466
|
+
}
|
|
4467
|
+
return fileType ?? tiffFileType;
|
|
4468
|
+
}
|
|
4469
|
+
if (version === 43) return tiffFileType;
|
|
4470
|
+
}
|
|
4471
|
+
/**
|
|
4472
|
+
Scan check MPEG 1 or 2 Layer 3 header, or 'layer 0' for ADTS (MPEG sync-word 0xFFE).
|
|
4473
|
+
|
|
4474
|
+
@param offset - Offset to scan for sync-preamble.
|
|
4475
|
+
@returns {{ext: string, mime: string}}
|
|
4476
|
+
*/
|
|
4477
|
+
scanMpeg(offset) {
|
|
4478
|
+
if (this.check([255, 224], {
|
|
4479
|
+
offset,
|
|
4480
|
+
mask: [255, 224]
|
|
4481
|
+
})) {
|
|
4482
|
+
if (this.check([16], {
|
|
4483
|
+
offset: offset + 1,
|
|
4484
|
+
mask: [22]
|
|
4485
|
+
})) {
|
|
4486
|
+
if (this.check([8], {
|
|
4487
|
+
offset: offset + 1,
|
|
4488
|
+
mask: [8]
|
|
4489
|
+
})) return {
|
|
4490
|
+
ext: "aac",
|
|
4491
|
+
mime: "audio/aac"
|
|
4492
|
+
};
|
|
4493
|
+
return {
|
|
4494
|
+
ext: "aac",
|
|
4495
|
+
mime: "audio/aac"
|
|
4496
|
+
};
|
|
4497
|
+
}
|
|
4498
|
+
if (this.check([2], {
|
|
4499
|
+
offset: offset + 1,
|
|
4500
|
+
mask: [6]
|
|
4501
|
+
})) return {
|
|
4502
|
+
ext: "mp3",
|
|
4503
|
+
mime: "audio/mpeg"
|
|
4504
|
+
};
|
|
4505
|
+
if (this.check([4], {
|
|
4506
|
+
offset: offset + 1,
|
|
4507
|
+
mask: [6]
|
|
4508
|
+
})) return {
|
|
4509
|
+
ext: "mp2",
|
|
4510
|
+
mime: "audio/mpeg"
|
|
4511
|
+
};
|
|
4512
|
+
if (this.check([6], {
|
|
4513
|
+
offset: offset + 1,
|
|
4514
|
+
mask: [6]
|
|
4515
|
+
})) return {
|
|
4516
|
+
ext: "mp1",
|
|
4517
|
+
mime: "audio/mpeg"
|
|
4518
|
+
};
|
|
4519
|
+
}
|
|
4520
|
+
}
|
|
4521
|
+
};
|
|
4522
|
+
const supportedExtensions = new Set(extensions);
|
|
4523
|
+
const supportedMimeTypes = new Set(mimeTypes);
|
|
4524
|
+
|
|
4525
|
+
//#endregion
|
|
4526
|
+
export { fileTypeFromBlob };
|
|
4527
|
+
//# sourceMappingURL=file-type-BNd4XJK1.mjs.map
|