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