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,233 @@
|
|
|
1
|
+
import { StringType, UINT32_LE } from 'token-types';
|
|
2
|
+
import initDebug from 'debug';
|
|
3
|
+
import { DataDescriptor, EndOfCentralDirectoryRecordToken, FileHeader, LocalFileHeaderToken, Signature } from "./ZipToken.js";
|
|
4
|
+
function signatureToArray(signature) {
|
|
5
|
+
const signatureBytes = new Uint8Array(UINT32_LE.len);
|
|
6
|
+
UINT32_LE.put(signatureBytes, 0, signature);
|
|
7
|
+
return signatureBytes;
|
|
8
|
+
}
|
|
9
|
+
const debug = initDebug('tokenizer:inflate');
|
|
10
|
+
const syncBufferSize = 256 * 1024;
|
|
11
|
+
const ddSignatureArray = signatureToArray(Signature.DataDescriptor);
|
|
12
|
+
const eocdSignatureBytes = signatureToArray(Signature.EndOfCentralDirectory);
|
|
13
|
+
export class ZipHandler {
|
|
14
|
+
constructor(tokenizer) {
|
|
15
|
+
this.tokenizer = tokenizer;
|
|
16
|
+
this.syncBuffer = new Uint8Array(syncBufferSize);
|
|
17
|
+
}
|
|
18
|
+
async isZip() {
|
|
19
|
+
return await this.peekSignature() === Signature.LocalFileHeader;
|
|
20
|
+
}
|
|
21
|
+
peekSignature() {
|
|
22
|
+
return this.tokenizer.peekToken(UINT32_LE);
|
|
23
|
+
}
|
|
24
|
+
async findEndOfCentralDirectoryLocator() {
|
|
25
|
+
const randomReadTokenizer = this.tokenizer;
|
|
26
|
+
const chunkLength = Math.min(16 * 1024, randomReadTokenizer.fileInfo.size);
|
|
27
|
+
const buffer = this.syncBuffer.subarray(0, chunkLength);
|
|
28
|
+
await this.tokenizer.readBuffer(buffer, { position: randomReadTokenizer.fileInfo.size - chunkLength });
|
|
29
|
+
// Search the buffer from end to beginning for EOCD signature
|
|
30
|
+
// const signature = 0x06054b50;
|
|
31
|
+
for (let i = buffer.length - 4; i >= 0; i--) {
|
|
32
|
+
// Compare 4 bytes directly without calling readUInt32LE
|
|
33
|
+
if (buffer[i] === eocdSignatureBytes[0] &&
|
|
34
|
+
buffer[i + 1] === eocdSignatureBytes[1] &&
|
|
35
|
+
buffer[i + 2] === eocdSignatureBytes[2] &&
|
|
36
|
+
buffer[i + 3] === eocdSignatureBytes[3]) {
|
|
37
|
+
return randomReadTokenizer.fileInfo.size - chunkLength + i;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return -1;
|
|
41
|
+
}
|
|
42
|
+
async readCentralDirectory() {
|
|
43
|
+
if (!this.tokenizer.supportsRandomAccess()) {
|
|
44
|
+
debug('Cannot reading central-directory without random-read support');
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
debug('Reading central-directory...');
|
|
48
|
+
const pos = this.tokenizer.position;
|
|
49
|
+
const offset = await this.findEndOfCentralDirectoryLocator();
|
|
50
|
+
if (offset > 0) {
|
|
51
|
+
debug('Central-directory 32-bit signature found');
|
|
52
|
+
const eocdHeader = await this.tokenizer.readToken(EndOfCentralDirectoryRecordToken, offset);
|
|
53
|
+
const files = [];
|
|
54
|
+
this.tokenizer.setPosition(eocdHeader.offsetOfStartOfCd);
|
|
55
|
+
for (let n = 0; n < eocdHeader.nrOfEntriesOfSize; ++n) {
|
|
56
|
+
const entry = await this.tokenizer.readToken(FileHeader);
|
|
57
|
+
if (entry.signature !== Signature.CentralFileHeader) {
|
|
58
|
+
throw new Error('Expected Central-File-Header signature');
|
|
59
|
+
}
|
|
60
|
+
entry.filename = await this.tokenizer.readToken(new StringType(entry.filenameLength, 'utf-8'));
|
|
61
|
+
await this.tokenizer.ignore(entry.extraFieldLength);
|
|
62
|
+
await this.tokenizer.ignore(entry.fileCommentLength);
|
|
63
|
+
files.push(entry);
|
|
64
|
+
debug(`Add central-directory file-entry: n=${n + 1}/${files.length}: filename=${files[n].filename}`);
|
|
65
|
+
}
|
|
66
|
+
this.tokenizer.setPosition(pos);
|
|
67
|
+
return files;
|
|
68
|
+
}
|
|
69
|
+
this.tokenizer.setPosition(pos);
|
|
70
|
+
}
|
|
71
|
+
async unzip(fileCb) {
|
|
72
|
+
const entries = await this.readCentralDirectory();
|
|
73
|
+
if (entries) {
|
|
74
|
+
// Use Central Directory to iterate over files
|
|
75
|
+
return this.iterateOverCentralDirectory(entries, fileCb);
|
|
76
|
+
}
|
|
77
|
+
// Scan Zip files for local-file-header
|
|
78
|
+
let stop = false;
|
|
79
|
+
do {
|
|
80
|
+
const zipHeader = await this.readLocalFileHeader();
|
|
81
|
+
if (!zipHeader)
|
|
82
|
+
break;
|
|
83
|
+
const next = fileCb(zipHeader);
|
|
84
|
+
stop = !!next.stop;
|
|
85
|
+
let fileData;
|
|
86
|
+
await this.tokenizer.ignore(zipHeader.extraFieldLength);
|
|
87
|
+
if (zipHeader.dataDescriptor && zipHeader.compressedSize === 0) {
|
|
88
|
+
const chunks = [];
|
|
89
|
+
let len = syncBufferSize;
|
|
90
|
+
debug('Compressed-file-size unknown, scanning for next data-descriptor-signature....');
|
|
91
|
+
let nextHeaderIndex = -1;
|
|
92
|
+
while (nextHeaderIndex < 0 && len === syncBufferSize) {
|
|
93
|
+
len = await this.tokenizer.peekBuffer(this.syncBuffer, { mayBeLess: true });
|
|
94
|
+
nextHeaderIndex = indexOf(this.syncBuffer.subarray(0, len), ddSignatureArray);
|
|
95
|
+
const size = nextHeaderIndex >= 0 ? nextHeaderIndex : len;
|
|
96
|
+
if (next.handler) {
|
|
97
|
+
const data = new Uint8Array(size);
|
|
98
|
+
await this.tokenizer.readBuffer(data);
|
|
99
|
+
chunks.push(data);
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
// Move position to the next header if found, skip the whole buffer otherwise
|
|
103
|
+
await this.tokenizer.ignore(size);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
debug(`Found data-descriptor-signature at pos=${this.tokenizer.position}`);
|
|
107
|
+
if (next.handler) {
|
|
108
|
+
await this.inflate(zipHeader, mergeArrays(chunks), next.handler);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
if (next.handler) {
|
|
113
|
+
debug(`Reading compressed-file-data: ${zipHeader.compressedSize} bytes`);
|
|
114
|
+
fileData = new Uint8Array(zipHeader.compressedSize);
|
|
115
|
+
await this.tokenizer.readBuffer(fileData);
|
|
116
|
+
await this.inflate(zipHeader, fileData, next.handler);
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
debug(`Ignoring compressed-file-data: ${zipHeader.compressedSize} bytes`);
|
|
120
|
+
await this.tokenizer.ignore(zipHeader.compressedSize);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
debug(`Reading data-descriptor at pos=${this.tokenizer.position}`);
|
|
124
|
+
if (zipHeader.dataDescriptor) {
|
|
125
|
+
// await this.tokenizer.ignore(DataDescriptor.len);
|
|
126
|
+
const dataDescriptor = await this.tokenizer.readToken(DataDescriptor);
|
|
127
|
+
if (dataDescriptor.signature !== 0x08074b50) {
|
|
128
|
+
throw new Error(`Expected data-descriptor-signature at position ${this.tokenizer.position - DataDescriptor.len}`);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
} while (!stop);
|
|
132
|
+
}
|
|
133
|
+
async iterateOverCentralDirectory(entries, fileCb) {
|
|
134
|
+
for (const fileHeader of entries) {
|
|
135
|
+
const next = fileCb(fileHeader);
|
|
136
|
+
if (next.handler) {
|
|
137
|
+
this.tokenizer.setPosition(fileHeader.relativeOffsetOfLocalHeader);
|
|
138
|
+
const zipHeader = await this.readLocalFileHeader();
|
|
139
|
+
if (zipHeader) {
|
|
140
|
+
await this.tokenizer.ignore(zipHeader.extraFieldLength);
|
|
141
|
+
const fileData = new Uint8Array(fileHeader.compressedSize);
|
|
142
|
+
await this.tokenizer.readBuffer(fileData);
|
|
143
|
+
await this.inflate(zipHeader, fileData, next.handler);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
if (next.stop)
|
|
147
|
+
break;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
async inflate(zipHeader, fileData, cb) {
|
|
151
|
+
if (zipHeader.compressedMethod === 0) {
|
|
152
|
+
// Stored (uncompressed)
|
|
153
|
+
return cb(fileData);
|
|
154
|
+
}
|
|
155
|
+
if (zipHeader.compressedMethod !== 8) {
|
|
156
|
+
throw new Error(`Unsupported ZIP compression method: ${zipHeader.compressedMethod}`);
|
|
157
|
+
}
|
|
158
|
+
debug(`Decompress filename=${zipHeader.filename}, compressed-size=${fileData.length}`);
|
|
159
|
+
const uncompressedData = await ZipHandler.decompressDeflateRaw(fileData);
|
|
160
|
+
return cb(uncompressedData);
|
|
161
|
+
}
|
|
162
|
+
static async decompressDeflateRaw(data) {
|
|
163
|
+
// Wrap Uint8Array in a ReadableStream without copying
|
|
164
|
+
const input = new ReadableStream({
|
|
165
|
+
start(controller) {
|
|
166
|
+
controller.enqueue(data);
|
|
167
|
+
controller.close();
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
const ds = new DecompressionStream("deflate-raw");
|
|
171
|
+
const output = input.pipeThrough(ds);
|
|
172
|
+
try {
|
|
173
|
+
// Collect decompressed bytes from the output stream
|
|
174
|
+
const response = new Response(output);
|
|
175
|
+
const buffer = await response.arrayBuffer();
|
|
176
|
+
return new Uint8Array(buffer);
|
|
177
|
+
}
|
|
178
|
+
catch (err) {
|
|
179
|
+
// Provide ZIP-specific error context
|
|
180
|
+
const message = err instanceof Error
|
|
181
|
+
? `Failed to deflate ZIP entry: ${err.message}`
|
|
182
|
+
: "Unknown decompression error in ZIP entry";
|
|
183
|
+
throw new TypeError(message);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
async readLocalFileHeader() {
|
|
187
|
+
const signature = await this.tokenizer.peekToken(UINT32_LE);
|
|
188
|
+
if (signature === Signature.LocalFileHeader) {
|
|
189
|
+
const header = await this.tokenizer.readToken(LocalFileHeaderToken);
|
|
190
|
+
header.filename = await this.tokenizer.readToken(new StringType(header.filenameLength, 'utf-8'));
|
|
191
|
+
return header;
|
|
192
|
+
}
|
|
193
|
+
if (signature === Signature.CentralFileHeader) {
|
|
194
|
+
return false;
|
|
195
|
+
}
|
|
196
|
+
if (signature === 0xE011CFD0) {
|
|
197
|
+
throw new Error('Encrypted ZIP');
|
|
198
|
+
}
|
|
199
|
+
throw new Error('Unexpected signature');
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
function indexOf(buffer, portion) {
|
|
203
|
+
const bufferLength = buffer.length;
|
|
204
|
+
const portionLength = portion.length;
|
|
205
|
+
// Return -1 if the portion is longer than the buffer
|
|
206
|
+
if (portionLength > bufferLength)
|
|
207
|
+
return -1;
|
|
208
|
+
// Search for the portion in the buffer
|
|
209
|
+
for (let i = 0; i <= bufferLength - portionLength; i++) {
|
|
210
|
+
let found = true;
|
|
211
|
+
for (let j = 0; j < portionLength; j++) {
|
|
212
|
+
if (buffer[i + j] !== portion[j]) {
|
|
213
|
+
found = false;
|
|
214
|
+
break;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
if (found) {
|
|
218
|
+
return i; // Return the starting offset
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
return -1; // Not found
|
|
222
|
+
}
|
|
223
|
+
function mergeArrays(chunks) {
|
|
224
|
+
// Concatenate chunks into a single Uint8Array
|
|
225
|
+
const totalLength = chunks.reduce((acc, curr) => acc + curr.length, 0);
|
|
226
|
+
const mergedArray = new Uint8Array(totalLength);
|
|
227
|
+
let offset = 0;
|
|
228
|
+
for (const chunk of chunks) {
|
|
229
|
+
mergedArray.set(chunk, offset);
|
|
230
|
+
offset += chunk.length;
|
|
231
|
+
}
|
|
232
|
+
return mergedArray;
|
|
233
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ref https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT
|
|
3
|
+
*/
|
|
4
|
+
import type { IGetToken } from "strtok3";
|
|
5
|
+
export declare const Signature: {
|
|
6
|
+
LocalFileHeader: number;
|
|
7
|
+
DataDescriptor: number;
|
|
8
|
+
CentralFileHeader: number;
|
|
9
|
+
EndOfCentralDirectory: number;
|
|
10
|
+
};
|
|
11
|
+
interface IDataDescriptor {
|
|
12
|
+
signature: number;
|
|
13
|
+
compressedSize: number;
|
|
14
|
+
uncompressedSize: number;
|
|
15
|
+
}
|
|
16
|
+
export interface ILocalFileHeader extends IDataDescriptor {
|
|
17
|
+
minVersion: number;
|
|
18
|
+
dataDescriptor: boolean;
|
|
19
|
+
compressedMethod: number;
|
|
20
|
+
compressedSize: number;
|
|
21
|
+
uncompressedSize: number;
|
|
22
|
+
filenameLength: number;
|
|
23
|
+
extraFieldLength: number;
|
|
24
|
+
filename: string;
|
|
25
|
+
}
|
|
26
|
+
export declare const DataDescriptor: IGetToken<IDataDescriptor>;
|
|
27
|
+
/**
|
|
28
|
+
* First part of the ZIP Local File Header
|
|
29
|
+
* Offset | Bytes| Description
|
|
30
|
+
* -------|------+-------------------------------------------------------------------
|
|
31
|
+
* 0 | 4 | Signature (0x04034b50)
|
|
32
|
+
* 4 | 2 | Minimum version needed to extract
|
|
33
|
+
* 6 | 2 | Bit flag
|
|
34
|
+
* 8 | 2 | Compression method
|
|
35
|
+
* 10 | 2 | File last modification time (MS-DOS format)
|
|
36
|
+
* 12 | 2 | File last modification date (MS-DOS format)
|
|
37
|
+
* 14 | 4 | CRC-32 of uncompressed data
|
|
38
|
+
* 18 | 4 | Compressed size
|
|
39
|
+
* 22 | 4 | Uncompressed size
|
|
40
|
+
* 26 | 2 | File name length (n)
|
|
41
|
+
* 28 | 2 | Extra field length (m)
|
|
42
|
+
* 30 | n | File name
|
|
43
|
+
* 30 + n | m | Extra field
|
|
44
|
+
*/
|
|
45
|
+
export declare const LocalFileHeaderToken: IGetToken<ILocalFileHeader>;
|
|
46
|
+
interface IEndOfCentralDirectoryRecord {
|
|
47
|
+
signature: number;
|
|
48
|
+
nrOfThisDisk: number;
|
|
49
|
+
nrOfThisDiskWithTheStart: number;
|
|
50
|
+
nrOfEntriesOnThisDisk: number;
|
|
51
|
+
nrOfEntriesOfSize: number;
|
|
52
|
+
sizeOfCd: number;
|
|
53
|
+
offsetOfStartOfCd: number;
|
|
54
|
+
zipFileCommentLength: number;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* 4.3.16 End of central directory record:
|
|
58
|
+
* end of central dir signature (0x06064b50) 4 bytes
|
|
59
|
+
* number of this disk 2 bytes
|
|
60
|
+
* number of the disk with the start of the central directory 2 bytes
|
|
61
|
+
* total number of entries in the central directory on this disk 2 bytes
|
|
62
|
+
* total number of entries in the size of the central directory 2 bytes
|
|
63
|
+
* sizeOfTheCentralDirectory 4 bytes
|
|
64
|
+
* offset of start of central directory with respect to the starting disk number 4 bytes
|
|
65
|
+
* .ZIP file comment length 2 bytes
|
|
66
|
+
* .ZIP file comment (variable size)
|
|
67
|
+
*/
|
|
68
|
+
export declare const EndOfCentralDirectoryRecordToken: IGetToken<IEndOfCentralDirectoryRecord>;
|
|
69
|
+
export interface IFileHeader extends ILocalFileHeader {
|
|
70
|
+
fileCommentLength: number;
|
|
71
|
+
relativeOffsetOfLocalHeader: number;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* File header:
|
|
75
|
+
* central file header signature 4 bytes 0 (0x02014b50)
|
|
76
|
+
* version made by 2 bytes 4
|
|
77
|
+
* version needed to extract 2 bytes 6
|
|
78
|
+
* general purpose bit flag 2 bytes 8
|
|
79
|
+
* compression method 2 bytes 10
|
|
80
|
+
* last mod file time 2 bytes 12
|
|
81
|
+
* last mod file date 2 bytes 14
|
|
82
|
+
* crc-32 4 bytes 16
|
|
83
|
+
* compressed size 4 bytes 20
|
|
84
|
+
* uncompressed size 4 bytes 24
|
|
85
|
+
* file name length 2 bytes 28
|
|
86
|
+
* extra field length 2 bytes 30
|
|
87
|
+
* file comment length 2 bytes 32
|
|
88
|
+
* disk number start 2 bytes 34
|
|
89
|
+
* internal file attributes 2 bytes 36
|
|
90
|
+
* external file attributes 4 bytes 38
|
|
91
|
+
* relative offset of local header 4 bytes 42
|
|
92
|
+
*/
|
|
93
|
+
export declare const FileHeader: IGetToken<IFileHeader>;
|
|
94
|
+
export {};
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ref https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT
|
|
3
|
+
*/
|
|
4
|
+
import { UINT16_LE, UINT32_LE } from "token-types";
|
|
5
|
+
export const Signature = {
|
|
6
|
+
LocalFileHeader: 0x04034b50,
|
|
7
|
+
DataDescriptor: 0x08074b50,
|
|
8
|
+
CentralFileHeader: 0x02014b50,
|
|
9
|
+
EndOfCentralDirectory: 0x06054b50
|
|
10
|
+
};
|
|
11
|
+
export const DataDescriptor = {
|
|
12
|
+
get(array) {
|
|
13
|
+
return {
|
|
14
|
+
signature: UINT32_LE.get(array, 0),
|
|
15
|
+
compressedSize: UINT32_LE.get(array, 8),
|
|
16
|
+
uncompressedSize: UINT32_LE.get(array, 12),
|
|
17
|
+
};
|
|
18
|
+
}, len: 16
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* First part of the ZIP Local File Header
|
|
22
|
+
* Offset | Bytes| Description
|
|
23
|
+
* -------|------+-------------------------------------------------------------------
|
|
24
|
+
* 0 | 4 | Signature (0x04034b50)
|
|
25
|
+
* 4 | 2 | Minimum version needed to extract
|
|
26
|
+
* 6 | 2 | Bit flag
|
|
27
|
+
* 8 | 2 | Compression method
|
|
28
|
+
* 10 | 2 | File last modification time (MS-DOS format)
|
|
29
|
+
* 12 | 2 | File last modification date (MS-DOS format)
|
|
30
|
+
* 14 | 4 | CRC-32 of uncompressed data
|
|
31
|
+
* 18 | 4 | Compressed size
|
|
32
|
+
* 22 | 4 | Uncompressed size
|
|
33
|
+
* 26 | 2 | File name length (n)
|
|
34
|
+
* 28 | 2 | Extra field length (m)
|
|
35
|
+
* 30 | n | File name
|
|
36
|
+
* 30 + n | m | Extra field
|
|
37
|
+
*/
|
|
38
|
+
export const LocalFileHeaderToken = {
|
|
39
|
+
get(array) {
|
|
40
|
+
const flags = UINT16_LE.get(array, 6);
|
|
41
|
+
return {
|
|
42
|
+
signature: UINT32_LE.get(array, 0),
|
|
43
|
+
minVersion: UINT16_LE.get(array, 4),
|
|
44
|
+
dataDescriptor: !!(flags & 0x0008),
|
|
45
|
+
compressedMethod: UINT16_LE.get(array, 8),
|
|
46
|
+
compressedSize: UINT32_LE.get(array, 18),
|
|
47
|
+
uncompressedSize: UINT32_LE.get(array, 22),
|
|
48
|
+
filenameLength: UINT16_LE.get(array, 26),
|
|
49
|
+
extraFieldLength: UINT16_LE.get(array, 28),
|
|
50
|
+
filename: null
|
|
51
|
+
};
|
|
52
|
+
}, len: 30
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* 4.3.16 End of central directory record:
|
|
56
|
+
* end of central dir signature (0x06064b50) 4 bytes
|
|
57
|
+
* number of this disk 2 bytes
|
|
58
|
+
* number of the disk with the start of the central directory 2 bytes
|
|
59
|
+
* total number of entries in the central directory on this disk 2 bytes
|
|
60
|
+
* total number of entries in the size of the central directory 2 bytes
|
|
61
|
+
* sizeOfTheCentralDirectory 4 bytes
|
|
62
|
+
* offset of start of central directory with respect to the starting disk number 4 bytes
|
|
63
|
+
* .ZIP file comment length 2 bytes
|
|
64
|
+
* .ZIP file comment (variable size)
|
|
65
|
+
*/
|
|
66
|
+
export const EndOfCentralDirectoryRecordToken = {
|
|
67
|
+
get(array) {
|
|
68
|
+
return {
|
|
69
|
+
signature: UINT32_LE.get(array, 0),
|
|
70
|
+
nrOfThisDisk: UINT16_LE.get(array, 4),
|
|
71
|
+
nrOfThisDiskWithTheStart: UINT16_LE.get(array, 6),
|
|
72
|
+
nrOfEntriesOnThisDisk: UINT16_LE.get(array, 8),
|
|
73
|
+
nrOfEntriesOfSize: UINT16_LE.get(array, 10),
|
|
74
|
+
sizeOfCd: UINT32_LE.get(array, 12),
|
|
75
|
+
offsetOfStartOfCd: UINT32_LE.get(array, 16),
|
|
76
|
+
zipFileCommentLength: UINT16_LE.get(array, 20),
|
|
77
|
+
};
|
|
78
|
+
}, len: 22
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* File header:
|
|
82
|
+
* central file header signature 4 bytes 0 (0x02014b50)
|
|
83
|
+
* version made by 2 bytes 4
|
|
84
|
+
* version needed to extract 2 bytes 6
|
|
85
|
+
* general purpose bit flag 2 bytes 8
|
|
86
|
+
* compression method 2 bytes 10
|
|
87
|
+
* last mod file time 2 bytes 12
|
|
88
|
+
* last mod file date 2 bytes 14
|
|
89
|
+
* crc-32 4 bytes 16
|
|
90
|
+
* compressed size 4 bytes 20
|
|
91
|
+
* uncompressed size 4 bytes 24
|
|
92
|
+
* file name length 2 bytes 28
|
|
93
|
+
* extra field length 2 bytes 30
|
|
94
|
+
* file comment length 2 bytes 32
|
|
95
|
+
* disk number start 2 bytes 34
|
|
96
|
+
* internal file attributes 2 bytes 36
|
|
97
|
+
* external file attributes 4 bytes 38
|
|
98
|
+
* relative offset of local header 4 bytes 42
|
|
99
|
+
*/
|
|
100
|
+
export const FileHeader = {
|
|
101
|
+
get(array) {
|
|
102
|
+
const flags = UINT16_LE.get(array, 8);
|
|
103
|
+
return {
|
|
104
|
+
signature: UINT32_LE.get(array, 0),
|
|
105
|
+
minVersion: UINT16_LE.get(array, 6),
|
|
106
|
+
dataDescriptor: !!(flags & 0x0008),
|
|
107
|
+
compressedMethod: UINT16_LE.get(array, 10),
|
|
108
|
+
compressedSize: UINT32_LE.get(array, 20),
|
|
109
|
+
uncompressedSize: UINT32_LE.get(array, 24),
|
|
110
|
+
filenameLength: UINT16_LE.get(array, 28),
|
|
111
|
+
extraFieldLength: UINT16_LE.get(array, 30),
|
|
112
|
+
fileCommentLength: UINT16_LE.get(array, 32),
|
|
113
|
+
relativeOffsetOfLocalHeader: UINT32_LE.get(array, 42),
|
|
114
|
+
filename: null
|
|
115
|
+
};
|
|
116
|
+
}, len: 46
|
|
117
|
+
};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tokenizer/inflate",
|
|
3
|
+
"version": "0.4.1",
|
|
4
|
+
"description": "Tokenized zip support",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": "./lib/index.js",
|
|
7
|
+
"files": [
|
|
8
|
+
"lib/**/*.js",
|
|
9
|
+
"lib/**/*.d.ts"
|
|
10
|
+
],
|
|
11
|
+
"scripts": {
|
|
12
|
+
"clean": "del-cli 'lib/**/*.js' 'lib/**/*.js.map' 'lib/**/*.d.ts' 'test/**/*.js' 'test/**/*.js.map'",
|
|
13
|
+
"compile-src": "tsc -p lib",
|
|
14
|
+
"compile-test": "tsc -p test",
|
|
15
|
+
"compile": "yarn run compile-src && yarn run compile-test",
|
|
16
|
+
"build": "yarn run clean && yarn run compile",
|
|
17
|
+
"prepublishOnly": "yarn run build",
|
|
18
|
+
"eslint": "eslint lib test",
|
|
19
|
+
"lint:md": "remark -u preset-lint-recommended .",
|
|
20
|
+
"lint:ts": "biome check",
|
|
21
|
+
"fix": "yarn run biome lint --write",
|
|
22
|
+
"test": "mocha",
|
|
23
|
+
"start": "yarn run compile && yarn run lint && yarn run cover-test",
|
|
24
|
+
"update-biome": "yarn add -D --exact @biomejs/biome && npx @biomejs/biome migrate --write"
|
|
25
|
+
},
|
|
26
|
+
"engines": {
|
|
27
|
+
"node": ">=18"
|
|
28
|
+
},
|
|
29
|
+
"author": {
|
|
30
|
+
"name": "Borewit",
|
|
31
|
+
"url": "https://github.com/Borewit"
|
|
32
|
+
},
|
|
33
|
+
"license": "MIT",
|
|
34
|
+
"packageManager": "yarn@4.9.1",
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@aws-sdk/client-s3": "^3.934.0",
|
|
37
|
+
"@biomejs/biome": "2.3.6",
|
|
38
|
+
"@tokenizer/s3": "^1.0.1",
|
|
39
|
+
"@types/chai": "^5.2.3",
|
|
40
|
+
"@types/debug": "^4",
|
|
41
|
+
"@types/mocha": "^10.0.10",
|
|
42
|
+
"@types/node": "^24.10.1",
|
|
43
|
+
"chai": "^6.2.1",
|
|
44
|
+
"del-cli": "^7.0.0",
|
|
45
|
+
"file-type": "^21.1.0",
|
|
46
|
+
"mocha": "^11.7.5",
|
|
47
|
+
"strtok3": "^10.3.4",
|
|
48
|
+
"ts-node": "^10.9.2",
|
|
49
|
+
"typescript": "^5.9.3"
|
|
50
|
+
},
|
|
51
|
+
"dependencies": {
|
|
52
|
+
"debug": "^4.4.3",
|
|
53
|
+
"token-types": "^6.1.1"
|
|
54
|
+
},
|
|
55
|
+
"repository": {
|
|
56
|
+
"type": "git",
|
|
57
|
+
"url": "https://github.com/Borewit/tokenizer-inflate.git"
|
|
58
|
+
},
|
|
59
|
+
"bugs": {
|
|
60
|
+
"url": "hhttps://github.com/Borewit/tokenizer-inflate/issues"
|
|
61
|
+
},
|
|
62
|
+
"funding": {
|
|
63
|
+
"type": "github",
|
|
64
|
+
"url": "https://github.com/sponsors/Borewit"
|
|
65
|
+
},
|
|
66
|
+
"keywords": [
|
|
67
|
+
"zip",
|
|
68
|
+
"unzip",
|
|
69
|
+
"decompress",
|
|
70
|
+
"inflate",
|
|
71
|
+
"strtok3",
|
|
72
|
+
"tokenizer",
|
|
73
|
+
"stream",
|
|
74
|
+
"S3"
|
|
75
|
+
]
|
|
76
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
[](https://www.npmjs.com/package/@tokenizer/token)
|
|
2
|
+
[](https://npmcharts.com/compare/@tokenizer/token?interval=30)
|
|
3
|
+
|
|
4
|
+
# @tokenizer/token
|
|
5
|
+
|
|
6
|
+
TypeScript definition of an [strtok3](https://github.com/Borewit/strtok3) token.
|
|
7
|
+
|
|
8
|
+
## Licence
|
|
9
|
+
|
|
10
|
+
(The MIT License)
|
|
11
|
+
|
|
12
|
+
Copyright (c) 2020 Borewit
|
|
13
|
+
|
|
14
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
15
|
+
|
|
16
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
17
|
+
|
|
18
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
19
|
+
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Read-only token
|
|
3
|
+
* See https://github.com/Borewit/strtok3 for more information
|
|
4
|
+
*/
|
|
5
|
+
export interface IGetToken<Value, Array extends Uint8Array = Uint8Array> {
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Length of encoded token in bytes
|
|
9
|
+
*/
|
|
10
|
+
len: number;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Decode value from buffer at offset
|
|
14
|
+
* @param array - Uint8Array to read the decoded value from
|
|
15
|
+
* @param offset - Decode offset
|
|
16
|
+
* @return decoded value
|
|
17
|
+
*/
|
|
18
|
+
get(array: Array, offset: number): Value;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface IToken<Value, Array extends Uint8Array = Uint8Array> extends IGetToken<Value, Array> {
|
|
22
|
+
/**
|
|
23
|
+
* Encode value to buffer
|
|
24
|
+
* @param array - Uint8Array to write the encoded value to
|
|
25
|
+
* @param offset - Buffer write offset
|
|
26
|
+
* @param value - Value to decode of type T
|
|
27
|
+
* @return offset plus number of bytes written
|
|
28
|
+
*/
|
|
29
|
+
put(array: Array, offset: number, value: Value): number
|
|
30
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tokenizer/token",
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "TypeScript definition for strtok3 token",
|
|
5
|
+
"main": "",
|
|
6
|
+
"types": "index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"index.d.ts"
|
|
9
|
+
],
|
|
10
|
+
"keywords": [
|
|
11
|
+
"token",
|
|
12
|
+
"interface",
|
|
13
|
+
"tokenizer",
|
|
14
|
+
"TypeScript"
|
|
15
|
+
],
|
|
16
|
+
"author": {
|
|
17
|
+
"name": "Borewit",
|
|
18
|
+
"url": "https://github.com/Borewit"
|
|
19
|
+
},
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "https://github.com/Borewit/tokenizer-token.git"
|
|
24
|
+
},
|
|
25
|
+
"bugs": {
|
|
26
|
+
"url": "https://github.com/Borewit/tokenizer-token/issues"
|
|
27
|
+
},
|
|
28
|
+
"typeScriptVersion": "3.0",
|
|
29
|
+
"dependencies": {},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@types/node": "^13.1.0"
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
(The MIT License)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2014-2017 TJ Holowaychuk <tj@vision-media.ca>
|
|
4
|
+
Copyright (c) 2018-2021 Josh Junon
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
|
7
|
+
and associated documentation files (the 'Software'), to deal in the Software without restriction,
|
|
8
|
+
including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
9
|
+
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
|
|
10
|
+
subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial
|
|
13
|
+
portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
|
|
16
|
+
LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
17
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
18
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
19
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
20
|
+
|