@cj-tech-master/excelts 1.4.5 → 1.5.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/dist/browser/excelts.iife.js +454 -159
- package/dist/browser/excelts.iife.js.map +1 -1
- package/dist/browser/excelts.iife.min.js +28 -28
- package/dist/cjs/doc/anchor.js +25 -11
- package/dist/cjs/doc/cell.js +75 -43
- package/dist/cjs/doc/column.js +74 -22
- package/dist/cjs/doc/defined-names.js +53 -7
- package/dist/cjs/doc/image.js +11 -8
- package/dist/cjs/doc/range.js +64 -28
- package/dist/cjs/doc/row.js +72 -31
- package/dist/cjs/doc/table.js +3 -5
- package/dist/cjs/doc/workbook.js +30 -6
- package/dist/cjs/doc/worksheet.js +165 -41
- package/dist/cjs/utils/sheet-utils.js +3 -1
- package/dist/cjs/utils/unzip/extract.js +30 -82
- package/dist/cjs/utils/unzip/index.js +18 -2
- package/dist/cjs/utils/unzip/zip-parser.js +458 -0
- package/dist/esm/doc/anchor.js +25 -11
- package/dist/esm/doc/cell.js +75 -43
- package/dist/esm/doc/column.js +74 -22
- package/dist/esm/doc/defined-names.js +53 -7
- package/dist/esm/doc/image.js +11 -8
- package/dist/esm/doc/range.js +64 -28
- package/dist/esm/doc/row.js +72 -31
- package/dist/esm/doc/table.js +3 -5
- package/dist/esm/doc/workbook.js +30 -6
- package/dist/esm/doc/worksheet.js +165 -41
- package/dist/esm/utils/sheet-utils.js +3 -1
- package/dist/esm/utils/unzip/extract.js +28 -82
- package/dist/esm/utils/unzip/index.js +17 -2
- package/dist/esm/utils/unzip/zip-parser.js +451 -0
- package/dist/types/doc/anchor.d.ts +14 -7
- package/dist/types/doc/cell.d.ts +78 -37
- package/dist/types/doc/column.d.ts +72 -36
- package/dist/types/doc/defined-names.d.ts +11 -8
- package/dist/types/doc/image.d.ts +29 -12
- package/dist/types/doc/pivot-table.d.ts +1 -1
- package/dist/types/doc/range.d.ts +15 -4
- package/dist/types/doc/row.d.ts +78 -40
- package/dist/types/doc/table.d.ts +21 -36
- package/dist/types/doc/workbook.d.ts +54 -34
- package/dist/types/doc/worksheet.d.ts +255 -83
- package/dist/types/stream/xlsx/worksheet-reader.d.ts +3 -5
- package/dist/types/types.d.ts +86 -26
- package/dist/types/utils/col-cache.d.ts +11 -8
- package/dist/types/utils/unzip/extract.d.ts +16 -14
- package/dist/types/utils/unzip/index.d.ts +15 -1
- package/dist/types/utils/unzip/zip-parser.d.ts +92 -0
- package/package.json +1 -1
package/dist/types/types.d.ts
CHANGED
|
@@ -2,8 +2,7 @@
|
|
|
2
2
|
* Type definitions for ExcelTS
|
|
3
3
|
* This file exports all public types used by the library
|
|
4
4
|
*/
|
|
5
|
-
|
|
6
|
-
export type Buffer = ArrayBuffer;
|
|
5
|
+
export type Buffer = Uint8Array;
|
|
7
6
|
export declare enum PaperSize {
|
|
8
7
|
Legal = 5,
|
|
9
8
|
Executive = 7,
|
|
@@ -92,14 +91,26 @@ export interface FillGradientPath {
|
|
|
92
91
|
stops: GradientStop[];
|
|
93
92
|
}
|
|
94
93
|
export type Fill = FillPattern | FillGradientAngle | FillGradientPath;
|
|
95
|
-
export interface
|
|
96
|
-
|
|
94
|
+
export interface NumFmt {
|
|
95
|
+
id: number;
|
|
96
|
+
formatCode: string;
|
|
97
|
+
}
|
|
98
|
+
interface StyleBase {
|
|
97
99
|
font: Partial<Font>;
|
|
98
100
|
alignment: Partial<Alignment>;
|
|
99
101
|
protection: Partial<Protection>;
|
|
100
102
|
border: Partial<Borders>;
|
|
101
103
|
fill: Fill;
|
|
102
104
|
}
|
|
105
|
+
export interface StyleInput extends StyleBase {
|
|
106
|
+
numFmt: string;
|
|
107
|
+
}
|
|
108
|
+
export interface StyleOutput extends StyleBase {
|
|
109
|
+
numFmt: NumFmt;
|
|
110
|
+
}
|
|
111
|
+
export interface Style extends StyleBase {
|
|
112
|
+
numFmt: string | NumFmt;
|
|
113
|
+
}
|
|
103
114
|
export interface Margins {
|
|
104
115
|
top: number;
|
|
105
116
|
left: number;
|
|
@@ -143,13 +154,13 @@ export interface HeaderFooter {
|
|
|
143
154
|
firstFooter: string;
|
|
144
155
|
}
|
|
145
156
|
export interface WorksheetViewCommon {
|
|
146
|
-
rightToLeft
|
|
147
|
-
activeCell
|
|
148
|
-
showRuler
|
|
149
|
-
showRowColHeaders
|
|
150
|
-
showGridLines
|
|
151
|
-
zoomScale
|
|
152
|
-
zoomScaleNormal
|
|
157
|
+
rightToLeft?: boolean;
|
|
158
|
+
activeCell?: string;
|
|
159
|
+
showRuler?: boolean;
|
|
160
|
+
showRowColHeaders?: boolean;
|
|
161
|
+
showGridLines?: boolean;
|
|
162
|
+
zoomScale?: number;
|
|
163
|
+
zoomScaleNormal?: number;
|
|
153
164
|
}
|
|
154
165
|
export interface WorksheetViewNormal {
|
|
155
166
|
state: "normal";
|
|
@@ -248,13 +259,22 @@ export interface CellFormulaValue {
|
|
|
248
259
|
result?: number | string | boolean | Date | CellErrorValue;
|
|
249
260
|
date1904?: boolean;
|
|
250
261
|
}
|
|
262
|
+
/** Array formula that spans multiple cells */
|
|
263
|
+
export interface CellArrayFormulaValue {
|
|
264
|
+
formula: string;
|
|
265
|
+
result?: number | string | boolean | Date | CellErrorValue;
|
|
266
|
+
/** Must be "array" for array formulas */
|
|
267
|
+
shareType: "array";
|
|
268
|
+
/** The range this array formula applies to, e.g. "A1:B2" */
|
|
269
|
+
ref: string;
|
|
270
|
+
}
|
|
251
271
|
export interface CellSharedFormulaValue {
|
|
252
272
|
sharedFormula: string;
|
|
253
273
|
readonly formula?: string;
|
|
254
274
|
result?: number | string | boolean | Date | CellErrorValue;
|
|
255
275
|
date1904?: boolean;
|
|
256
276
|
}
|
|
257
|
-
export type CellValue = null | number | string | boolean | Date | undefined | CellErrorValue | CellRichTextValue | CellHyperlinkValue | CellFormulaValue | CellSharedFormulaValue;
|
|
277
|
+
export type CellValue = null | number | string | boolean | Date | undefined | CellErrorValue | CellRichTextValue | CellHyperlinkValue | CellFormulaValue | CellArrayFormulaValue | CellSharedFormulaValue;
|
|
258
278
|
export interface CommentMargins {
|
|
259
279
|
insetmode: "auto" | "custom";
|
|
260
280
|
inset: number[];
|
|
@@ -271,11 +291,9 @@ export interface Comment {
|
|
|
271
291
|
editAs?: CommentEditAs;
|
|
272
292
|
}
|
|
273
293
|
export type DataValidationOperator = "between" | "notBetween" | "equal" | "notEqual" | "greaterThan" | "lessThan" | "greaterThanOrEqual" | "lessThanOrEqual";
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
formulae: any[];
|
|
294
|
+
/** Base properties shared by all data validation types */
|
|
295
|
+
interface DataValidationBase {
|
|
277
296
|
allowBlank?: boolean;
|
|
278
|
-
operator?: DataValidationOperator;
|
|
279
297
|
error?: string;
|
|
280
298
|
errorTitle?: string;
|
|
281
299
|
errorStyle?: string;
|
|
@@ -284,16 +302,23 @@ export interface DataValidation {
|
|
|
284
302
|
showErrorMessage?: boolean;
|
|
285
303
|
showInputMessage?: boolean;
|
|
286
304
|
}
|
|
305
|
+
/** Data validation that requires formulae and operator */
|
|
306
|
+
export interface DataValidationWithFormulae extends DataValidationBase {
|
|
307
|
+
type: "list" | "whole" | "decimal" | "date" | "textLength" | "custom";
|
|
308
|
+
formulae: any[];
|
|
309
|
+
operator?: DataValidationOperator;
|
|
310
|
+
}
|
|
311
|
+
/** Data validation type 'any' - no formulae needed */
|
|
312
|
+
export interface DataValidationAny extends DataValidationBase {
|
|
313
|
+
type: "any";
|
|
314
|
+
}
|
|
315
|
+
export type DataValidation = DataValidationWithFormulae | DataValidationAny;
|
|
287
316
|
export interface Image {
|
|
288
317
|
extension: "jpeg" | "png" | "gif";
|
|
289
318
|
base64?: string;
|
|
290
319
|
filename?: string;
|
|
291
320
|
buffer?: Buffer;
|
|
292
321
|
}
|
|
293
|
-
export interface ImageRange {
|
|
294
|
-
tl: IAnchor;
|
|
295
|
-
br: IAnchor;
|
|
296
|
-
}
|
|
297
322
|
export interface ImagePosition {
|
|
298
323
|
tl: {
|
|
299
324
|
col: number;
|
|
@@ -304,6 +329,34 @@ export interface ImagePosition {
|
|
|
304
329
|
height: number;
|
|
305
330
|
};
|
|
306
331
|
}
|
|
332
|
+
/** Anchor position for image placement */
|
|
333
|
+
export interface ImageAnchor {
|
|
334
|
+
col: number;
|
|
335
|
+
row: number;
|
|
336
|
+
nativeCol?: number;
|
|
337
|
+
nativeRow?: number;
|
|
338
|
+
nativeColOff?: number;
|
|
339
|
+
nativeRowOff?: number;
|
|
340
|
+
}
|
|
341
|
+
/** Range input for addImage - can be a string like "A1:B2" or an object */
|
|
342
|
+
export type AddImageRange = string | {
|
|
343
|
+
/** Top-left anchor position */
|
|
344
|
+
tl: ImageAnchor | string;
|
|
345
|
+
/** Bottom-right anchor position (optional if ext is provided) */
|
|
346
|
+
br?: ImageAnchor | string;
|
|
347
|
+
/** Image dimensions (alternative to br) */
|
|
348
|
+
ext?: {
|
|
349
|
+
width: number;
|
|
350
|
+
height: number;
|
|
351
|
+
};
|
|
352
|
+
/** How the image behaves when cells are resized */
|
|
353
|
+
editAs?: "oneCell" | "twoCell" | "absolute";
|
|
354
|
+
/** Hyperlink for the image */
|
|
355
|
+
hyperlinks?: {
|
|
356
|
+
hyperlink?: string;
|
|
357
|
+
tooltip?: string;
|
|
358
|
+
};
|
|
359
|
+
};
|
|
307
360
|
export interface ImageHyperlinkValue {
|
|
308
361
|
hyperlink: string;
|
|
309
362
|
tooltip?: string;
|
|
@@ -319,7 +372,7 @@ export type Address = {
|
|
|
319
372
|
address: string;
|
|
320
373
|
col: number;
|
|
321
374
|
row: number;
|
|
322
|
-
$col$row
|
|
375
|
+
$col$row?: string;
|
|
323
376
|
};
|
|
324
377
|
export type RowValues = CellValue[] | {
|
|
325
378
|
[key: string]: CellValue;
|
|
@@ -331,10 +384,10 @@ export type IconSetTypes = "5Arrows" | "5ArrowsGray" | "5Boxes" | "5Quarters" |
|
|
|
331
384
|
export type CfvoTypes = "percentile" | "percent" | "num" | "min" | "max" | "formula" | "autoMin" | "autoMax";
|
|
332
385
|
export interface Cvfo {
|
|
333
386
|
type: CfvoTypes;
|
|
334
|
-
value?: number;
|
|
387
|
+
value?: number | string;
|
|
335
388
|
}
|
|
336
389
|
export interface ConditionalFormattingBaseRule {
|
|
337
|
-
priority
|
|
390
|
+
priority?: number;
|
|
338
391
|
style?: Partial<Style>;
|
|
339
392
|
}
|
|
340
393
|
export interface ExpressionRuleType extends ConditionalFormattingBaseRule {
|
|
@@ -350,11 +403,11 @@ export interface Top10RuleType extends ConditionalFormattingBaseRule {
|
|
|
350
403
|
type: "top10";
|
|
351
404
|
rank: number;
|
|
352
405
|
percent: boolean;
|
|
353
|
-
bottom
|
|
406
|
+
bottom?: boolean;
|
|
354
407
|
}
|
|
355
408
|
export interface AboveAverageRuleType extends ConditionalFormattingBaseRule {
|
|
356
409
|
type: "aboveAverage";
|
|
357
|
-
aboveAverage
|
|
410
|
+
aboveAverage?: boolean;
|
|
358
411
|
}
|
|
359
412
|
export interface ColorScaleRuleType extends ConditionalFormattingBaseRule {
|
|
360
413
|
type: "colorScale";
|
|
@@ -390,12 +443,17 @@ export interface DataBarRuleType extends ConditionalFormattingBaseRule {
|
|
|
390
443
|
axisPosition?: "auto" | "middle" | "none";
|
|
391
444
|
direction?: "context" | "leftToRight" | "rightToLeft";
|
|
392
445
|
cfvo?: Cvfo[];
|
|
446
|
+
color?: Partial<Color>;
|
|
393
447
|
}
|
|
394
448
|
export type ConditionalFormattingRule = ExpressionRuleType | CellIsRuleType | Top10RuleType | AboveAverageRuleType | ColorScaleRuleType | IconSetRuleType | ContainsTextRuleType | TimePeriodRuleType | DataBarRuleType;
|
|
395
449
|
export interface ConditionalFormattingOptions {
|
|
396
450
|
ref: string;
|
|
397
451
|
rules: ConditionalFormattingRule[];
|
|
398
452
|
}
|
|
453
|
+
export interface ConditionalFormattingOptions {
|
|
454
|
+
ref: string;
|
|
455
|
+
rules: ConditionalFormattingRule[];
|
|
456
|
+
}
|
|
399
457
|
export interface TableStyleProperties {
|
|
400
458
|
theme?: string;
|
|
401
459
|
showFirstColumn?: boolean;
|
|
@@ -409,6 +467,7 @@ export interface TableColumnProperties {
|
|
|
409
467
|
totalsRowLabel?: string;
|
|
410
468
|
totalsRowFunction?: "none" | "average" | "countNums" | "count" | "max" | "min" | "stdDev" | "var" | "sum" | "custom";
|
|
411
469
|
totalsRowFormula?: string;
|
|
470
|
+
totalsRowResult?: CellFormulaValue["result"];
|
|
412
471
|
style?: Partial<Style>;
|
|
413
472
|
}
|
|
414
473
|
export interface TableProperties {
|
|
@@ -459,6 +518,7 @@ export type DefinedNamesModel = DefinedNamesRanges[];
|
|
|
459
518
|
export interface RowBreak {
|
|
460
519
|
id: number;
|
|
461
520
|
max: number;
|
|
462
|
-
min
|
|
521
|
+
min?: number;
|
|
463
522
|
man: number;
|
|
464
523
|
}
|
|
524
|
+
export {};
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import type { Address, Location } from "../types.js";
|
|
2
|
-
type
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
type CachedAddress = Address & {
|
|
3
|
+
$col$row: string;
|
|
4
|
+
};
|
|
5
|
+
export type DecodedRange = Location & {
|
|
6
|
+
tl: string | CachedAddress;
|
|
7
|
+
br: string | CachedAddress;
|
|
5
8
|
dimensions: string;
|
|
6
9
|
sheetName?: string;
|
|
7
10
|
};
|
|
@@ -9,21 +12,21 @@ interface ErrorReference {
|
|
|
9
12
|
error: string;
|
|
10
13
|
sheetName?: string;
|
|
11
14
|
}
|
|
12
|
-
type DecodeExResult =
|
|
15
|
+
type DecodeExResult = CachedAddress | DecodedRange | ErrorReference;
|
|
13
16
|
interface ColCache {
|
|
14
17
|
_dictionary: string[];
|
|
15
18
|
_l2nFill: number;
|
|
16
19
|
_l2n: Record<string, number>;
|
|
17
20
|
_n2l: string[];
|
|
18
|
-
_hash: Record<string,
|
|
21
|
+
_hash: Record<string, CachedAddress>;
|
|
19
22
|
_level(n: number): number;
|
|
20
23
|
_fill(level: number): void;
|
|
21
24
|
l2n(l: string): number;
|
|
22
25
|
n2l(n: number): string;
|
|
23
26
|
validateAddress(value: string): boolean;
|
|
24
|
-
decodeAddress(value: string):
|
|
25
|
-
getAddress(r: number | string, c?: number):
|
|
26
|
-
decode(value: string):
|
|
27
|
+
decodeAddress(value: string): CachedAddress;
|
|
28
|
+
getAddress(r: number | string, c?: number): CachedAddress;
|
|
29
|
+
decode(value: string): CachedAddress | DecodedRange;
|
|
27
30
|
decodeEx(value: string): DecodeExResult;
|
|
28
31
|
encodeAddress(row: number, col: number): string;
|
|
29
32
|
encode(...args: number[]): string;
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Simple ZIP extraction utilities
|
|
3
3
|
* Provides easy-to-use Promise-based API for extracting ZIP files
|
|
4
|
+
* Works in both Node.js and browser environments
|
|
4
5
|
*/
|
|
5
|
-
import { type
|
|
6
|
+
import { type ZipEntryInfo } from "./zip-parser.js";
|
|
6
7
|
/**
|
|
7
8
|
* Extracted file entry
|
|
8
9
|
*/
|
|
9
10
|
export interface ExtractedFile {
|
|
10
11
|
/** File path within the ZIP */
|
|
11
12
|
path: string;
|
|
12
|
-
/** File content as
|
|
13
|
-
data:
|
|
13
|
+
/** File content as Uint8Array */
|
|
14
|
+
data: Uint8Array;
|
|
14
15
|
/** Whether this is a directory */
|
|
15
16
|
isDirectory: boolean;
|
|
16
17
|
/** Uncompressed size */
|
|
@@ -19,7 +20,7 @@ export interface ExtractedFile {
|
|
|
19
20
|
/**
|
|
20
21
|
* Extract all files from a ZIP buffer
|
|
21
22
|
*
|
|
22
|
-
* @param zipData - ZIP file data as Buffer or
|
|
23
|
+
* @param zipData - ZIP file data as Buffer, Uint8Array, or ArrayBuffer
|
|
23
24
|
* @returns Map of file paths to their content
|
|
24
25
|
*
|
|
25
26
|
* @example
|
|
@@ -34,13 +35,13 @@ export interface ExtractedFile {
|
|
|
34
35
|
* }
|
|
35
36
|
* ```
|
|
36
37
|
*/
|
|
37
|
-
export declare function extractAll(zipData:
|
|
38
|
+
export declare function extractAll(zipData: Uint8Array | ArrayBuffer): Promise<Map<string, ExtractedFile>>;
|
|
38
39
|
/**
|
|
39
40
|
* Extract a single file from a ZIP buffer
|
|
40
41
|
*
|
|
41
|
-
* @param zipData - ZIP file data as Buffer or
|
|
42
|
+
* @param zipData - ZIP file data as Buffer, Uint8Array, or ArrayBuffer
|
|
42
43
|
* @param filePath - Path of the file to extract
|
|
43
|
-
* @returns File content as
|
|
44
|
+
* @returns File content as Uint8Array, or null if not found
|
|
44
45
|
*
|
|
45
46
|
* @example
|
|
46
47
|
* ```ts
|
|
@@ -49,15 +50,15 @@ export declare function extractAll(zipData: Buffer | Uint8Array): Promise<Map<st
|
|
|
49
50
|
* const zipData = fs.readFileSync("archive.zip");
|
|
50
51
|
* const content = await extractFile(zipData, "readme.txt");
|
|
51
52
|
* if (content) {
|
|
52
|
-
* console.log(
|
|
53
|
+
* console.log(new TextDecoder().decode(content));
|
|
53
54
|
* }
|
|
54
55
|
* ```
|
|
55
56
|
*/
|
|
56
|
-
export declare function extractFile(zipData:
|
|
57
|
+
export declare function extractFile(zipData: Uint8Array | ArrayBuffer, filePath: string): Promise<Uint8Array | null>;
|
|
57
58
|
/**
|
|
58
59
|
* List all file paths in a ZIP buffer (without extracting content)
|
|
59
60
|
*
|
|
60
|
-
* @param zipData - ZIP file data as Buffer or
|
|
61
|
+
* @param zipData - ZIP file data as Buffer, Uint8Array, or ArrayBuffer
|
|
61
62
|
* @returns Array of file paths
|
|
62
63
|
*
|
|
63
64
|
* @example
|
|
@@ -69,11 +70,11 @@ export declare function extractFile(zipData: Buffer | Uint8Array, filePath: stri
|
|
|
69
70
|
* console.log(paths); // ["file1.txt", "folder/file2.txt", ...]
|
|
70
71
|
* ```
|
|
71
72
|
*/
|
|
72
|
-
export declare function listFiles(zipData:
|
|
73
|
+
export declare function listFiles(zipData: Uint8Array | ArrayBuffer): Promise<string[]>;
|
|
73
74
|
/**
|
|
74
75
|
* Iterate over ZIP entries with a callback (memory efficient for large ZIPs)
|
|
75
76
|
*
|
|
76
|
-
* @param zipData - ZIP file data as Buffer or
|
|
77
|
+
* @param zipData - ZIP file data as Buffer, Uint8Array, or ArrayBuffer
|
|
77
78
|
* @param callback - Async callback for each entry, return false to stop iteration
|
|
78
79
|
*
|
|
79
80
|
* @example
|
|
@@ -83,10 +84,11 @@ export declare function listFiles(zipData: Buffer | Uint8Array): Promise<string[
|
|
|
83
84
|
* await forEachEntry(zipData, async (path, getData) => {
|
|
84
85
|
* if (path.endsWith(".xml")) {
|
|
85
86
|
* const content = await getData();
|
|
86
|
-
* console.log(
|
|
87
|
+
* console.log(new TextDecoder().decode(content));
|
|
87
88
|
* }
|
|
88
89
|
* return true; // continue iteration
|
|
89
90
|
* });
|
|
90
91
|
* ```
|
|
91
92
|
*/
|
|
92
|
-
export declare function forEachEntry(zipData:
|
|
93
|
+
export declare function forEachEntry(zipData: Uint8Array | ArrayBuffer, callback: (path: string, getData: () => Promise<Uint8Array>, entry: ZipEntryInfo) => Promise<boolean | void>): Promise<void>;
|
|
94
|
+
export { ZipParser, type ZipEntryInfo, type ZipParseOptions } from "./zip-parser.js";
|
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Unzip utilities for parsing ZIP archives
|
|
3
|
+
*
|
|
4
|
+
* Two APIs are provided:
|
|
5
|
+
*
|
|
6
|
+
* 1. **Stream-based API** (Node.js only):
|
|
7
|
+
* - `Parse`, `createParse` - Parse ZIP files as a stream
|
|
8
|
+
* - Best for large files where you don't want to load entire file into memory
|
|
9
|
+
* - Requires Node.js `stream` module
|
|
10
|
+
*
|
|
11
|
+
* 2. **Buffer-based API** (Browser + Node.js):
|
|
12
|
+
* - `extractAll`, `extractFile`, `listFiles`, `forEachEntry`, `ZipParser`
|
|
13
|
+
* - Works in both Node.js and browser environments
|
|
14
|
+
* - Uses native `DecompressionStream` in browser, `zlib` in Node.js
|
|
15
|
+
* - Best for files already loaded into memory (ArrayBuffer, Uint8Array)
|
|
16
|
+
*
|
|
3
17
|
* Original source: https://github.com/ZJONSSON/node-unzipper
|
|
4
18
|
* License: MIT
|
|
5
19
|
*/
|
|
@@ -10,4 +24,4 @@ export { bufferStream } from "./buffer-stream.js";
|
|
|
10
24
|
export { parse as parseBuffer } from "./parse-buffer.js";
|
|
11
25
|
export { parseDateTime } from "./parse-datetime.js";
|
|
12
26
|
export { parseExtraField, type ExtraField, type ZipVars } from "./parse-extra-field.js";
|
|
13
|
-
export { extractAll, extractFile, listFiles, forEachEntry, type ExtractedFile } from "./extract.js";
|
|
27
|
+
export { extractAll, extractFile, listFiles, forEachEntry, ZipParser, type ExtractedFile, type ZipEntryInfo, type ZipParseOptions } from "./extract.js";
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure Uint8Array-based ZIP parser
|
|
3
|
+
* Works in both Node.js and browser environments
|
|
4
|
+
* No dependency on Node.js stream module
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Parsed ZIP entry
|
|
8
|
+
*/
|
|
9
|
+
export interface ZipEntryInfo {
|
|
10
|
+
/** File path within the ZIP */
|
|
11
|
+
path: string;
|
|
12
|
+
/** Whether this is a directory */
|
|
13
|
+
isDirectory: boolean;
|
|
14
|
+
/** Compressed size */
|
|
15
|
+
compressedSize: number;
|
|
16
|
+
/** Uncompressed size */
|
|
17
|
+
uncompressedSize: number;
|
|
18
|
+
/** Compression method (0 = stored, 8 = deflate) */
|
|
19
|
+
compressionMethod: number;
|
|
20
|
+
/** CRC-32 checksum */
|
|
21
|
+
crc32: number;
|
|
22
|
+
/** Last modified date */
|
|
23
|
+
lastModified: Date;
|
|
24
|
+
/** Offset to local file header */
|
|
25
|
+
localHeaderOffset: number;
|
|
26
|
+
/** File comment */
|
|
27
|
+
comment: string;
|
|
28
|
+
/** External file attributes */
|
|
29
|
+
externalAttributes: number;
|
|
30
|
+
/** Is encrypted */
|
|
31
|
+
isEncrypted: boolean;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* ZIP parsing options
|
|
35
|
+
*/
|
|
36
|
+
export interface ZipParseOptions {
|
|
37
|
+
/** Whether to decode file names as UTF-8 (default: true) */
|
|
38
|
+
decodeStrings?: boolean;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Parse ZIP file entries from Central Directory
|
|
42
|
+
*/
|
|
43
|
+
export declare function parseZipEntries(data: Uint8Array, options?: ZipParseOptions): ZipEntryInfo[];
|
|
44
|
+
/**
|
|
45
|
+
* Extract file data for a specific entry
|
|
46
|
+
*/
|
|
47
|
+
export declare function extractEntryData(data: Uint8Array, entry: ZipEntryInfo): Promise<Uint8Array>;
|
|
48
|
+
/**
|
|
49
|
+
* Extract file data synchronously (Node.js only)
|
|
50
|
+
*/
|
|
51
|
+
export declare function extractEntryDataSync(data: Uint8Array, entry: ZipEntryInfo): Uint8Array;
|
|
52
|
+
/**
|
|
53
|
+
* High-level ZIP parser class
|
|
54
|
+
*/
|
|
55
|
+
export declare class ZipParser {
|
|
56
|
+
private data;
|
|
57
|
+
private entries;
|
|
58
|
+
private entryMap;
|
|
59
|
+
constructor(data: Uint8Array | ArrayBuffer, options?: ZipParseOptions);
|
|
60
|
+
/**
|
|
61
|
+
* Get all entries in the ZIP file
|
|
62
|
+
*/
|
|
63
|
+
getEntries(): ZipEntryInfo[];
|
|
64
|
+
/**
|
|
65
|
+
* Get entry by path
|
|
66
|
+
*/
|
|
67
|
+
getEntry(path: string): ZipEntryInfo | undefined;
|
|
68
|
+
/**
|
|
69
|
+
* Check if entry exists
|
|
70
|
+
*/
|
|
71
|
+
hasEntry(path: string): boolean;
|
|
72
|
+
/**
|
|
73
|
+
* List all file paths
|
|
74
|
+
*/
|
|
75
|
+
listFiles(): string[];
|
|
76
|
+
/**
|
|
77
|
+
* Extract a single file (async)
|
|
78
|
+
*/
|
|
79
|
+
extract(path: string): Promise<Uint8Array | null>;
|
|
80
|
+
/**
|
|
81
|
+
* Extract a single file (sync, Node.js only)
|
|
82
|
+
*/
|
|
83
|
+
extractSync(path: string): Uint8Array | null;
|
|
84
|
+
/**
|
|
85
|
+
* Extract all files (async)
|
|
86
|
+
*/
|
|
87
|
+
extractAll(): Promise<Map<string, Uint8Array>>;
|
|
88
|
+
/**
|
|
89
|
+
* Iterate over entries with async callback
|
|
90
|
+
*/
|
|
91
|
+
forEach(callback: (entry: ZipEntryInfo, getData: () => Promise<Uint8Array>) => Promise<boolean | void>): Promise<void>;
|
|
92
|
+
}
|