llonebot-dist 6.6.4
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.
- dist/default_config.json +68 -0
- dist/llonebot.js +48348 -0
- dist/llonebot.js.map +1 -0
- dist/node_modules/@borewit/text-codec/LICENSE.txt +9 -0
- dist/node_modules/@borewit/text-codec/README.md +76 -0
- dist/node_modules/@borewit/text-codec/lib/index.d.ts +8 -0
- dist/node_modules/@borewit/text-codec/lib/index.js +161 -0
- dist/node_modules/@borewit/text-codec/package.json +68 -0
- dist/node_modules/@minatojs/sql.js/LICENSE +44 -0
- dist/node_modules/@minatojs/sql.js/README.md +357 -0
- dist/node_modules/@minatojs/sql.js/dist/sql-wasm.d.ts +316 -0
- dist/node_modules/@minatojs/sql.js/dist/sql-wasm.js +225 -0
- dist/node_modules/@minatojs/sql.js/dist/sql-wasm.wasm +0 -0
- dist/node_modules/@minatojs/sql.js/package.json +58 -0
- dist/node_modules/@tokenizer/inflate/LICENSE +15 -0
- dist/node_modules/@tokenizer/inflate/README.md +114 -0
- dist/node_modules/@tokenizer/inflate/lib/GzipHandler.d.ts +6 -0
- dist/node_modules/@tokenizer/inflate/lib/GzipHandler.js +19 -0
- dist/node_modules/@tokenizer/inflate/lib/ZipHandler.d.ts +26 -0
- dist/node_modules/@tokenizer/inflate/lib/ZipHandler.js +233 -0
- dist/node_modules/@tokenizer/inflate/lib/ZipToken.d.ts +94 -0
- dist/node_modules/@tokenizer/inflate/lib/ZipToken.js +117 -0
- dist/node_modules/@tokenizer/inflate/lib/index.d.ts +3 -0
- dist/node_modules/@tokenizer/inflate/lib/index.js +2 -0
- dist/node_modules/@tokenizer/inflate/package.json +76 -0
- dist/node_modules/@tokenizer/token/README.md +19 -0
- dist/node_modules/@tokenizer/token/index.d.ts +30 -0
- dist/node_modules/@tokenizer/token/package.json +33 -0
- dist/node_modules/debug/LICENSE +20 -0
- dist/node_modules/debug/README.md +481 -0
- dist/node_modules/debug/package.json +64 -0
- dist/node_modules/debug/src/browser.js +272 -0
- dist/node_modules/debug/src/common.js +292 -0
- dist/node_modules/debug/src/index.js +10 -0
- dist/node_modules/debug/src/node.js +263 -0
- dist/node_modules/file-type/core.d.ts +253 -0
- dist/node_modules/file-type/core.js +1899 -0
- dist/node_modules/file-type/index.d.ts +98 -0
- dist/node_modules/file-type/index.js +86 -0
- dist/node_modules/file-type/license +9 -0
- dist/node_modules/file-type/package.json +288 -0
- dist/node_modules/file-type/readme.md +674 -0
- dist/node_modules/file-type/supported.js +356 -0
- dist/node_modules/file-type/util.js +60 -0
- dist/node_modules/ieee754/LICENSE +11 -0
- dist/node_modules/ieee754/README.md +51 -0
- dist/node_modules/ieee754/index.d.ts +10 -0
- dist/node_modules/ieee754/index.js +85 -0
- dist/node_modules/ieee754/package.json +52 -0
- dist/node_modules/ms/index.js +162 -0
- dist/node_modules/ms/license.md +21 -0
- dist/node_modules/ms/package.json +38 -0
- dist/node_modules/ms/readme.md +59 -0
- dist/node_modules/silk-wasm/LICENSE +21 -0
- dist/node_modules/silk-wasm/README.md +85 -0
- dist/node_modules/silk-wasm/lib/index.cjs +16 -0
- dist/node_modules/silk-wasm/lib/index.d.ts +70 -0
- dist/node_modules/silk-wasm/lib/index.mjs +16 -0
- dist/node_modules/silk-wasm/lib/silk.wasm +0 -0
- dist/node_modules/silk-wasm/lib/utils.d.ts +4 -0
- dist/node_modules/silk-wasm/package.json +39 -0
- dist/node_modules/strtok3/LICENSE.txt +21 -0
- dist/node_modules/strtok3/README.md +399 -0
- dist/node_modules/strtok3/lib/AbstractTokenizer.d.ts +76 -0
- dist/node_modules/strtok3/lib/AbstractTokenizer.js +108 -0
- dist/node_modules/strtok3/lib/BlobTokenizer.d.ts +29 -0
- dist/node_modules/strtok3/lib/BlobTokenizer.js +53 -0
- dist/node_modules/strtok3/lib/BufferTokenizer.d.ts +29 -0
- dist/node_modules/strtok3/lib/BufferTokenizer.js +52 -0
- dist/node_modules/strtok3/lib/FileTokenizer.d.ts +37 -0
- dist/node_modules/strtok3/lib/FileTokenizer.js +61 -0
- dist/node_modules/strtok3/lib/ReadStreamTokenizer.d.ts +31 -0
- dist/node_modules/strtok3/lib/ReadStreamTokenizer.js +102 -0
- dist/node_modules/strtok3/lib/core.d.ts +40 -0
- dist/node_modules/strtok3/lib/core.js +62 -0
- dist/node_modules/strtok3/lib/index.d.ts +16 -0
- dist/node_modules/strtok3/lib/index.js +22 -0
- dist/node_modules/strtok3/lib/stream/AbstractStreamReader.d.ts +54 -0
- dist/node_modules/strtok3/lib/stream/AbstractStreamReader.js +71 -0
- dist/node_modules/strtok3/lib/stream/Deferred.d.ts +6 -0
- dist/node_modules/strtok3/lib/stream/Deferred.js +10 -0
- dist/node_modules/strtok3/lib/stream/Errors.d.ts +10 -0
- dist/node_modules/strtok3/lib/stream/Errors.js +16 -0
- dist/node_modules/strtok3/lib/stream/StreamReader.d.ts +29 -0
- dist/node_modules/strtok3/lib/stream/StreamReader.js +83 -0
- dist/node_modules/strtok3/lib/stream/WebStreamByobReader.d.ts +14 -0
- dist/node_modules/strtok3/lib/stream/WebStreamByobReader.js +27 -0
- dist/node_modules/strtok3/lib/stream/WebStreamDefaultReader.d.ts +19 -0
- dist/node_modules/strtok3/lib/stream/WebStreamDefaultReader.js +62 -0
- dist/node_modules/strtok3/lib/stream/WebStreamReader.d.ts +14 -0
- dist/node_modules/strtok3/lib/stream/WebStreamReader.js +13 -0
- dist/node_modules/strtok3/lib/stream/WebStreamReaderFactory.d.ts +5 -0
- dist/node_modules/strtok3/lib/stream/WebStreamReaderFactory.js +19 -0
- dist/node_modules/strtok3/lib/stream/index.d.ts +6 -0
- dist/node_modules/strtok3/lib/stream/index.js +5 -0
- dist/node_modules/strtok3/lib/types.d.ts +139 -0
- dist/node_modules/strtok3/lib/types.js +1 -0
- dist/node_modules/strtok3/package.json +94 -0
- dist/node_modules/token-types/LICENSE.txt +9 -0
- dist/node_modules/token-types/README.md +120 -0
- dist/node_modules/token-types/lib/index.d.ts +135 -0
- dist/node_modules/token-types/lib/index.js +401 -0
- dist/node_modules/token-types/package.json +81 -0
- dist/node_modules/uint8array-extras/index.d.ts +312 -0
- dist/node_modules/uint8array-extras/index.js +321 -0
- dist/node_modules/uint8array-extras/license +9 -0
- dist/node_modules/uint8array-extras/package.json +54 -0
- dist/node_modules/uint8array-extras/readme.md +301 -0
- dist/node_modules/ws/LICENSE +20 -0
- dist/node_modules/ws/README.md +548 -0
- dist/node_modules/ws/browser.js +8 -0
- dist/node_modules/ws/index.js +13 -0
- dist/node_modules/ws/lib/buffer-util.js +131 -0
- dist/node_modules/ws/lib/constants.js +18 -0
- dist/node_modules/ws/lib/event-target.js +292 -0
- dist/node_modules/ws/lib/extension.js +203 -0
- dist/node_modules/ws/lib/limiter.js +55 -0
- dist/node_modules/ws/lib/permessage-deflate.js +528 -0
- dist/node_modules/ws/lib/receiver.js +706 -0
- dist/node_modules/ws/lib/sender.js +602 -0
- dist/node_modules/ws/lib/stream.js +161 -0
- dist/node_modules/ws/lib/subprotocol.js +62 -0
- dist/node_modules/ws/lib/validation.js +152 -0
- dist/node_modules/ws/lib/websocket-server.js +550 -0
- dist/node_modules/ws/lib/websocket.js +1388 -0
- dist/node_modules/ws/package.json +69 -0
- dist/node_modules/ws/wrapper.mjs +8 -0
- dist/package.json +1 -0
- dist/webui/assets/index-B9vGhdCO.js +256 -0
- dist/webui/assets/index-DaqFU7JR.css +1 -0
- dist/webui/index.html +13 -0
- dist/webui/logo.jpg +0 -0
- dist//344/275/277/347/224/250/350/257/264/346/230/216.txt +11 -0
- dist//346/233/264/346/226/260/346/227/245/345/277/227.txt +399 -0
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Module dependencies.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
const tty = require('tty');
|
|
6
|
+
const util = require('util');
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* This is the Node.js implementation of `debug()`.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
exports.init = init;
|
|
13
|
+
exports.log = log;
|
|
14
|
+
exports.formatArgs = formatArgs;
|
|
15
|
+
exports.save = save;
|
|
16
|
+
exports.load = load;
|
|
17
|
+
exports.useColors = useColors;
|
|
18
|
+
exports.destroy = util.deprecate(
|
|
19
|
+
() => {},
|
|
20
|
+
'Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.'
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Colors.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
exports.colors = [6, 2, 3, 4, 5, 1];
|
|
28
|
+
|
|
29
|
+
try {
|
|
30
|
+
// Optional dependency (as in, doesn't need to be installed, NOT like optionalDependencies in package.json)
|
|
31
|
+
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
32
|
+
const supportsColor = require('supports-color');
|
|
33
|
+
|
|
34
|
+
if (supportsColor && (supportsColor.stderr || supportsColor).level >= 2) {
|
|
35
|
+
exports.colors = [
|
|
36
|
+
20,
|
|
37
|
+
21,
|
|
38
|
+
26,
|
|
39
|
+
27,
|
|
40
|
+
32,
|
|
41
|
+
33,
|
|
42
|
+
38,
|
|
43
|
+
39,
|
|
44
|
+
40,
|
|
45
|
+
41,
|
|
46
|
+
42,
|
|
47
|
+
43,
|
|
48
|
+
44,
|
|
49
|
+
45,
|
|
50
|
+
56,
|
|
51
|
+
57,
|
|
52
|
+
62,
|
|
53
|
+
63,
|
|
54
|
+
68,
|
|
55
|
+
69,
|
|
56
|
+
74,
|
|
57
|
+
75,
|
|
58
|
+
76,
|
|
59
|
+
77,
|
|
60
|
+
78,
|
|
61
|
+
79,
|
|
62
|
+
80,
|
|
63
|
+
81,
|
|
64
|
+
92,
|
|
65
|
+
93,
|
|
66
|
+
98,
|
|
67
|
+
99,
|
|
68
|
+
112,
|
|
69
|
+
113,
|
|
70
|
+
128,
|
|
71
|
+
129,
|
|
72
|
+
134,
|
|
73
|
+
135,
|
|
74
|
+
148,
|
|
75
|
+
149,
|
|
76
|
+
160,
|
|
77
|
+
161,
|
|
78
|
+
162,
|
|
79
|
+
163,
|
|
80
|
+
164,
|
|
81
|
+
165,
|
|
82
|
+
166,
|
|
83
|
+
167,
|
|
84
|
+
168,
|
|
85
|
+
169,
|
|
86
|
+
170,
|
|
87
|
+
171,
|
|
88
|
+
172,
|
|
89
|
+
173,
|
|
90
|
+
178,
|
|
91
|
+
179,
|
|
92
|
+
184,
|
|
93
|
+
185,
|
|
94
|
+
196,
|
|
95
|
+
197,
|
|
96
|
+
198,
|
|
97
|
+
199,
|
|
98
|
+
200,
|
|
99
|
+
201,
|
|
100
|
+
202,
|
|
101
|
+
203,
|
|
102
|
+
204,
|
|
103
|
+
205,
|
|
104
|
+
206,
|
|
105
|
+
207,
|
|
106
|
+
208,
|
|
107
|
+
209,
|
|
108
|
+
214,
|
|
109
|
+
215,
|
|
110
|
+
220,
|
|
111
|
+
221
|
|
112
|
+
];
|
|
113
|
+
}
|
|
114
|
+
} catch (error) {
|
|
115
|
+
// Swallow - we only care if `supports-color` is available; it doesn't have to be.
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Build up the default `inspectOpts` object from the environment variables.
|
|
120
|
+
*
|
|
121
|
+
* $ DEBUG_COLORS=no DEBUG_DEPTH=10 DEBUG_SHOW_HIDDEN=enabled node script.js
|
|
122
|
+
*/
|
|
123
|
+
|
|
124
|
+
exports.inspectOpts = Object.keys(process.env).filter(key => {
|
|
125
|
+
return /^debug_/i.test(key);
|
|
126
|
+
}).reduce((obj, key) => {
|
|
127
|
+
// Camel-case
|
|
128
|
+
const prop = key
|
|
129
|
+
.substring(6)
|
|
130
|
+
.toLowerCase()
|
|
131
|
+
.replace(/_([a-z])/g, (_, k) => {
|
|
132
|
+
return k.toUpperCase();
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
// Coerce string value into JS value
|
|
136
|
+
let val = process.env[key];
|
|
137
|
+
if (/^(yes|on|true|enabled)$/i.test(val)) {
|
|
138
|
+
val = true;
|
|
139
|
+
} else if (/^(no|off|false|disabled)$/i.test(val)) {
|
|
140
|
+
val = false;
|
|
141
|
+
} else if (val === 'null') {
|
|
142
|
+
val = null;
|
|
143
|
+
} else {
|
|
144
|
+
val = Number(val);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
obj[prop] = val;
|
|
148
|
+
return obj;
|
|
149
|
+
}, {});
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Is stdout a TTY? Colored output is enabled when `true`.
|
|
153
|
+
*/
|
|
154
|
+
|
|
155
|
+
function useColors() {
|
|
156
|
+
return 'colors' in exports.inspectOpts ?
|
|
157
|
+
Boolean(exports.inspectOpts.colors) :
|
|
158
|
+
tty.isatty(process.stderr.fd);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Adds ANSI color escape codes if enabled.
|
|
163
|
+
*
|
|
164
|
+
* @api public
|
|
165
|
+
*/
|
|
166
|
+
|
|
167
|
+
function formatArgs(args) {
|
|
168
|
+
const {namespace: name, useColors} = this;
|
|
169
|
+
|
|
170
|
+
if (useColors) {
|
|
171
|
+
const c = this.color;
|
|
172
|
+
const colorCode = '\u001B[3' + (c < 8 ? c : '8;5;' + c);
|
|
173
|
+
const prefix = ` ${colorCode};1m${name} \u001B[0m`;
|
|
174
|
+
|
|
175
|
+
args[0] = prefix + args[0].split('\n').join('\n' + prefix);
|
|
176
|
+
args.push(colorCode + 'm+' + module.exports.humanize(this.diff) + '\u001B[0m');
|
|
177
|
+
} else {
|
|
178
|
+
args[0] = getDate() + name + ' ' + args[0];
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function getDate() {
|
|
183
|
+
if (exports.inspectOpts.hideDate) {
|
|
184
|
+
return '';
|
|
185
|
+
}
|
|
186
|
+
return new Date().toISOString() + ' ';
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Invokes `util.formatWithOptions()` with the specified arguments and writes to stderr.
|
|
191
|
+
*/
|
|
192
|
+
|
|
193
|
+
function log(...args) {
|
|
194
|
+
return process.stderr.write(util.formatWithOptions(exports.inspectOpts, ...args) + '\n');
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Save `namespaces`.
|
|
199
|
+
*
|
|
200
|
+
* @param {String} namespaces
|
|
201
|
+
* @api private
|
|
202
|
+
*/
|
|
203
|
+
function save(namespaces) {
|
|
204
|
+
if (namespaces) {
|
|
205
|
+
process.env.DEBUG = namespaces;
|
|
206
|
+
} else {
|
|
207
|
+
// If you set a process.env field to null or undefined, it gets cast to the
|
|
208
|
+
// string 'null' or 'undefined'. Just delete instead.
|
|
209
|
+
delete process.env.DEBUG;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Load `namespaces`.
|
|
215
|
+
*
|
|
216
|
+
* @return {String} returns the previously persisted debug modes
|
|
217
|
+
* @api private
|
|
218
|
+
*/
|
|
219
|
+
|
|
220
|
+
function load() {
|
|
221
|
+
return process.env.DEBUG;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Init logic for `debug` instances.
|
|
226
|
+
*
|
|
227
|
+
* Create a new `inspectOpts` object in case `useColors` is set
|
|
228
|
+
* differently for a particular `debug` instance.
|
|
229
|
+
*/
|
|
230
|
+
|
|
231
|
+
function init(debug) {
|
|
232
|
+
debug.inspectOpts = {};
|
|
233
|
+
|
|
234
|
+
const keys = Object.keys(exports.inspectOpts);
|
|
235
|
+
for (let i = 0; i < keys.length; i++) {
|
|
236
|
+
debug.inspectOpts[keys[i]] = exports.inspectOpts[keys[i]];
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
module.exports = require('./common')(exports);
|
|
241
|
+
|
|
242
|
+
const {formatters} = module.exports;
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Map %o to `util.inspect()`, all on a single line.
|
|
246
|
+
*/
|
|
247
|
+
|
|
248
|
+
formatters.o = function (v) {
|
|
249
|
+
this.inspectOpts.colors = this.useColors;
|
|
250
|
+
return util.inspect(v, this.inspectOpts)
|
|
251
|
+
.split('\n')
|
|
252
|
+
.map(str => str.trim())
|
|
253
|
+
.join(' ');
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Map %O to `util.inspect()`, allowing multiple lines if needed.
|
|
258
|
+
*/
|
|
259
|
+
|
|
260
|
+
formatters.O = function (v) {
|
|
261
|
+
this.inspectOpts.colors = this.useColors;
|
|
262
|
+
return util.inspect(v, this.inspectOpts);
|
|
263
|
+
};
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Typings for primary entry point, Node.js specific typings can be found in index.d.ts
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type {ReadableStream as WebReadableStream} from 'node:stream/web';
|
|
6
|
+
import type {ITokenizer, AnyWebByteStream} from 'strtok3';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
Either the Node.js ReadableStream or the `lib.dom.d.ts` ReadableStream.
|
|
10
|
+
Related issue: https://github.com/DefinitelyTyped/DefinitelyTyped/pull/60377
|
|
11
|
+
*/
|
|
12
|
+
export type AnyWebReadableStream<G> = WebReadableStream<G> | ReadableStream<G>;
|
|
13
|
+
|
|
14
|
+
export type FileTypeResult = {
|
|
15
|
+
/**
|
|
16
|
+
One of the supported [file types](https://github.com/sindresorhus/file-type#supported-file-types).
|
|
17
|
+
*/
|
|
18
|
+
readonly ext: string;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
The detected [MIME type](https://en.wikipedia.org/wiki/Internet_media_type).
|
|
22
|
+
*/
|
|
23
|
+
readonly mime: string;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
Detect the file type of a `Uint8Array` or `ArrayBuffer`.
|
|
28
|
+
|
|
29
|
+
The file type is detected by checking the [magic number](https://en.wikipedia.org/wiki/Magic_number_(programming)#Magic_numbers_in_files) of the buffer.
|
|
30
|
+
|
|
31
|
+
If file access is available, it is recommended to use `.fromFile()` instead.
|
|
32
|
+
|
|
33
|
+
@param buffer - An Uint8Array or ArrayBuffer representing file data. It works best if the buffer contains the entire file. It may work with a smaller portion as well.
|
|
34
|
+
@param options - Options to override default behavior.
|
|
35
|
+
@returns The detected file type, or `undefined` when there is no match.
|
|
36
|
+
*/
|
|
37
|
+
export function fileTypeFromBuffer(buffer: Uint8Array | ArrayBuffer, options?: FileTypeOptions): Promise<FileTypeResult | undefined>;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
Detect the file type of a [web `ReadableStream`](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream).
|
|
41
|
+
|
|
42
|
+
The file type is detected by checking the [magic number](https://en.wikipedia.org/wiki/Magic_number_(programming)#Magic_numbers_in_files) of the buffer.
|
|
43
|
+
|
|
44
|
+
@param stream - A [web `ReadableStream`](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream) streaming a file to examine.
|
|
45
|
+
@param options - Options to override default behavior.
|
|
46
|
+
@returns A `Promise` for an object with the detected file type, or `undefined` when there is no match.
|
|
47
|
+
*/
|
|
48
|
+
export function fileTypeFromStream(stream: AnyWebByteStream, options?: FileTypeOptions): Promise<FileTypeResult | undefined>;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
Detect the file type from an [`ITokenizer`](https://github.com/Borewit/strtok3#tokenizer) source.
|
|
52
|
+
|
|
53
|
+
This method is used internally, but can also be used for a special "tokenizer" reader.
|
|
54
|
+
|
|
55
|
+
A tokenizer propagates the internal read functions, allowing alternative transport mechanisms, to access files, to be implemented and used.
|
|
56
|
+
|
|
57
|
+
@param tokenizer - File source implementing the tokenizer interface.
|
|
58
|
+
@param options - Options to override default behavior.
|
|
59
|
+
@returns The detected file type, or `undefined` when there is no match.
|
|
60
|
+
|
|
61
|
+
An example is [`@tokenizer/http`](https://github.com/Borewit/tokenizer-http), which requests data using [HTTP-range-requests](https://developer.mozilla.org/en-US/docs/Web/HTTP/Range_requests). A difference with a conventional stream and the [*tokenizer*](https://github.com/Borewit/strtok3#tokenizer), is that it is able to *ignore* (seek, fast-forward) in the stream. For example, you may only need and read the first 6 bytes, and the last 128 bytes, which may be an advantage in case reading the entire file would take longer.
|
|
62
|
+
|
|
63
|
+
@example
|
|
64
|
+
```
|
|
65
|
+
import {makeTokenizer} from '@tokenizer/http';
|
|
66
|
+
import {fileTypeFromTokenizer} from 'file-type';
|
|
67
|
+
|
|
68
|
+
const audioTrackUrl = 'https://test-audio.netlify.com/Various%20Artists%20-%202009%20-%20netBloc%20Vol%2024_%20tiuqottigeloot%20%5BMP3-V2%5D/01%20-%20Diablo%20Swing%20Orchestra%20-%20Heroines.mp3';
|
|
69
|
+
|
|
70
|
+
const httpTokenizer = await makeTokenizer(audioTrackUrl);
|
|
71
|
+
const fileType = await fileTypeFromTokenizer(httpTokenizer);
|
|
72
|
+
|
|
73
|
+
console.log(fileType);
|
|
74
|
+
//=> {ext: 'mp3', mime: 'audio/mpeg'}
|
|
75
|
+
```
|
|
76
|
+
*/
|
|
77
|
+
export function fileTypeFromTokenizer(tokenizer: ITokenizer, options?: FileTypeOptions): Promise<FileTypeResult | undefined>;
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
Supported file extensions.
|
|
81
|
+
*/
|
|
82
|
+
export const supportedExtensions: ReadonlySet<string>;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
Supported MIME types.
|
|
86
|
+
*/
|
|
87
|
+
export const supportedMimeTypes: ReadonlySet<string>;
|
|
88
|
+
|
|
89
|
+
export type StreamOptions = {
|
|
90
|
+
/**
|
|
91
|
+
The default sample size in bytes.
|
|
92
|
+
|
|
93
|
+
@default 4100
|
|
94
|
+
*/
|
|
95
|
+
readonly sampleSize?: number;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
Detect the file type of a [`Blob`](https://nodejs.org/api/buffer.html#class-blob) or [`File`](https://developer.mozilla.org/en-US/docs/Web/API/File).
|
|
100
|
+
|
|
101
|
+
@param blob - The [`Blob`](https://nodejs.org/api/buffer.html#class-blob) used for file detection.
|
|
102
|
+
@param options - Options to override default behavior.
|
|
103
|
+
@returns The detected file type, or `undefined` when there is no match.
|
|
104
|
+
|
|
105
|
+
@example
|
|
106
|
+
```
|
|
107
|
+
import {fileTypeFromBlob} from 'file-type';
|
|
108
|
+
|
|
109
|
+
const blob = new Blob(['<?xml version="1.0" encoding="ISO-8859-1" ?>'], {
|
|
110
|
+
type: 'text/plain',
|
|
111
|
+
endings: 'native'
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
console.log(await fileTypeFromBlob(blob));
|
|
115
|
+
//=> {ext: 'txt', mime: 'text/plain'}
|
|
116
|
+
```
|
|
117
|
+
*/
|
|
118
|
+
export declare function fileTypeFromBlob(blob: Blob, options?: FileTypeOptions): Promise<FileTypeResult | undefined>;
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
A custom file type detector.
|
|
122
|
+
|
|
123
|
+
Custom file type detectors are plugins designed to extend the default detection capabilities.
|
|
124
|
+
They allow support for uncommon file types, non-binary formats, or customized detection behavior.
|
|
125
|
+
|
|
126
|
+
Detectors can be added via the constructor options or by modifying `FileTypeParser#detectors` directly.
|
|
127
|
+
Detectors provided through the constructor are executed before the default ones.
|
|
128
|
+
|
|
129
|
+
Detectors can be added via the constructor options or by directly modifying `FileTypeParser#detectors`.
|
|
130
|
+
|
|
131
|
+
### Example adding a detector
|
|
132
|
+
|
|
133
|
+
```js
|
|
134
|
+
import {FileTypeParser} from 'file-type';
|
|
135
|
+
import {detectXml} from '@file-type/xml';
|
|
136
|
+
|
|
137
|
+
const parser = new FileTypeParser({customDetectors: [detectXml]});
|
|
138
|
+
const fileType = await parser.fromFile('sample.kml');
|
|
139
|
+
console.log(fileType);
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### Available-third party file-type detectors
|
|
143
|
+
|
|
144
|
+
- [@file-type/xml](https://github.com/Borewit/file-type-xml): Detects common XML file types, such as GLM, KML, MusicXML, RSS, SVG, and XHTML
|
|
145
|
+
|
|
146
|
+
### Detector execution flow
|
|
147
|
+
|
|
148
|
+
If a detector returns `undefined`, the following rules apply:
|
|
149
|
+
|
|
150
|
+
1. **No Tokenizer Interaction**: If the detector does not modify the tokenizer's position, the next detector in the sequence is executed.
|
|
151
|
+
2. **Tokenizer Interaction**: If the detector modifies the tokenizer's position (`tokenizer.position` is advanced), no further detectors are executed. In this case, the file type remains `undefined`, as subsequent detectors cannot evaluate the content. This is an exceptional scenario, as it prevents any other detectors from determining the file type.
|
|
152
|
+
|
|
153
|
+
### Example writing a custom detector
|
|
154
|
+
|
|
155
|
+
Below is an example of a custom detector array. This can be passed to the `FileTypeParser` via the `fileTypeOptions` argument.
|
|
156
|
+
|
|
157
|
+
```
|
|
158
|
+
import {FileTypeParser} from 'file-type';
|
|
159
|
+
|
|
160
|
+
const customDetectors = [
|
|
161
|
+
async tokenizer => {
|
|
162
|
+
const unicornHeader = [85, 78, 73, 67, 79, 82, 78]; // "UNICORN" in ASCII decimal
|
|
163
|
+
|
|
164
|
+
const buffer = new Uint8Array(unicornHeader.length);
|
|
165
|
+
await tokenizer.peekBuffer(buffer, {length: unicornHeader.length, mayBeLess: true});
|
|
166
|
+
if (unicornHeader.every((value, index) => value === buffer[index])) {
|
|
167
|
+
return {ext: 'unicorn', mime: 'application/unicorn'};
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
return undefined;
|
|
171
|
+
},
|
|
172
|
+
];
|
|
173
|
+
|
|
174
|
+
const buffer = new Uint8Array([85, 78, 73, 67, 79, 82, 78]);
|
|
175
|
+
const parser = new FileTypeParser({customDetectors});
|
|
176
|
+
const fileType = await parser.fromBuffer(buffer);
|
|
177
|
+
console.log(fileType); // {ext: 'unicorn', mime: 'application/unicorn'}
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
@param tokenizer - The [tokenizer](https://github.com/Borewit/strtok3#tokenizer) used to read file content.
|
|
181
|
+
@param fileType - The file type detected by standard or previous custom detectors, or `undefined` if no match is found.
|
|
182
|
+
@returns The detected file type, or `undefined` if no match is found.
|
|
183
|
+
*/
|
|
184
|
+
export type Detector = {
|
|
185
|
+
id: string;
|
|
186
|
+
detect: (tokenizer: ITokenizer, fileType?: FileTypeResult) => Promise<FileTypeResult | undefined>;
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
export type FileTypeOptions = {
|
|
190
|
+
customDetectors?: Iterable<Detector>;
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
Specifies the byte tolerance for locating the first MPEG audio frame (e.g. `.mp1`, `.mp2`, `.mp3`, `.aac`).
|
|
194
|
+
|
|
195
|
+
Allows detection to handle slight sync offsets between the expected and actual frame start. Common in malformed or incorrectly muxed files, which, while technically invalid, do occur in the wild.
|
|
196
|
+
|
|
197
|
+
A tolerance of 10 bytes covers most cases.
|
|
198
|
+
|
|
199
|
+
@default 0
|
|
200
|
+
*/
|
|
201
|
+
mpegOffsetTolerance?: number;
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
export declare class TokenizerPositionError extends Error {
|
|
205
|
+
constructor(message?: string);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export type AnyWebReadableByteStreamWithFileType = AnyWebReadableStream<Uint8Array> & {
|
|
209
|
+
readonly fileType?: FileTypeResult;
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
Workaround for using `bundler` as the module-resolution in TypeScript.
|
|
214
|
+
*/
|
|
215
|
+
export function fileTypeFromFile(filePath: string, options?: {customDetectors?: Iterable<Detector>}): Promise<FileTypeResult | undefined>;
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
Returns a `Promise` which resolves to the original readable stream argument, but with an added `fileType` property, which is an object like the one returned from `fileTypeFromFile()`.
|
|
219
|
+
|
|
220
|
+
This method can be handy to put in a stream pipeline, but it comes with a price. Internally `stream()` builds up a buffer of `sampleSize` bytes, used as a sample, to determine the file type. The sample size impacts the file detection resolution. A smaller sample size will result in lower probability of the best file type detection.
|
|
221
|
+
*/
|
|
222
|
+
export function fileTypeStream(webStream: AnyWebReadableStream<Uint8Array>, options?: StreamOptions): Promise<AnyWebReadableByteStreamWithFileType>;
|
|
223
|
+
|
|
224
|
+
export declare class FileTypeParser {
|
|
225
|
+
/**
|
|
226
|
+
File type detectors.
|
|
227
|
+
|
|
228
|
+
Initialized with a single entry holding the built-in detector function.
|
|
229
|
+
*/
|
|
230
|
+
detectors: Detector[];
|
|
231
|
+
|
|
232
|
+
constructor(options?: {customDetectors?: Iterable<Detector>; signal?: AbortSignal});
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
Works the same way as {@link fileTypeFromBuffer}, additionally taking into account custom detectors (if any were provided to the constructor).
|
|
236
|
+
*/
|
|
237
|
+
fromBuffer(buffer: Uint8Array | ArrayBuffer): Promise<FileTypeResult | undefined>;
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
Works the same way as {@link fileTypeFromTokenizer}, additionally taking into account custom detectors (if any were provided to the constructor).
|
|
241
|
+
*/
|
|
242
|
+
fromTokenizer(tokenizer: ITokenizer): Promise<FileTypeResult | undefined>;
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
Works the same way as {@link fileTypeFromBlob}, additionally taking into account custom detectors (if any were provided to the constructor).
|
|
246
|
+
*/
|
|
247
|
+
fromBlob(blob: Blob): Promise<FileTypeResult | undefined>;
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
Works the same way as {@link fileTypeStream}, additionally taking into account custom detectors (if any were provided to the constructor).
|
|
251
|
+
*/
|
|
252
|
+
toDetectionStream(webStream: AnyWebReadableStream<Uint8Array>, options?: StreamOptions): Promise<AnyWebReadableByteStreamWithFileType>;
|
|
253
|
+
}
|