llm-large-files 0.5.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1402 -467
- package/README.md +188 -60
- package/dist/analyze.d.ts +5 -0
- package/dist/analyze.d.ts.map +1 -1
- package/dist/analyze.js +96 -47
- package/dist/analyze.js.map +1 -1
- package/dist/anthropic/adapter.d.ts +14 -3
- package/dist/anthropic/adapter.d.ts.map +1 -1
- package/dist/anthropic/adapter.js +190 -39
- package/dist/anthropic/adapter.js.map +1 -1
- package/dist/ask.d.ts +60 -4
- package/dist/ask.d.ts.map +1 -1
- package/dist/ask.js +1068 -206
- package/dist/ask.js.map +1 -1
- package/dist/encoding.d.ts +17 -0
- package/dist/encoding.d.ts.map +1 -0
- package/dist/encoding.js +852 -0
- package/dist/encoding.js.map +1 -0
- package/dist/errors.d.ts +4 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +15 -0
- package/dist/errors.js.map +1 -1
- package/dist/events.d.ts +333 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +159 -0
- package/dist/events.js.map +1 -0
- package/dist/evidence.d.ts +2 -0
- package/dist/evidence.d.ts.map +1 -1
- package/dist/evidence.js +3 -2
- package/dist/evidence.js.map +1 -1
- package/dist/extract.d.ts +35 -3
- package/dist/extract.d.ts.map +1 -1
- package/dist/extract.js +626 -58
- package/dist/extract.js.map +1 -1
- package/dist/gemini/adapter.d.ts +17 -8
- package/dist/gemini/adapter.d.ts.map +1 -1
- package/dist/gemini/adapter.js +108 -61
- package/dist/gemini/adapter.js.map +1 -1
- package/dist/gemini/chat.d.ts +23 -3
- package/dist/gemini/chat.d.ts.map +1 -1
- package/dist/gemini/chat.js +6 -2
- package/dist/gemini/chat.js.map +1 -1
- package/dist/gemini/errors.d.ts +9 -4
- package/dist/gemini/errors.d.ts.map +1 -1
- package/dist/gemini/errors.js +32 -0
- package/dist/gemini/errors.js.map +1 -1
- package/dist/gemini/generate.d.ts +10 -2
- package/dist/gemini/generate.d.ts.map +1 -1
- package/dist/gemini/generate.js +13 -7
- package/dist/gemini/generate.js.map +1 -1
- package/dist/gemini/index.d.ts +3 -3
- package/dist/gemini/index.d.ts.map +1 -1
- package/dist/gemini/index.js +2 -2
- package/dist/gemini/index.js.map +1 -1
- package/dist/gemini/sse.d.ts +1 -1
- package/dist/gemini/sse.d.ts.map +1 -1
- package/dist/gemini/sse.js +1 -1
- package/dist/gemini/sse.js.map +1 -1
- package/dist/http.d.ts +116 -0
- package/dist/http.d.ts.map +1 -1
- package/dist/http.js +347 -1
- package/dist/http.js.map +1 -1
- package/dist/index.d.ts +11 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -4
- package/dist/index.js.map +1 -1
- package/dist/library.d.ts +67 -5
- package/dist/library.d.ts.map +1 -1
- package/dist/library.js +405 -85
- package/dist/library.js.map +1 -1
- package/dist/map-reduce.d.ts +28 -1
- package/dist/map-reduce.d.ts.map +1 -1
- package/dist/map-reduce.js +240 -52
- package/dist/map-reduce.js.map +1 -1
- package/dist/model.d.ts +84 -2
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +182 -1
- package/dist/model.js.map +1 -1
- package/dist/node/handlers.d.ts +20 -4
- package/dist/node/handlers.d.ts.map +1 -1
- package/dist/node/handlers.js +122 -20
- package/dist/node/handlers.js.map +1 -1
- package/dist/node/index.d.ts +2 -0
- package/dist/node/index.d.ts.map +1 -1
- package/dist/node/index.js +1 -0
- package/dist/node/index.js.map +1 -1
- package/dist/node/sse.d.ts +59 -0
- package/dist/node/sse.d.ts.map +1 -0
- package/dist/node/sse.js +174 -0
- package/dist/node/sse.js.map +1 -0
- package/dist/openai/adapter.d.ts +29 -5
- package/dist/openai/adapter.d.ts.map +1 -1
- package/dist/openai/adapter.js +311 -37
- package/dist/openai/adapter.js.map +1 -1
- package/dist/output-limit.d.ts +14 -2
- package/dist/output-limit.d.ts.map +1 -1
- package/dist/output-limit.js +39 -10
- package/dist/output-limit.js.map +1 -1
- package/dist/pause.d.ts +24 -0
- package/dist/pause.d.ts.map +1 -0
- package/dist/pause.js +38 -0
- package/dist/pause.js.map +1 -0
- package/dist/pdf-pages.d.ts +32 -2
- package/dist/pdf-pages.d.ts.map +1 -1
- package/dist/pdf-pages.js +275 -14
- package/dist/pdf-pages.js.map +1 -1
- package/dist/pdf-pictures.d.ts +30 -3
- package/dist/pdf-pictures.d.ts.map +1 -1
- package/dist/pdf-pictures.js +50 -8
- package/dist/pdf-pictures.js.map +1 -1
- package/dist/pdf-work.d.ts +40 -0
- package/dist/pdf-work.d.ts.map +1 -0
- package/dist/pdf-work.js +734 -0
- package/dist/pdf-work.js.map +1 -0
- package/dist/plan.d.ts +22 -4
- package/dist/plan.d.ts.map +1 -1
- package/dist/plan.js +61 -12
- package/dist/plan.js.map +1 -1
- package/dist/retry.d.ts +23 -1
- package/dist/retry.d.ts.map +1 -1
- package/dist/retry.js +33 -3
- package/dist/retry.js.map +1 -1
- package/dist/search.d.ts +8 -2
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +60 -10
- package/dist/search.js.map +1 -1
- package/dist/sse.d.ts +35 -2
- package/dist/sse.d.ts.map +1 -1
- package/dist/sse.js +145 -31
- package/dist/sse.js.map +1 -1
- package/dist/stores.d.ts.map +1 -1
- package/dist/stores.js +5 -2
- package/dist/stores.js.map +1 -1
- package/dist/text-index.d.ts +6 -0
- package/dist/text-index.d.ts.map +1 -1
- package/dist/text-index.js +25 -8
- package/dist/text-index.js.map +1 -1
- package/dist/text.d.ts +62 -2
- package/dist/text.d.ts.map +1 -1
- package/dist/text.js +314 -14
- package/dist/text.js.map +1 -1
- package/dist/tools.d.ts +61 -1
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +269 -42
- package/dist/tools.js.map +1 -1
- package/dist/types.d.ts +102 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/zip-directory.d.ts +43 -0
- package/dist/zip-directory.d.ts.map +1 -0
- package/dist/zip-directory.js +130 -0
- package/dist/zip-directory.js.map +1 -0
- package/docs/README.md +288 -0
- package/docs/api.md +37 -381
- package/docs/configuration.md +28 -558
- package/docs/getting-started.md +407 -223
- package/docs/guides/anthropic.md +590 -0
- package/docs/guides/conversations.md +629 -0
- package/docs/guides/costs-and-limits.md +726 -0
- package/docs/guides/deployment.md +654 -0
- package/docs/guides/errors-and-reliability.md +735 -0
- package/docs/guides/explorer-model.md +399 -0
- package/docs/guides/openai-compatible.md +602 -0
- package/docs/guides/own-adapter-and-loop.md +1169 -0
- package/docs/guides/pdfs.md +971 -0
- package/docs/guides/storage.md +731 -0
- package/docs/guides/testing.md +1199 -0
- package/docs/guides/vertex-and-gemini.md +717 -0
- package/docs/guides/web-app.md +1589 -0
- package/docs/how-it-works.md +1012 -164
- package/docs/measurements.md +881 -0
- package/docs/publishing.md +274 -46
- package/docs/reference/anthropic.md +427 -0
- package/docs/reference/ask.md +892 -0
- package/docs/reference/errors-and-retries.md +758 -0
- package/docs/reference/events.md +993 -0
- package/docs/reference/gemini.md +823 -0
- package/docs/reference/library.md +1467 -0
- package/docs/reference/node.md +528 -0
- package/docs/reference/openai.md +385 -0
- package/docs/reference/tools.md +883 -0
- package/docs/security.md +897 -103
- package/docs/troubleshooting.md +1390 -0
- package/package.json +2 -2
- package/src/analyze.ts +93 -42
- package/src/anthropic/adapter.ts +196 -39
- package/src/ask.ts +1087 -202
- package/src/encoding.ts +850 -0
- package/src/errors.ts +17 -0
- package/src/events.ts +442 -0
- package/src/evidence.ts +5 -2
- package/src/extract.ts +602 -62
- package/src/gemini/adapter.ts +118 -65
- package/src/gemini/chat.ts +28 -4
- package/src/gemini/errors.ts +34 -1
- package/src/gemini/generate.ts +23 -10
- package/src/gemini/index.ts +3 -3
- package/src/gemini/sse.ts +1 -1
- package/src/http.ts +376 -1
- package/src/index.ts +27 -5
- package/src/library.ts +459 -85
- package/src/map-reduce.ts +252 -51
- package/src/model.ts +236 -3
- package/src/node/handlers.ts +137 -22
- package/src/node/index.ts +2 -0
- package/src/node/sse.ts +198 -0
- package/src/openai/adapter.ts +306 -38
- package/src/output-limit.ts +44 -8
- package/src/pause.ts +41 -0
- package/src/pdf-pages.ts +268 -15
- package/src/pdf-pictures.ts +56 -9
- package/src/pdf-work.ts +722 -0
- package/src/plan.ts +68 -12
- package/src/retry.ts +49 -5
- package/src/search.ts +63 -10
- package/src/sse.ts +153 -28
- package/src/stores.ts +5 -2
- package/src/text-index.ts +26 -7
- package/src/text.ts +323 -13
- package/src/tools.ts +261 -42
- package/src/types.ts +107 -4
- package/src/zip-directory.ts +136 -0
package/dist/types.d.ts
CHANGED
|
@@ -42,6 +42,19 @@ export type DocumentMeta = {
|
|
|
42
42
|
/** Lines longer than the wrap limit are split so every line stays readable by line number. */
|
|
43
43
|
wrappedLines: number;
|
|
44
44
|
pages?: number;
|
|
45
|
+
/**
|
|
46
|
+
* The older encoding a text file was read in, because it is not UTF-8: "windows-1255" for a
|
|
47
|
+
* Hebrew CSV that Excel saved. Lines of it that are valid UTF-8 are read as UTF-8 all the same.
|
|
48
|
+
* Absent for valid UTF-8, for a file read as UTF-8 with characters that are not valid (see
|
|
49
|
+
* `replacedCharacters`), for UTF-16, for PDF, DOCX and PPTX, and on documents from before 0.6.0.
|
|
50
|
+
*/
|
|
51
|
+
encoding?: string;
|
|
52
|
+
/**
|
|
53
|
+
* Characters of a text file that were not valid in the encoding it was read in, such as a
|
|
54
|
+
* character cut in two at the end of a UTF-8 log, or a byte that `encoding` does not have: each
|
|
55
|
+
* is stored as U+FFFD (�). Absent when there were none, and on documents from before 0.6.0.
|
|
56
|
+
*/
|
|
57
|
+
replacedCharacters?: number;
|
|
45
58
|
/**
|
|
46
59
|
* True when the uploaded file itself is kept in the store next to its text (see `keepOriginals`).
|
|
47
60
|
* Recorded here so that planning a request does not have to load the file to know.
|
|
@@ -66,6 +79,10 @@ export type DocumentSummary = {
|
|
|
66
79
|
lines: number;
|
|
67
80
|
estimatedTokens: number;
|
|
68
81
|
pages?: number;
|
|
82
|
+
/** See `DocumentMeta.encoding`. */
|
|
83
|
+
encoding?: string;
|
|
84
|
+
/** See `DocumentMeta.replacedCharacters`. */
|
|
85
|
+
replacedCharacters?: number;
|
|
69
86
|
expiresAt: string;
|
|
70
87
|
};
|
|
71
88
|
/** Where extracted text lives. Implement this for Redis, S3, a database, etc. */
|
|
@@ -104,6 +121,13 @@ export interface DocumentStore {
|
|
|
104
121
|
export type ExtractedText = {
|
|
105
122
|
text: string;
|
|
106
123
|
pages?: number;
|
|
124
|
+
/**
|
|
125
|
+
* The older encoding the file was read in, when it is not UTF-8. Kept as `DocumentMeta.encoding`
|
|
126
|
+
* when it is a name, and not one of UTF-8 or UTF-16.
|
|
127
|
+
*/
|
|
128
|
+
encoding?: string;
|
|
129
|
+
/** Characters that were not valid in the encoding the file was read in, each now U+FFFD. Kept as `DocumentMeta.replacedCharacters`. */
|
|
130
|
+
replacedCharacters?: number;
|
|
107
131
|
};
|
|
108
132
|
export type ExtractInput = {
|
|
109
133
|
name: string;
|
|
@@ -115,6 +139,37 @@ export type ExtractInput = {
|
|
|
115
139
|
* always was. An extractor of your own may ignore it.
|
|
116
140
|
*/
|
|
117
141
|
scannedPages?: number;
|
|
142
|
+
/**
|
|
143
|
+
* Aborted when the ingest's time is up (`ingestTimeoutMs`) or the caller gave up
|
|
144
|
+
* (`IngestInput.signal`). The built-in extractors stop between pages and pieces; its `reason`
|
|
145
|
+
* is the error to throw. An extractor of your own should stop too: `ingest` stops waiting for it
|
|
146
|
+
* either way, but cannot stop the work it does.
|
|
147
|
+
*/
|
|
148
|
+
signal?: AbortSignal;
|
|
149
|
+
/**
|
|
150
|
+
* The most text to keep from this file, in UTF-8 bytes (`maxTextBytes`). The built-in extractors
|
|
151
|
+
* refuse a file as soon as its text grows past it. `ingest` refuses any larger result.
|
|
152
|
+
*/
|
|
153
|
+
maxTextBytes?: number;
|
|
154
|
+
/** The most pages to read from one PDF (`maxPdfPages`). The built-in PDF extractor refuses more. */
|
|
155
|
+
maxPages?: number;
|
|
156
|
+
/**
|
|
157
|
+
* Call it as the extraction goes on, so `ingest` can report progress (`IngestInput.onEvent`).
|
|
158
|
+
* The built-in extractors call it for each page of a PDF (also for the page check and the
|
|
159
|
+
* picture marks: `stage` "check" and "pictures"), each part of a DOCX or PPTX, and once when a
|
|
160
|
+
* text file not in UTF-8 is decoded ("decode"). Calls after the extractor returned are dropped. An
|
|
161
|
+
* extractor of your own may ignore it. New in 0.7.0.
|
|
162
|
+
*/
|
|
163
|
+
onProgress?: (progress: ExtractProgress) => void;
|
|
164
|
+
};
|
|
165
|
+
/** How far an extraction is, for `ExtractInput.onProgress`. */
|
|
166
|
+
export type ExtractProgress = {
|
|
167
|
+
/** "extract" (the default): text read; "check": pages checked before reading; "pictures": pages looked at for pictures; "decode": bytes of a text file decoded. */
|
|
168
|
+
stage?: "extract" | "check" | "pictures" | "decode";
|
|
169
|
+
done: number;
|
|
170
|
+
/** Absent when not known. */
|
|
171
|
+
total?: number;
|
|
172
|
+
unit: "pages" | "parts" | "bytes";
|
|
118
173
|
};
|
|
119
174
|
export type Extractor = (bytes: Uint8Array, input: ExtractInput) => Promise<ExtractedText>;
|
|
120
175
|
/** The limits of the model connection the documents must fit through. */
|
|
@@ -167,7 +222,8 @@ export type ToolOutput = {
|
|
|
167
222
|
export type ToolCallLimits = {
|
|
168
223
|
/**
|
|
169
224
|
* The most bytes the files of this call may have together. Give the room left in your request,
|
|
170
|
-
* times 3/4 when files are sent as base64. Defaults to
|
|
225
|
+
* times 3/4 when files are sent as base64. Defaults to 3/8 of `maxRequestBytes` less 262,144
|
|
226
|
+
* (the 256 KB the library keeps free in a request).
|
|
171
227
|
*/
|
|
172
228
|
maxFileBytes?: number;
|
|
173
229
|
/** The most pages this call may show. Lower it as the pages already shown use up your token budget. */
|
|
@@ -178,6 +234,48 @@ export type ToolCallLimits = {
|
|
|
178
234
|
* says where to go on.
|
|
179
235
|
*/
|
|
180
236
|
maxResultCharacters?: number;
|
|
237
|
+
/**
|
|
238
|
+
* The most model requests a whole-file read (`analyze_whole_document`) may make: what the
|
|
239
|
+
* question has left of `limits.requests`. A part the model refuses as too large is read as two
|
|
240
|
+
* halves only while that and `maxMapChunks` allow it.
|
|
241
|
+
*/
|
|
242
|
+
maxRequests?: number;
|
|
243
|
+
};
|
|
244
|
+
/**
|
|
245
|
+
* Listeners for one tool call, next to its limits. New in 0.7.0: with them, the progress of two
|
|
246
|
+
* whole-file reads that run at once can be told apart.
|
|
247
|
+
*/
|
|
248
|
+
export type ToolCallHooks = {
|
|
249
|
+
/** Progress of this call (a whole-file read), in place of `ToolOptions.onProgress` for it. */
|
|
250
|
+
onProgress?: ProgressListener;
|
|
251
|
+
/**
|
|
252
|
+
* Each model request this call makes (a whole-file read), as it starts. Tell the handle it
|
|
253
|
+
* returns about each retry of that request, and when it ends.
|
|
254
|
+
*/
|
|
255
|
+
onRequest?: (request: ToolRequestStart) => ToolRequestHandle;
|
|
256
|
+
};
|
|
257
|
+
/** One model request of a tool call (`ToolCallHooks.onRequest`). */
|
|
258
|
+
export type ToolRequestHandle = {
|
|
259
|
+
/** The request failed and is sent again after `delayMs`. */
|
|
260
|
+
retry(notice: {
|
|
261
|
+
attempt: number;
|
|
262
|
+
delayMs: number;
|
|
263
|
+
error: unknown;
|
|
264
|
+
}): void;
|
|
265
|
+
/** The request ended, after any retries. Call it once. */
|
|
266
|
+
end(end: ToolRequestEnd): void;
|
|
267
|
+
};
|
|
268
|
+
/** A model request of a tool call, as it starts (`ToolCallHooks.onRequest`). */
|
|
269
|
+
export type ToolRequestStart = {
|
|
270
|
+
purpose: "part" | "merge" | "final";
|
|
271
|
+
/** "part 3 of 12", "first half of part 3 of 12", "round 2: 1 of 4", "the answer". */
|
|
272
|
+
detail: string;
|
|
273
|
+
};
|
|
274
|
+
/** A model request of a tool call, as it ends. */
|
|
275
|
+
export type ToolRequestEnd = {
|
|
276
|
+
outcome: "ok" | "error";
|
|
277
|
+
usage?: GenerateUsage;
|
|
278
|
+
error?: unknown;
|
|
181
279
|
};
|
|
182
280
|
/** The name of `ToolCallLimits` before 0.5.0. */
|
|
183
281
|
export type ToolFileLimits = ToolCallLimits;
|
|
@@ -193,7 +291,7 @@ export type ToolSet = {
|
|
|
193
291
|
* Runs a tool call and also returns the files it produced, to be sent to the model with the
|
|
194
292
|
* result. Use it in place of `execute` in a loop that can send files.
|
|
195
293
|
*/
|
|
196
|
-
executeWithFiles(name: string, args: Record<string, unknown>, limits?: ToolCallLimits): Promise<ToolOutput>;
|
|
294
|
+
executeWithFiles(name: string, args: Record<string, unknown>, limits?: ToolCallLimits, hooks?: ToolCallHooks): Promise<ToolOutput>;
|
|
197
295
|
/** A short, human-readable line describing a call, for progress UIs. */
|
|
198
296
|
describe(name: string, args: Record<string, unknown>): string;
|
|
199
297
|
/**
|
|
@@ -223,7 +321,8 @@ export type GenerateText = (request: {
|
|
|
223
321
|
onTruncated?: () => void;
|
|
224
322
|
/**
|
|
225
323
|
* Call this once for every request that was answered, with the tokens it used, so that the cost
|
|
226
|
-
* of a whole-document read is counted. Optional: without it
|
|
324
|
+
* of a whole-document read is counted. Optional: without it, `askWithFiles` still counts each
|
|
325
|
+
* answered request (in `usage.requests` and against `limits.requests`), but not its tokens.
|
|
227
326
|
*/
|
|
228
327
|
onUsage?: (usage: GenerateUsage) => void;
|
|
229
328
|
}) => Promise<string>;
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,UAAU,GAAG,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,KAAK,GAAG,MAAM,GAAG,MAAM,CAAC;AAEpG,MAAM,MAAM,YAAY,GAAG;IACzB,iDAAiD;IACjD,IAAI,EAAE,MAAM,CAAC;IACb,0BAA0B;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAA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AAE,YAAY,CAAC;IACnB,iGAAiG;IACjG,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC5B,mGAAmG;IACnG,WAAW,EAAE,MAAM,CAAC;IACpB,qEAAqE;IACrE,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB;;;OAGG;IACH,QAAQ,EAAE,YAAY,EAAE,CAAC;CAC1B,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reads the directory of a ZIP file the way JSZip 3.10 reads it, before JSZip does, and adds up
|
|
3
|
+
* what JSZip would keep from it. JSZip reads the whole directory into memory before it unpacks any
|
|
4
|
+
* part, and the directory is written by whoever made the file: its count of parts, where it
|
|
5
|
+
* starts, and how long each record is. So the count of parts is not taken from the end record. The
|
|
6
|
+
* directory is found where JSZip will find it, and its records are walked as JSZip will walk them,
|
|
7
|
+
* each by its own lengths, until JSZip would stop, or the file is past a limit.
|
|
8
|
+
*/
|
|
9
|
+
/** What JSZip would keep in memory from the directory of a ZIP file. */
|
|
10
|
+
export type ZipDirectory = {
|
|
11
|
+
/** The parts JSZip would read, counted to one past the limit. */
|
|
12
|
+
parts: number;
|
|
13
|
+
/** Their extra fields, counted to one past the limit: JSZip keeps about 250 bytes for each. */
|
|
14
|
+
extraFields: number;
|
|
15
|
+
/**
|
|
16
|
+
* The bytes JSZip turns into text, or goes through one by one, counted until they pass the
|
|
17
|
+
* limit: the comment of the file, and for each part the name in the local header it points to
|
|
18
|
+
* (a header that many parts point to counts once for each), its comment, and the data of its
|
|
19
|
+
* ZIP64 (1), Unicode Path (0x7075) and Unicode Comment (0x6375) extra fields. That data may run
|
|
20
|
+
* past the record, over the records after it.
|
|
21
|
+
*/
|
|
22
|
+
textBytes: number;
|
|
23
|
+
/**
|
|
24
|
+
* The ZIP64 end record says it is longer than its fields. JSZip reads what follows in a loop that
|
|
25
|
+
* does not move on: it stops when it runs out of data, or never.
|
|
26
|
+
*/
|
|
27
|
+
endless: boolean;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* What JSZip would keep from the directory of `bytes`, up to the limits. Undefined when JSZip
|
|
31
|
+
* would stop before it reads any part: the file is not a ZIP, or is damaged, and JSZip will say
|
|
32
|
+
* so.
|
|
33
|
+
*
|
|
34
|
+
* JSZip reads the whole directory, then the local header of each part, and stops at the first part
|
|
35
|
+
* it cannot read (a local header that is not there, an unknown way of packing). The names and
|
|
36
|
+
* comments of the parts after it are counted too: such a file is not read either way.
|
|
37
|
+
*/
|
|
38
|
+
export declare function readZipDirectory(bytes: Uint8Array, limits: {
|
|
39
|
+
parts: number;
|
|
40
|
+
extraFields: number;
|
|
41
|
+
textBytes: number;
|
|
42
|
+
}): ZipDirectory | undefined;
|
|
43
|
+
//# sourceMappingURL=zip-directory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zip-directory.d.ts","sourceRoot":"","sources":["../src/zip-directory.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,wEAAwE;AACxE,MAAM,MAAM,YAAY,GAAG;IACzB,iEAAiE;IACjE,KAAK,EAAE,MAAM,CAAC;IACd,+FAA+F;IAC/F,WAAW,EAAE,MAAM,CAAC;IACpB;;;;;;OAMG;IACH,SAAS,EAAE,MAAM,CAAC;IAClB;;;OAGG;IACH,OAAO,EAAE,OAAO,CAAC;CAClB,CAAC;AAQF;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,GAAG,YAAY,GAAG,SAAS,CA0F/I"}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reads the directory of a ZIP file the way JSZip 3.10 reads it, before JSZip does, and adds up
|
|
3
|
+
* what JSZip would keep from it. JSZip reads the whole directory into memory before it unpacks any
|
|
4
|
+
* part, and the directory is written by whoever made the file: its count of parts, where it
|
|
5
|
+
* starts, and how long each record is. So the count of parts is not taken from the end record. The
|
|
6
|
+
* directory is found where JSZip will find it, and its records are walked as JSZip will walk them,
|
|
7
|
+
* each by its own lengths, until JSZip would stop, or the file is past a limit.
|
|
8
|
+
*/
|
|
9
|
+
const LOCAL = 0x04034b50;
|
|
10
|
+
const CENTRAL = 0x02014b50;
|
|
11
|
+
const END = 0x06054b50;
|
|
12
|
+
const LOCATOR = 0x07064b50;
|
|
13
|
+
const END64 = 0x06064b50;
|
|
14
|
+
/**
|
|
15
|
+
* What JSZip would keep from the directory of `bytes`, up to the limits. Undefined when JSZip
|
|
16
|
+
* would stop before it reads any part: the file is not a ZIP, or is damaged, and JSZip will say
|
|
17
|
+
* so.
|
|
18
|
+
*
|
|
19
|
+
* JSZip reads the whole directory, then the local header of each part, and stops at the first part
|
|
20
|
+
* it cannot read (a local header that is not there, an unknown way of packing). The names and
|
|
21
|
+
* comments of the parts after it are counted too: such a file is not read either way.
|
|
22
|
+
*/
|
|
23
|
+
export function readZipDirectory(bytes, limits) {
|
|
24
|
+
const length = bytes.length;
|
|
25
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
26
|
+
// JSZip reads 4 bytes as a signed number, and of 8 bytes only the low 4, as a signed number.
|
|
27
|
+
const int = (at) => view.getInt32(at, true);
|
|
28
|
+
const short = (at) => view.getUint16(at, true);
|
|
29
|
+
const at4 = (at, signature) => at >= 0 && at + 4 <= length && view.getUint32(at, true) === signature;
|
|
30
|
+
// JSZip looks for a record from the end of the whole file, not only of its last 64 KB.
|
|
31
|
+
const whole = Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
32
|
+
const lastIndexOf = (signature) => {
|
|
33
|
+
const needle = Buffer.alloc(4);
|
|
34
|
+
needle.writeUInt32LE(signature);
|
|
35
|
+
return whole.lastIndexOf(needle);
|
|
36
|
+
};
|
|
37
|
+
// The end record: 22 bytes, then its comment.
|
|
38
|
+
const end = lastIndexOf(END);
|
|
39
|
+
if (end < 0 || end + 22 > length || end + 22 + short(end + 20) > length)
|
|
40
|
+
return undefined;
|
|
41
|
+
let size = int(end + 12);
|
|
42
|
+
let offset = int(end + 16);
|
|
43
|
+
let zip64 = 0;
|
|
44
|
+
if ([4, 6, 8, 10].some((field) => short(end + field) === 0xffff) || size === -1 || offset === -1) {
|
|
45
|
+
// A field too small for its value: JSZip reads the ZIP64 end record where the last ZIP64
|
|
46
|
+
// locator of the file says it is, or else the last ZIP64 end record of the file.
|
|
47
|
+
const locator = lastIndexOf(LOCATOR);
|
|
48
|
+
if (locator < 0 || locator + 20 > length || int(locator + 16) > 1)
|
|
49
|
+
return undefined;
|
|
50
|
+
let end64 = int(locator + 8);
|
|
51
|
+
if (end64 < 0 || end64 + 4 > length)
|
|
52
|
+
return undefined;
|
|
53
|
+
if (!at4(end64, END64))
|
|
54
|
+
end64 = lastIndexOf(END64);
|
|
55
|
+
if (end64 < 0 || end64 + 56 > length)
|
|
56
|
+
return undefined;
|
|
57
|
+
if (int(end64 + 4) > 44)
|
|
58
|
+
return { parts: 0, extraFields: 0, textBytes: 0, endless: true };
|
|
59
|
+
zip64 = 20 + 12 + int(end64 + 4);
|
|
60
|
+
size = int(end64 + 40);
|
|
61
|
+
offset = int(end64 + 48);
|
|
62
|
+
}
|
|
63
|
+
// Bytes before the archive, such as a program that unpacks it: JSZip reads every offset after them.
|
|
64
|
+
const before = end - (offset + size + zip64);
|
|
65
|
+
if (before < 0 || offset < 0 || before + offset > length)
|
|
66
|
+
return undefined;
|
|
67
|
+
const directory = { parts: 0, extraFields: 0, textBytes: short(end + 20), endless: false };
|
|
68
|
+
/** Adds bytes JSZip turns into text or goes through, and says whether they are past the limit. */
|
|
69
|
+
const text = (count) => (directory.textBytes += count) > limits.textBytes;
|
|
70
|
+
let at = before + offset;
|
|
71
|
+
// A record: 46 bytes, the name, the extra fields and the comment.
|
|
72
|
+
while (at4(at, CENTRAL) && at + 46 <= length) {
|
|
73
|
+
// JSZip stops at an encrypted part.
|
|
74
|
+
if (short(at + 8) & 1)
|
|
75
|
+
break;
|
|
76
|
+
const extraStart = at + 46 + short(at + 28);
|
|
77
|
+
const extraEnd = extraStart + short(at + 30);
|
|
78
|
+
if (extraEnd > length)
|
|
79
|
+
break;
|
|
80
|
+
// Each extra field is 4 bytes and its data, read while more than 4 bytes are left. JSZip keeps
|
|
81
|
+
// the last ZIP64 field (id 1) and goes on from the end of the extra fields.
|
|
82
|
+
let field = extraStart;
|
|
83
|
+
let zip64Data = -1;
|
|
84
|
+
let zip64End = -1;
|
|
85
|
+
while (field + 4 < extraEnd) {
|
|
86
|
+
if (++directory.extraFields > limits.extraFields)
|
|
87
|
+
return directory;
|
|
88
|
+
const id = short(field);
|
|
89
|
+
const fieldEnd = field + 4 + short(field + 2);
|
|
90
|
+
// JSZip goes through the data of these fields byte by byte, and decodes the Unicode ones as
|
|
91
|
+
// text, even when the data runs past the extra fields of the record.
|
|
92
|
+
if ((id === 1 || id === 0x7075 || id === 0x6375) && text(fieldEnd - field - 4))
|
|
93
|
+
return directory;
|
|
94
|
+
if (id === 1) {
|
|
95
|
+
zip64Data = field + 4;
|
|
96
|
+
zip64End = fieldEnd;
|
|
97
|
+
}
|
|
98
|
+
field = fieldEnd;
|
|
99
|
+
}
|
|
100
|
+
if (field > length)
|
|
101
|
+
break;
|
|
102
|
+
let local = int(at + 42);
|
|
103
|
+
if (zip64Data >= 0) {
|
|
104
|
+
// The ZIP64 field holds, 8 bytes each, the sizes and the offset the record has no room for,
|
|
105
|
+
// in that order.
|
|
106
|
+
const values = [int(at + 24), int(at + 20), local].filter((value) => value === -1).length;
|
|
107
|
+
if (zip64Data + 8 * values > zip64End)
|
|
108
|
+
break;
|
|
109
|
+
if (local === -1)
|
|
110
|
+
local = int(zip64Data + 8 * values - 8);
|
|
111
|
+
}
|
|
112
|
+
const comment = short(at + 32);
|
|
113
|
+
const next = extraEnd + comment;
|
|
114
|
+
if (next > length)
|
|
115
|
+
break;
|
|
116
|
+
if (++directory.parts > limits.parts)
|
|
117
|
+
return directory;
|
|
118
|
+
if (text(comment))
|
|
119
|
+
return directory;
|
|
120
|
+
// The name is decoded from the local header the part points to.
|
|
121
|
+
const header = before + local;
|
|
122
|
+
if (local >= 0 && at4(header, LOCAL) && header + 30 <= length && header + 30 + short(header + 26) <= length) {
|
|
123
|
+
if (text(short(header + 26)))
|
|
124
|
+
return directory;
|
|
125
|
+
}
|
|
126
|
+
at = next;
|
|
127
|
+
}
|
|
128
|
+
return directory;
|
|
129
|
+
}
|
|
130
|
+
//# sourceMappingURL=zip-directory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zip-directory.js","sourceRoot":"","sources":["../src/zip-directory.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAuBH,MAAM,KAAK,GAAG,UAAU,CAAC;AACzB,MAAM,OAAO,GAAG,UAAU,CAAC;AAC3B,MAAM,GAAG,GAAG,UAAU,CAAC;AACvB,MAAM,OAAO,GAAG,UAAU,CAAC;AAC3B,MAAM,KAAK,GAAG,UAAU,CAAC;AAEzB;;;;;;;;GAQG;AACH,MAAM,UAAU,gBAAgB,CAAC,KAAiB,EAAE,MAAiE;IACnH,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;IAC5B,MAAM,IAAI,GAAG,IAAI,QAAQ,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,UAAU,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC;IAC5E,6FAA6F;IAC7F,MAAM,GAAG,GAAG,CAAC,EAAU,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;IACpD,MAAM,KAAK,GAAG,CAAC,EAAU,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;IACvD,MAAM,GAAG,GAAG,C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