@cj-tech-master/excelts 1.4.5-canary.20251212143538.45665af → 1.4.5-canary.20251212160853.7621827
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 +1 -1
- package/dist/browser/excelts.iife.min.js +1 -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/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/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
|
@@ -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
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cj-tech-master/excelts",
|
|
3
|
-
"version": "1.4.5-canary.
|
|
3
|
+
"version": "1.4.5-canary.20251212160853.7621827",
|
|
4
4
|
"description": "TypeScript Excel Workbook Manager - Read and Write xlsx and csv Files.",
|
|
5
5
|
"private": false,
|
|
6
6
|
"publishConfig": {
|