@cj-tech-master/excelts 4.2.0 → 4.2.1-canary.20260112134913.a3cecdd
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 +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} +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/utils/ooxml-validator.d.ts +48 -0
- package/dist/browser/modules/excel/utils/ooxml-validator.js +469 -0
- package/dist/browser/modules/excel/worksheet.js +5 -2
- 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/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 +117 -5
- 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/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 -42
- package/dist/browser/modules/stream/streams.browser.js +941 -823
- 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} +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 +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} +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/utils/ooxml-validator.js +475 -0
- package/dist/cjs/modules/excel/worksheet.js +5 -2
- 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/sheet/page-setup-xform.js +16 -2
- package/dist/cjs/modules/excel/xlsx/xform/sheet/worksheet-xform.js +117 -5
- 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/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 +947 -834
- 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/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 +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} +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/utils/ooxml-validator.js +469 -0
- package/dist/esm/modules/excel/worksheet.js +5 -2
- 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/sheet/page-setup-xform.js +16 -2
- package/dist/esm/modules/excel/xlsx/xform/sheet/worksheet-xform.js +117 -5
- 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/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 +941 -823
- 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 +81 -0
- package/dist/iife/excelts.iife.js +4979 -2800
- 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 +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} +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/excel/utils/ooxml-validator.d.ts +48 -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 -42
- package/dist/types/modules/stream/streams.d.ts +4 -20
- package/package.json +19 -15
- 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
|
@@ -7,18 +7,16 @@ exports.Parse = void 0;
|
|
|
7
7
|
exports.createParseClass = createParseClass;
|
|
8
8
|
exports.createParse = createParse;
|
|
9
9
|
const zlib_1 = __importDefault(require("zlib"));
|
|
10
|
-
const
|
|
11
|
-
const parse_base_1 = require("./parse.base.js");
|
|
12
|
-
const zip_constants_1 = require("./zip-constants.js");
|
|
10
|
+
const stream_base_1 = require("./stream.base.js");
|
|
13
11
|
/**
|
|
14
12
|
* Creates an InflateRaw stream using Node.js native zlib.
|
|
15
13
|
*/
|
|
16
14
|
function createInflateRaw() {
|
|
17
15
|
return zlib_1.default.createInflateRaw();
|
|
18
16
|
}
|
|
19
|
-
const dataDescriptorSignature =
|
|
17
|
+
const dataDescriptorSignature = stream_base_1.DATA_DESCRIPTOR_SIGNATURE_BYTES;
|
|
20
18
|
function createParseClass(createInflateRawFn) {
|
|
21
|
-
return class Parse extends
|
|
19
|
+
return class Parse extends stream_base_1.PullStream {
|
|
22
20
|
constructor(opts = {}) {
|
|
23
21
|
super();
|
|
24
22
|
this._driverState = {};
|
|
@@ -58,7 +56,7 @@ function createParseClass(createInflateRawFn) {
|
|
|
58
56
|
}
|
|
59
57
|
};
|
|
60
58
|
// Parse records as data arrives. Only emit `close` when parsing is complete.
|
|
61
|
-
(0,
|
|
59
|
+
(0, stream_base_1.runParseLoop)(this._opts, io, emitter, createInflateRawFn, this._driverState, (data) => zlib_1.default.inflateRawSync(data)).catch((e) => {
|
|
62
60
|
if (!this.__emittedError || this.__emittedError !== e) {
|
|
63
61
|
this.emit("error", e);
|
|
64
62
|
}
|
|
@@ -69,11 +67,14 @@ function createParseClass(createInflateRawFn) {
|
|
|
69
67
|
* Stream file data until we reach a DATA_DESCRIPTOR record boundary.
|
|
70
68
|
*/
|
|
71
69
|
_streamUntilValidatedDataDescriptor() {
|
|
72
|
-
return (0,
|
|
70
|
+
return (0, stream_base_1.streamUntilValidatedDataDescriptor)({
|
|
73
71
|
source: {
|
|
74
|
-
getView: () => this._queue.view(),
|
|
75
72
|
getLength: () => this._queue.length,
|
|
76
73
|
read: (length) => this._queue.read(length),
|
|
74
|
+
peekChunks: (length) => this._queue.peekChunks(length),
|
|
75
|
+
discard: (length) => this._queue.discard(length),
|
|
76
|
+
indexOfPattern: (pattern, startIndex) => this._queue.indexOfPattern(pattern, startIndex),
|
|
77
|
+
peekUint32LE: (offset) => this._queue.peekUint32LE(offset),
|
|
77
78
|
isFinished: () => this.finished,
|
|
78
79
|
onDataAvailable: (cb) => {
|
|
79
80
|
this.on("chunk", cb);
|
|
@@ -6,11 +6,11 @@
|
|
|
6
6
|
*/
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
8
|
exports.ZipParser = void 0;
|
|
9
|
-
const compress_1 = require("
|
|
10
|
-
const binary_1 = require("
|
|
11
|
-
const timestamps_1 = require("
|
|
12
|
-
const zip_extra_fields_1 = require("
|
|
13
|
-
const
|
|
9
|
+
const compress_1 = require("../compression/compress.js");
|
|
10
|
+
const binary_1 = require("../utils/binary.js");
|
|
11
|
+
const timestamps_1 = require("../utils/timestamps.js");
|
|
12
|
+
const zip_extra_fields_1 = require("../utils/zip-extra-fields.js");
|
|
13
|
+
const zip_records_1 = require("../zip-spec/zip-records.js");
|
|
14
14
|
/**
|
|
15
15
|
* Find the End of Central Directory record
|
|
16
16
|
* Searches backwards from the end of the file
|
|
@@ -19,9 +19,13 @@ function findEndOfCentralDir(data) {
|
|
|
19
19
|
// EOCD is at least 22 bytes, search backwards
|
|
20
20
|
// Comment can be up to 65535 bytes
|
|
21
21
|
const minOffset = Math.max(0, data.length - 65557);
|
|
22
|
-
|
|
22
|
+
// Signature bytes (little-endian): 0x06054b50 -> 50 4b 05 06
|
|
23
|
+
const b0 = 0x50;
|
|
24
|
+
const b1 = 0x4b;
|
|
25
|
+
const b2 = 0x05;
|
|
26
|
+
const b3 = 0x06;
|
|
23
27
|
for (let i = data.length - 22; i >= minOffset; i--) {
|
|
24
|
-
if (
|
|
28
|
+
if (data[i] === b0 && data[i + 1] === b1 && data[i + 2] === b2 && data[i + 3] === b3) {
|
|
25
29
|
return i;
|
|
26
30
|
}
|
|
27
31
|
}
|
|
@@ -36,8 +40,11 @@ function findZip64EOCDLocator(data, eocdOffset) {
|
|
|
36
40
|
if (locatorOffset < 0) {
|
|
37
41
|
return -1;
|
|
38
42
|
}
|
|
39
|
-
|
|
40
|
-
if (
|
|
43
|
+
// Signature bytes (little-endian): 0x07064b50 -> 50 4b 06 07
|
|
44
|
+
if (data[locatorOffset] === 0x50 &&
|
|
45
|
+
data[locatorOffset + 1] === 0x4b &&
|
|
46
|
+
data[locatorOffset + 2] === 0x06 &&
|
|
47
|
+
data[locatorOffset + 3] === 0x07) {
|
|
41
48
|
return locatorOffset;
|
|
42
49
|
}
|
|
43
50
|
return -1;
|
|
@@ -47,7 +54,7 @@ function findZip64EOCDLocator(data, eocdOffset) {
|
|
|
47
54
|
*/
|
|
48
55
|
function parseZipEntries(data, options = {}) {
|
|
49
56
|
const { decodeStrings = true } = options;
|
|
50
|
-
|
|
57
|
+
let entries = [];
|
|
51
58
|
// Find End of Central Directory
|
|
52
59
|
const eocdOffset = findEndOfCentralDir(data);
|
|
53
60
|
if (eocdOffset === -1) {
|
|
@@ -81,7 +88,7 @@ function parseZipEntries(data, options = {}) {
|
|
|
81
88
|
// Read ZIP64 EOCD
|
|
82
89
|
const zip64Reader = new binary_1.BinaryReader(data, zip64EOCDOffset);
|
|
83
90
|
const zip64Sig = zip64Reader.readUint32();
|
|
84
|
-
if (zip64Sig ===
|
|
91
|
+
if (zip64Sig === zip_records_1.ZIP64_END_OF_CENTRAL_DIR_SIG) {
|
|
85
92
|
zip64Reader.skip(8); // size of ZIP64 EOCD
|
|
86
93
|
zip64Reader.skip(2); // version made by
|
|
87
94
|
zip64Reader.skip(2); // version needed
|
|
@@ -91,19 +98,23 @@ function parseZipEntries(data, options = {}) {
|
|
|
91
98
|
zip64Reader.skip(8); // central directory size (unused)
|
|
92
99
|
const zip64CentralDirOffset = Number(zip64Reader.readBigUint64());
|
|
93
100
|
// Use ZIP64 values if standard values are maxed out
|
|
94
|
-
if (totalEntries ===
|
|
101
|
+
if (totalEntries === zip_records_1.UINT16_MAX) {
|
|
95
102
|
totalEntries = zip64TotalEntries;
|
|
96
103
|
}
|
|
97
|
-
if (centralDirOffset ===
|
|
104
|
+
if (centralDirOffset === zip_records_1.UINT32_MAX) {
|
|
98
105
|
centralDirOffset = zip64CentralDirOffset;
|
|
99
106
|
}
|
|
100
107
|
}
|
|
101
108
|
}
|
|
109
|
+
// Preallocate to avoid repeated array growth on large archives.
|
|
110
|
+
if (totalEntries > 0) {
|
|
111
|
+
entries = new Array(totalEntries);
|
|
112
|
+
}
|
|
102
113
|
// Read Central Directory entries
|
|
103
114
|
const centralReader = new binary_1.BinaryReader(data, centralDirOffset);
|
|
104
115
|
for (let i = 0; i < totalEntries; i++) {
|
|
105
116
|
const sig = centralReader.readUint32();
|
|
106
|
-
if (sig !==
|
|
117
|
+
if (sig !== zip_records_1.CENTRAL_DIR_HEADER_SIG) {
|
|
107
118
|
throw new Error(`Invalid Central Directory header signature at entry ${i}`);
|
|
108
119
|
}
|
|
109
120
|
// Central Directory File Header format:
|
|
@@ -147,23 +158,26 @@ function parseZipEntries(data, options = {}) {
|
|
|
147
158
|
// Check for UTF-8 flag (bit 11)
|
|
148
159
|
const isUtf8 = (flags & 0x800) !== 0;
|
|
149
160
|
const useUtf8 = decodeStrings && isUtf8;
|
|
150
|
-
const fileName = centralReader.readString(fileNameLength, useUtf8);
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
161
|
+
const fileName = fileNameLength > 0 ? centralReader.readString(fileNameLength, useUtf8) : "";
|
|
162
|
+
let extraFields = {};
|
|
163
|
+
if (extraFieldLength > 0) {
|
|
164
|
+
const extraField = centralReader.readBytes(extraFieldLength);
|
|
165
|
+
const vars = {
|
|
166
|
+
compressedSize,
|
|
167
|
+
uncompressedSize,
|
|
168
|
+
offsetToLocalFileHeader: localHeaderOffset
|
|
169
|
+
};
|
|
170
|
+
extraFields = (0, zip_extra_fields_1.parseZipExtraFields)(extraField, vars);
|
|
171
|
+
compressedSize = vars.compressedSize;
|
|
172
|
+
uncompressedSize = vars.uncompressedSize;
|
|
173
|
+
localHeaderOffset = vars.offsetToLocalFileHeader ?? localHeaderOffset;
|
|
174
|
+
}
|
|
175
|
+
const comment = commentLength > 0 ? centralReader.readString(commentLength, useUtf8) : "";
|
|
162
176
|
const isDirectory = fileName.endsWith("/") || (externalAttributes & 0x10) !== 0;
|
|
163
177
|
const isEncrypted = (flags & 0x01) !== 0;
|
|
164
178
|
const unixSecondsMtime = extraFields.mtimeUnixSeconds;
|
|
165
179
|
const lastModified = (0, timestamps_1.resolveZipLastModifiedDateFromUnixSeconds)(lastModDate, lastModTime, unixSecondsMtime);
|
|
166
|
-
entries
|
|
180
|
+
entries[i] = {
|
|
167
181
|
path: fileName,
|
|
168
182
|
isDirectory,
|
|
169
183
|
compressedSize,
|
|
@@ -175,7 +189,7 @@ function parseZipEntries(data, options = {}) {
|
|
|
175
189
|
comment,
|
|
176
190
|
externalAttributes,
|
|
177
191
|
isEncrypted
|
|
178
|
-
}
|
|
192
|
+
};
|
|
179
193
|
}
|
|
180
194
|
return entries;
|
|
181
195
|
}
|
|
@@ -190,10 +204,10 @@ async function extractEntryData(data, entry) {
|
|
|
190
204
|
throw new Error(`File "${entry.path}" is encrypted and cannot be extracted`);
|
|
191
205
|
}
|
|
192
206
|
const compressedData = readEntryCompressedData(data, entry);
|
|
193
|
-
if (entry.compressionMethod ===
|
|
207
|
+
if (entry.compressionMethod === zip_records_1.COMPRESSION_STORE) {
|
|
194
208
|
return compressedData;
|
|
195
209
|
}
|
|
196
|
-
if (entry.compressionMethod ===
|
|
210
|
+
if (entry.compressionMethod === zip_records_1.COMPRESSION_DEFLATE) {
|
|
197
211
|
return (0, compress_1.decompress)(compressedData);
|
|
198
212
|
}
|
|
199
213
|
throw new Error(`Unsupported compression method: ${entry.compressionMethod}`);
|
|
@@ -209,10 +223,10 @@ function extractEntryDataSync(data, entry) {
|
|
|
209
223
|
throw new Error(`File "${entry.path}" is encrypted and cannot be extracted`);
|
|
210
224
|
}
|
|
211
225
|
const compressedData = readEntryCompressedData(data, entry);
|
|
212
|
-
if (entry.compressionMethod ===
|
|
226
|
+
if (entry.compressionMethod === zip_records_1.COMPRESSION_STORE) {
|
|
213
227
|
return compressedData;
|
|
214
228
|
}
|
|
215
|
-
if (entry.compressionMethod ===
|
|
229
|
+
if (entry.compressionMethod === zip_records_1.COMPRESSION_DEFLATE) {
|
|
216
230
|
return (0, compress_1.decompressSync)(compressedData);
|
|
217
231
|
}
|
|
218
232
|
throw new Error(`Unsupported compression method: ${entry.compressionMethod}`);
|
|
@@ -220,7 +234,7 @@ function extractEntryDataSync(data, entry) {
|
|
|
220
234
|
function readEntryCompressedData(data, entry) {
|
|
221
235
|
const reader = new binary_1.BinaryReader(data, entry.localHeaderOffset);
|
|
222
236
|
const sig = reader.readUint32();
|
|
223
|
-
if (sig !==
|
|
237
|
+
if (sig !== zip_records_1.LOCAL_FILE_HEADER_SIG) {
|
|
224
238
|
throw new Error(`Invalid local file header signature for "${entry.path}"`);
|
|
225
239
|
}
|
|
226
240
|
reader.skip(2); // version needed
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createAsyncQueue = createAsyncQueue;
|
|
4
|
+
function createAsyncQueue() {
|
|
5
|
+
const values = [];
|
|
6
|
+
let valuesHead = 0;
|
|
7
|
+
const waiters = [];
|
|
8
|
+
let waitersHead = 0;
|
|
9
|
+
let done = false;
|
|
10
|
+
let error = null;
|
|
11
|
+
const maybeCompact = () => {
|
|
12
|
+
// Prevent unbounded growth of the underlying arrays.
|
|
13
|
+
if (valuesHead > 1024 && valuesHead * 2 > values.length) {
|
|
14
|
+
values.splice(0, valuesHead);
|
|
15
|
+
valuesHead = 0;
|
|
16
|
+
}
|
|
17
|
+
if (waitersHead > 1024 && waitersHead * 2 > waiters.length) {
|
|
18
|
+
waiters.splice(0, waitersHead);
|
|
19
|
+
waitersHead = 0;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
const shiftWaiter = () => {
|
|
23
|
+
while (waitersHead < waiters.length) {
|
|
24
|
+
const w = waiters[waitersHead];
|
|
25
|
+
waiters[waitersHead] = undefined;
|
|
26
|
+
waitersHead++;
|
|
27
|
+
if (w) {
|
|
28
|
+
maybeCompact();
|
|
29
|
+
return w;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
maybeCompact();
|
|
33
|
+
return undefined;
|
|
34
|
+
};
|
|
35
|
+
const shiftValue = () => {
|
|
36
|
+
while (valuesHead < values.length) {
|
|
37
|
+
const v = values[valuesHead];
|
|
38
|
+
values[valuesHead] = undefined;
|
|
39
|
+
valuesHead++;
|
|
40
|
+
if (v !== undefined) {
|
|
41
|
+
maybeCompact();
|
|
42
|
+
return v;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
maybeCompact();
|
|
46
|
+
return undefined;
|
|
47
|
+
};
|
|
48
|
+
const push = (value) => {
|
|
49
|
+
if (done || error) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
const waiter = shiftWaiter();
|
|
53
|
+
if (waiter) {
|
|
54
|
+
waiter.resolve({ value, done: false });
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
values.push(value);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
const fail = (err) => {
|
|
61
|
+
if (done || error) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
error = err;
|
|
65
|
+
while (true) {
|
|
66
|
+
const waiter = shiftWaiter();
|
|
67
|
+
if (!waiter) {
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
waiter.reject(err);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
const close = () => {
|
|
74
|
+
if (done || error) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
done = true;
|
|
78
|
+
while (true) {
|
|
79
|
+
const waiter = shiftWaiter();
|
|
80
|
+
if (!waiter) {
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
waiter.resolve({ value: undefined, done: true });
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
const iterable = {
|
|
87
|
+
[Symbol.asyncIterator]() {
|
|
88
|
+
return {
|
|
89
|
+
next() {
|
|
90
|
+
if (error) {
|
|
91
|
+
return Promise.reject(error);
|
|
92
|
+
}
|
|
93
|
+
const value = shiftValue();
|
|
94
|
+
if (value !== undefined) {
|
|
95
|
+
return Promise.resolve({ value, done: false });
|
|
96
|
+
}
|
|
97
|
+
if (done) {
|
|
98
|
+
return Promise.resolve({ value: undefined, done: true });
|
|
99
|
+
}
|
|
100
|
+
return new Promise((resolve, reject) => waiters.push({ resolve, reject }));
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
return { push, fail, close, iterable };
|
|
106
|
+
}
|
|
@@ -50,21 +50,18 @@ function indexOfUint8ArrayPattern(buffer, pattern, startIndex = 0) {
|
|
|
50
50
|
}
|
|
51
51
|
// Fast paths for small patterns (very common in ZIP parsing: 2/3/4-byte signatures).
|
|
52
52
|
if (patLen === 1) {
|
|
53
|
-
|
|
54
|
-
for (let i = start; i < bufLen; i++) {
|
|
55
|
-
if (buffer[i] === p0) {
|
|
56
|
-
return i;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
return -1;
|
|
53
|
+
return buffer.indexOf(pattern[0], start);
|
|
60
54
|
}
|
|
61
55
|
if (patLen === 2) {
|
|
62
56
|
const p0 = pattern[0];
|
|
63
57
|
const p1 = pattern[1];
|
|
64
|
-
|
|
65
|
-
|
|
58
|
+
const last = bufLen - 2;
|
|
59
|
+
let i = buffer.indexOf(p0, start);
|
|
60
|
+
while (i !== -1 && i <= last) {
|
|
61
|
+
if (buffer[i + 1] === p1) {
|
|
66
62
|
return i;
|
|
67
63
|
}
|
|
64
|
+
i = buffer.indexOf(p0, i + 1);
|
|
68
65
|
}
|
|
69
66
|
return -1;
|
|
70
67
|
}
|
|
@@ -72,10 +69,13 @@ function indexOfUint8ArrayPattern(buffer, pattern, startIndex = 0) {
|
|
|
72
69
|
const p0 = pattern[0];
|
|
73
70
|
const p1 = pattern[1];
|
|
74
71
|
const p2 = pattern[2];
|
|
75
|
-
|
|
76
|
-
|
|
72
|
+
const last = bufLen - 3;
|
|
73
|
+
let i = buffer.indexOf(p0, start);
|
|
74
|
+
while (i !== -1 && i <= last) {
|
|
75
|
+
if (buffer[i + 1] === p1 && buffer[i + 2] === p2) {
|
|
77
76
|
return i;
|
|
78
77
|
}
|
|
78
|
+
i = buffer.indexOf(p0, i + 1);
|
|
79
79
|
}
|
|
80
80
|
return -1;
|
|
81
81
|
}
|
|
@@ -84,13 +84,13 @@ function indexOfUint8ArrayPattern(buffer, pattern, startIndex = 0) {
|
|
|
84
84
|
const p1 = pattern[1];
|
|
85
85
|
const p2 = pattern[2];
|
|
86
86
|
const p3 = pattern[3];
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
buffer[i + 3] === p3) {
|
|
87
|
+
const last = bufLen - 4;
|
|
88
|
+
let i = buffer.indexOf(p0, start);
|
|
89
|
+
while (i !== -1 && i <= last) {
|
|
90
|
+
if (buffer[i + 1] === p1 && buffer[i + 2] === p2 && buffer[i + 3] === p3) {
|
|
92
91
|
return i;
|
|
93
92
|
}
|
|
93
|
+
i = buffer.indexOf(p0, i + 1);
|
|
94
94
|
}
|
|
95
95
|
return -1;
|
|
96
96
|
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isProbablyIncompressible = isProbablyIncompressible;
|
|
4
|
+
const DEFAULT_SAMPLE_BYTES = 64 * 1024;
|
|
5
|
+
const MIN_DECISION_BYTES = 16 * 1024;
|
|
6
|
+
function log2(x) {
|
|
7
|
+
return Math.log(x) / Math.LN2;
|
|
8
|
+
}
|
|
9
|
+
function shannonEntropy(bytes) {
|
|
10
|
+
const counts = new Uint32Array(256);
|
|
11
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
12
|
+
counts[bytes[i]] += 1;
|
|
13
|
+
}
|
|
14
|
+
let entropy = 0;
|
|
15
|
+
const total = bytes.length;
|
|
16
|
+
for (let i = 0; i < 256; i++) {
|
|
17
|
+
const count = counts[i];
|
|
18
|
+
if (count === 0) {
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
const p = count / total;
|
|
22
|
+
entropy -= p * log2(p);
|
|
23
|
+
}
|
|
24
|
+
return entropy;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Heuristic: detect incompressible (high-entropy) data.
|
|
28
|
+
*
|
|
29
|
+
* This is a performance optimization: if data looks random, DEFLATE usually
|
|
30
|
+
* wastes CPU and may even produce slightly larger output.
|
|
31
|
+
*/
|
|
32
|
+
function isProbablyIncompressible(data, options = {}) {
|
|
33
|
+
const sampleBytes = options.sampleBytes ?? DEFAULT_SAMPLE_BYTES;
|
|
34
|
+
const minDecisionBytes = options.minDecisionBytes ?? MIN_DECISION_BYTES;
|
|
35
|
+
const len = Math.min(data.length, sampleBytes);
|
|
36
|
+
if (len < minDecisionBytes) {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
const sample = data.subarray(0, len);
|
|
40
|
+
// Fast-ish early filter: if there are too few unique bytes, it's probably compressible.
|
|
41
|
+
// (e.g. text, repeated patterns)
|
|
42
|
+
const seen = new Uint8Array(256);
|
|
43
|
+
let unique = 0;
|
|
44
|
+
for (let i = 0; i < sample.length; i++) {
|
|
45
|
+
const b = sample[i];
|
|
46
|
+
if (seen[b] === 0) {
|
|
47
|
+
seen[b] = 1;
|
|
48
|
+
unique += 1;
|
|
49
|
+
if (unique >= 200) {
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (unique < 200) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
// Shannon entropy in bits/byte; random tends to ~8.
|
|
58
|
+
// Threshold picked to be conservative.
|
|
59
|
+
return shannonEntropy(sample) >= 7.95;
|
|
60
|
+
}
|
|
@@ -2,28 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parse = parse;
|
|
4
4
|
exports.parseTyped = parseTyped;
|
|
5
|
-
/**
|
|
6
|
-
* Read unsigned little-endian integer from Uint8Array
|
|
7
|
-
*/
|
|
8
|
-
function readUIntLE(buffer, offset, size) {
|
|
9
|
-
const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
10
|
-
switch (size) {
|
|
11
|
-
case 1:
|
|
12
|
-
return view.getUint8(offset);
|
|
13
|
-
case 2:
|
|
14
|
-
return view.getUint16(offset, true);
|
|
15
|
-
case 4:
|
|
16
|
-
return view.getUint32(offset, true);
|
|
17
|
-
case 8: {
|
|
18
|
-
// Read as BigUint64 and convert to Number
|
|
19
|
-
const low = view.getUint32(offset, true);
|
|
20
|
-
const high = view.getUint32(offset + 4, true);
|
|
21
|
-
return high * 0x100000000 + low;
|
|
22
|
-
}
|
|
23
|
-
default:
|
|
24
|
-
throw new Error("Unsupported UInt LE size!");
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
5
|
/**
|
|
28
6
|
* Parses sequential unsigned little endian numbers from the head of the passed buffer according to
|
|
29
7
|
* the specified format passed. If the buffer is not large enough to satisfy the full format,
|
|
@@ -42,10 +20,30 @@ function readUIntLE(buffer, offset, size) {
|
|
|
42
20
|
*/
|
|
43
21
|
function parse(buffer, format) {
|
|
44
22
|
const result = {};
|
|
23
|
+
const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
45
24
|
let offset = 0;
|
|
46
25
|
for (const [key, size] of format) {
|
|
47
26
|
if (buffer.length >= offset + size) {
|
|
48
|
-
|
|
27
|
+
switch (size) {
|
|
28
|
+
case 1:
|
|
29
|
+
result[key] = view.getUint8(offset);
|
|
30
|
+
break;
|
|
31
|
+
case 2:
|
|
32
|
+
result[key] = view.getUint16(offset, true);
|
|
33
|
+
break;
|
|
34
|
+
case 4:
|
|
35
|
+
result[key] = view.getUint32(offset, true);
|
|
36
|
+
break;
|
|
37
|
+
case 8: {
|
|
38
|
+
// Keep behavior (Number) while avoiding BigInt costs.
|
|
39
|
+
const low = view.getUint32(offset, true);
|
|
40
|
+
const high = view.getUint32(offset + 4, true);
|
|
41
|
+
result[key] = high * 0x100000000 + low;
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
default:
|
|
45
|
+
throw new Error("Unsupported UInt LE size!");
|
|
46
|
+
}
|
|
49
47
|
}
|
|
50
48
|
else {
|
|
51
49
|
result[key] = null;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PatternScanner = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Stateful helper for incremental pattern scanning in growing buffers.
|
|
6
|
+
*
|
|
7
|
+
* The scanner tracks a `searchFrom` cursor and an `overlap` region so callers
|
|
8
|
+
* can avoid rescanning bytes that cannot start a match.
|
|
9
|
+
*/
|
|
10
|
+
class PatternScanner {
|
|
11
|
+
constructor(pattern) {
|
|
12
|
+
this.searchFrom = 0;
|
|
13
|
+
this.pattern = pattern;
|
|
14
|
+
this.overlap = Math.max(0, pattern.length - 1);
|
|
15
|
+
}
|
|
16
|
+
/** Find the next match index starting at the current `searchFrom`. */
|
|
17
|
+
find(target) {
|
|
18
|
+
return target.indexOfPattern(this.pattern, this.searchFrom);
|
|
19
|
+
}
|
|
20
|
+
/** Update `searchFrom` after consuming `consumed` bytes from the front. */
|
|
21
|
+
onConsume(consumed) {
|
|
22
|
+
if (consumed > 0) {
|
|
23
|
+
this.searchFrom = Math.max(0, this.searchFrom - consumed);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/** Update `searchFrom` after a no-match scan on a buffer of length `bufferLength`. */
|
|
27
|
+
onNoMatch(bufferLength) {
|
|
28
|
+
this.searchFrom = Math.max(this.searchFrom, Math.max(0, bufferLength - this.overlap));
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.PatternScanner = PatternScanner;
|
|
@@ -6,7 +6,68 @@ exports.resolveZipLastModifiedDateFromUnixSeconds = resolveZipLastModifiedDateFr
|
|
|
6
6
|
exports.resolveZipLastModifiedDateFromExtraField = resolveZipLastModifiedDateFromExtraField;
|
|
7
7
|
exports.buildZipTimestampExtraField = buildZipTimestampExtraField;
|
|
8
8
|
exports.dateToZipDos = dateToZipDos;
|
|
9
|
-
const
|
|
9
|
+
const EXTENDED_TIMESTAMP_ID = 0x5455;
|
|
10
|
+
function clampUint32(value) {
|
|
11
|
+
if (!Number.isFinite(value)) {
|
|
12
|
+
return 0;
|
|
13
|
+
}
|
|
14
|
+
if (value <= 0) {
|
|
15
|
+
return 0;
|
|
16
|
+
}
|
|
17
|
+
// 0xFFFFFFFF fits JS safe integer.
|
|
18
|
+
if (value >= 0xffffffff) {
|
|
19
|
+
return 0xffffffff;
|
|
20
|
+
}
|
|
21
|
+
return value >>> 0;
|
|
22
|
+
}
|
|
23
|
+
function unixSecondsFromDate(date) {
|
|
24
|
+
return clampUint32(Math.floor(date.getTime() / 1000));
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Parse Info-ZIP "Extended Timestamp" extra field (0x5455) and return mtime.
|
|
28
|
+
* Returns Unix seconds (UTC) if present.
|
|
29
|
+
*/
|
|
30
|
+
function parseExtendedTimestampMtimeUnixSeconds(extraField) {
|
|
31
|
+
const view = new DataView(extraField.buffer, extraField.byteOffset, extraField.byteLength);
|
|
32
|
+
let offset = 0;
|
|
33
|
+
while (offset + 4 <= extraField.length) {
|
|
34
|
+
const headerId = view.getUint16(offset, true);
|
|
35
|
+
const dataSize = view.getUint16(offset + 2, true);
|
|
36
|
+
const dataStart = offset + 4;
|
|
37
|
+
const dataEnd = dataStart + dataSize;
|
|
38
|
+
if (dataEnd > extraField.length) {
|
|
39
|
+
break;
|
|
40
|
+
}
|
|
41
|
+
if (headerId === EXTENDED_TIMESTAMP_ID && dataSize >= 1) {
|
|
42
|
+
const flags = extraField[dataStart];
|
|
43
|
+
if ((flags & 0x01) !== 0 && dataSize >= 5) {
|
|
44
|
+
// mtime is 4 bytes right after flags.
|
|
45
|
+
return view.getUint32(dataStart + 1, true) >>> 0;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
offset = dataEnd;
|
|
49
|
+
}
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Build Info-ZIP "Extended Timestamp" extra field (0x5455).
|
|
54
|
+
* We write only mtime (UTC, Unix seconds) to minimize size.
|
|
55
|
+
*/
|
|
56
|
+
function buildExtendedTimestampExtraFieldFromUnixSeconds(unixSeconds) {
|
|
57
|
+
const ts = clampUint32(unixSeconds);
|
|
58
|
+
// flags(1) + mtime(4)
|
|
59
|
+
const payloadSize = 5;
|
|
60
|
+
const out = new Uint8Array(4 + payloadSize);
|
|
61
|
+
const view = new DataView(out.buffer);
|
|
62
|
+
view.setUint16(0, EXTENDED_TIMESTAMP_ID, true);
|
|
63
|
+
view.setUint16(2, payloadSize, true);
|
|
64
|
+
out[4] = 0x01; // mtime present
|
|
65
|
+
view.setUint32(5, ts, true);
|
|
66
|
+
return out;
|
|
67
|
+
}
|
|
68
|
+
function buildExtendedTimestampExtraFieldFromDate(date) {
|
|
69
|
+
return buildExtendedTimestampExtraFieldFromUnixSeconds(unixSecondsFromDate(date));
|
|
70
|
+
}
|
|
10
71
|
/**
|
|
11
72
|
* DOS date/time helpers for ZIP files.
|
|
12
73
|
*/
|
|
@@ -44,11 +105,11 @@ function resolveZipLastModifiedDateFromUnixSeconds(dosDate, dosTime, mtimeUnixSe
|
|
|
44
105
|
return new Date(mtimeUnixSeconds * 1000);
|
|
45
106
|
}
|
|
46
107
|
function resolveZipLastModifiedDateFromExtraField(dosDate, dosTime, extraField) {
|
|
47
|
-
const unixSeconds =
|
|
108
|
+
const unixSeconds = parseExtendedTimestampMtimeUnixSeconds(extraField);
|
|
48
109
|
return resolveZipLastModifiedDateFromUnixSeconds(dosDate, dosTime, unixSeconds);
|
|
49
110
|
}
|
|
50
111
|
function buildZipTimestampExtraField(modTime, mode) {
|
|
51
|
-
return mode === "dos+utc" ?
|
|
112
|
+
return mode === "dos+utc" ? buildExtendedTimestampExtraFieldFromDate(modTime) : new Uint8Array(0);
|
|
52
113
|
}
|
|
53
114
|
function dateToZipDos(modTime) {
|
|
54
115
|
const [dosTime, dosDate] = dateToDos(modTime);
|