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.
Files changed (134) hide show
  1. dist/default_config.json +68 -0
  2. dist/llonebot.js +48348 -0
  3. dist/llonebot.js.map +1 -0
  4. dist/node_modules/@borewit/text-codec/LICENSE.txt +9 -0
  5. dist/node_modules/@borewit/text-codec/README.md +76 -0
  6. dist/node_modules/@borewit/text-codec/lib/index.d.ts +8 -0
  7. dist/node_modules/@borewit/text-codec/lib/index.js +161 -0
  8. dist/node_modules/@borewit/text-codec/package.json +68 -0
  9. dist/node_modules/@minatojs/sql.js/LICENSE +44 -0
  10. dist/node_modules/@minatojs/sql.js/README.md +357 -0
  11. dist/node_modules/@minatojs/sql.js/dist/sql-wasm.d.ts +316 -0
  12. dist/node_modules/@minatojs/sql.js/dist/sql-wasm.js +225 -0
  13. dist/node_modules/@minatojs/sql.js/dist/sql-wasm.wasm +0 -0
  14. dist/node_modules/@minatojs/sql.js/package.json +58 -0
  15. dist/node_modules/@tokenizer/inflate/LICENSE +15 -0
  16. dist/node_modules/@tokenizer/inflate/README.md +114 -0
  17. dist/node_modules/@tokenizer/inflate/lib/GzipHandler.d.ts +6 -0
  18. dist/node_modules/@tokenizer/inflate/lib/GzipHandler.js +19 -0
  19. dist/node_modules/@tokenizer/inflate/lib/ZipHandler.d.ts +26 -0
  20. dist/node_modules/@tokenizer/inflate/lib/ZipHandler.js +233 -0
  21. dist/node_modules/@tokenizer/inflate/lib/ZipToken.d.ts +94 -0
  22. dist/node_modules/@tokenizer/inflate/lib/ZipToken.js +117 -0
  23. dist/node_modules/@tokenizer/inflate/lib/index.d.ts +3 -0
  24. dist/node_modules/@tokenizer/inflate/lib/index.js +2 -0
  25. dist/node_modules/@tokenizer/inflate/package.json +76 -0
  26. dist/node_modules/@tokenizer/token/README.md +19 -0
  27. dist/node_modules/@tokenizer/token/index.d.ts +30 -0
  28. dist/node_modules/@tokenizer/token/package.json +33 -0
  29. dist/node_modules/debug/LICENSE +20 -0
  30. dist/node_modules/debug/README.md +481 -0
  31. dist/node_modules/debug/package.json +64 -0
  32. dist/node_modules/debug/src/browser.js +272 -0
  33. dist/node_modules/debug/src/common.js +292 -0
  34. dist/node_modules/debug/src/index.js +10 -0
  35. dist/node_modules/debug/src/node.js +263 -0
  36. dist/node_modules/file-type/core.d.ts +253 -0
  37. dist/node_modules/file-type/core.js +1899 -0
  38. dist/node_modules/file-type/index.d.ts +98 -0
  39. dist/node_modules/file-type/index.js +86 -0
  40. dist/node_modules/file-type/license +9 -0
  41. dist/node_modules/file-type/package.json +288 -0
  42. dist/node_modules/file-type/readme.md +674 -0
  43. dist/node_modules/file-type/supported.js +356 -0
  44. dist/node_modules/file-type/util.js +60 -0
  45. dist/node_modules/ieee754/LICENSE +11 -0
  46. dist/node_modules/ieee754/README.md +51 -0
  47. dist/node_modules/ieee754/index.d.ts +10 -0
  48. dist/node_modules/ieee754/index.js +85 -0
  49. dist/node_modules/ieee754/package.json +52 -0
  50. dist/node_modules/ms/index.js +162 -0
  51. dist/node_modules/ms/license.md +21 -0
  52. dist/node_modules/ms/package.json +38 -0
  53. dist/node_modules/ms/readme.md +59 -0
  54. dist/node_modules/silk-wasm/LICENSE +21 -0
  55. dist/node_modules/silk-wasm/README.md +85 -0
  56. dist/node_modules/silk-wasm/lib/index.cjs +16 -0
  57. dist/node_modules/silk-wasm/lib/index.d.ts +70 -0
  58. dist/node_modules/silk-wasm/lib/index.mjs +16 -0
  59. dist/node_modules/silk-wasm/lib/silk.wasm +0 -0
  60. dist/node_modules/silk-wasm/lib/utils.d.ts +4 -0
  61. dist/node_modules/silk-wasm/package.json +39 -0
  62. dist/node_modules/strtok3/LICENSE.txt +21 -0
  63. dist/node_modules/strtok3/README.md +399 -0
  64. dist/node_modules/strtok3/lib/AbstractTokenizer.d.ts +76 -0
  65. dist/node_modules/strtok3/lib/AbstractTokenizer.js +108 -0
  66. dist/node_modules/strtok3/lib/BlobTokenizer.d.ts +29 -0
  67. dist/node_modules/strtok3/lib/BlobTokenizer.js +53 -0
  68. dist/node_modules/strtok3/lib/BufferTokenizer.d.ts +29 -0
  69. dist/node_modules/strtok3/lib/BufferTokenizer.js +52 -0
  70. dist/node_modules/strtok3/lib/FileTokenizer.d.ts +37 -0
  71. dist/node_modules/strtok3/lib/FileTokenizer.js +61 -0
  72. dist/node_modules/strtok3/lib/ReadStreamTokenizer.d.ts +31 -0
  73. dist/node_modules/strtok3/lib/ReadStreamTokenizer.js +102 -0
  74. dist/node_modules/strtok3/lib/core.d.ts +40 -0
  75. dist/node_modules/strtok3/lib/core.js +62 -0
  76. dist/node_modules/strtok3/lib/index.d.ts +16 -0
  77. dist/node_modules/strtok3/lib/index.js +22 -0
  78. dist/node_modules/strtok3/lib/stream/AbstractStreamReader.d.ts +54 -0
  79. dist/node_modules/strtok3/lib/stream/AbstractStreamReader.js +71 -0
  80. dist/node_modules/strtok3/lib/stream/Deferred.d.ts +6 -0
  81. dist/node_modules/strtok3/lib/stream/Deferred.js +10 -0
  82. dist/node_modules/strtok3/lib/stream/Errors.d.ts +10 -0
  83. dist/node_modules/strtok3/lib/stream/Errors.js +16 -0
  84. dist/node_modules/strtok3/lib/stream/StreamReader.d.ts +29 -0
  85. dist/node_modules/strtok3/lib/stream/StreamReader.js +83 -0
  86. dist/node_modules/strtok3/lib/stream/WebStreamByobReader.d.ts +14 -0
  87. dist/node_modules/strtok3/lib/stream/WebStreamByobReader.js +27 -0
  88. dist/node_modules/strtok3/lib/stream/WebStreamDefaultReader.d.ts +19 -0
  89. dist/node_modules/strtok3/lib/stream/WebStreamDefaultReader.js +62 -0
  90. dist/node_modules/strtok3/lib/stream/WebStreamReader.d.ts +14 -0
  91. dist/node_modules/strtok3/lib/stream/WebStreamReader.js +13 -0
  92. dist/node_modules/strtok3/lib/stream/WebStreamReaderFactory.d.ts +5 -0
  93. dist/node_modules/strtok3/lib/stream/WebStreamReaderFactory.js +19 -0
  94. dist/node_modules/strtok3/lib/stream/index.d.ts +6 -0
  95. dist/node_modules/strtok3/lib/stream/index.js +5 -0
  96. dist/node_modules/strtok3/lib/types.d.ts +139 -0
  97. dist/node_modules/strtok3/lib/types.js +1 -0
  98. dist/node_modules/strtok3/package.json +94 -0
  99. dist/node_modules/token-types/LICENSE.txt +9 -0
  100. dist/node_modules/token-types/README.md +120 -0
  101. dist/node_modules/token-types/lib/index.d.ts +135 -0
  102. dist/node_modules/token-types/lib/index.js +401 -0
  103. dist/node_modules/token-types/package.json +81 -0
  104. dist/node_modules/uint8array-extras/index.d.ts +312 -0
  105. dist/node_modules/uint8array-extras/index.js +321 -0
  106. dist/node_modules/uint8array-extras/license +9 -0
  107. dist/node_modules/uint8array-extras/package.json +54 -0
  108. dist/node_modules/uint8array-extras/readme.md +301 -0
  109. dist/node_modules/ws/LICENSE +20 -0
  110. dist/node_modules/ws/README.md +548 -0
  111. dist/node_modules/ws/browser.js +8 -0
  112. dist/node_modules/ws/index.js +13 -0
  113. dist/node_modules/ws/lib/buffer-util.js +131 -0
  114. dist/node_modules/ws/lib/constants.js +18 -0
  115. dist/node_modules/ws/lib/event-target.js +292 -0
  116. dist/node_modules/ws/lib/extension.js +203 -0
  117. dist/node_modules/ws/lib/limiter.js +55 -0
  118. dist/node_modules/ws/lib/permessage-deflate.js +528 -0
  119. dist/node_modules/ws/lib/receiver.js +706 -0
  120. dist/node_modules/ws/lib/sender.js +602 -0
  121. dist/node_modules/ws/lib/stream.js +161 -0
  122. dist/node_modules/ws/lib/subprotocol.js +62 -0
  123. dist/node_modules/ws/lib/validation.js +152 -0
  124. dist/node_modules/ws/lib/websocket-server.js +550 -0
  125. dist/node_modules/ws/lib/websocket.js +1388 -0
  126. dist/node_modules/ws/package.json +69 -0
  127. dist/node_modules/ws/wrapper.mjs +8 -0
  128. dist/package.json +1 -0
  129. dist/webui/assets/index-B9vGhdCO.js +256 -0
  130. dist/webui/assets/index-DaqFU7JR.css +1 -0
  131. dist/webui/index.html +13 -0
  132. dist/webui/logo.jpg +0 -0
  133. dist//344/275/277/347/224/250/350/257/264/346/230/216.txt +11 -0
  134. dist//346/233/264/346/226/260/346/227/245/345/277/227.txt +399 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright © 2025 Borewit
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,399 @@
1
+ [![Node.js CI](https://github.com/Borewit/strtok3/actions/workflows/ci.yml/badge.svg)](https://github.com/Borewit/strtok3/actions/workflows/ci.yml)
2
+ [![CodeQL](https://github.com/Borewit/strtok3/actions/workflows/codeql.yml/badge.svg?branch=master)](https://github.com/Borewit/strtok3/actions/workflows/codeql.yml)
3
+ [![NPM version](https://badge.fury.io/js/strtok3.svg)](https://npmjs.org/package/strtok3)
4
+ [![npm downloads](http://img.shields.io/npm/dm/strtok3.svg)](https://npmcharts.com/compare/strtok3,token-types?start=1200&interval=30)
5
+ [![DeepScan grade](https://deepscan.io/api/teams/5165/projects/8526/branches/103329/badge/grade.svg)](https://deepscan.io/dashboard#view=project&tid=5165&pid=8526&bid=103329)
6
+ [![Known Vulnerabilities](https://snyk.io/test/github/Borewit/strtok3/badge.svg?targetFile=package.json)](https://snyk.io/test/github/Borewit/strtok3?targetFile=package.json)
7
+ [![Codacy Badge](https://api.codacy.com/project/badge/Grade/59dd6795e61949fb97066ca52e6097ef)](https://www.codacy.com/app/Borewit/strtok3?utm_source=github.com&utm_medium=referral&utm_content=Borewit/strtok3&utm_campaign=Badge_Grade)
8
+ # strtok3
9
+
10
+ A promise based streaming [*tokenizer*](#tokenizer-object) for [Node.js](http://nodejs.org) and browsers.
11
+
12
+ The `strtok3` module provides several methods for creating a [*tokenizer*](#tokenizer-object) from various input sources.
13
+ Designed for:
14
+ * Seamless support in streaming environments.
15
+ * Efficiently decode binary data, strings, and numbers.
16
+ * Reading [predefined](https://github.com/Borewit/token-types) or custom tokens.
17
+ * Offering [*tokenizers*](#tokenizer-object) for reading from [files](#method-strtok3fromfile), [streams](#fromstream-function) or [Uint8Arrays](#frombuffer-function).
18
+
19
+ ### Features
20
+ `strtok3` can read from:
21
+ * Files, using a file path as input.
22
+ * Node.js [streams](https://nodejs.org/api/stream.html).
23
+ * [Buffer](https://nodejs.org/api/buffer.html) or [Uint8Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array).
24
+ * HTTP chunked transfer provided by [@tokenizer/http](https://github.com/Borewit/tokenizer-http).
25
+ * [Amazon S3](https://aws.amazon.com/s3) chunks with [@tokenizer/s3](https://github.com/Borewit/tokenizer-s3).
26
+
27
+ ## Installation
28
+
29
+ ```sh
30
+ npm install strtok3
31
+ ```
32
+
33
+ ### Compatibility
34
+
35
+ Starting with version 7, the module has migrated from [CommonJS](https://en.wikipedia.org/wiki/CommonJS) to [pure ECMAScript Module (ESM)](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c).
36
+ The distributed JavaScript codebase is compliant with the [ECMAScript 2020 (11th Edition)](https://en.wikipedia.org/wiki/ECMAScript_version_history#11th_Edition_%E2%80%93_ECMAScript_2020) standard.
37
+
38
+ Requires a modern browser, Node.js (V8) ≥ 18 engine or Bun (JavaScriptCore) ≥ 1.2.
39
+
40
+ For TypeScript CommonJs backward compatibility, you can use [load-esm](https://github.com/Borewit/load-esm).
41
+
42
+ > [!NOTE]
43
+ > This module requires a [Node.js ≥ 16](https://nodejs.org/en/about/previous-releases) engine.
44
+ > It can also be used in a browser environment when bundled with a module bundler.
45
+
46
+ ## Support the Project
47
+ If you find this project useful and would like to support its development, consider sponsoring or contributing:
48
+
49
+ - [Become a sponsor to Borewit](https://github.com/sponsors/Borewit)
50
+
51
+ - Buy me a coffee:
52
+
53
+ <a href="https://www.buymeacoffee.com/borewit" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/default-orange.png" alt="Buy me A coffee" height="41" width="174"></a>
54
+
55
+ ## API Documentation
56
+
57
+ ### strtok3 methods
58
+
59
+ Use one of the methods to instantiate an [*abstract tokenizer*](#tokenizer-object):
60
+ - [fromBlob](#fromblob-function)
61
+ - [fromBuffer](#frombuffer-function)
62
+ - [fromFile](#fromfile-function)*
63
+ - [fromStream](#fromstream-function)*
64
+ - [fromWebStream](#fromwebstream-function)
65
+
66
+ > [!NOTE]
67
+ > `fromFile` and `fromStream` only available when importing this module with Node.js
68
+
69
+ All methods return a [`Tokenizer`](#tokenizer-object), either directly or via a promise.
70
+
71
+ #### `fromBlob()` function
72
+
73
+ Create a tokenizer from a [Blob](https://developer.mozilla.org/en-US/docs/Web/API/Blob).
74
+
75
+ ```ts
76
+ function fromBlob(blob: Blob, options?: ITokenizerOptions): BlobTokenizer
77
+ ```
78
+
79
+ | Parameter | Optional | Type | Description |
80
+ |-----------|-----------|---------------------------------------------------|----------------------------------------------------------------------------------------|
81
+ | blob | no | [Blob](https://developer.mozilla.org/en-US/docs/Web/API/Blob) | [Blob](https://developer.mozilla.org/en-US/docs/Web/API/Blob) or [File](https://developer.mozilla.org/en-US/docs/Web/API/File) to read from |
82
+ | options | yes | [ITokenizerOptions](#ITokenizerOptions) | Tokenizer options |
83
+
84
+ Returns a [*tokenizer*](#tokenizer-object).
85
+
86
+ ```js
87
+ import { fromBlob } from 'strtok3';
88
+ import { openAsBlob } from 'node:fs';
89
+ import * as Token from 'token-types';
90
+
91
+ async function parse() {
92
+ const blob = await openAsBlob('somefile.bin');
93
+
94
+ const tokenizer = fromBlob(blob);
95
+
96
+ const myUint8Number = await tokenizer.readToken(Token.UINT8);
97
+ console.log(`My number: ${myUint8Number}`);
98
+ }
99
+
100
+ parse();
101
+
102
+ ```
103
+
104
+ #### `fromBuffer()` function
105
+
106
+ Create a tokenizer from memory ([Uint8Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array) or Node.js [Buffer](https://nodejs.org/api/buffer.html)).
107
+
108
+ ```ts
109
+ function fromBuffer(uint8Array: Uint8Array, options?: ITokenizerOptions): BufferTokenizer
110
+ ```
111
+
112
+ | Parameter | Optional | Type | Description |
113
+ |------------|----------|--------------------------------------------------|-----------------------------------|
114
+ | uint8Array | no | [Uint8Array](https://nodejs.org/api/buffer.html) | Buffer or Uint8Array to read from |
115
+ | options | yes | [ITokenizerOptions](#ITokenizerOptions) | Tokenizer options |
116
+
117
+ Returns a [*tokenizer*](#tokenizer-object).
118
+
119
+ ```js
120
+ import { fromBuffer } from 'strtok3';
121
+ import * as Token from 'token-types';
122
+
123
+ const tokenizer = fromBuffer(buffer);
124
+
125
+ async function parse() {
126
+ const myUint8Number = await tokenizer.readToken(Token.UINT8);
127
+ console.log(`My number: ${myUint8Number}`);
128
+ }
129
+
130
+ parse();
131
+ ```
132
+
133
+ #### `fromFile` function
134
+
135
+ Creates a [*tokenizer*](#tokenizer-object) from a local file.
136
+
137
+ ```ts
138
+ function fromFile(sourceFilePath: string): Promise<FileTokenizer>
139
+ ```
140
+
141
+ | Parameter | Type | Description |
142
+ |----------------|----------|----------------------------|
143
+ | sourceFilePath | `string` | Path to file to read from |
144
+
145
+ > [!NOTE]
146
+ > - Only available for Node.js engines
147
+ > - `fromFile` automatically embeds [file-information](#file-information)
148
+
149
+ A Promise resolving to a [*tokenizer*](#tokenizer-object) which can be used to parse a file.
150
+
151
+ ```js
152
+ import { fromFile } from 'strtok3';
153
+ import * as Token from 'token-types';
154
+
155
+ async function parse() {
156
+ const tokenizer = await fromFile('somefile.bin');
157
+ try {
158
+ const myNumber = await tokenizer.readToken(Token.UINT8);
159
+ console.log(`My number: ${myNumber}`);
160
+ } finally {
161
+ tokenizer.close(); // Close the file
162
+ }
163
+ }
164
+
165
+ parse();
166
+
167
+
168
+ ```
169
+
170
+ #### `fromWebStream()` function
171
+
172
+ Create a tokenizer from a [WHATWG ReadableStream](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream).
173
+
174
+ ```ts
175
+ function fromWebStream(webStream: AnyWebByteStream, options?: ITokenizerOptions): ReadStreamTokenizer
176
+ ```
177
+
178
+ | Parameter | Optional | Type | Description |
179
+ |----------------|----------|--------------------------------------------------------------------------|------------------------------------|
180
+ | webStream | no | [ReadableStream](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream) | WHATWG ReadableStream to read from |
181
+ | options | yes | [ITokenizerOptions](#ITokenizerOptions) | Tokenizer options |
182
+
183
+ Returns a [*tokenizer*](#tokenizer-object).
184
+
185
+ ```js
186
+ import { fromWebStream } from 'strtok3';
187
+ import * as Token from 'token-types';
188
+
189
+ async function parse() {
190
+ const tokenizer = fromWebStream(readableStream);
191
+ try {
192
+ const myUint8Number = await tokenizer.readToken(Token.UINT8);
193
+ console.log(`My number: ${myUint8Number}`);
194
+ } finally {
195
+ await tokenizer.close();
196
+ }
197
+ }
198
+
199
+ parse();
200
+ ```
201
+
202
+ ### `Tokenizer` object
203
+ The *tokenizer* is an abstraction of a [stream](https://nodejs.org/api/stream.html), file or [Uint8Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array), allowing _reading_ or _peeking_ from the stream.
204
+ It can also be translated in chunked reads, as done in [@tokenizer/http](https://github.com/Borewit/tokenizer-http);
205
+
206
+ #### Key Features:
207
+
208
+ - Supports seeking within the stream using `tokenizer.ignore()`.
209
+ - Offers `peek` methods to preview data without advancing the read pointer.
210
+ - Maintains the read position via tokenizer.position.
211
+
212
+ #### Tokenizer functions
213
+
214
+ _Read_ methods advance the stream pointer, while _peek_ methods do not.
215
+
216
+ There are two kind of functions:
217
+ 1. *read* methods: used to read a *token* of [Buffer](https://nodejs.org/api/buffer.html) from the [*tokenizer*](#tokenizer-object). The position of the *tokenizer-stream* will advance with the size of the token.
218
+ 2. *peek* methods: same as the read, but it will *not* advance the pointer. It allows to read (peek) ahead.
219
+
220
+ #### `readBuffer` function
221
+
222
+ Read data from the _tokenizer_ into provided "buffer" (`Uint8Array`).
223
+ `readBuffer(buffer, options?)`
224
+
225
+ ```ts
226
+ readBuffer(buffer: Uint8Array, options?: IReadChunkOptions): Promise<number>;
227
+ ```
228
+
229
+ | Parameter | Type | Description |
230
+ |------------|----------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
231
+ | buffer | [Buffer](https://nodejs.org/api/buffer.html) &#124; Uint8Array | Target buffer to write the data read to |
232
+ | options | [IReadChunkOptions](#ireadchunkoptions) | An integer specifying the number of bytes to read |
233
+
234
+ Return promise with number of bytes read.
235
+ The number of bytes read may be less than requested if the `mayBeLess` flag is set.
236
+
237
+ #### `peekBuffer` function
238
+
239
+ Peek (read ahead), from [*tokenizer*](#tokenizer-object), into the buffer without advancing the stream pointer.
240
+
241
+ ```ts
242
+ peekBuffer(uint8Array: Uint8Array, options?: IReadChunkOptions): Promise<number>;
243
+ ```
244
+
245
+ | Parameter | Type | Description |
246
+ |------------|-----------------------------------------|-----------------------------------------------------|
247
+ | buffer | Buffer &#124; Uint8Array | Target buffer to write the data read (peeked) to. |
248
+ | options | [IReadChunkOptions](#ireadchunkoptions) | An integer specifying the number of bytes to read. | |
249
+
250
+ Return value `Promise<number>` Promise with number of bytes read. The number of bytes read may be less if the `mayBeLess` flag was set.
251
+
252
+ #### `readToken` function
253
+
254
+ Read a *token* from the tokenizer-stream.
255
+
256
+ ```ts
257
+ readToken<Value>(token: IGetToken<Value>, position: number = this.position): Promise<Value>
258
+ ```
259
+
260
+ | Parameter | Type | Description |
261
+ |------------|-------------------------|---------------------------------------------------------------------------------------------------------------------- |
262
+ | token | [IGetToken](#IGetToken) | Token to read from the tokenizer-stream. |
263
+ | position? | number | Offset where to begin reading within the file. If position is null, data will be read from the current file position. |
264
+
265
+ Return value `Promise<number>`. Promise with number of bytes read. The number of bytes read maybe if less, `mayBeLess` flag was set.
266
+
267
+ #### `peek` function
268
+
269
+ Peek a *token* from the [*tokenizer*](#tokenizer-object).
270
+
271
+ ```ts
272
+ peekToken<Value>(token: IGetToken<Value>, position: number = this.position): Promise<Value>
273
+ ```
274
+
275
+ | Parameter | Type | Description |
276
+ |------------|----------------------------|-------------------------------------------------------------------------------------------------------------------------|
277
+ | token | [IGetToken<T>](#IGetToken) | Token to read from the tokenizer-stream. |
278
+ | position? | number | Offset where to begin reading within the file. If position is null, data will be read from the current file position. |
279
+
280
+ Return a promise with the token value peeked from the [*tokenizer*](#tokenizer-object).
281
+
282
+ #### `readNumber` function
283
+
284
+ Read a numeric [*token*](#token) from the [*tokenizer*](#tokenizer-object).
285
+
286
+ ```ts
287
+ readNumber(token: IToken<number>): Promise<number>
288
+ ```
289
+
290
+ | Parameter | Type | Description |
291
+ |------------|---------------------------------|----------------------------------------------------|
292
+ | token | [IGetToken<number>](#IGetToken) | Numeric token to read from the tokenizer-stream. |
293
+
294
+ A promise resolving to a numeric value read and decoded from the *tokenizer-stream*.
295
+
296
+ #### `ignore` function
297
+
298
+ Advance the offset pointer with the token number of bytes provided.
299
+
300
+ ```ts
301
+ ignore(length: number): Promise<number>
302
+ ```
303
+
304
+ | Parameter | Type | Description |
305
+ |------------|--------|------------------------------------------------------------------|
306
+ | length | number | Number of bytes to ignore. Will advance the `tokenizer.position` |
307
+
308
+ A promise resolving to the number of bytes ignored from the *tokenizer-stream*.
309
+
310
+ #### `close` function
311
+ Clean up resources, such as closing a file pointer if applicable.
312
+
313
+ #### `Tokenizer` attributes
314
+
315
+ - `fileInfo`
316
+
317
+ Optional attribute describing the file information, see [IFileInfo](#IFileInfo)
318
+
319
+ - `position`
320
+
321
+ Pointer to the current position in the [*tokenizer*](#tokenizer-object) stream.
322
+ If a *position* is provided to a _read_ or _peek_ method, is should be, at least, equal or greater than this value.
323
+
324
+ ### `IReadChunkOptions` interface
325
+
326
+ Each attribute is optional:
327
+
328
+ | Attribute | Type | Description |
329
+ |-----------|---------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
330
+ | length | number | Requested number of bytes to read. |
331
+ | position | number | Position where to peek from the file. If position is null, data will be read from the [current file position](#attribute-tokenizerposition). Position may not be less then [tokenizer.position](#attribute-tokenizerposition) |
332
+ | mayBeLess | boolean | If and only if set, will not throw an EOF error if less than the requested `mayBeLess` could be read. |
333
+
334
+ Example usage:
335
+ ```js
336
+ tokenizer.peekBuffer(buffer, {mayBeLess: true});
337
+ ```
338
+
339
+ ### `IFileInfo` interface
340
+
341
+ Provides optional metadata about the file being tokenized.
342
+
343
+ | Attribute | Type | Description |
344
+ |-----------|---------|---------------------------------------------------------------------------------------------------|
345
+ | size | number | File size in bytes |
346
+ | mimeType | string | [MIME-type](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types) of file. |
347
+ | path | string | File path |
348
+ | url | string | File URL |
349
+
350
+ ### `Token` object
351
+
352
+ The *token* is basically a description of what to read from the [*tokenizer-stream*](#tokenizer-object).
353
+ A basic set of *token types* can be found here: [*token-types*](https://github.com/Borewit/token-types).
354
+
355
+ A token is something which implements the following interface:
356
+ ```ts
357
+ export interface IGetToken<T> {
358
+
359
+ /**
360
+ * Length in bytes of encoded value
361
+ */
362
+ len: number;
363
+
364
+ /**
365
+ * Decode value from buffer at offset
366
+ * @param buf Buffer to read the decoded value from
367
+ * @param off Decode offset
368
+ */
369
+ get(buf: Uint8Array, off: number): T;
370
+ }
371
+ ```
372
+ The *tokenizer* reads `token.len` bytes from the *tokenizer-stream* into a Buffer.
373
+ The `token.get` will be called with the Buffer. `token.get` is responsible for conversion from the buffer to the desired output type.
374
+
375
+ ### Working with Web-API readable stream
376
+ To convert a [Web-API readable stream](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStreamDefaultReader) into a [Node.js readable stream]((https://nodejs.org/api/stream.html#stream_readable_streams)), you can use [readable-web-to-node-stream](https://github.com/Borewit/readable-web-to-node-stream) to convert one in another.
377
+
378
+ ```js
379
+ import { fromWebStream } from 'strtok3';
380
+ import { ReadableWebToNodeStream } from 'readable-web-to-node-stream';
381
+
382
+ (async () => {
383
+
384
+ const response = await fetch(url);
385
+ const readableWebStream = response.body; // Web-API readable stream
386
+ const webStream = new ReadableWebToNodeStream(readableWebStream); // convert to Node.js readable stream
387
+
388
+ const tokenizer = fromWebStream(webStream); // And we now have tokenizer in a web environment
389
+ })();
390
+ ```
391
+
392
+ ## Dependencies
393
+
394
+ Dependencies:
395
+ - [@tokenizer/token](https://github.com/Borewit/tokenizer-token): Provides token definitions and utilities used by `strtok3` for interpreting binary data.
396
+
397
+ ## Licence
398
+
399
+ This project is licensed under the [MIT License](LICENSE.txt). Feel free to use, modify, and distribute as needed.
@@ -0,0 +1,76 @@
1
+ import type { ITokenizer, IFileInfo, IReadChunkOptions, ITokenizerOptions } from './types.js';
2
+ import type { IGetToken, IToken } from '@tokenizer/token';
3
+ interface INormalizedReadChunkOptions extends IReadChunkOptions {
4
+ length: number;
5
+ position: number;
6
+ mayBeLess?: boolean;
7
+ }
8
+ /**
9
+ * Core tokenizer
10
+ */
11
+ export declare abstract class AbstractTokenizer implements ITokenizer {
12
+ private onClose?;
13
+ private numBuffer;
14
+ abstract fileInfo: IFileInfo;
15
+ /**
16
+ * Tokenizer-stream position
17
+ */
18
+ position: number;
19
+ /**
20
+ * Constructor
21
+ * @param options Tokenizer options
22
+ * @protected
23
+ */
24
+ protected constructor(options?: ITokenizerOptions);
25
+ abstract supportsRandomAccess(): boolean;
26
+ /**
27
+ * Read buffer from tokenizer
28
+ * @param buffer - Target buffer to fill with data read from the tokenizer-stream
29
+ * @param options - Additional read options
30
+ * @returns Promise with number of bytes read
31
+ */
32
+ abstract readBuffer(buffer: Uint8Array, options?: IReadChunkOptions): Promise<number>;
33
+ /**
34
+ * Peek (read ahead) buffer from tokenizer
35
+ * @param uint8Array - Target buffer to fill with data peeked from the tokenizer-stream
36
+ * @param options - Peek behaviour options
37
+ * @returns Promise with number of bytes read
38
+ */
39
+ abstract peekBuffer(uint8Array: Uint8Array, options?: IReadChunkOptions): Promise<number>;
40
+ /**
41
+ * Read a token from the tokenizer-stream
42
+ * @param token - The token to read
43
+ * @param position - If provided, the desired position in the tokenizer-stream
44
+ * @returns Promise with token data
45
+ */
46
+ readToken<Value>(token: IGetToken<Value>, position?: number): Promise<Value>;
47
+ /**
48
+ * Peek a token from the tokenizer-stream.
49
+ * @param token - Token to peek from the tokenizer-stream.
50
+ * @param position - Offset where to begin reading within the file. If position is null, data will be read from the current file position.
51
+ * @returns Promise with token data
52
+ */
53
+ peekToken<Value>(token: IGetToken<Value>, position?: number): Promise<Value>;
54
+ /**
55
+ * Read a numeric token from the stream
56
+ * @param token - Numeric token
57
+ * @returns Promise with number
58
+ */
59
+ readNumber(token: IToken<number>): Promise<number>;
60
+ /**
61
+ * Read a numeric token from the stream
62
+ * @param token - Numeric token
63
+ * @returns Promise with number
64
+ */
65
+ peekNumber(token: IToken<number>): Promise<number>;
66
+ /**
67
+ * Ignore number of bytes, advances the pointer in under tokenizer-stream.
68
+ * @param length - Number of bytes to ignore
69
+ * @return resolves the number of bytes ignored, equals length if this available, otherwise the number of bytes available
70
+ */
71
+ ignore(length: number): Promise<number>;
72
+ close(): Promise<void>;
73
+ protected normalizeOptions(uint8Array: Uint8Array, options?: IReadChunkOptions): INormalizedReadChunkOptions;
74
+ abort(): Promise<void>;
75
+ }
76
+ export {};
@@ -0,0 +1,108 @@
1
+ import { EndOfStreamError } from './stream/index.js';
2
+ /**
3
+ * Core tokenizer
4
+ */
5
+ export class AbstractTokenizer {
6
+ /**
7
+ * Constructor
8
+ * @param options Tokenizer options
9
+ * @protected
10
+ */
11
+ constructor(options) {
12
+ this.numBuffer = new Uint8Array(8);
13
+ /**
14
+ * Tokenizer-stream position
15
+ */
16
+ this.position = 0;
17
+ this.onClose = options?.onClose;
18
+ if (options?.abortSignal) {
19
+ options.abortSignal.addEventListener('abort', () => {
20
+ this.abort();
21
+ });
22
+ }
23
+ }
24
+ /**
25
+ * Read a token from the tokenizer-stream
26
+ * @param token - The token to read
27
+ * @param position - If provided, the desired position in the tokenizer-stream
28
+ * @returns Promise with token data
29
+ */
30
+ async readToken(token, position = this.position) {
31
+ const uint8Array = new Uint8Array(token.len);
32
+ const len = await this.readBuffer(uint8Array, { position });
33
+ if (len < token.len)
34
+ throw new EndOfStreamError();
35
+ return token.get(uint8Array, 0);
36
+ }
37
+ /**
38
+ * Peek a token from the tokenizer-stream.
39
+ * @param token - Token to peek from the tokenizer-stream.
40
+ * @param position - Offset where to begin reading within the file. If position is null, data will be read from the current file position.
41
+ * @returns Promise with token data
42
+ */
43
+ async peekToken(token, position = this.position) {
44
+ const uint8Array = new Uint8Array(token.len);
45
+ const len = await this.peekBuffer(uint8Array, { position });
46
+ if (len < token.len)
47
+ throw new EndOfStreamError();
48
+ return token.get(uint8Array, 0);
49
+ }
50
+ /**
51
+ * Read a numeric token from the stream
52
+ * @param token - Numeric token
53
+ * @returns Promise with number
54
+ */
55
+ async readNumber(token) {
56
+ const len = await this.readBuffer(this.numBuffer, { length: token.len });
57
+ if (len < token.len)
58
+ throw new EndOfStreamError();
59
+ return token.get(this.numBuffer, 0);
60
+ }
61
+ /**
62
+ * Read a numeric token from the stream
63
+ * @param token - Numeric token
64
+ * @returns Promise with number
65
+ */
66
+ async peekNumber(token) {
67
+ const len = await this.peekBuffer(this.numBuffer, { length: token.len });
68
+ if (len < token.len)
69
+ throw new EndOfStreamError();
70
+ return token.get(this.numBuffer, 0);
71
+ }
72
+ /**
73
+ * Ignore number of bytes, advances the pointer in under tokenizer-stream.
74
+ * @param length - Number of bytes to ignore
75
+ * @return resolves the number of bytes ignored, equals length if this available, otherwise the number of bytes available
76
+ */
77
+ async ignore(length) {
78
+ if (this.fileInfo.size !== undefined) {
79
+ const bytesLeft = this.fileInfo.size - this.position;
80
+ if (length > bytesLeft) {
81
+ this.position += bytesLeft;
82
+ return bytesLeft;
83
+ }
84
+ }
85
+ this.position += length;
86
+ return length;
87
+ }
88
+ async close() {
89
+ await this.abort();
90
+ await this.onClose?.();
91
+ }
92
+ normalizeOptions(uint8Array, options) {
93
+ if (!this.supportsRandomAccess() && options && options.position !== undefined && options.position < this.position) {
94
+ throw new Error('`options.position` must be equal or greater than `tokenizer.position`');
95
+ }
96
+ return {
97
+ ...{
98
+ mayBeLess: false,
99
+ offset: 0,
100
+ length: uint8Array.length,
101
+ position: this.position
102
+ }, ...options
103
+ };
104
+ }
105
+ abort() {
106
+ return Promise.resolve(); // Ignore abort signal
107
+ }
108
+ }
@@ -0,0 +1,29 @@
1
+ import type { ITokenizerOptions, IReadChunkOptions, IRandomAccessFileInfo, IRandomAccessTokenizer } from './types.js';
2
+ import { AbstractTokenizer } from './AbstractTokenizer.js';
3
+ export declare class BlobTokenizer extends AbstractTokenizer implements IRandomAccessTokenizer {
4
+ private blob;
5
+ fileInfo: IRandomAccessFileInfo;
6
+ /**
7
+ * Construct BufferTokenizer
8
+ * @param blob - Uint8Array to tokenize
9
+ * @param options Tokenizer options
10
+ */
11
+ constructor(blob: Blob, options?: ITokenizerOptions);
12
+ /**
13
+ * Read buffer from tokenizer
14
+ * @param uint8Array - Uint8Array to tokenize
15
+ * @param options - Read behaviour options
16
+ * @returns {Promise<number>}
17
+ */
18
+ readBuffer(uint8Array: Uint8Array, options?: IReadChunkOptions): Promise<number>;
19
+ /**
20
+ * Peek (read ahead) buffer from tokenizer
21
+ * @param buffer
22
+ * @param options - Read behaviour options
23
+ * @returns {Promise<number>}
24
+ */
25
+ peekBuffer(buffer: Uint8Array, options?: IReadChunkOptions): Promise<number>;
26
+ close(): Promise<void>;
27
+ supportsRandomAccess(): boolean;
28
+ setPosition(position: number): void;
29
+ }