@cj-tech-master/excelts 4.2.0 → 4.2.1-canary.20260111102127.f808a37
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 +0 -31
- package/dist/browser/index.browser.d.ts +1 -0
- package/dist/browser/index.browser.js +12 -0
- package/dist/{types/modules/archive → browser/modules/archive/compression}/compress.base.d.ts +1 -0
- package/dist/browser/modules/archive/{compress.base.js → compression/compress.base.js} +2 -1
- package/dist/{types/modules/archive → browser/modules/archive/compression}/compress.browser.d.ts +10 -8
- package/dist/{esm/modules/archive → browser/modules/archive/compression}/compress.browser.js +18 -19
- package/dist/browser/modules/archive/{compress.d.ts → compression/compress.d.ts} +2 -2
- package/dist/browser/modules/archive/{compress.js → compression/compress.js} +1 -1
- package/dist/browser/modules/archive/{crc32.browser.d.ts → compression/crc32.browser.d.ts} +1 -1
- package/dist/browser/modules/archive/{crc32.d.ts → compression/crc32.d.ts} +1 -1
- package/dist/browser/modules/archive/{crc32.js → compression/crc32.js} +1 -1
- package/dist/browser/modules/archive/{deflate-fallback.js → compression/deflate-fallback.js} +1 -1
- package/dist/browser/modules/archive/{streaming-compress.browser.d.ts → compression/streaming-compress.browser.d.ts} +2 -2
- package/dist/browser/modules/archive/{streaming-compress.browser.js → compression/streaming-compress.browser.js} +3 -3
- package/dist/browser/modules/archive/{streaming-compress.d.ts → compression/streaming-compress.d.ts} +2 -2
- package/dist/browser/modules/archive/{streaming-compress.js → compression/streaming-compress.js} +2 -2
- package/dist/browser/modules/archive/defaults.d.ts +1 -0
- package/dist/browser/modules/archive/defaults.js +6 -3
- package/dist/browser/modules/archive/index.base.d.ts +4 -4
- package/dist/browser/modules/archive/index.base.js +3 -6
- package/dist/browser/modules/archive/index.browser.d.ts +3 -4
- package/dist/browser/modules/archive/index.browser.js +3 -7
- package/dist/browser/modules/archive/index.d.ts +3 -4
- package/dist/browser/modules/archive/index.js +3 -5
- package/dist/browser/modules/archive/internal/byte-queue.d.ts +33 -0
- package/dist/browser/modules/archive/internal/byte-queue.js +407 -0
- package/dist/browser/modules/archive/io/archive-sink.d.ts +9 -0
- package/dist/browser/modules/archive/io/archive-sink.js +77 -0
- package/dist/browser/modules/archive/io/archive-source.d.ts +8 -0
- package/dist/browser/modules/archive/io/archive-source.js +107 -0
- package/dist/browser/modules/archive/{extract.d.ts → unzip/extract.d.ts} +2 -2
- package/dist/browser/modules/archive/unzip/index.d.ts +40 -0
- package/dist/browser/modules/archive/unzip/index.js +164 -0
- package/dist/browser/modules/archive/{parse.base.d.ts → unzip/stream.base.d.ts} +58 -3
- package/dist/browser/modules/archive/unzip/stream.base.js +1022 -0
- package/dist/browser/modules/archive/{parse.browser.d.ts → unzip/stream.browser.d.ts} +1 -1
- package/dist/browser/modules/archive/{parse.browser.js → unzip/stream.browser.js} +376 -110
- package/dist/browser/modules/archive/{parse.d.ts → unzip/stream.d.ts} +2 -2
- package/dist/{esm/modules/archive/parse.js → browser/modules/archive/unzip/stream.js} +7 -6
- package/dist/{types/modules/archive → browser/modules/archive/unzip}/zip-parser.d.ts +1 -1
- package/dist/{esm/modules/archive → browser/modules/archive/unzip}/zip-parser.js +38 -24
- package/dist/browser/modules/archive/utils/async-queue.d.ts +7 -0
- package/dist/browser/modules/archive/utils/async-queue.js +103 -0
- package/dist/browser/modules/archive/utils/bytes.js +16 -16
- package/dist/browser/modules/archive/utils/compressibility.d.ts +10 -0
- package/dist/browser/modules/archive/utils/compressibility.js +57 -0
- package/dist/browser/modules/archive/utils/parse-buffer.js +21 -23
- package/dist/browser/modules/archive/utils/pattern-scanner.d.ts +21 -0
- package/dist/browser/modules/archive/utils/pattern-scanner.js +27 -0
- package/dist/browser/modules/archive/utils/timestamps.js +62 -1
- package/dist/browser/modules/archive/utils/zip-extra-fields.d.ts +1 -1
- package/dist/browser/modules/archive/utils/zip-extra-fields.js +26 -14
- package/dist/browser/modules/archive/zip/index.d.ts +42 -0
- package/dist/browser/modules/archive/zip/index.js +157 -0
- package/dist/browser/modules/archive/{streaming-zip.d.ts → zip/stream.d.ts} +28 -5
- package/dist/browser/modules/archive/{streaming-zip.js → zip/stream.js} +192 -48
- package/dist/browser/modules/archive/zip/zip-bytes.d.ts +73 -0
- package/dist/browser/modules/archive/zip/zip-bytes.js +239 -0
- package/dist/{esm/modules/archive → browser/modules/archive/zip}/zip-entry-metadata.js +3 -3
- package/dist/browser/modules/archive/{zip-records.d.ts → zip-spec/zip-records.d.ts} +20 -0
- package/dist/browser/modules/archive/zip-spec/zip-records.js +126 -0
- package/dist/browser/modules/excel/form-control.d.ts +2 -0
- package/dist/browser/modules/excel/form-control.js +54 -16
- 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/xform/sheet/worksheet-xform.js +17 -3
- package/dist/browser/modules/excel/xlsx/xlsx.browser.js +3 -6
- package/dist/browser/modules/excel/xlsx/xlsx.js +1 -1
- package/dist/browser/modules/stream/streams.browser.d.ts +28 -28
- package/dist/browser/modules/stream/streams.browser.js +850 -697
- package/dist/browser/modules/stream/streams.js +140 -58
- package/dist/cjs/modules/archive/{compress.base.js → compression/compress.base.js} +2 -1
- package/dist/cjs/modules/archive/{compress.browser.js → compression/compress.browser.js} +18 -19
- package/dist/cjs/modules/archive/{compress.js → compression/compress.js} +1 -1
- package/dist/cjs/modules/archive/{crc32.js → compression/crc32.js} +1 -1
- package/dist/cjs/modules/archive/{deflate-fallback.js → compression/deflate-fallback.js} +1 -1
- package/dist/cjs/modules/archive/{streaming-compress.browser.js → compression/streaming-compress.browser.js} +3 -3
- package/dist/cjs/modules/archive/{streaming-compress.js → compression/streaming-compress.js} +2 -2
- package/dist/cjs/modules/archive/defaults.js +7 -4
- package/dist/cjs/modules/archive/index.base.js +9 -19
- package/dist/cjs/modules/archive/index.browser.js +4 -10
- package/dist/cjs/modules/archive/index.js +4 -8
- package/dist/cjs/modules/archive/internal/byte-queue.js +411 -0
- package/dist/cjs/modules/archive/io/archive-sink.js +82 -0
- package/dist/cjs/modules/archive/io/archive-source.js +114 -0
- package/dist/cjs/modules/archive/unzip/index.js +170 -0
- package/dist/cjs/modules/archive/unzip/stream.base.js +1044 -0
- package/dist/cjs/modules/archive/{parse.browser.js → unzip/stream.browser.js} +377 -111
- package/dist/cjs/modules/archive/{parse.js → unzip/stream.js} +9 -8
- package/dist/cjs/modules/archive/{zip-parser.js → unzip/zip-parser.js} +47 -33
- package/dist/cjs/modules/archive/utils/async-queue.js +106 -0
- package/dist/cjs/modules/archive/utils/bytes.js +16 -16
- package/dist/cjs/modules/archive/utils/compressibility.js +60 -0
- package/dist/cjs/modules/archive/utils/parse-buffer.js +21 -23
- package/dist/cjs/modules/archive/utils/pattern-scanner.js +31 -0
- package/dist/cjs/modules/archive/utils/timestamps.js +64 -3
- package/dist/cjs/modules/archive/utils/zip-extra-fields.js +26 -14
- package/dist/cjs/modules/archive/zip/index.js +162 -0
- package/dist/cjs/modules/archive/{streaming-zip.js → zip/stream.js} +194 -50
- package/dist/cjs/modules/archive/zip/zip-bytes.js +242 -0
- package/dist/cjs/modules/archive/{zip-entry-metadata.js → zip/zip-entry-metadata.js} +5 -5
- package/dist/cjs/modules/archive/zip-spec/zip-records.js +136 -0
- package/dist/cjs/modules/excel/form-control.js +54 -16
- 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/xform/sheet/worksheet-xform.js +17 -3
- package/dist/cjs/modules/excel/xlsx/xlsx.browser.js +6 -9
- package/dist/cjs/modules/excel/xlsx/xlsx.js +2 -2
- package/dist/cjs/modules/stream/streams.browser.js +850 -697
- package/dist/cjs/modules/stream/streams.js +140 -58
- package/dist/esm/index.browser.js +12 -0
- package/dist/esm/modules/archive/{compress.base.js → compression/compress.base.js} +2 -1
- package/dist/{browser/modules/archive → esm/modules/archive/compression}/compress.browser.js +18 -19
- package/dist/esm/modules/archive/{compress.js → compression/compress.js} +1 -1
- package/dist/esm/modules/archive/{crc32.js → compression/crc32.js} +1 -1
- package/dist/esm/modules/archive/{deflate-fallback.js → compression/deflate-fallback.js} +1 -1
- package/dist/esm/modules/archive/{streaming-compress.browser.js → compression/streaming-compress.browser.js} +3 -3
- package/dist/esm/modules/archive/{streaming-compress.js → compression/streaming-compress.js} +2 -2
- package/dist/esm/modules/archive/defaults.js +6 -3
- package/dist/esm/modules/archive/index.base.js +3 -6
- package/dist/esm/modules/archive/index.browser.js +3 -7
- package/dist/esm/modules/archive/index.js +3 -5
- package/dist/esm/modules/archive/internal/byte-queue.js +407 -0
- package/dist/esm/modules/archive/io/archive-sink.js +77 -0
- package/dist/esm/modules/archive/io/archive-source.js +107 -0
- package/dist/esm/modules/archive/unzip/index.js +164 -0
- package/dist/esm/modules/archive/unzip/stream.base.js +1022 -0
- package/dist/esm/modules/archive/{parse.browser.js → unzip/stream.browser.js} +376 -110
- package/dist/{browser/modules/archive/parse.js → esm/modules/archive/unzip/stream.js} +7 -6
- package/dist/{browser/modules/archive → esm/modules/archive/unzip}/zip-parser.js +38 -24
- package/dist/esm/modules/archive/utils/async-queue.js +103 -0
- package/dist/esm/modules/archive/utils/bytes.js +16 -16
- package/dist/esm/modules/archive/utils/compressibility.js +57 -0
- package/dist/esm/modules/archive/utils/parse-buffer.js +21 -23
- package/dist/esm/modules/archive/utils/pattern-scanner.js +27 -0
- package/dist/esm/modules/archive/utils/timestamps.js +62 -1
- package/dist/esm/modules/archive/utils/zip-extra-fields.js +26 -14
- package/dist/esm/modules/archive/zip/index.js +157 -0
- package/dist/esm/modules/archive/{streaming-zip.js → zip/stream.js} +192 -48
- package/dist/esm/modules/archive/zip/zip-bytes.js +239 -0
- package/dist/{browser/modules/archive → esm/modules/archive/zip}/zip-entry-metadata.js +3 -3
- package/dist/esm/modules/archive/zip-spec/zip-records.js +126 -0
- package/dist/esm/modules/excel/form-control.js +54 -16
- 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/xform/sheet/worksheet-xform.js +17 -3
- package/dist/esm/modules/excel/xlsx/xlsx.browser.js +3 -6
- package/dist/esm/modules/excel/xlsx/xlsx.js +1 -1
- package/dist/esm/modules/stream/streams.browser.js +850 -697
- package/dist/esm/modules/stream/streams.js +140 -58
- package/dist/iife/THIRD_PARTY_NOTICES.md +81 -0
- package/dist/iife/excelts.iife.js +4777 -2863
- package/dist/iife/excelts.iife.js.map +1 -1
- package/dist/iife/excelts.iife.min.js +103 -31
- package/dist/types/index.browser.d.ts +1 -0
- package/dist/{browser/modules/archive → types/modules/archive/compression}/compress.base.d.ts +1 -0
- package/dist/{browser/modules/archive → types/modules/archive/compression}/compress.browser.d.ts +10 -8
- package/dist/types/modules/archive/{streaming-compress.browser.d.ts → compression/streaming-compress.browser.d.ts} +1 -1
- package/dist/types/modules/archive/defaults.d.ts +1 -0
- package/dist/types/modules/archive/index.base.d.ts +4 -4
- package/dist/types/modules/archive/index.browser.d.ts +3 -4
- package/dist/types/modules/archive/index.d.ts +3 -4
- package/dist/types/modules/archive/internal/byte-queue.d.ts +33 -0
- package/dist/types/modules/archive/io/archive-sink.d.ts +9 -0
- package/dist/types/modules/archive/io/archive-source.d.ts +8 -0
- package/dist/types/modules/archive/unzip/index.d.ts +40 -0
- package/dist/types/modules/archive/{parse.base.d.ts → unzip/stream.base.d.ts} +60 -5
- package/dist/types/modules/archive/{parse.browser.d.ts → unzip/stream.browser.d.ts} +2 -2
- package/dist/types/modules/archive/{parse.d.ts → unzip/stream.d.ts} +3 -3
- package/dist/{browser/modules/archive → types/modules/archive/unzip}/zip-parser.d.ts +1 -1
- package/dist/types/modules/archive/utils/async-queue.d.ts +7 -0
- package/dist/types/modules/archive/utils/compressibility.d.ts +10 -0
- package/dist/types/modules/archive/utils/pattern-scanner.d.ts +21 -0
- package/dist/types/modules/archive/utils/zip-extra-fields.d.ts +1 -1
- package/dist/types/modules/archive/zip/index.d.ts +42 -0
- package/dist/types/modules/archive/{streaming-zip.d.ts → zip/stream.d.ts} +29 -6
- package/dist/types/modules/archive/zip/zip-bytes.d.ts +73 -0
- package/dist/types/modules/archive/{zip-entry-metadata.d.ts → zip/zip-entry-metadata.d.ts} +1 -1
- package/dist/types/modules/archive/{zip-records.d.ts → zip-spec/zip-records.d.ts} +20 -0
- package/dist/types/modules/excel/form-control.d.ts +2 -0
- package/dist/types/modules/excel/stream/workbook-writer.browser.d.ts +1 -1
- package/dist/types/modules/stream/streams.browser.d.ts +28 -28
- package/package.json +10 -6
- package/dist/browser/modules/archive/byte-queue.d.ts +0 -18
- package/dist/browser/modules/archive/byte-queue.js +0 -125
- package/dist/browser/modules/archive/parse.base.js +0 -610
- package/dist/browser/modules/archive/utils/zip-extra.d.ts +0 -18
- package/dist/browser/modules/archive/utils/zip-extra.js +0 -68
- package/dist/browser/modules/archive/zip-builder.d.ts +0 -117
- package/dist/browser/modules/archive/zip-builder.js +0 -292
- package/dist/browser/modules/archive/zip-constants.d.ts +0 -18
- package/dist/browser/modules/archive/zip-constants.js +0 -23
- package/dist/browser/modules/archive/zip-records.js +0 -84
- package/dist/cjs/modules/archive/byte-queue.js +0 -129
- package/dist/cjs/modules/archive/parse.base.js +0 -632
- package/dist/cjs/modules/archive/utils/zip-extra.js +0 -74
- package/dist/cjs/modules/archive/zip-builder.js +0 -297
- package/dist/cjs/modules/archive/zip-constants.js +0 -26
- package/dist/cjs/modules/archive/zip-records.js +0 -90
- package/dist/esm/modules/archive/byte-queue.js +0 -125
- package/dist/esm/modules/archive/parse.base.js +0 -610
- package/dist/esm/modules/archive/utils/zip-extra.js +0 -68
- package/dist/esm/modules/archive/zip-builder.js +0 -292
- package/dist/esm/modules/archive/zip-constants.js +0 -23
- package/dist/esm/modules/archive/zip-records.js +0 -84
- package/dist/types/modules/archive/byte-queue.d.ts +0 -18
- package/dist/types/modules/archive/utils/zip-extra.d.ts +0 -18
- package/dist/types/modules/archive/zip-builder.d.ts +0 -117
- package/dist/types/modules/archive/zip-constants.d.ts +0 -18
- /package/dist/browser/modules/archive/{crc32.base.d.ts → compression/crc32.base.d.ts} +0 -0
- /package/dist/browser/modules/archive/{crc32.base.js → compression/crc32.base.js} +0 -0
- /package/dist/browser/modules/archive/{crc32.browser.js → compression/crc32.browser.js} +0 -0
- /package/dist/browser/modules/archive/{deflate-fallback.d.ts → compression/deflate-fallback.d.ts} +0 -0
- /package/dist/browser/modules/archive/{streaming-compress.base.d.ts → compression/streaming-compress.base.d.ts} +0 -0
- /package/dist/browser/modules/archive/{streaming-compress.base.js → compression/streaming-compress.base.js} +0 -0
- /package/dist/browser/modules/archive/{extract.js → unzip/extract.js} +0 -0
- /package/dist/browser/modules/archive/{zip-entry-metadata.d.ts → zip/zip-entry-metadata.d.ts} +0 -0
- /package/dist/browser/modules/archive/{zip-entry-info.d.ts → zip-spec/zip-entry-info.d.ts} +0 -0
- /package/dist/browser/modules/archive/{zip-entry-info.js → zip-spec/zip-entry-info.js} +0 -0
- /package/dist/cjs/modules/archive/{crc32.base.js → compression/crc32.base.js} +0 -0
- /package/dist/cjs/modules/archive/{crc32.browser.js → compression/crc32.browser.js} +0 -0
- /package/dist/cjs/modules/archive/{streaming-compress.base.js → compression/streaming-compress.base.js} +0 -0
- /package/dist/cjs/modules/archive/{extract.js → unzip/extract.js} +0 -0
- /package/dist/cjs/modules/archive/{zip-entry-info.js → zip-spec/zip-entry-info.js} +0 -0
- /package/dist/esm/modules/archive/{crc32.base.js → compression/crc32.base.js} +0 -0
- /package/dist/esm/modules/archive/{crc32.browser.js → compression/crc32.browser.js} +0 -0
- /package/dist/esm/modules/archive/{streaming-compress.base.js → compression/streaming-compress.base.js} +0 -0
- /package/dist/esm/modules/archive/{extract.js → unzip/extract.js} +0 -0
- /package/dist/esm/modules/archive/{zip-entry-info.js → zip-spec/zip-entry-info.js} +0 -0
- /package/dist/{LICENSE → iife/LICENSE} +0 -0
- /package/dist/types/modules/archive/{compress.d.ts → compression/compress.d.ts} +0 -0
- /package/dist/types/modules/archive/{crc32.base.d.ts → compression/crc32.base.d.ts} +0 -0
- /package/dist/types/modules/archive/{crc32.browser.d.ts → compression/crc32.browser.d.ts} +0 -0
- /package/dist/types/modules/archive/{crc32.d.ts → compression/crc32.d.ts} +0 -0
- /package/dist/types/modules/archive/{deflate-fallback.d.ts → compression/deflate-fallback.d.ts} +0 -0
- /package/dist/types/modules/archive/{streaming-compress.base.d.ts → compression/streaming-compress.base.d.ts} +0 -0
- /package/dist/types/modules/archive/{streaming-compress.d.ts → compression/streaming-compress.d.ts} +0 -0
- /package/dist/types/modules/archive/{extract.d.ts → unzip/extract.d.ts} +0 -0
- /package/dist/types/modules/archive/{zip-entry-info.d.ts → zip-spec/zip-entry-info.d.ts} +0 -0
|
@@ -0,0 +1,411 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ByteQueue = void 0;
|
|
4
|
+
const bytes_1 = require("../utils/bytes.js");
|
|
5
|
+
class ByteQueue {
|
|
6
|
+
constructor(initial) {
|
|
7
|
+
// Store data as immutable chunks to avoid copying on append.
|
|
8
|
+
this._chunks = [];
|
|
9
|
+
this._headOffset = 0;
|
|
10
|
+
this._length = 0;
|
|
11
|
+
// Lazily materialized contiguous view (used only by callers that require a single buffer).
|
|
12
|
+
this._cachedView = null;
|
|
13
|
+
this._cachedLength = 0;
|
|
14
|
+
if (initial && initial.length > 0) {
|
|
15
|
+
this.reset(initial);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
get length() {
|
|
19
|
+
return this._length;
|
|
20
|
+
}
|
|
21
|
+
isEmpty() {
|
|
22
|
+
return this.length === 0;
|
|
23
|
+
}
|
|
24
|
+
view() {
|
|
25
|
+
if (this._length === 0) {
|
|
26
|
+
return ByteQueue.EMPTY;
|
|
27
|
+
}
|
|
28
|
+
// Fast path: single chunk.
|
|
29
|
+
if (this._chunks.length === 1) {
|
|
30
|
+
const c = this._chunks[0];
|
|
31
|
+
return c.subarray(this._headOffset, this._headOffset + this._length);
|
|
32
|
+
}
|
|
33
|
+
if (this._cachedView && this._cachedLength === this._length) {
|
|
34
|
+
return this._cachedView;
|
|
35
|
+
}
|
|
36
|
+
const out = new Uint8Array(this._length);
|
|
37
|
+
let offset = 0;
|
|
38
|
+
for (let i = 0; i < this._chunks.length; i++) {
|
|
39
|
+
const c = this._chunks[i];
|
|
40
|
+
const start = i === 0 ? this._headOffset : 0;
|
|
41
|
+
const end = i === this._chunks.length - 1 ? start + (this._length - offset) : c.length;
|
|
42
|
+
out.set(c.subarray(start, end), offset);
|
|
43
|
+
offset += end - start;
|
|
44
|
+
if (offset >= out.length) {
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
this._cachedView = out;
|
|
49
|
+
this._cachedLength = this._length;
|
|
50
|
+
return out;
|
|
51
|
+
}
|
|
52
|
+
reset(data) {
|
|
53
|
+
this._cachedView = null;
|
|
54
|
+
this._cachedLength = 0;
|
|
55
|
+
this._chunks = [];
|
|
56
|
+
this._headOffset = 0;
|
|
57
|
+
this._length = 0;
|
|
58
|
+
if (!data || data.length === 0) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
// Keep a private copy to ensure future writes cannot mutate the source.
|
|
62
|
+
const copy = new Uint8Array(data.length);
|
|
63
|
+
copy.set(data);
|
|
64
|
+
this._chunks = [copy];
|
|
65
|
+
this._headOffset = 0;
|
|
66
|
+
this._length = copy.length;
|
|
67
|
+
}
|
|
68
|
+
append(chunk) {
|
|
69
|
+
if (chunk.length === 0) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
this._cachedView = null;
|
|
73
|
+
this._cachedLength = 0;
|
|
74
|
+
this._chunks.push(chunk);
|
|
75
|
+
this._length += chunk.length;
|
|
76
|
+
}
|
|
77
|
+
read(length) {
|
|
78
|
+
if (length <= 0) {
|
|
79
|
+
return new Uint8Array(0);
|
|
80
|
+
}
|
|
81
|
+
if (length > this._length) {
|
|
82
|
+
throw new RangeError("ByteQueue: read beyond available data");
|
|
83
|
+
}
|
|
84
|
+
this._cachedView = null;
|
|
85
|
+
this._cachedLength = 0;
|
|
86
|
+
if (this._chunks.length === 1) {
|
|
87
|
+
const c = this._chunks[0];
|
|
88
|
+
const start = this._headOffset;
|
|
89
|
+
const end = start + length;
|
|
90
|
+
const out = c.subarray(start, end);
|
|
91
|
+
this._headOffset = end;
|
|
92
|
+
this._length -= length;
|
|
93
|
+
if (this._length === 0) {
|
|
94
|
+
this._chunks = [];
|
|
95
|
+
this._headOffset = 0;
|
|
96
|
+
}
|
|
97
|
+
else if (this._headOffset >= c.length) {
|
|
98
|
+
this._chunks.shift();
|
|
99
|
+
this._headOffset = 0;
|
|
100
|
+
}
|
|
101
|
+
return out;
|
|
102
|
+
}
|
|
103
|
+
// Slow path: spans multiple chunks, copy into a single output buffer.
|
|
104
|
+
const out = new Uint8Array(length);
|
|
105
|
+
let outOffset = 0;
|
|
106
|
+
let remaining = length;
|
|
107
|
+
while (remaining > 0) {
|
|
108
|
+
const c = this._chunks[0];
|
|
109
|
+
const start = this._headOffset;
|
|
110
|
+
const available = c.length - start;
|
|
111
|
+
const toCopy = Math.min(available, remaining);
|
|
112
|
+
out.set(c.subarray(start, start + toCopy), outOffset);
|
|
113
|
+
outOffset += toCopy;
|
|
114
|
+
remaining -= toCopy;
|
|
115
|
+
this._headOffset += toCopy;
|
|
116
|
+
this._length -= toCopy;
|
|
117
|
+
if (this._headOffset >= c.length) {
|
|
118
|
+
this._chunks.shift();
|
|
119
|
+
this._headOffset = 0;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
if (this._length === 0) {
|
|
123
|
+
this._chunks = [];
|
|
124
|
+
this._headOffset = 0;
|
|
125
|
+
}
|
|
126
|
+
return out;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Return a list of chunk views totaling `length` bytes without consuming.
|
|
130
|
+
*
|
|
131
|
+
* This avoids materializing a contiguous buffer for streaming write paths.
|
|
132
|
+
*/
|
|
133
|
+
peekChunks(length) {
|
|
134
|
+
if (length <= 0) {
|
|
135
|
+
return [];
|
|
136
|
+
}
|
|
137
|
+
if (length > this._length) {
|
|
138
|
+
throw new RangeError("ByteQueue: peek beyond available data");
|
|
139
|
+
}
|
|
140
|
+
// Fast path: single chunk.
|
|
141
|
+
if (this._chunks.length === 1) {
|
|
142
|
+
const c = this._chunks[0];
|
|
143
|
+
const start = this._headOffset;
|
|
144
|
+
return [c.subarray(start, start + length)];
|
|
145
|
+
}
|
|
146
|
+
const parts = [];
|
|
147
|
+
let remaining = length;
|
|
148
|
+
for (let i = 0; i < this._chunks.length && remaining > 0; i++) {
|
|
149
|
+
const c = this._chunks[i];
|
|
150
|
+
const start = i === 0 ? this._headOffset : 0;
|
|
151
|
+
const avail = c.length - start;
|
|
152
|
+
if (avail <= 0) {
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
const toTake = Math.min(avail, remaining);
|
|
156
|
+
parts.push(c.subarray(start, start + toTake));
|
|
157
|
+
remaining -= toTake;
|
|
158
|
+
}
|
|
159
|
+
return parts;
|
|
160
|
+
}
|
|
161
|
+
discard(length) {
|
|
162
|
+
if (length <= 0) {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
if (length >= this._length) {
|
|
166
|
+
this._chunks = [];
|
|
167
|
+
this._headOffset = 0;
|
|
168
|
+
this._length = 0;
|
|
169
|
+
this._cachedView = null;
|
|
170
|
+
this._cachedLength = 0;
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
this._cachedView = null;
|
|
174
|
+
this._cachedLength = 0;
|
|
175
|
+
let remaining = length;
|
|
176
|
+
while (remaining > 0) {
|
|
177
|
+
const c = this._chunks[0];
|
|
178
|
+
const start = this._headOffset;
|
|
179
|
+
const available = c.length - start;
|
|
180
|
+
const toDrop = Math.min(available, remaining);
|
|
181
|
+
this._headOffset += toDrop;
|
|
182
|
+
this._length -= toDrop;
|
|
183
|
+
remaining -= toDrop;
|
|
184
|
+
if (this._headOffset >= c.length) {
|
|
185
|
+
this._chunks.shift();
|
|
186
|
+
this._headOffset = 0;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
if (this._length === 0) {
|
|
190
|
+
this._chunks = [];
|
|
191
|
+
this._headOffset = 0;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Find the first index of `pattern` within the queue.
|
|
196
|
+
*
|
|
197
|
+
* This avoids materializing a contiguous `view()` for common small patterns
|
|
198
|
+
* (ZIP signatures are typically 2-4 bytes).
|
|
199
|
+
*/
|
|
200
|
+
indexOfPattern(pattern, startIndex = 0) {
|
|
201
|
+
const patLen = pattern.length;
|
|
202
|
+
if (patLen === 0) {
|
|
203
|
+
return 0;
|
|
204
|
+
}
|
|
205
|
+
const len = this._length;
|
|
206
|
+
if (patLen > len) {
|
|
207
|
+
return -1;
|
|
208
|
+
}
|
|
209
|
+
let start = startIndex | 0;
|
|
210
|
+
if (start < 0) {
|
|
211
|
+
start = 0;
|
|
212
|
+
}
|
|
213
|
+
if (start > len - patLen) {
|
|
214
|
+
return -1;
|
|
215
|
+
}
|
|
216
|
+
// Fast path: single chunk.
|
|
217
|
+
if (this._chunks.length === 1) {
|
|
218
|
+
const c = this._chunks[0];
|
|
219
|
+
const base = this._headOffset;
|
|
220
|
+
const view = c.subarray(base, base + len);
|
|
221
|
+
// Delegate to native indexOf checks for 1..4 bytes.
|
|
222
|
+
if (patLen === 1) {
|
|
223
|
+
return view.indexOf(pattern[0], start);
|
|
224
|
+
}
|
|
225
|
+
return (0, bytes_1.indexOfUint8ArrayPattern)(view, pattern, start);
|
|
226
|
+
}
|
|
227
|
+
// Multi-chunk: optimize only for very common small patterns.
|
|
228
|
+
if (patLen > 4) {
|
|
229
|
+
// Rare: materialize view.
|
|
230
|
+
const v = this.view();
|
|
231
|
+
return (0, bytes_1.indexOfUint8ArrayPattern)(v, pattern, start);
|
|
232
|
+
}
|
|
233
|
+
const b0 = pattern[0];
|
|
234
|
+
const b1 = patLen >= 2 ? pattern[1] : 0;
|
|
235
|
+
const b2 = patLen >= 3 ? pattern[2] : 0;
|
|
236
|
+
const b3 = patLen >= 4 ? pattern[3] : 0;
|
|
237
|
+
const chunks = this._chunks;
|
|
238
|
+
const peekByteAcrossChunks = (chunkIndex, absoluteIndex) => {
|
|
239
|
+
let ci = chunkIndex;
|
|
240
|
+
let idx = absoluteIndex;
|
|
241
|
+
while (ci < chunks.length) {
|
|
242
|
+
const c = chunks[ci];
|
|
243
|
+
if (idx < c.length) {
|
|
244
|
+
return c[idx] | 0;
|
|
245
|
+
}
|
|
246
|
+
idx -= c.length;
|
|
247
|
+
ci++;
|
|
248
|
+
}
|
|
249
|
+
return null;
|
|
250
|
+
};
|
|
251
|
+
let globalBase = 0;
|
|
252
|
+
for (let ci = 0; ci < chunks.length; ci++) {
|
|
253
|
+
const c = chunks[ci];
|
|
254
|
+
const chunkOffset = ci === 0 ? this._headOffset : 0;
|
|
255
|
+
const chunkLen = c.length - chunkOffset;
|
|
256
|
+
if (chunkLen <= 0) {
|
|
257
|
+
continue;
|
|
258
|
+
}
|
|
259
|
+
const chunkStartGlobal = globalBase;
|
|
260
|
+
const chunkEndGlobal = chunkStartGlobal + chunkLen;
|
|
261
|
+
// Compute local start for this chunk.
|
|
262
|
+
const localStart = start <= chunkStartGlobal
|
|
263
|
+
? chunkOffset
|
|
264
|
+
: start >= chunkEndGlobal
|
|
265
|
+
? c.length
|
|
266
|
+
: chunkOffset + (start - chunkStartGlobal);
|
|
267
|
+
if (localStart > c.length - 1) {
|
|
268
|
+
globalBase += chunkLen;
|
|
269
|
+
continue;
|
|
270
|
+
}
|
|
271
|
+
const lastLocal = c.length - 1;
|
|
272
|
+
let i = c.indexOf(b0, localStart);
|
|
273
|
+
while (i !== -1 && i <= lastLocal) {
|
|
274
|
+
const globalPos = chunkStartGlobal + (i - chunkOffset);
|
|
275
|
+
if (globalPos > len - patLen) {
|
|
276
|
+
return -1;
|
|
277
|
+
}
|
|
278
|
+
if (patLen === 1) {
|
|
279
|
+
return globalPos;
|
|
280
|
+
}
|
|
281
|
+
// Fast path: match stays fully inside the current chunk.
|
|
282
|
+
// Avoid calling peekByte() which walks the chunk list per byte.
|
|
283
|
+
const staysInChunk = i + patLen <= c.length;
|
|
284
|
+
if (staysInChunk) {
|
|
285
|
+
if (c[i + 1] !== b1) {
|
|
286
|
+
i = c.indexOf(b0, i + 1);
|
|
287
|
+
continue;
|
|
288
|
+
}
|
|
289
|
+
if (patLen === 2) {
|
|
290
|
+
return globalPos;
|
|
291
|
+
}
|
|
292
|
+
if (c[i + 2] !== b2) {
|
|
293
|
+
i = c.indexOf(b0, i + 1);
|
|
294
|
+
continue;
|
|
295
|
+
}
|
|
296
|
+
if (patLen === 3) {
|
|
297
|
+
return globalPos;
|
|
298
|
+
}
|
|
299
|
+
if (c[i + 3] !== b3) {
|
|
300
|
+
i = c.indexOf(b0, i + 1);
|
|
301
|
+
continue;
|
|
302
|
+
}
|
|
303
|
+
return globalPos;
|
|
304
|
+
}
|
|
305
|
+
// Slow path: pattern spans chunks.
|
|
306
|
+
const b1v = peekByteAcrossChunks(ci, i + 1);
|
|
307
|
+
if (b1v === null || b1v !== b1) {
|
|
308
|
+
i = c.indexOf(b0, i + 1);
|
|
309
|
+
continue;
|
|
310
|
+
}
|
|
311
|
+
if (patLen === 2) {
|
|
312
|
+
return globalPos;
|
|
313
|
+
}
|
|
314
|
+
const b2v = peekByteAcrossChunks(ci, i + 2);
|
|
315
|
+
if (b2v === null || b2v !== b2) {
|
|
316
|
+
i = c.indexOf(b0, i + 1);
|
|
317
|
+
continue;
|
|
318
|
+
}
|
|
319
|
+
if (patLen === 3) {
|
|
320
|
+
return globalPos;
|
|
321
|
+
}
|
|
322
|
+
const b3v = peekByteAcrossChunks(ci, i + 3);
|
|
323
|
+
if (b3v === null || b3v !== b3) {
|
|
324
|
+
i = c.indexOf(b0, i + 1);
|
|
325
|
+
continue;
|
|
326
|
+
}
|
|
327
|
+
return globalPos;
|
|
328
|
+
}
|
|
329
|
+
globalBase += chunkLen;
|
|
330
|
+
}
|
|
331
|
+
return -1;
|
|
332
|
+
}
|
|
333
|
+
/** Peek a little-endian uint32 at `offset` without consuming bytes. Returns null if not enough bytes. */
|
|
334
|
+
peekUint32LE(offset) {
|
|
335
|
+
const off = offset | 0;
|
|
336
|
+
if (off < 0 || off + 4 > this._length) {
|
|
337
|
+
return null;
|
|
338
|
+
}
|
|
339
|
+
// Try to read contiguously from a single chunk to avoid 4x chunk-walk.
|
|
340
|
+
const chunks = this._chunks;
|
|
341
|
+
let remaining = off;
|
|
342
|
+
for (let i = 0; i < chunks.length; i++) {
|
|
343
|
+
const c = chunks[i];
|
|
344
|
+
const start = i === 0 ? this._headOffset : 0;
|
|
345
|
+
const avail = c.length - start;
|
|
346
|
+
if (remaining < avail) {
|
|
347
|
+
const idx = start + remaining;
|
|
348
|
+
if (idx + 4 <= c.length) {
|
|
349
|
+
const b0 = c[idx] | 0;
|
|
350
|
+
const b1 = c[idx + 1] | 0;
|
|
351
|
+
const b2 = c[idx + 2] | 0;
|
|
352
|
+
const b3 = c[idx + 3] | 0;
|
|
353
|
+
return (b0 | (b1 << 8) | (b2 << 16) | (b3 << 24)) >>> 0;
|
|
354
|
+
}
|
|
355
|
+
// Cross-chunk read (rare): walk forward across chunks once.
|
|
356
|
+
const b0 = c[idx] | 0;
|
|
357
|
+
let b1 = 0;
|
|
358
|
+
let b2 = 0;
|
|
359
|
+
let b3 = 0;
|
|
360
|
+
let ci = i;
|
|
361
|
+
let pos = idx + 1;
|
|
362
|
+
for (let k = 1; k < 4; k++) {
|
|
363
|
+
while (ci < chunks.length) {
|
|
364
|
+
const cc = chunks[ci];
|
|
365
|
+
if (pos < cc.length) {
|
|
366
|
+
const v = cc[pos] | 0;
|
|
367
|
+
if (k === 1) {
|
|
368
|
+
b1 = v;
|
|
369
|
+
}
|
|
370
|
+
else if (k === 2) {
|
|
371
|
+
b2 = v;
|
|
372
|
+
}
|
|
373
|
+
else {
|
|
374
|
+
b3 = v;
|
|
375
|
+
}
|
|
376
|
+
pos++;
|
|
377
|
+
break;
|
|
378
|
+
}
|
|
379
|
+
ci++;
|
|
380
|
+
pos = 0;
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
return (b0 | (b1 << 8) | (b2 << 16) | (b3 << 24)) >>> 0;
|
|
384
|
+
}
|
|
385
|
+
remaining -= avail;
|
|
386
|
+
}
|
|
387
|
+
// Should be unreachable due to bounds check above.
|
|
388
|
+
return null;
|
|
389
|
+
}
|
|
390
|
+
/** Peek a single byte at `offset` without consuming bytes. */
|
|
391
|
+
peekByte(offset) {
|
|
392
|
+
const off = offset | 0;
|
|
393
|
+
if (off < 0 || off >= this._length) {
|
|
394
|
+
throw new RangeError("ByteQueue: peek beyond available data");
|
|
395
|
+
}
|
|
396
|
+
let remaining = off;
|
|
397
|
+
for (let i = 0; i < this._chunks.length; i++) {
|
|
398
|
+
const c = this._chunks[i];
|
|
399
|
+
const start = i === 0 ? this._headOffset : 0;
|
|
400
|
+
const avail = c.length - start;
|
|
401
|
+
if (remaining < avail) {
|
|
402
|
+
return c[start + remaining] | 0;
|
|
403
|
+
}
|
|
404
|
+
remaining -= avail;
|
|
405
|
+
}
|
|
406
|
+
// Should be unreachable.
|
|
407
|
+
throw new RangeError("ByteQueue: peek beyond available data");
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
exports.ByteQueue = ByteQueue;
|
|
411
|
+
ByteQueue.EMPTY = new Uint8Array(0);
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isWritableStream = isWritableStream;
|
|
4
|
+
exports.pipeIterableToSink = pipeIterableToSink;
|
|
5
|
+
exports.collect = collect;
|
|
6
|
+
function isWritableStream(value) {
|
|
7
|
+
return !!value && typeof value === "object" && typeof value.getWriter === "function";
|
|
8
|
+
}
|
|
9
|
+
function once(emitter, event) {
|
|
10
|
+
return new Promise((resolve, reject) => {
|
|
11
|
+
const onError = (err) => {
|
|
12
|
+
cleanup();
|
|
13
|
+
reject(err instanceof Error ? err : new Error(String(err)));
|
|
14
|
+
};
|
|
15
|
+
const onDone = () => {
|
|
16
|
+
cleanup();
|
|
17
|
+
resolve();
|
|
18
|
+
};
|
|
19
|
+
const cleanup = () => {
|
|
20
|
+
emitter.off?.("error", onError);
|
|
21
|
+
emitter.off?.(event, onDone);
|
|
22
|
+
emitter.removeListener?.("error", onError);
|
|
23
|
+
emitter.removeListener?.(event, onDone);
|
|
24
|
+
};
|
|
25
|
+
emitter.on?.("error", onError);
|
|
26
|
+
emitter.on?.(event, onDone);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
async function pipeIterableToSink(iterable, sink) {
|
|
30
|
+
if (isWritableStream(sink)) {
|
|
31
|
+
const writer = sink.getWriter();
|
|
32
|
+
try {
|
|
33
|
+
for await (const chunk of iterable) {
|
|
34
|
+
await writer.write(chunk);
|
|
35
|
+
}
|
|
36
|
+
await writer.close();
|
|
37
|
+
}
|
|
38
|
+
finally {
|
|
39
|
+
try {
|
|
40
|
+
writer.releaseLock();
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
// Ignore
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
// Node-style Writable
|
|
49
|
+
for await (const chunk of iterable) {
|
|
50
|
+
const ok = sink.write(chunk);
|
|
51
|
+
if (ok === false && typeof sink.once === "function") {
|
|
52
|
+
await once(sink, "drain");
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (typeof sink.end === "function") {
|
|
56
|
+
sink.end();
|
|
57
|
+
}
|
|
58
|
+
if (typeof sink.once === "function") {
|
|
59
|
+
await Promise.race([once(sink, "finish"), once(sink, "close")]);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
async function collect(iterable) {
|
|
63
|
+
const chunks = [];
|
|
64
|
+
let total = 0;
|
|
65
|
+
for await (const chunk of iterable) {
|
|
66
|
+
chunks.push(chunk);
|
|
67
|
+
total += chunk.length;
|
|
68
|
+
}
|
|
69
|
+
if (chunks.length === 0) {
|
|
70
|
+
return new Uint8Array(0);
|
|
71
|
+
}
|
|
72
|
+
if (chunks.length === 1) {
|
|
73
|
+
return chunks[0];
|
|
74
|
+
}
|
|
75
|
+
const out = new Uint8Array(total);
|
|
76
|
+
let offset = 0;
|
|
77
|
+
for (const chunk of chunks) {
|
|
78
|
+
out.set(chunk, offset);
|
|
79
|
+
offset += chunk.length;
|
|
80
|
+
}
|
|
81
|
+
return out;
|
|
82
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isReadableStream = isReadableStream;
|
|
4
|
+
exports.isAsyncIterable = isAsyncIterable;
|
|
5
|
+
exports.toUint8ArraySync = toUint8ArraySync;
|
|
6
|
+
exports.toUint8Array = toUint8Array;
|
|
7
|
+
exports.toAsyncIterable = toAsyncIterable;
|
|
8
|
+
const text_1 = require("../utils/text.js");
|
|
9
|
+
function isReadableStream(value) {
|
|
10
|
+
return !!value && typeof value === "object" && typeof value.getReader === "function";
|
|
11
|
+
}
|
|
12
|
+
function isAsyncIterable(value) {
|
|
13
|
+
return (!!value &&
|
|
14
|
+
(typeof value === "object" || typeof value === "function") &&
|
|
15
|
+
typeof value[Symbol.asyncIterator] === "function");
|
|
16
|
+
}
|
|
17
|
+
function normalizeChunk(value) {
|
|
18
|
+
if (!value) {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
if (value instanceof Uint8Array) {
|
|
22
|
+
return value.length ? value : null;
|
|
23
|
+
}
|
|
24
|
+
if (typeof value === "string") {
|
|
25
|
+
const bytes = (0, text_1.encodeUtf8)(value);
|
|
26
|
+
return bytes.length ? bytes : null;
|
|
27
|
+
}
|
|
28
|
+
if (value instanceof ArrayBuffer) {
|
|
29
|
+
return value.byteLength ? new Uint8Array(value) : null;
|
|
30
|
+
}
|
|
31
|
+
if (ArrayBuffer.isView(value)) {
|
|
32
|
+
return value.byteLength
|
|
33
|
+
? new Uint8Array(value.buffer, value.byteOffset, value.byteLength)
|
|
34
|
+
: null;
|
|
35
|
+
}
|
|
36
|
+
// Best-effort: treat unknown chunk as Uint8Array-like.
|
|
37
|
+
if (typeof value.length === "number" && value.length) {
|
|
38
|
+
return value;
|
|
39
|
+
}
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
function toUint8ArraySync(source) {
|
|
43
|
+
if (source instanceof Uint8Array) {
|
|
44
|
+
return source;
|
|
45
|
+
}
|
|
46
|
+
if (typeof source === "string") {
|
|
47
|
+
return (0, text_1.encodeUtf8)(source);
|
|
48
|
+
}
|
|
49
|
+
return new Uint8Array(source);
|
|
50
|
+
}
|
|
51
|
+
async function toUint8Array(source) {
|
|
52
|
+
if (source instanceof Uint8Array) {
|
|
53
|
+
return source;
|
|
54
|
+
}
|
|
55
|
+
if (typeof source === "string") {
|
|
56
|
+
return (0, text_1.encodeUtf8)(source);
|
|
57
|
+
}
|
|
58
|
+
if (source instanceof ArrayBuffer) {
|
|
59
|
+
return new Uint8Array(source);
|
|
60
|
+
}
|
|
61
|
+
const buf = await source.arrayBuffer();
|
|
62
|
+
return new Uint8Array(buf);
|
|
63
|
+
}
|
|
64
|
+
async function* toAsyncIterable(source) {
|
|
65
|
+
if (source instanceof Uint8Array) {
|
|
66
|
+
yield source;
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
if (typeof source === "string") {
|
|
70
|
+
yield (0, text_1.encodeUtf8)(source);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if (source instanceof ArrayBuffer) {
|
|
74
|
+
yield new Uint8Array(source);
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
if (typeof Blob !== "undefined" && source instanceof Blob) {
|
|
78
|
+
yield await toUint8Array(source);
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
if (isReadableStream(source)) {
|
|
82
|
+
const reader = source.getReader();
|
|
83
|
+
try {
|
|
84
|
+
while (true) {
|
|
85
|
+
const { done, value } = await reader.read();
|
|
86
|
+
if (done) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
const chunk = normalizeChunk(value);
|
|
90
|
+
if (chunk) {
|
|
91
|
+
yield chunk;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
finally {
|
|
96
|
+
try {
|
|
97
|
+
reader.releaseLock();
|
|
98
|
+
}
|
|
99
|
+
catch {
|
|
100
|
+
// Ignore
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
if (isAsyncIterable(source)) {
|
|
105
|
+
for await (const value of source) {
|
|
106
|
+
const chunk = normalizeChunk(value);
|
|
107
|
+
if (chunk) {
|
|
108
|
+
yield chunk;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
throw new Error("Unsupported archive source");
|
|
114
|
+
}
|