@cj-tech-master/excelts 4.2.1-canary.20260111102127.f808a37 → 4.2.1
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/THIRD_PARTY_NOTICES.md +31 -0
- package/dist/browser/index.browser.d.ts +0 -1
- package/dist/browser/index.browser.js +0 -12
- package/dist/browser/modules/archive/byte-queue.d.ts +18 -0
- package/dist/browser/modules/archive/byte-queue.js +125 -0
- package/dist/browser/modules/archive/{compression/compress.base.js → compress.base.js} +1 -1
- package/dist/browser/modules/archive/{compression/compress.browser.d.ts → compress.browser.d.ts} +8 -2
- package/dist/{esm/modules/archive/compression → browser/modules/archive}/compress.browser.js +11 -3
- package/dist/browser/modules/archive/{compression/compress.d.ts → compress.d.ts} +2 -2
- package/dist/{esm/modules/archive/compression → browser/modules/archive}/compress.js +1 -1
- package/dist/browser/modules/archive/{compression/crc32.browser.d.ts → crc32.browser.d.ts} +1 -1
- package/dist/browser/modules/archive/{compression/crc32.d.ts → crc32.d.ts} +1 -1
- package/dist/browser/modules/archive/{compression/crc32.js → crc32.js} +1 -1
- package/dist/browser/modules/archive/defaults.d.ts +0 -1
- package/dist/browser/modules/archive/defaults.js +3 -6
- package/dist/browser/modules/archive/{compression/deflate-fallback.js → deflate-fallback.js} +1 -1
- package/dist/browser/modules/archive/{unzip/extract.d.ts → extract.d.ts} +2 -2
- package/dist/browser/modules/archive/index.base.d.ts +4 -4
- package/dist/browser/modules/archive/index.base.js +6 -3
- package/dist/browser/modules/archive/index.browser.d.ts +4 -3
- package/dist/browser/modules/archive/index.browser.js +7 -3
- package/dist/browser/modules/archive/index.d.ts +4 -3
- package/dist/browser/modules/archive/index.js +5 -3
- package/dist/browser/modules/archive/{unzip/stream.base.d.ts → parse.base.d.ts} +2 -36
- package/dist/browser/modules/archive/parse.base.js +644 -0
- package/dist/browser/modules/archive/{unzip/stream.browser.d.ts → parse.browser.d.ts} +1 -1
- package/dist/{esm/modules/archive/unzip/stream.browser.js → browser/modules/archive/parse.browser.js} +110 -371
- package/dist/browser/modules/archive/{unzip/stream.d.ts → parse.d.ts} +2 -2
- package/dist/{esm/modules/archive/unzip/stream.js → browser/modules/archive/parse.js} +5 -6
- package/dist/browser/modules/archive/{compression/streaming-compress.browser.d.ts → streaming-compress.browser.d.ts} +2 -2
- package/dist/browser/modules/archive/{compression/streaming-compress.browser.js → streaming-compress.browser.js} +3 -3
- package/dist/browser/modules/archive/{compression/streaming-compress.d.ts → streaming-compress.d.ts} +2 -2
- package/dist/browser/modules/archive/{compression/streaming-compress.js → streaming-compress.js} +2 -2
- package/dist/browser/modules/archive/{zip/stream.d.ts → streaming-zip.d.ts} +5 -28
- package/dist/{esm/modules/archive/zip/stream.js → browser/modules/archive/streaming-zip.js} +48 -192
- package/dist/browser/modules/archive/utils/bytes.js +16 -16
- package/dist/browser/modules/archive/utils/parse-buffer.js +23 -21
- package/dist/browser/modules/archive/utils/timestamps.js +1 -62
- package/dist/browser/modules/archive/utils/zip-extra-fields.d.ts +1 -1
- package/dist/browser/modules/archive/utils/zip-extra-fields.js +14 -26
- package/dist/browser/modules/archive/utils/zip-extra.d.ts +18 -0
- package/dist/browser/modules/archive/utils/zip-extra.js +68 -0
- package/dist/browser/modules/archive/zip-builder.d.ts +117 -0
- package/dist/browser/modules/archive/zip-builder.js +292 -0
- package/dist/browser/modules/archive/zip-constants.d.ts +18 -0
- package/dist/browser/modules/archive/zip-constants.js +23 -0
- package/dist/{esm/modules/archive/zip → browser/modules/archive}/zip-entry-metadata.js +3 -3
- package/dist/{types/modules/archive/unzip → browser/modules/archive}/zip-parser.d.ts +1 -1
- package/dist/{esm/modules/archive/unzip → browser/modules/archive}/zip-parser.js +24 -38
- package/dist/browser/modules/archive/{zip-spec/zip-records.d.ts → zip-records.d.ts} +0 -20
- package/dist/browser/modules/archive/zip-records.js +84 -0
- package/dist/browser/modules/excel/stream/workbook-reader.browser.js +1 -1
- package/dist/browser/modules/excel/stream/workbook-writer.browser.d.ts +1 -1
- package/dist/browser/modules/excel/stream/workbook-writer.browser.js +1 -1
- package/dist/browser/modules/excel/xlsx/xlsx.browser.js +6 -3
- package/dist/browser/modules/excel/xlsx/xlsx.js +1 -1
- package/dist/browser/modules/stream/streams.browser.d.ts +30 -28
- package/dist/browser/modules/stream/streams.browser.js +710 -830
- package/dist/browser/modules/stream/streams.js +58 -140
- package/dist/cjs/modules/archive/byte-queue.js +129 -0
- package/dist/cjs/modules/archive/{compression/compress.base.js → compress.base.js} +1 -1
- package/dist/cjs/modules/archive/{compression/compress.browser.js → compress.browser.js} +11 -3
- package/dist/cjs/modules/archive/{compression/compress.js → compress.js} +1 -1
- package/dist/cjs/modules/archive/{compression/crc32.js → crc32.js} +1 -1
- package/dist/cjs/modules/archive/defaults.js +4 -7
- package/dist/cjs/modules/archive/{compression/deflate-fallback.js → deflate-fallback.js} +1 -1
- package/dist/cjs/modules/archive/index.base.js +19 -9
- package/dist/cjs/modules/archive/index.browser.js +10 -4
- package/dist/cjs/modules/archive/index.js +8 -4
- package/dist/cjs/modules/archive/parse.base.js +666 -0
- package/dist/cjs/modules/archive/{unzip/stream.browser.js → parse.browser.js} +111 -372
- package/dist/cjs/modules/archive/{unzip/stream.js → parse.js} +8 -9
- package/dist/cjs/modules/archive/{compression/streaming-compress.browser.js → streaming-compress.browser.js} +3 -3
- package/dist/cjs/modules/archive/{compression/streaming-compress.js → streaming-compress.js} +2 -2
- package/dist/cjs/modules/archive/{zip/stream.js → streaming-zip.js} +50 -194
- package/dist/cjs/modules/archive/utils/bytes.js +16 -16
- package/dist/cjs/modules/archive/utils/parse-buffer.js +23 -21
- package/dist/cjs/modules/archive/utils/timestamps.js +3 -64
- package/dist/cjs/modules/archive/utils/zip-extra-fields.js +14 -26
- package/dist/cjs/modules/archive/utils/zip-extra.js +74 -0
- package/dist/cjs/modules/archive/zip-builder.js +297 -0
- package/dist/cjs/modules/archive/zip-constants.js +26 -0
- package/dist/cjs/modules/archive/{zip/zip-entry-metadata.js → zip-entry-metadata.js} +5 -5
- package/dist/cjs/modules/archive/{unzip/zip-parser.js → zip-parser.js} +33 -47
- package/dist/cjs/modules/archive/zip-records.js +90 -0
- package/dist/cjs/modules/excel/stream/workbook-reader.browser.js +2 -2
- package/dist/cjs/modules/excel/stream/workbook-writer.browser.js +4 -4
- package/dist/cjs/modules/excel/xlsx/xlsx.browser.js +9 -6
- package/dist/cjs/modules/excel/xlsx/xlsx.js +2 -2
- package/dist/cjs/modules/stream/streams.browser.js +710 -830
- package/dist/cjs/modules/stream/streams.js +58 -140
- package/dist/esm/index.browser.js +0 -12
- package/dist/esm/modules/archive/byte-queue.js +125 -0
- package/dist/esm/modules/archive/{compression/compress.base.js → compress.base.js} +1 -1
- package/dist/{browser/modules/archive/compression → esm/modules/archive}/compress.browser.js +11 -3
- package/dist/{browser/modules/archive/compression → esm/modules/archive}/compress.js +1 -1
- package/dist/esm/modules/archive/{compression/crc32.js → crc32.js} +1 -1
- package/dist/esm/modules/archive/defaults.js +3 -6
- package/dist/esm/modules/archive/{compression/deflate-fallback.js → deflate-fallback.js} +1 -1
- package/dist/esm/modules/archive/index.base.js +6 -3
- package/dist/esm/modules/archive/index.browser.js +7 -3
- package/dist/esm/modules/archive/index.js +5 -3
- package/dist/esm/modules/archive/parse.base.js +644 -0
- package/dist/{browser/modules/archive/unzip/stream.browser.js → esm/modules/archive/parse.browser.js} +110 -371
- package/dist/{browser/modules/archive/unzip/stream.js → esm/modules/archive/parse.js} +5 -6
- package/dist/esm/modules/archive/{compression/streaming-compress.browser.js → streaming-compress.browser.js} +3 -3
- package/dist/esm/modules/archive/{compression/streaming-compress.js → streaming-compress.js} +2 -2
- package/dist/{browser/modules/archive/zip/stream.js → esm/modules/archive/streaming-zip.js} +48 -192
- package/dist/esm/modules/archive/utils/bytes.js +16 -16
- package/dist/esm/modules/archive/utils/parse-buffer.js +23 -21
- package/dist/esm/modules/archive/utils/timestamps.js +1 -62
- package/dist/esm/modules/archive/utils/zip-extra-fields.js +14 -26
- package/dist/esm/modules/archive/utils/zip-extra.js +68 -0
- package/dist/esm/modules/archive/zip-builder.js +292 -0
- package/dist/esm/modules/archive/zip-constants.js +23 -0
- package/dist/{browser/modules/archive/zip → esm/modules/archive}/zip-entry-metadata.js +3 -3
- package/dist/{browser/modules/archive/unzip → esm/modules/archive}/zip-parser.js +24 -38
- package/dist/esm/modules/archive/zip-records.js +84 -0
- package/dist/esm/modules/excel/stream/workbook-reader.browser.js +1 -1
- package/dist/esm/modules/excel/stream/workbook-writer.browser.js +1 -1
- package/dist/esm/modules/excel/xlsx/xlsx.browser.js +6 -3
- package/dist/esm/modules/excel/xlsx/xlsx.js +1 -1
- package/dist/esm/modules/stream/streams.browser.js +710 -830
- package/dist/esm/modules/stream/streams.js +58 -140
- package/dist/iife/THIRD_PARTY_NOTICES.md +31 -0
- package/dist/iife/excelts.iife.js +4425 -6215
- package/dist/iife/excelts.iife.js.map +1 -1
- package/dist/iife/excelts.iife.min.js +31 -103
- package/dist/types/index.browser.d.ts +0 -1
- package/dist/types/modules/archive/byte-queue.d.ts +18 -0
- package/dist/types/modules/archive/{compression/compress.browser.d.ts → compress.browser.d.ts} +8 -2
- package/dist/types/modules/archive/defaults.d.ts +0 -1
- package/dist/types/modules/archive/index.base.d.ts +4 -4
- package/dist/types/modules/archive/index.browser.d.ts +4 -3
- package/dist/types/modules/archive/index.d.ts +4 -3
- package/dist/types/modules/archive/{unzip/stream.base.d.ts → parse.base.d.ts} +4 -38
- package/dist/types/modules/archive/{unzip/stream.browser.d.ts → parse.browser.d.ts} +2 -2
- package/dist/types/modules/archive/{unzip/stream.d.ts → parse.d.ts} +3 -3
- package/dist/types/modules/archive/{compression/streaming-compress.browser.d.ts → streaming-compress.browser.d.ts} +1 -1
- package/dist/types/modules/archive/{zip/stream.d.ts → streaming-zip.d.ts} +6 -29
- package/dist/types/modules/archive/utils/zip-extra-fields.d.ts +1 -1
- package/dist/types/modules/archive/utils/zip-extra.d.ts +18 -0
- package/dist/types/modules/archive/zip-builder.d.ts +117 -0
- package/dist/types/modules/archive/zip-constants.d.ts +18 -0
- package/dist/types/modules/archive/{zip/zip-entry-metadata.d.ts → zip-entry-metadata.d.ts} +1 -1
- package/dist/{browser/modules/archive/unzip → types/modules/archive}/zip-parser.d.ts +1 -1
- package/dist/types/modules/archive/{zip-spec/zip-records.d.ts → zip-records.d.ts} +0 -20
- package/dist/types/modules/excel/stream/workbook-writer.browser.d.ts +1 -1
- package/dist/types/modules/stream/streams.browser.d.ts +30 -28
- package/package.json +1 -5
- package/dist/browser/modules/archive/internal/byte-queue.d.ts +0 -33
- package/dist/browser/modules/archive/internal/byte-queue.js +0 -407
- package/dist/browser/modules/archive/io/archive-sink.d.ts +0 -9
- package/dist/browser/modules/archive/io/archive-sink.js +0 -77
- package/dist/browser/modules/archive/io/archive-source.d.ts +0 -8
- package/dist/browser/modules/archive/io/archive-source.js +0 -107
- package/dist/browser/modules/archive/unzip/index.d.ts +0 -40
- package/dist/browser/modules/archive/unzip/index.js +0 -164
- package/dist/browser/modules/archive/unzip/stream.base.js +0 -1022
- package/dist/browser/modules/archive/utils/async-queue.d.ts +0 -7
- package/dist/browser/modules/archive/utils/async-queue.js +0 -103
- package/dist/browser/modules/archive/utils/compressibility.d.ts +0 -10
- package/dist/browser/modules/archive/utils/compressibility.js +0 -57
- package/dist/browser/modules/archive/utils/pattern-scanner.d.ts +0 -21
- package/dist/browser/modules/archive/utils/pattern-scanner.js +0 -27
- package/dist/browser/modules/archive/zip/index.d.ts +0 -42
- package/dist/browser/modules/archive/zip/index.js +0 -157
- package/dist/browser/modules/archive/zip/zip-bytes.d.ts +0 -73
- package/dist/browser/modules/archive/zip/zip-bytes.js +0 -239
- package/dist/browser/modules/archive/zip-spec/zip-records.js +0 -126
- package/dist/cjs/modules/archive/internal/byte-queue.js +0 -411
- package/dist/cjs/modules/archive/io/archive-sink.js +0 -82
- package/dist/cjs/modules/archive/io/archive-source.js +0 -114
- package/dist/cjs/modules/archive/unzip/index.js +0 -170
- package/dist/cjs/modules/archive/unzip/stream.base.js +0 -1044
- package/dist/cjs/modules/archive/utils/async-queue.js +0 -106
- package/dist/cjs/modules/archive/utils/compressibility.js +0 -60
- package/dist/cjs/modules/archive/utils/pattern-scanner.js +0 -31
- package/dist/cjs/modules/archive/zip/index.js +0 -162
- package/dist/cjs/modules/archive/zip/zip-bytes.js +0 -242
- package/dist/cjs/modules/archive/zip-spec/zip-records.js +0 -136
- package/dist/esm/modules/archive/internal/byte-queue.js +0 -407
- package/dist/esm/modules/archive/io/archive-sink.js +0 -77
- package/dist/esm/modules/archive/io/archive-source.js +0 -107
- package/dist/esm/modules/archive/unzip/index.js +0 -164
- package/dist/esm/modules/archive/unzip/stream.base.js +0 -1022
- package/dist/esm/modules/archive/utils/async-queue.js +0 -103
- package/dist/esm/modules/archive/utils/compressibility.js +0 -57
- package/dist/esm/modules/archive/utils/pattern-scanner.js +0 -27
- package/dist/esm/modules/archive/zip/index.js +0 -157
- package/dist/esm/modules/archive/zip/zip-bytes.js +0 -239
- package/dist/esm/modules/archive/zip-spec/zip-records.js +0 -126
- package/dist/types/modules/archive/internal/byte-queue.d.ts +0 -33
- package/dist/types/modules/archive/io/archive-sink.d.ts +0 -9
- package/dist/types/modules/archive/io/archive-source.d.ts +0 -8
- package/dist/types/modules/archive/unzip/index.d.ts +0 -40
- package/dist/types/modules/archive/utils/async-queue.d.ts +0 -7
- package/dist/types/modules/archive/utils/compressibility.d.ts +0 -10
- package/dist/types/modules/archive/utils/pattern-scanner.d.ts +0 -21
- package/dist/types/modules/archive/zip/index.d.ts +0 -42
- package/dist/types/modules/archive/zip/zip-bytes.d.ts +0 -73
- /package/dist/browser/modules/archive/{compression/compress.base.d.ts → compress.base.d.ts} +0 -0
- /package/dist/browser/modules/archive/{compression/crc32.base.d.ts → crc32.base.d.ts} +0 -0
- /package/dist/browser/modules/archive/{compression/crc32.base.js → crc32.base.js} +0 -0
- /package/dist/browser/modules/archive/{compression/crc32.browser.js → crc32.browser.js} +0 -0
- /package/dist/browser/modules/archive/{compression/deflate-fallback.d.ts → deflate-fallback.d.ts} +0 -0
- /package/dist/browser/modules/archive/{unzip/extract.js → extract.js} +0 -0
- /package/dist/browser/modules/archive/{compression/streaming-compress.base.d.ts → streaming-compress.base.d.ts} +0 -0
- /package/dist/browser/modules/archive/{compression/streaming-compress.base.js → streaming-compress.base.js} +0 -0
- /package/dist/browser/modules/archive/{zip-spec/zip-entry-info.d.ts → zip-entry-info.d.ts} +0 -0
- /package/dist/browser/modules/archive/{zip-spec/zip-entry-info.js → zip-entry-info.js} +0 -0
- /package/dist/browser/modules/archive/{zip/zip-entry-metadata.d.ts → zip-entry-metadata.d.ts} +0 -0
- /package/dist/cjs/modules/archive/{compression/crc32.base.js → crc32.base.js} +0 -0
- /package/dist/cjs/modules/archive/{compression/crc32.browser.js → crc32.browser.js} +0 -0
- /package/dist/cjs/modules/archive/{unzip/extract.js → extract.js} +0 -0
- /package/dist/cjs/modules/archive/{compression/streaming-compress.base.js → streaming-compress.base.js} +0 -0
- /package/dist/cjs/modules/archive/{zip-spec/zip-entry-info.js → zip-entry-info.js} +0 -0
- /package/dist/esm/modules/archive/{compression/crc32.base.js → crc32.base.js} +0 -0
- /package/dist/esm/modules/archive/{compression/crc32.browser.js → crc32.browser.js} +0 -0
- /package/dist/esm/modules/archive/{unzip/extract.js → extract.js} +0 -0
- /package/dist/esm/modules/archive/{compression/streaming-compress.base.js → streaming-compress.base.js} +0 -0
- /package/dist/esm/modules/archive/{zip-spec/zip-entry-info.js → zip-entry-info.js} +0 -0
- /package/dist/types/modules/archive/{compression/compress.base.d.ts → compress.base.d.ts} +0 -0
- /package/dist/types/modules/archive/{compression/compress.d.ts → compress.d.ts} +0 -0
- /package/dist/types/modules/archive/{compression/crc32.base.d.ts → crc32.base.d.ts} +0 -0
- /package/dist/types/modules/archive/{compression/crc32.browser.d.ts → crc32.browser.d.ts} +0 -0
- /package/dist/types/modules/archive/{compression/crc32.d.ts → crc32.d.ts} +0 -0
- /package/dist/types/modules/archive/{compression/deflate-fallback.d.ts → deflate-fallback.d.ts} +0 -0
- /package/dist/types/modules/archive/{unzip/extract.d.ts → extract.d.ts} +0 -0
- /package/dist/types/modules/archive/{compression/streaming-compress.base.d.ts → streaming-compress.base.d.ts} +0 -0
- /package/dist/types/modules/archive/{compression/streaming-compress.d.ts → streaming-compress.d.ts} +0 -0
- /package/dist/types/modules/archive/{zip-spec/zip-entry-info.d.ts → zip-entry-info.d.ts} +0 -0
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import { encodeUtf8 } from "../utils/text.js";
|
|
2
|
-
export function isReadableStream(value) {
|
|
3
|
-
return !!value && typeof value === "object" && typeof value.getReader === "function";
|
|
4
|
-
}
|
|
5
|
-
export function isAsyncIterable(value) {
|
|
6
|
-
return (!!value &&
|
|
7
|
-
(typeof value === "object" || typeof value === "function") &&
|
|
8
|
-
typeof value[Symbol.asyncIterator] === "function");
|
|
9
|
-
}
|
|
10
|
-
function normalizeChunk(value) {
|
|
11
|
-
if (!value) {
|
|
12
|
-
return null;
|
|
13
|
-
}
|
|
14
|
-
if (value instanceof Uint8Array) {
|
|
15
|
-
return value.length ? value : null;
|
|
16
|
-
}
|
|
17
|
-
if (typeof value === "string") {
|
|
18
|
-
const bytes = encodeUtf8(value);
|
|
19
|
-
return bytes.length ? bytes : null;
|
|
20
|
-
}
|
|
21
|
-
if (value instanceof ArrayBuffer) {
|
|
22
|
-
return value.byteLength ? new Uint8Array(value) : null;
|
|
23
|
-
}
|
|
24
|
-
if (ArrayBuffer.isView(value)) {
|
|
25
|
-
return value.byteLength
|
|
26
|
-
? new Uint8Array(value.buffer, value.byteOffset, value.byteLength)
|
|
27
|
-
: null;
|
|
28
|
-
}
|
|
29
|
-
// Best-effort: treat unknown chunk as Uint8Array-like.
|
|
30
|
-
if (typeof value.length === "number" && value.length) {
|
|
31
|
-
return value;
|
|
32
|
-
}
|
|
33
|
-
return null;
|
|
34
|
-
}
|
|
35
|
-
export function toUint8ArraySync(source) {
|
|
36
|
-
if (source instanceof Uint8Array) {
|
|
37
|
-
return source;
|
|
38
|
-
}
|
|
39
|
-
if (typeof source === "string") {
|
|
40
|
-
return encodeUtf8(source);
|
|
41
|
-
}
|
|
42
|
-
return new Uint8Array(source);
|
|
43
|
-
}
|
|
44
|
-
export async function toUint8Array(source) {
|
|
45
|
-
if (source instanceof Uint8Array) {
|
|
46
|
-
return source;
|
|
47
|
-
}
|
|
48
|
-
if (typeof source === "string") {
|
|
49
|
-
return encodeUtf8(source);
|
|
50
|
-
}
|
|
51
|
-
if (source instanceof ArrayBuffer) {
|
|
52
|
-
return new Uint8Array(source);
|
|
53
|
-
}
|
|
54
|
-
const buf = await source.arrayBuffer();
|
|
55
|
-
return new Uint8Array(buf);
|
|
56
|
-
}
|
|
57
|
-
export async function* toAsyncIterable(source) {
|
|
58
|
-
if (source instanceof Uint8Array) {
|
|
59
|
-
yield source;
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
if (typeof source === "string") {
|
|
63
|
-
yield encodeUtf8(source);
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
if (source instanceof ArrayBuffer) {
|
|
67
|
-
yield new Uint8Array(source);
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
if (typeof Blob !== "undefined" && source instanceof Blob) {
|
|
71
|
-
yield await toUint8Array(source);
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
if (isReadableStream(source)) {
|
|
75
|
-
const reader = source.getReader();
|
|
76
|
-
try {
|
|
77
|
-
while (true) {
|
|
78
|
-
const { done, value } = await reader.read();
|
|
79
|
-
if (done) {
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
const chunk = normalizeChunk(value);
|
|
83
|
-
if (chunk) {
|
|
84
|
-
yield chunk;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
finally {
|
|
89
|
-
try {
|
|
90
|
-
reader.releaseLock();
|
|
91
|
-
}
|
|
92
|
-
catch {
|
|
93
|
-
// Ignore
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
if (isAsyncIterable(source)) {
|
|
98
|
-
for await (const value of source) {
|
|
99
|
-
const chunk = normalizeChunk(value);
|
|
100
|
-
if (chunk) {
|
|
101
|
-
yield chunk;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
|
-
throw new Error("Unsupported archive source");
|
|
107
|
-
}
|
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
import { ZipParser } from "./zip-parser.js";
|
|
2
|
-
import { createParse } from "./stream.js";
|
|
3
|
-
import { pipeIterableToSink } from "../io/archive-sink.js";
|
|
4
|
-
import { toAsyncIterable, toUint8Array } from "../io/archive-source.js";
|
|
5
|
-
const textDecoderCache = new Map();
|
|
6
|
-
function getTextDecoder(encoding) {
|
|
7
|
-
const key = encoding ?? "utf-8";
|
|
8
|
-
const cached = textDecoderCache.get(key);
|
|
9
|
-
if (cached) {
|
|
10
|
-
return cached;
|
|
11
|
-
}
|
|
12
|
-
const decoder = new TextDecoder(key);
|
|
13
|
-
textDecoderCache.set(key, decoder);
|
|
14
|
-
return decoder;
|
|
15
|
-
}
|
|
16
|
-
export class UnzipEntry {
|
|
17
|
-
constructor(args) {
|
|
18
|
-
if (args.kind === "buffer") {
|
|
19
|
-
this._parser = args.parser;
|
|
20
|
-
this._info = args.info;
|
|
21
|
-
this.path = args.info.path;
|
|
22
|
-
this.isDirectory = args.info.isDirectory;
|
|
23
|
-
}
|
|
24
|
-
else {
|
|
25
|
-
this._parseEntry = args.entry;
|
|
26
|
-
this.path = args.entry.path;
|
|
27
|
-
this.isDirectory = args.entry.type === "Directory";
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
async bytes() {
|
|
31
|
-
if (this._parser && this._info) {
|
|
32
|
-
const out = await this._parser.extract(this._info.path);
|
|
33
|
-
return out ?? new Uint8Array(0);
|
|
34
|
-
}
|
|
35
|
-
if (this._parseEntry) {
|
|
36
|
-
const data = await this._parseEntry.buffer();
|
|
37
|
-
// In Node.js, `entry.buffer()` may return a Buffer, which causes
|
|
38
|
-
// deep-equality mismatches against Uint8Array in tests.
|
|
39
|
-
if (typeof Buffer !== "undefined" && data instanceof Buffer) {
|
|
40
|
-
return new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
|
|
41
|
-
}
|
|
42
|
-
return data;
|
|
43
|
-
}
|
|
44
|
-
return new Uint8Array(0);
|
|
45
|
-
}
|
|
46
|
-
async *stream() {
|
|
47
|
-
if (this._parser && this._info) {
|
|
48
|
-
const data = await this.bytes();
|
|
49
|
-
if (data.length) {
|
|
50
|
-
yield data;
|
|
51
|
-
}
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
if (this._parseEntry) {
|
|
55
|
-
for await (const chunk of this._parseEntry) {
|
|
56
|
-
yield chunk;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
async pipeTo(sink) {
|
|
61
|
-
await pipeIterableToSink(this.stream(), sink);
|
|
62
|
-
}
|
|
63
|
-
async text(encoding) {
|
|
64
|
-
const bytes = await this.bytes();
|
|
65
|
-
return getTextDecoder(encoding).decode(bytes);
|
|
66
|
-
}
|
|
67
|
-
discard() {
|
|
68
|
-
if (this._parseEntry) {
|
|
69
|
-
this._parseEntry.autodrain();
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
export class ZipReader {
|
|
74
|
-
constructor(source, options = {}) {
|
|
75
|
-
this._bufferParser = null;
|
|
76
|
-
this._source = source;
|
|
77
|
-
this._options = options;
|
|
78
|
-
}
|
|
79
|
-
async _ensureBufferParser() {
|
|
80
|
-
if (this._bufferParser) {
|
|
81
|
-
return this._bufferParser;
|
|
82
|
-
}
|
|
83
|
-
if (this._source instanceof Uint8Array ||
|
|
84
|
-
this._source instanceof ArrayBuffer ||
|
|
85
|
-
typeof this._source === "string" ||
|
|
86
|
-
(typeof Blob !== "undefined" && this._source instanceof Blob)) {
|
|
87
|
-
const bytes = await toUint8Array(this._source);
|
|
88
|
-
this._bufferParser = new ZipParser(bytes, {
|
|
89
|
-
decodeStrings: this._options.decodeStrings
|
|
90
|
-
});
|
|
91
|
-
return this._bufferParser;
|
|
92
|
-
}
|
|
93
|
-
throw new Error("This ZIP source is streaming; random access is not available");
|
|
94
|
-
}
|
|
95
|
-
async get(path) {
|
|
96
|
-
const parser = await this._ensureBufferParser();
|
|
97
|
-
const info = parser.getEntry(path);
|
|
98
|
-
if (!info) {
|
|
99
|
-
return null;
|
|
100
|
-
}
|
|
101
|
-
return new UnzipEntry({ kind: "buffer", parser, info });
|
|
102
|
-
}
|
|
103
|
-
async *entries() {
|
|
104
|
-
// Buffer mode
|
|
105
|
-
if (this._source instanceof Uint8Array ||
|
|
106
|
-
this._source instanceof ArrayBuffer ||
|
|
107
|
-
typeof this._source === "string" ||
|
|
108
|
-
(typeof Blob !== "undefined" && this._source instanceof Blob)) {
|
|
109
|
-
const parser = await this._ensureBufferParser();
|
|
110
|
-
for (const info of parser.getEntries()) {
|
|
111
|
-
yield new UnzipEntry({ kind: "buffer", parser, info });
|
|
112
|
-
}
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
// Streaming mode
|
|
116
|
-
// Always prefer forceStream mode for backpressure and bounded buffering.
|
|
117
|
-
const parse = createParse({ ...(this._options.parse ?? {}), forceStream: true });
|
|
118
|
-
const feedPromise = (async () => {
|
|
119
|
-
try {
|
|
120
|
-
for await (const chunk of toAsyncIterable(this._source)) {
|
|
121
|
-
await new Promise((resolve, reject) => {
|
|
122
|
-
parse.write(chunk, (err) => {
|
|
123
|
-
if (err) {
|
|
124
|
-
reject(err);
|
|
125
|
-
}
|
|
126
|
-
else {
|
|
127
|
-
resolve();
|
|
128
|
-
}
|
|
129
|
-
});
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
parse.end();
|
|
133
|
-
await parse.promise();
|
|
134
|
-
}
|
|
135
|
-
catch (e) {
|
|
136
|
-
parse.destroy(e instanceof Error ? e : new Error(String(e)));
|
|
137
|
-
throw e;
|
|
138
|
-
}
|
|
139
|
-
})();
|
|
140
|
-
try {
|
|
141
|
-
for await (const entry of parse) {
|
|
142
|
-
yield new UnzipEntry({ kind: "stream", entry });
|
|
143
|
-
}
|
|
144
|
-
await feedPromise;
|
|
145
|
-
}
|
|
146
|
-
finally {
|
|
147
|
-
// Ensure the feed task does not get stranded.
|
|
148
|
-
await feedPromise.catch(() => { });
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
async bytes(path) {
|
|
152
|
-
const entry = await this.get(path);
|
|
153
|
-
if (!entry) {
|
|
154
|
-
return null;
|
|
155
|
-
}
|
|
156
|
-
return entry.bytes();
|
|
157
|
-
}
|
|
158
|
-
async close() {
|
|
159
|
-
// No persistent resources in buffer mode.
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
export function unzip(source, options) {
|
|
163
|
-
return new ZipReader(source, options);
|
|
164
|
-
}
|