@awacloud/fw 0.1.0 → 1.0.0
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/CHANGELOG.md +125 -0
- package/NOTICE +8 -0
- package/README.md +163 -31
- package/dist/build/fw.core.pure.meta.json +6 -6
- package/dist/build/fw.core.pure.min.js +15 -12
- package/dist/build/fw.full.pure.meta.json +13 -7
- package/dist/build/fw.full.pure.min.js +45 -42
- package/dist/build/fw.minimal.pure.meta.json +6 -6
- package/dist/build/fw.minimal.pure.min.js +16 -13
- package/dist/build/fw.pack.compress-heavy.pure.meta.json +6 -6
- package/dist/build/fw.pack.compress-heavy.pure.min.js +3 -3
- package/dist/build/fw.pack.crypto-advanced.pure.meta.json +6 -6
- package/dist/build/fw.pack.crypto-advanced.pure.min.js +1 -1
- package/dist/build/fw.pack.crypto-basic.pure.meta.json +6 -6
- package/dist/build/fw.pack.crypto-basic.pure.min.js +1 -1
- package/dist/build/fw.pack.crypto-identity.pure.meta.json +7 -6
- package/dist/build/fw.pack.crypto-identity.pure.min.js +4 -4
- package/dist/build/fw.pwa.pure.meta.json +7 -6
- package/dist/build/fw.pwa.pure.min.js +38 -35
- package/dist/build/fw.site-interactive.pure.meta.json +6 -6
- package/dist/build/fw.site-interactive.pure.min.js +37 -34
- package/dist/build/fw.site.pure.meta.json +6 -6
- package/dist/build/fw.site.pure.min.js +24 -21
- package/dist/build/fw.spa.pure.meta.json +8 -7
- package/dist/build/fw.spa.pure.min.js +41 -38
- package/dist/build/sanity-base-classic.min.js +1 -1
- package/dist/build/sanity.min.js +1 -1
- package/dist/types/core/internal.d.ts +29 -0
- package/dist/types/core/internal.d.ts.map +1 -0
- package/dist/types/core/logger.d.ts +23 -4
- package/dist/types/core/logger.d.ts.map +1 -1
- package/dist/types/core/modules.d.ts +374 -61
- package/dist/types/core/modules.d.ts.map +1 -1
- package/dist/types/core/runtime.d.ts +10 -6
- package/dist/types/core/runtime.d.ts.map +1 -1
- package/dist/types/core/worker-helper.d.ts +35 -0
- package/dist/types/core/worker-helper.d.ts.map +1 -1
- package/dist/types/crypto/cipher/aes.d.ts +1 -7
- package/dist/types/crypto/cipher/aes.d.ts.map +1 -1
- package/dist/types/crypto/cipher/chacha20.d.ts +0 -10
- package/dist/types/crypto/cipher/chacha20.d.ts.map +1 -1
- package/dist/types/crypto/hash/argon2.d.ts +0 -15
- package/dist/types/crypto/hash/argon2.d.ts.map +1 -1
- package/dist/types/crypto/hash/blake2b.d.ts.map +1 -1
- package/dist/types/crypto/hash/hmac.d.ts.map +1 -1
- package/dist/types/crypto/hash/pbkdf2.d.ts.map +1 -1
- package/dist/types/crypto/hash/poly1305.d.ts.map +1 -1
- package/dist/types/crypto/hash/sha224.d.ts +1 -1
- package/dist/types/crypto/hash/sha256.d.ts +4 -13
- package/dist/types/crypto/hash/sha256.d.ts.map +1 -1
- package/dist/types/crypto/hash/sha3.d.ts.map +1 -1
- package/dist/types/crypto/hash/sha384.d.ts +1 -1
- package/dist/types/crypto/hash/sha512.d.ts +4 -13
- package/dist/types/crypto/hash/sha512.d.ts.map +1 -1
- package/dist/types/crypto/mode/cmac.d.ts +0 -6
- package/dist/types/crypto/mode/cmac.d.ts.map +1 -1
- package/dist/types/crypto/mode/ctr.d.ts +0 -6
- package/dist/types/crypto/mode/ctr.d.ts.map +1 -1
- package/dist/types/crypto/mode/gcm.d.ts +0 -9
- package/dist/types/crypto/mode/gcm.d.ts.map +1 -1
- package/dist/types/crypto/pkc/ecc.d.ts +0 -1
- package/dist/types/crypto/pkc/ecc.d.ts.map +1 -1
- package/dist/types/crypto/pkc/ed25519.d.ts +4 -25
- package/dist/types/crypto/pkc/ed25519.d.ts.map +1 -1
- package/dist/types/crypto/pkc/hybridSign.d.ts +25 -5
- package/dist/types/crypto/pkc/hybridSign.d.ts.map +1 -1
- package/dist/types/crypto/pkc/ml_dsa.d.ts +6 -26
- package/dist/types/crypto/pkc/ml_dsa.d.ts.map +1 -1
- package/dist/types/crypto/pkc/ml_kem.d.ts +0 -43
- package/dist/types/crypto/pkc/ml_kem.d.ts.map +1 -1
- package/dist/types/crypto/pkc/rsa.d.ts +0 -24
- package/dist/types/crypto/pkc/rsa.d.ts.map +1 -1
- package/dist/types/crypto/pkc/slh_dsa.d.ts +6 -16
- package/dist/types/crypto/pkc/slh_dsa.d.ts.map +1 -1
- package/dist/types/crypto/pkc/x25519.d.ts +0 -6
- package/dist/types/crypto/pkc/x25519.d.ts.map +1 -1
- package/dist/types/crypto/utils/bitArray.d.ts +0 -8
- package/dist/types/crypto/utils/bitArray.d.ts.map +1 -1
- package/dist/types/crypto/utils/jws.d.ts +6 -14
- package/dist/types/crypto/utils/jws.d.ts.map +1 -1
- package/dist/types/crypto/utils/keyformat.d.ts +52 -0
- package/dist/types/crypto/utils/keyformat.d.ts.map +1 -1
- package/dist/types/crypto/utils/random.d.ts +1 -10
- package/dist/types/crypto/utils/random.d.ts.map +1 -1
- package/dist/types/crypto/utils/rsaKeygen.d.ts +0 -10
- package/dist/types/crypto/utils/rsaKeygen.d.ts.map +1 -1
- package/dist/types/crypto/utils/uuid.d.ts.map +1 -1
- package/dist/types/crypto/utils/x509.d.ts +397 -0
- package/dist/types/crypto/utils/x509.d.ts.map +1 -0
- package/dist/types/crypto/wasm/argon2.d.ts +2 -1
- package/dist/types/crypto/wasm/argon2.d.ts.map +1 -1
- package/dist/types/crypto/wasm/pbkdf2.d.ts +2 -2
- package/dist/types/crypto/wasm/pbkdf2.d.ts.map +1 -1
- package/dist/types/crypto/wasm/rsa.d.ts.map +1 -1
- package/dist/types/crypto/wasm/runtime.d.ts +13 -0
- package/dist/types/crypto/wasm/runtime.d.ts.map +1 -1
- package/dist/types/crypto/webcrypto/aes.d.ts.map +1 -1
- package/dist/types/crypto/webcrypto/aeskw.d.ts.map +1 -1
- package/dist/types/crypto/webcrypto/digest.d.ts +0 -4
- package/dist/types/crypto/webcrypto/digest.d.ts.map +1 -1
- package/dist/types/crypto/webcrypto/rsa.d.ts.map +1 -1
- package/dist/types/dom/fs/fileIntake.d.ts +59 -0
- package/dist/types/dom/fs/fileIntake.d.ts.map +1 -0
- package/dist/types/dom/fs/fsAccess.d.ts.map +1 -1
- package/dist/types/dom/query/dnd.d.ts.map +1 -1
- package/dist/types/dom/query/sound.d.ts +89 -0
- package/dist/types/dom/query/sound.d.ts.map +1 -0
- package/dist/types/dom/rendering/chart.d.ts.map +1 -1
- package/dist/types/dom/rendering/component.d.ts +9 -3
- package/dist/types/dom/rendering/component.d.ts.map +1 -1
- package/dist/types/dom/rendering/parser.d.ts +39 -0
- package/dist/types/dom/rendering/parser.d.ts.map +1 -1
- package/dist/types/dom/rendering/render.d.ts.map +1 -1
- package/dist/types/dom/rendering/sanitize.d.ts +4 -0
- package/dist/types/dom/rendering/sanitize.d.ts.map +1 -1
- package/dist/types/dom/rendering/secPolicy.d.ts.map +1 -1
- package/dist/types/dom/rendering/styleSheet.d.ts +74 -0
- package/dist/types/dom/rendering/styleSheet.d.ts.map +1 -0
- package/dist/types/dom/rendering/template.d.ts +9 -3
- package/dist/types/dom/rendering/template.d.ts.map +1 -1
- package/dist/types/dom/rendering/themeTokens.d.ts +9 -3
- package/dist/types/dom/rendering/themeTokens.d.ts.map +1 -1
- package/dist/types/dom/rendering/uiSession-core.d.ts +9 -3
- package/dist/types/dom/rendering/uiSession-core.d.ts.map +1 -1
- package/dist/types/dom/rendering/uiSession-list.d.ts +9 -3
- package/dist/types/dom/rendering/uiSession-list.d.ts.map +1 -1
- package/dist/types/dom/rendering/uiSession.d.ts +18 -6
- package/dist/types/dom/rendering/uiSession.d.ts.map +1 -1
- package/dist/types/dom/sw/installPrompt.d.ts +89 -0
- package/dist/types/dom/sw/installPrompt.d.ts.map +1 -0
- package/dist/types/dom/sw/precache.d.ts +149 -0
- package/dist/types/dom/sw/precache.d.ts.map +1 -0
- package/dist/types/dom/sw/swUpdate.d.ts +129 -0
- package/dist/types/dom/sw/swUpdate.d.ts.map +1 -0
- package/dist/types/dom/utils/clipboard.d.ts +8 -0
- package/dist/types/dom/utils/clipboard.d.ts.map +1 -1
- package/dist/types/dom/utils/keybindings.d.ts.map +1 -1
- package/dist/types/dom/utils/route.d.ts.map +1 -1
- package/dist/types/dom/utils/ua.d.ts +2 -2
- package/dist/types/dom/utils/ua.d.ts.map +1 -1
- package/dist/types/io/calc/crc32.d.ts.map +1 -1
- package/dist/types/io/codec/b64.d.ts +24 -0
- package/dist/types/io/codec/b64.d.ts.map +1 -1
- package/dist/types/io/codec/cbor.d.ts +1 -0
- package/dist/types/io/codec/cbor.d.ts.map +1 -1
- package/dist/types/io/codec/hex.d.ts.map +1 -1
- package/dist/types/io/codec/msgpack.d.ts +1 -0
- package/dist/types/io/codec/msgpack.d.ts.map +1 -1
- package/dist/types/io/codec/url.d.ts +3 -1
- package/dist/types/io/codec/url.d.ts.map +1 -1
- package/dist/types/io/codec/utf8.d.ts.map +1 -1
- package/dist/types/io/compress/bitstream.d.ts +1 -1
- package/dist/types/io/compress/brotli.d.ts +0 -1
- package/dist/types/io/compress/brotli.d.ts.map +1 -1
- package/dist/types/io/compress/brotli_shared.d.ts +0 -4
- package/dist/types/io/compress/brotli_shared.d.ts.map +1 -1
- package/dist/types/io/compress/deflate.d.ts +14 -1
- package/dist/types/io/compress/deflate.d.ts.map +1 -1
- package/dist/types/io/compress/gzip.d.ts +4 -0
- package/dist/types/io/compress/gzip.d.ts.map +1 -1
- package/dist/types/io/compress/huffman.d.ts +7 -0
- package/dist/types/io/compress/huffman.d.ts.map +1 -1
- package/dist/types/io/compress/lz4.d.ts +4 -2
- package/dist/types/io/compress/lz4.d.ts.map +1 -1
- package/dist/types/io/compress/lz77.d.ts +17 -0
- package/dist/types/io/compress/lz77.d.ts.map +1 -1
- package/dist/types/io/compress/lzw.d.ts +2 -0
- package/dist/types/io/compress/lzw.d.ts.map +1 -1
- package/dist/types/io/compress/zip.d.ts.map +1 -1
- package/dist/types/io/compress/zlib.d.ts +9 -2
- package/dist/types/io/compress/zlib.d.ts.map +1 -1
- package/dist/types/io/math/linalg.d.ts.map +1 -1
- package/dist/types/process/rpc.d.ts.map +1 -1
- package/dist/types/process/workerPool.d.ts.map +1 -1
- package/dist/types/sanity/base.d.ts +12 -2
- package/dist/types/sanity/base.d.ts.map +1 -1
- package/dist/types/sanity/lockdown.d.ts +6 -5
- package/dist/types/sanity/lockdown.d.ts.map +1 -1
- package/dist/types/sanity/wasm-gate.d.ts +1 -1
- package/docs/README.md +17 -10
- package/docs/api/README.md +5 -5
- package/docs/api/core/logger.md +2 -1
- package/docs/api/core/modules.md +3 -3
- package/docs/api/core/runtime.md +9 -9
- package/docs/api/core/worker-helper.md +12 -2
- package/docs/api/crypto/README.md +1 -1
- package/docs/api/crypto/cipher/README.md +2 -2
- package/docs/api/crypto/cipher/aes.md +5 -10
- package/docs/api/crypto/cipher/chacha20.md +3 -8
- package/docs/api/crypto/hash/README.md +5 -5
- package/docs/api/crypto/hash/adf.md +21 -11
- package/docs/api/crypto/hash/argon2.md +3 -12
- package/docs/api/crypto/hash/blake2b.md +12 -14
- package/docs/api/crypto/hash/pbkdf2.md +1 -1
- package/docs/api/crypto/hash/sha224.md +2 -2
- package/docs/api/crypto/hash/sha256.md +4 -4
- package/docs/api/crypto/hash/sha3.md +2 -2
- package/docs/api/crypto/hash/sha384.md +1 -1
- package/docs/api/crypto/hash/sha512.md +5 -5
- package/docs/api/crypto/hash/sha512_224.md +1 -1
- package/docs/api/crypto/hash/sha512_256.md +1 -1
- package/docs/api/crypto/mode/README.md +3 -3
- package/docs/api/crypto/mode/cbc.md +2 -2
- package/docs/api/crypto/mode/chacha20poly1305.md +1 -1
- package/docs/api/crypto/mode/cmac.md +4 -4
- package/docs/api/crypto/mode/ctr.md +2 -3
- package/docs/api/crypto/mode/gcm.md +5 -5
- package/docs/api/crypto/mode/kw.md +4 -4
- package/docs/api/crypto/pkc/README.md +8 -8
- package/docs/api/crypto/pkc/ecc.md +19 -17
- package/docs/api/crypto/pkc/ed25519.md +10 -15
- package/docs/api/crypto/pkc/hybridKem.md +8 -2
- package/docs/api/crypto/pkc/hybridSign.md +34 -7
- package/docs/api/crypto/pkc/ml_dsa.md +20 -19
- package/docs/api/crypto/pkc/ml_kem.md +3 -3
- package/docs/api/crypto/pkc/rsa.md +7 -9
- package/docs/api/crypto/pkc/slh_dsa.md +12 -12
- package/docs/api/crypto/pkc/x25519.md +5 -4
- package/docs/api/crypto/utils/README.md +7 -7
- package/docs/api/crypto/utils/aes_modes.md +2 -5
- package/docs/api/crypto/utils/asn1.md +25 -16
- package/docs/api/crypto/utils/jws.md +6 -4
- package/docs/api/crypto/utils/keyformat.md +24 -15
- package/docs/api/crypto/utils/pad.md +1 -1
- package/docs/api/crypto/utils/pem.md +3 -3
- package/docs/api/crypto/utils/random.md +3 -4
- package/docs/api/crypto/utils/rsaKeygen.md +2 -2
- package/docs/api/crypto/utils/totp.md +2 -2
- package/docs/api/crypto/utils/uuid.md +5 -5
- package/docs/api/crypto/utils/x509.md +124 -0
- package/docs/api/crypto/wasm/aes.md +1 -1
- package/docs/api/crypto/wasm/argon2.md +6 -4
- package/docs/api/crypto/wasm/ml_kem.md +1 -0
- package/docs/api/crypto/wasm/pbkdf2.md +8 -8
- package/docs/api/crypto/wasm/rsa.md +1 -1
- package/docs/api/crypto/wasm/runtime.md +27 -10
- package/docs/api/crypto/webcrypto/aes.md +1 -1
- package/docs/api/crypto/webcrypto/aeskw.md +2 -2
- package/docs/api/crypto/webcrypto/digest.md +3 -5
- package/docs/api/crypto/webcrypto/ecc.md +1 -1
- package/docs/api/crypto/webcrypto/ed25519.md +1 -1
- package/docs/api/crypto/webcrypto/rsa.md +3 -2
- package/docs/api/crypto/webcrypto/x25519.md +1 -1
- package/docs/api/dom/README.md +6 -1
- package/docs/api/dom/fs/README.md +1 -0
- package/docs/api/dom/fs/fileIntake.md +120 -0
- package/docs/api/dom/fs/fsAccess.md +1 -0
- package/docs/api/dom/fs/indexedDB.md +1 -1
- package/docs/api/dom/fs/storage.md +1 -1
- package/docs/api/dom/query/README.md +2 -1
- package/docs/api/dom/query/dnd.md +4 -1
- package/docs/api/dom/query/dom.md +5 -0
- package/docs/api/dom/query/sound.md +103 -0
- package/docs/api/dom/rendering/README.md +4 -3
- package/docs/api/dom/rendering/chart.md +5 -4
- package/docs/api/dom/rendering/component.md +25 -3
- package/docs/api/dom/rendering/parser.md +5 -2
- package/docs/api/dom/rendering/reactiveBind.md +1 -1
- package/docs/api/dom/rendering/render.md +2 -2
- package/docs/api/dom/rendering/sanitize.md +10 -2
- package/docs/api/dom/rendering/secPolicy.md +4 -4
- package/docs/api/dom/rendering/styleSheet.md +85 -0
- package/docs/api/dom/rendering/template.md +20 -5
- package/docs/api/dom/rendering/themeTokens.md +6 -3
- package/docs/api/dom/rendering/uiSession.md +18 -5
- package/docs/api/dom/rendering/virtualScroll.md +2 -2
- package/docs/api/dom/sensors/geolocation.md +1 -1
- package/docs/api/dom/sw/README.md +7 -1
- package/docs/api/dom/sw/cache.md +2 -1
- package/docs/api/dom/sw/installPrompt.md +111 -0
- package/docs/api/dom/sw/precache.md +124 -0
- package/docs/api/dom/sw/serviceWorker.md +4 -2
- package/docs/api/dom/sw/swUpdate.md +112 -0
- package/docs/api/dom/utils/clipboard.md +56 -5
- package/docs/api/dom/utils/entropyCollector.md +1 -1
- package/docs/api/dom/utils/keybindings.md +17 -2
- package/docs/api/dom/utils/leaderElection.md +2 -2
- package/docs/api/dom/utils/route.md +1 -0
- package/docs/api/dom/utils/ua.md +15 -10
- package/docs/api/io/calc/crc32.md +4 -1
- package/docs/api/io/codec/README.md +2 -2
- package/docs/api/io/codec/b64.md +31 -2
- package/docs/api/io/codec/buffer.md +1 -1
- package/docs/api/io/codec/cbor.md +6 -4
- package/docs/api/io/codec/csv.md +178 -178
- package/docs/api/io/codec/hex.md +10 -2
- package/docs/api/io/codec/msgpack.md +4 -3
- package/docs/api/io/codec/url.md +4 -3
- package/docs/api/io/codec/utf8.md +3 -3
- package/docs/api/io/compress/bitstream.md +6 -3
- package/docs/api/io/compress/brotli.md +36 -4
- package/docs/api/io/compress/brotli_shared.md +1 -1
- package/docs/api/io/compress/deflate.md +42 -34
- package/docs/api/io/compress/gzip.md +26 -6
- package/docs/api/io/compress/huffman.md +2 -1
- package/docs/api/io/compress/lz4.md +5 -3
- package/docs/api/io/compress/lz77.md +26 -3
- package/docs/api/io/compress/lzw.md +13 -8
- package/docs/api/io/compress/zip.md +36 -10
- package/docs/api/io/compress/zlib.md +21 -5
- package/docs/api/io/math/linalg.md +1 -1
- package/docs/api/io/utils/valid.md +1 -1
- package/docs/api/process/rpc.md +3 -2
- package/docs/api/process/workerPool.md +1 -1
- package/docs/api/sanity/base.md +9 -5
- package/docs/api/sanity/lockdown.md +7 -6
- package/docs/api/surface.json +12311 -0
- package/docs/api/typed.md +5 -3
- package/docs/dev/README.md +2 -0
- package/docs/dev/bench.md +76 -0
- package/docs/dev/crypto-references.md +54 -0
- package/docs/dev/provenance.md +30 -7
- package/docs/dev/publishing.md +7 -7
- package/docs/dev/runtime.md +1 -1
- package/docs/dev/testing.md +13 -0
- package/docs/evidence/l4-evidence.md +86 -0
- package/docs/evidence/pqc-hybrid-evidence.md +7 -6
- package/docs/guide/README.md +1 -0
- package/docs/guide/_QUICK_REF.md +5 -5
- package/docs/guide/doc-format.md +4 -3
- package/docs/guide/integrations-hmr.md +1 -1
- package/docs/guide/module-creation-workflow.md +8 -8
- package/docs/guide/rendering-pipeline.md +11 -4
- package/docs/guide/security.md +7 -5
- package/docs/guide/stability.md +123 -0
- package/docs/guide/tutorial-todo.md +20 -8
- package/docs/guide/typescript.md +9 -0
- package/docs/guide/worker-confinement.md +30 -17
- package/docs/notes/lz77-deflate-factorization.md +3 -3
- package/docs/tools/README.md +1 -1
- package/docs/tools/bundler.md +3 -3
- package/docs/tools/codegen.md +1 -1
- package/docs/tools/standalone.md +0 -1
- package/fw.config.json +2 -2
- package/integrations/_shared/catalog.generated.json +7 -1
- package/integrations/_shared/core.js +1 -1
- package/integrations/astro/index.js +1 -1
- package/integrations/eslint/README.md +7 -1
- package/integrations/nextjs/index.js +1 -1
- package/integrations/nodejs/README.md +3 -3
- package/integrations/turbopack/index.js +2 -2
- package/integrations/typedoc/categorize.js +1 -1
- package/integrations/typedoc/typedoc.json +2 -1
- package/integrations/vite/index.js +2 -2
- package/integrations/vite/vite-env.d.ts +7 -4
- package/integrations/webpack/index.js +3 -3
- package/package.json +76 -10
- package/src/core/internal.js +31 -0
- package/src/core/logger.js +95 -23
- package/src/core/modules.js +17 -8
- package/src/core/readyState.js +1 -1
- package/src/core/runtime.js +74 -27
- package/src/core/worker-helper.js +83 -4
- package/src/crypto/NIST_CONFORMANCE.md +47 -34
- package/src/crypto/cipher/aes.acvp.md +7 -8
- package/src/crypto/cipher/aes.js +280 -229
- package/src/crypto/cipher/chacha20.acvp.md +6 -7
- package/src/crypto/cipher/chacha20.js +91 -61
- package/src/crypto/hash/adf.js +1 -1
- package/src/crypto/hash/argon2.acvp.md +11 -15
- package/src/crypto/hash/argon2.js +9 -24
- package/src/crypto/hash/blake2b.js +157 -125
- package/src/crypto/hash/hkdf.acvp.md +15 -15
- package/src/crypto/hash/hkdf.js +1 -1
- package/src/crypto/hash/hmac.acvp.md +10 -12
- package/src/crypto/hash/hmac.js +5 -1
- package/src/crypto/hash/pbkdf2.acvp.md +13 -13
- package/src/crypto/hash/pbkdf2.js +36 -8
- package/src/crypto/hash/poly1305.acvp.md +10 -6
- package/src/crypto/hash/poly1305.js +171 -50
- package/src/crypto/hash/sha224.acvp.md +3 -3
- package/src/crypto/hash/sha224.js +4 -4
- package/src/crypto/hash/sha256.acvp.md +2 -2
- package/src/crypto/hash/sha256.js +514 -50
- package/src/crypto/hash/sha3.acvp.md +9 -9
- package/src/crypto/hash/sha3.js +127 -71
- package/src/crypto/hash/sha384.acvp.md +3 -3
- package/src/crypto/hash/sha384.js +4 -4
- package/src/crypto/hash/sha512.acvp.md +7 -8
- package/src/crypto/hash/sha512.js +107 -108
- package/src/crypto/hash/sha512_224.acvp.md +6 -6
- package/src/crypto/hash/sha512_224.js +2 -2
- package/src/crypto/hash/sha512_256.acvp.md +6 -6
- package/src/crypto/hash/sha512_256.js +2 -2
- package/src/crypto/mode/cbc.acvp.md +2 -2
- package/src/crypto/mode/cbc.js +1 -1
- package/src/crypto/mode/chacha20poly1305.acvp.md +6 -6
- package/src/crypto/mode/chacha20poly1305.js +3 -3
- package/src/crypto/mode/cmac.acvp.md +5 -5
- package/src/crypto/mode/cmac.js +8 -8
- package/src/crypto/mode/ctr.acvp.md +2 -2
- package/src/crypto/mode/ctr.js +1 -3
- package/src/crypto/mode/gcm.acvp.md +6 -6
- package/src/crypto/mode/gcm.js +7 -7
- package/src/crypto/mode/kw.acvp.md +4 -4
- package/src/crypto/mode/kw.js +5 -5
- package/src/crypto/pkc/ecc.acvp.md +13 -13
- package/src/crypto/pkc/ecc.js +9 -11
- package/src/crypto/pkc/ed25519.acvp.md +30 -34
- package/src/crypto/pkc/ed25519.js +453 -94
- package/src/crypto/pkc/hybrid-kat.provenance.md +4 -4
- package/src/crypto/pkc/hybridSign.js +103 -24
- package/src/crypto/pkc/ml_dsa.acvp.md +18 -18
- package/src/crypto/pkc/ml_dsa.js +29 -32
- package/src/crypto/pkc/ml_kem.acvp.md +7 -7
- package/src/crypto/pkc/ml_kem.js +15 -21
- package/src/crypto/pkc/rsa.acvp.md +11 -15
- package/src/crypto/pkc/rsa.js +7 -44
- package/src/crypto/pkc/slh_dsa.acvp.md +16 -16
- package/src/crypto/pkc/slh_dsa.js +16 -18
- package/src/crypto/pkc/x25519.acvp.md +13 -10
- package/src/crypto/pkc/x25519.js +273 -29
- package/src/crypto/utils/aes_modes.acvp.md +1 -2
- package/src/crypto/utils/aes_modes.js +2 -2
- package/src/crypto/utils/asn1-oid.js +1 -1
- package/src/crypto/utils/asn1.js +1 -1
- package/src/crypto/utils/bitArray.js +33 -48
- package/src/crypto/utils/bn.js +1 -1
- package/src/crypto/utils/jws.js +37 -41
- package/src/crypto/utils/keyformat.js +181 -2
- package/src/crypto/utils/pem.js +1 -1
- package/src/crypto/utils/random.acvp.md +5 -5
- package/src/crypto/utils/random.js +845 -846
- package/src/crypto/utils/rsaKeygen.acvp.md +3 -2
- package/src/crypto/utils/rsaKeygen.js +6 -6
- package/src/crypto/utils/totp.js +1 -1
- package/src/crypto/utils/uuid.acvp.md +5 -5
- package/src/crypto/utils/uuid.js +11 -10
- package/src/crypto/utils/x509.js +591 -0
- package/src/crypto/wasm/aes.js +1 -1
- package/src/crypto/wasm/aes.scalar.wasm +0 -0
- package/src/crypto/wasm/argon2.js +17 -1
- package/src/crypto/wasm/argon2.scalar.wasm +0 -0
- package/src/crypto/wasm/blake2b.scalar.wasm +0 -0
- package/src/crypto/wasm/blake2b.simd.wasm +0 -0
- package/src/crypto/wasm/chacha20poly1305.scalar.wasm +0 -0
- package/src/crypto/wasm/chacha20poly1305.simd.wasm +0 -0
- package/src/crypto/wasm/cmac.scalar.wasm +0 -0
- package/src/crypto/wasm/ecc.js +3 -3
- package/src/crypto/wasm/ecc.scalar.wasm +0 -0
- package/src/crypto/wasm/ed25519.js +1 -1
- package/src/crypto/wasm/ed25519.scalar.wasm +0 -0
- package/src/crypto/wasm/hkdf.scalar.wasm +0 -0
- package/src/crypto/wasm/hmac.scalar.wasm +0 -0
- package/src/crypto/wasm/ml_dsa.js +2 -2
- package/src/crypto/wasm/ml_dsa.scalar.wasm +0 -0
- package/src/crypto/wasm/ml_dsa.simd.wasm +0 -0
- package/src/crypto/wasm/ml_kem.js +2 -2
- package/src/crypto/wasm/ml_kem.scalar.wasm +0 -0
- package/src/crypto/wasm/ml_kem.simd.wasm +0 -0
- package/src/crypto/wasm/pbkdf2.js +8 -6
- package/src/crypto/wasm/pbkdf2.scalar.wasm +0 -0
- package/src/crypto/wasm/rsa.js +6 -5
- package/src/crypto/wasm/rsa.scalar.wasm +0 -0
- package/src/crypto/wasm/runtime.js +84 -17
- package/src/crypto/wasm/sha2.scalar.wasm +0 -0
- package/src/crypto/wasm/sha3.scalar.wasm +0 -0
- package/src/crypto/wasm/sha3.simd.wasm +0 -0
- package/src/crypto/wasm/slh_dsa.js +1 -1
- package/src/crypto/wasm/slh_dsa.scalar.wasm +0 -0
- package/src/crypto/wasm/x25519.js +1 -1
- package/src/crypto/wasm/x25519.scalar.wasm +0 -0
- package/src/crypto/webcrypto/aes.js +8 -2
- package/src/crypto/webcrypto/aeskw.js +7 -2
- package/src/crypto/webcrypto/digest.js +1 -15
- package/src/crypto/webcrypto/ecc.js +2 -2
- package/src/crypto/webcrypto/ed25519.js +2 -2
- package/src/crypto/webcrypto/hmac.js +2 -2
- package/src/crypto/webcrypto/rsa.js +7 -2
- package/src/crypto/webcrypto/x25519.js +2 -2
- package/src/dom/display/animate.js +1 -1
- package/src/dom/display/fullscreen.js +1 -1
- package/src/dom/fs/download.js +1 -1
- package/src/dom/fs/fileIntake.js +192 -0
- package/src/dom/fs/fsAccess.js +2 -3
- package/src/dom/fs/indexedDB.js +1 -1
- package/src/dom/fs/remoteStore.js +1 -1
- package/src/dom/fs/storage.js +1 -1
- package/src/dom/lifecycle/idle.js +1 -1
- package/src/dom/lifecycle/visibility.js +1 -1
- package/src/dom/lifecycle/wakeLock.js +1 -1
- package/src/dom/net/ajax.js +1 -1
- package/src/dom/net/network.js +1 -1
- package/src/dom/net/sse.js +1 -1
- package/src/dom/net/webrtc.js +1 -1
- package/src/dom/net/ws.js +1 -1
- package/src/dom/query/dnd.js +56 -4
- package/src/dom/query/dom.js +1 -1
- package/src/dom/query/events.js +1 -1
- package/src/dom/query/gesture.js +1 -1
- package/src/dom/query/media.js +1 -1
- package/src/dom/query/sound.js +333 -0
- package/src/dom/rendering/chart.js +736 -663
- package/src/dom/rendering/component.js +25 -14
- package/src/dom/rendering/devtools.js +2 -2
- package/src/dom/rendering/parser.js +155 -12
- package/src/dom/rendering/render.js +14 -4
- package/src/dom/rendering/sanitize.js +11 -4
- package/src/dom/rendering/secPolicy.js +6 -4
- package/src/dom/rendering/styleSheet.js +217 -0
- package/src/dom/rendering/template.js +72 -13
- package/src/dom/rendering/themeTokens.js +542 -522
- package/src/dom/rendering/uiSession-core.js +51 -6
- package/src/dom/rendering/uiSession-direct.js +1 -1
- package/src/dom/rendering/uiSession-list.js +4 -4
- package/src/dom/rendering/uiSession.js +1 -1
- package/src/dom/rendering/virtualScroll.js +341 -341
- package/src/dom/sensors/battery.js +1 -1
- package/src/dom/sensors/geolocation.js +1 -1
- package/src/dom/sensors/networkInfo.js +1 -1
- package/src/dom/sensors/sensors.js +1 -1
- package/src/dom/sw/backgroundSync.js +1 -1
- package/src/dom/sw/cache.js +1 -1
- package/src/dom/sw/installPrompt.js +151 -0
- package/src/dom/sw/precache.js +257 -0
- package/src/dom/sw/push.js +1 -1
- package/src/dom/sw/sharedWorker.js +1 -1
- package/src/dom/sw/swUpdate.js +239 -0
- package/src/dom/utils/a11y.js +1 -1
- package/src/dom/utils/clipboard.js +56 -6
- package/src/dom/utils/entropyCollector.js +1 -1
- package/src/dom/utils/focus.js +1 -1
- package/src/dom/utils/form.js +1 -1
- package/src/dom/utils/keybindings.js +600 -574
- package/src/dom/utils/leaderElection.js +1 -1
- package/src/dom/utils/notifications.js +1 -1
- package/src/dom/utils/permissions.js +107 -107
- package/src/dom/utils/route.js +14 -2
- package/src/dom/utils/ua.js +42 -28
- package/src/dom/utils/webauthn.js +1 -1
- package/src/io/binary/reader.js +1 -1
- package/src/io/binary/writer.js +1 -1
- package/src/io/calc/bigint.js +1 -1
- package/src/io/calc/crc32.js +28 -2
- package/src/io/calc/easing.js +514 -514
- package/src/io/codec/b64.js +189 -52
- package/src/io/codec/base32.js +1 -1
- package/src/io/codec/base58.js +1 -1
- package/src/io/codec/buffer.js +1 -1
- package/src/io/codec/cbor.js +111 -18
- package/src/io/codec/csv.js +1 -1
- package/src/io/codec/hex.js +51 -6
- package/src/io/codec/mime.js +1 -1
- package/src/io/codec/msgpack.js +47 -6
- package/src/io/codec/url.js +24 -7
- package/src/io/codec/utf8.js +5 -3
- package/src/io/codec/xml.js +1 -1
- package/src/io/compress/bitstream.js +2 -2
- package/src/io/compress/brotli.js +663 -163
- package/src/io/compress/brotli_dict.js +1 -1
- package/src/io/compress/brotli_dict_words.js +1 -1
- package/src/io/compress/brotli_frame.js +1 -1
- package/src/io/compress/brotli_shared.js +7 -7
- package/src/io/compress/deflate.js +87 -53
- package/src/io/compress/gzip.js +187 -74
- package/src/io/compress/huffman.js +24 -1
- package/src/io/compress/lz4.js +45 -7
- package/src/io/compress/lz77.js +148 -63
- package/src/io/compress/lzw.js +35 -19
- package/src/io/compress/zip.js +862 -815
- package/src/io/compress/zlib.js +87 -7
- package/src/io/i18n/i18n.js +1 -1
- package/src/io/math/fixed-point.js +1 -1
- package/src/io/math/geom.js +1 -1
- package/src/io/math/interp.js +1 -1
- package/src/io/math/linalg.js +10 -4
- package/src/io/math/stats.js +1 -1
- package/src/io/structures/btree.js +1 -1
- package/src/io/structures/heap.js +1 -1
- package/src/io/structures/lruCache.js +1 -1
- package/src/io/structures/ringBuffer.js +1 -1
- package/src/io/structures/tree-walker.js +1 -1
- package/src/io/structures/trie.js +1 -1
- package/src/io/sync/abort.js +1 -1
- package/src/io/sync/atomics.js +1 -1
- package/src/io/sync/cancellable.js +1 -1
- package/src/io/sync/channel.js +1 -1
- package/src/io/sync/mutex.js +1 -1
- package/src/io/sync/semaphore.js +1 -1
- package/src/io/sync/tokenBucket.js +1 -1
- package/src/io/text/ansi.js +1 -1
- package/src/io/text/html-entities.js +1 -1
- package/src/io/time/date.js +1 -1
- package/src/io/timing/clock.js +1 -1
- package/src/io/timing/rateLimit.js +1 -1
- package/src/io/timing/scheduler.js +1 -1
- package/src/io/utils/errors.js +1 -1
- package/src/io/utils/eventBus.js +1 -1
- package/src/io/utils/signal.js +1 -1
- package/src/io/utils/valid.js +1 -1
- package/src/main.js +1 -1
- package/src/process/message.js +1 -1
- package/src/process/rpc.js +7 -3
- package/src/process/workerPool.js +11 -4
- package/src/sanity/base.js +85 -39
- package/src/sanity/lockdown-apply.js +3 -3
- package/src/sanity/lockdown.js +58 -32
- package/src/sanity/wasm-gate.js +2 -2
- package/src/typed.js +7 -3
- package/third-party/NOTICE-brotli-dictionary.txt +69 -0
- package/third-party/NOTICE-fw-wasm-crypto.txt +576 -0
- package/third-party/NOTICE-whatwg-entities.txt +44 -0
- package/types/registry.generated.d.ts +7 -1
- package/types/typed.d.ts +7 -3
- package/dist/types/crypto/utils/aes_ctr.d.ts +0 -84
- package/dist/types/crypto/utils/aes_ctr.d.ts.map +0 -1
- package/docs/api/crypto/utils/aes_ctr.md +0 -71
- package/src/crypto/utils/aes_ctr.acvp.md +0 -67
- package/src/crypto/utils/aes_ctr.js +0 -134
package/src/io/compress/zip.js
CHANGED
|
@@ -1,815 +1,862 @@
|
|
|
1
|
-
|
|
2
|
-
// Author: Matthieu Bouilloux
|
|
3
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @fileoverview ZIP archive creation and extraction factory.
|
|
7
|
-
*
|
|
8
|
-
* Supports ZIP and ZIP64 format (for archives > 4 GB) with DEFLATE compression
|
|
9
|
-
* (method 8) and store (method 0) ISO/IEC 21320-1. File entries can be plain `Uint8Array` or
|
|
10
|
-
* `[Uint8Array, PerFileOptions]` tuples. Directory objects are flattened with
|
|
11
|
-
* a trailing `/` path separator.
|
|
12
|
-
*
|
|
13
|
-
* ## API
|
|
14
|
-
*
|
|
15
|
-
* | Method | Returns |
|
|
16
|
-
* |---|---|
|
|
17
|
-
* | `zipSync(files, opts?)` | `Uint8Array` - synchronous archive creation |
|
|
18
|
-
* | `unzipSync(data, opts?)` | `{ [path]: Uint8Array }` - synchronous extraction |
|
|
19
|
-
* | `zip(files, opts?)` | `Promise<Uint8Array>` |
|
|
20
|
-
* | `unzip(data, opts?)` | `Promise<{ [path]: Uint8Array }>` |
|
|
21
|
-
*
|
|
22
|
-
* ## Files argument
|
|
23
|
-
*
|
|
24
|
-
* ```js
|
|
25
|
-
* {
|
|
26
|
-
* 'file.txt': data, // Uint8Array
|
|
27
|
-
* 'archive/big.bin': [data, { level: 0 }], // with per-file options
|
|
28
|
-
* 'subdir/': {}, // directory entry
|
|
29
|
-
* }
|
|
30
|
-
* ```
|
|
31
|
-
*
|
|
32
|
-
* ## Per-file options
|
|
33
|
-
*
|
|
34
|
-
* `{ level?: 0–9, mtime?: number|Date, comment?: string, extra?: object }`
|
|
35
|
-
*
|
|
36
|
-
* Set `level: 0` to store without compression.
|
|
37
|
-
*
|
|
38
|
-
* ## Deterministic / reproducible archives
|
|
39
|
-
*
|
|
40
|
-
* `opts.mtime` (writer-level default) also accepts `number|Date`, on both
|
|
41
|
-
* write paths: `zipSync`/`zip`'s `opts` argument and `ZipStream`'s
|
|
42
|
-
* constructor `opts`. It seeds every entry that does not supply its own
|
|
43
|
-
* `p.mtime` (per-entry `mtime` always wins). Fixing the writer-level
|
|
44
|
-
* `mtime` makes two writes of an identical payload byte-identical —
|
|
45
|
-
* without it, each entry's timestamp defaults to `Date.now()` and bytes
|
|
46
|
-
* differ run to run. Valid range is 1980-2099 (MS-DOS date/time,
|
|
47
|
-
* 2-second resolution); outside it throws error code 10, fixed mtime
|
|
48
|
-
* included. This module only provides the option — a caller composing on
|
|
49
|
-
* top of `zip` (e.g. a document-format writer) must thread its own fixed
|
|
50
|
-
* `mtime` through to claim reproducible output.
|
|
51
|
-
*
|
|
52
|
-
* ## Extraction options
|
|
53
|
-
*
|
|
54
|
-
* `{ filter?: ({ name, size, originalSize, compression }) => boolean }`
|
|
55
|
-
*
|
|
56
|
-
*/
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Writer returned by `ZipStream.openEntry(...)`.
|
|
60
|
-
* @typedef {object} ZipEntryWriter
|
|
61
|
-
* @property {(chunk: Uint8Array, final?: boolean) => void} push
|
|
62
|
-
*/
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Streaming ZIP archive writer instance shape.
|
|
66
|
-
* @typedef {object} ZipStreamInstance
|
|
67
|
-
* @property {((chunk: Uint8Array, isFinal: boolean) => void)|null} ondata
|
|
68
|
-
* @property {(name: string, data: Uint8Array|[Uint8Array, object], opts?: object) => void} add
|
|
69
|
-
* @property {(name: string, opts?: object) => ZipEntryWriter} openEntry
|
|
70
|
-
* @property {() => void} finalize
|
|
71
|
-
*/
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Constructor for `ZipStream`.
|
|
75
|
-
* @typedef {new (opts?: object|((chunk: Uint8Array, isFinal: boolean) => void), ondata?: (chunk: Uint8Array, isFinal: boolean) => void) => ZipStreamInstance} ZipStreamCtor
|
|
76
|
-
*/
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Streaming ZIP reader instance shape.
|
|
80
|
-
* @typedef {object} ZipStreamReaderInstance
|
|
81
|
-
* @property {((name: string, data: Uint8Array, isFinal: boolean) => void)|null} onfile
|
|
82
|
-
* @property {(chunk: Uint8Array, final?: boolean) => void} push
|
|
83
|
-
*/
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Constructor for `ZipStreamReader`.
|
|
87
|
-
* @typedef {new (opts?: object|((name: string, data: Uint8Array, isFinal: boolean) => void), onfile?: (name: string, data: Uint8Array, isFinal: boolean) => void) => ZipStreamReaderInstance} ZipStreamReaderCtor
|
|
88
|
-
*/
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Public surface of `zip.factory(...)`.
|
|
92
|
-
* @typedef {object} ZipApi
|
|
93
|
-
* @property {(files: object, opts?: object) => Uint8Array} zipSync
|
|
94
|
-
* @property {(data: Uint8Array, opts?: object) => Object<string, Uint8Array>} unzipSync
|
|
95
|
-
* @property {(files: object, opts?: object) => Promise<Uint8Array>} zip
|
|
96
|
-
* @property {(data: Uint8Array, opts?: object) => Promise<Object<string, Uint8Array>>} unzip
|
|
97
|
-
* @property {ZipStreamCtor} ZipStream
|
|
98
|
-
* @property {ZipStreamReaderCtor} ZipStreamReader
|
|
99
|
-
*/
|
|
100
|
-
|
|
101
|
-
import { deflate } from './deflate.js';
|
|
102
|
-
import { crc32 } from '../calc/crc32.js';
|
|
103
|
-
|
|
104
|
-
export const zip = {
|
|
105
|
-
name: 'zip',
|
|
106
|
-
version: '1.0.0',
|
|
107
|
-
type: 'fw.io.compress',
|
|
108
|
-
dependencies: ['deflate', 'crc32'],
|
|
109
|
-
deps: [deflate, crc32],
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* @param {{ deflateSync, inflateSync, deflate, inflate, DeflateStream, InflateStream }} deflateModule
|
|
113
|
-
* @param {new() => {append: function(Uint8Array): void, get: function(): number}} Crc32 - constructor returned by crc32.factory()
|
|
114
|
-
* @returns {ZipApi}
|
|
115
|
-
*/
|
|
116
|
-
factory(deflateModule, Crc32) {
|
|
117
|
-
|
|
118
|
-
const { deflateSync, inflateSync, DeflateStream } = deflateModule;
|
|
119
|
-
|
|
120
|
-
// --- String ↔ Uint8Array helpers ---
|
|
121
|
-
|
|
122
|
-
// Native encoder/decoder (universal in modern environments)
|
|
123
|
-
const _te = typeof TextEncoder !== 'undefined' && new TextEncoder();
|
|
124
|
-
const _td = typeof TextDecoder !== 'undefined' && new TextDecoder();
|
|
125
|
-
|
|
126
|
-
function _strToU8(str) {
|
|
127
|
-
if (_te) return _te.encode(str);
|
|
128
|
-
// Fallback: manual UTF-8 for non-ASCII
|
|
129
|
-
const a = [];
|
|
130
|
-
for (let i = 0; i < str.length; ++i) {
|
|
131
|
-
let c = str.charCodeAt(i);
|
|
132
|
-
if (c < 0x80) {
|
|
133
|
-
a.push(c);
|
|
134
|
-
} else if (c < 0x800) {
|
|
135
|
-
a.push(0xC0 | (c >> 6), 0x80 | (c & 0x3F));
|
|
136
|
-
} else if (c > 0xD7FF && c < 0xE000) {
|
|
137
|
-
c = 0x10000 + (((c & 0x3FF) << 10) | (str.charCodeAt(++i) & 0x3FF));
|
|
138
|
-
a.push(0xF0 | (c >> 18), 0x80 | ((c >> 12) & 0x3F), 0x80 | ((c >> 6) & 0x3F), 0x80 | (c & 0x3F));
|
|
139
|
-
} else {
|
|
140
|
-
a.push(0xE0 | (c >> 12), 0x80 | ((c >> 6) & 0x3F), 0x80 | (c & 0x3F));
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
return new Uint8Array(a);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
// Decode bytes as UTF-8 (utf8=true) or Latin-1 (utf8=false)
|
|
147
|
-
function _u8ToStr(d, utf8) {
|
|
148
|
-
if (!utf8) {
|
|
149
|
-
// Latin-1: one char per byte
|
|
150
|
-
let r = '';
|
|
151
|
-
for (let i = 0; i < d.length; i += 16384)
|
|
152
|
-
r += String.fromCharCode(...d.subarray(i, i + 16384));
|
|
153
|
-
return r;
|
|
154
|
-
}
|
|
155
|
-
if (_td) return _td.decode(d);
|
|
156
|
-
// Fallback manual decode
|
|
157
|
-
let r = '';
|
|
158
|
-
for (let i = 0; i < d.length;) {
|
|
159
|
-
const b = d[i++];
|
|
160
|
-
if (b < 0x80) { r += String.fromCharCode(b); }
|
|
161
|
-
else if (b < 0xE0) { r += String.fromCharCode(((b & 0x1F) << 6) | (d[i++] & 0x3F)); }
|
|
162
|
-
else if (b < 0xF0) { r += String.fromCharCode(((b & 0x0F) << 12) | ((d[i++] & 0x3F) << 6) | (d[i++] & 0x3F)); }
|
|
163
|
-
else {
|
|
164
|
-
let cp = ((b & 0x07) << 18) | ((d[i++] & 0x3F) << 12) | ((d[i++] & 0x3F) << 6) | (d[i++] & 0x3F);
|
|
165
|
-
cp -= 0x10000;
|
|
166
|
-
r += String.fromCharCode(0xD800 | (cp >> 10), 0xDC00 | (cp & 0x3FF));
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
return r;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
// True when the string contains no characters outside Latin-1
|
|
173
|
-
function _isUTF8(str) {
|
|
174
|
-
for (let i = 0; i < str.length; ++i) if (str.charCodeAt(i) > 127) return true;
|
|
175
|
-
return false;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
// --- Byte-level helpers ---
|
|
179
|
-
|
|
180
|
-
function _r16(d, b) { return d[b] | (d[b + 1] << 8); }
|
|
181
|
-
function _r32(d, b) { return (d[b] | (d[b + 1] << 8) | (d[b + 2] << 16) | (d[b + 3] << 24)) >>> 0; }
|
|
182
|
-
function _r64(d, b) { return _r32(d, b) + _r32(d, b + 4) * 4294967296; }
|
|
183
|
-
|
|
184
|
-
function _w16(d, b, v) { d[b] = v & 0xFF; d[b + 1] = (v >> 8) & 0xFF; }
|
|
185
|
-
function _w32(d, b, v) { d[b] = v & 0xFF; d[b + 1] = (v >> 8) & 0xFF; d[b + 2] = (v >> 16) & 0xFF; d[b + 3] = (v >>> 24) & 0xFF; }
|
|
186
|
-
|
|
187
|
-
// --- MS-DOS date/time encoding ---
|
|
188
|
-
|
|
189
|
-
function _dosDateTime(mtime) {
|
|
190
|
-
const d = new Date(mtime ?? Date.now());
|
|
191
|
-
const y = d.getFullYear() - 1980;
|
|
192
|
-
if (y < 0 || y > 119) {
|
|
193
|
-
const e = new Error('date not in range 1980-2099');
|
|
194
|
-
// @ts-ignore - Error.code is a non-standard but widely-used extension
|
|
195
|
-
e.code = 10;
|
|
196
|
-
throw e;
|
|
197
|
-
}
|
|
198
|
-
return (y << 25) | ((d.getMonth() + 1) << 21) | (d.getDate() << 16)
|
|
199
|
-
| (d.getHours() << 11) | (d.getMinutes() << 5) | (d.getSeconds() >> 1);
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
// Deflate bit flag from level
|
|
203
|
-
function _dbf(l) { return l === 1 ? 3 : l < 6 ? 2 : l === 9 ? 1 : 0; }
|
|
204
|
-
|
|
205
|
-
// --- Extra field helpers ---
|
|
206
|
-
|
|
207
|
-
function _exfl(ex) {
|
|
208
|
-
let le = 0;
|
|
209
|
-
if (ex) for (const k in ex) {
|
|
210
|
-
const l = ex[k].length;
|
|
211
|
-
// @ts-ignore - Error.code is a non-standard but widely-used extension
|
|
212
|
-
if (l > 65535) { const e = new Error('extra field too long'); e.code = 9; throw e; }
|
|
213
|
-
le += l + 4;
|
|
214
|
-
}
|
|
215
|
-
return le;
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
function _writeExtra(d, b, ex) {
|
|
219
|
-
if (!ex) return b;
|
|
220
|
-
for (const k in ex) {
|
|
221
|
-
const exf = ex[k];
|
|
222
|
-
_w16(d, b, +k); _w16(d, b + 2, exf.length);
|
|
223
|
-
d.set(exf, b + 4);
|
|
224
|
-
b += 4 + exf.length;
|
|
225
|
-
}
|
|
226
|
-
return b;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
// --- Local file header (PK\x03\x04) ---
|
|
230
|
-
|
|
231
|
-
function _localHeaderSize(fnLen, exLen) {
|
|
232
|
-
return 30 + fnLen + exLen;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
function _writeLocalHeader(d, b, fn, fnBytes, u, compression, dosTime, crc, cSize, uSize, ex) {
|
|
236
|
-
_w32(d, b, 0x04034B50); b += 4; // signature
|
|
237
|
-
d[b] = 20; b += 2; // version needed
|
|
238
|
-
d[b] = (compression < 0 && 8); d[b + 1] = u && 8; b += 2; // flags: data descriptor, UTF-8
|
|
239
|
-
_w16(d, b, compression & 0xFFFF); b += 2; // compression method
|
|
240
|
-
_w32(d, b, dosTime); b += 4; // last mod
|
|
241
|
-
if (compression >= 0) {
|
|
242
|
-
_w32(d, b, crc); b += 4; // CRC-32
|
|
243
|
-
_w32(d, b, cSize); b += 4; // compressed size
|
|
244
|
-
_w32(d, b, uSize); b += 4; // uncompressed size
|
|
245
|
-
} else {
|
|
246
|
-
b += 12; // will be filled by data descriptor
|
|
247
|
-
}
|
|
248
|
-
_w16(d, b, fnBytes.length); b += 2; // filename length
|
|
249
|
-
_w16(d, b, _exfl(ex)); b += 2; // extra length
|
|
250
|
-
d.set(fnBytes, b); b += fnBytes.length;
|
|
251
|
-
return _writeExtra(d, b, ex);
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
// --- Central directory entry (PK\x01\x02) ---
|
|
255
|
-
|
|
256
|
-
function _centralEntrySize(fnLen, exLen, comLen) {
|
|
257
|
-
return 46 + fnLen + exLen + comLen;
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
function _writeCentralEntry(d, b, fnBytes, u, compression, dosTime, crc, cSize, uSize, localOffset, ex, comment) {
|
|
261
|
-
_w32(d, b, 0x02014B50); b += 4; // signature
|
|
262
|
-
d[b] = 20; d[b + 1] = 0; b += 2; // version made by
|
|
263
|
-
d[b] = 20; b += 2; // version needed
|
|
264
|
-
d[b] = _dbf(compression) << 1; d[b + 1] = u && 8; b += 2; // flags
|
|
265
|
-
_w16(d, b, compression < 0 ? 0 : compression & 0xFFFF); b += 2;
|
|
266
|
-
_w32(d, b, dosTime); b += 4;
|
|
267
|
-
_w32(d, b, crc); b += 4;
|
|
268
|
-
_w32(d, b, compression < 0 ? (-compression - 2) : cSize); b += 4;
|
|
269
|
-
_w32(d, b, uSize); b += 4;
|
|
270
|
-
_w16(d, b, fnBytes.length); b += 2;
|
|
271
|
-
const exl = _exfl(ex);
|
|
272
|
-
_w16(d, b, exl); b += 2;
|
|
273
|
-
const coml = comment ? comment.length : 0;
|
|
274
|
-
_w16(d, b, coml); b += 2;
|
|
275
|
-
b += 2; // disk number start
|
|
276
|
-
b += 2; // internal attributes
|
|
277
|
-
b += 4; // external attributes
|
|
278
|
-
_w32(d, b, localOffset); b += 4;
|
|
279
|
-
d.set(fnBytes, b); b += fnBytes.length;
|
|
280
|
-
b = _writeExtra(d, b, ex);
|
|
281
|
-
if (comment) { d.set(comment, b); b += coml; }
|
|
282
|
-
return b;
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
// --- End of central directory (PK\x05\x06) ---
|
|
286
|
-
|
|
287
|
-
function _writeEOCD(o, b, entryCount, cdSize, cdOffset) {
|
|
288
|
-
_w32(o, b, 0x06054B50); b += 4;
|
|
289
|
-
b += 4; // disk number + start disk
|
|
290
|
-
_w16(o, b, entryCount); b += 2;
|
|
291
|
-
_w16(o, b, entryCount); b += 2;
|
|
292
|
-
_w32(o, b, cdSize); b += 4;
|
|
293
|
-
_w32(o, b, cdOffset);
|
|
294
|
-
// comment length field (2 bytes, value 0): implicitly zero in output buffer
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
// --- ZIP64 extra field reader ---
|
|
298
|
-
|
|
299
|
-
function _z64e(d, b) {
|
|
300
|
-
while (_r16(d, b) !== 1) b += 4 + _r16(d, b + 2);
|
|
301
|
-
return [_r64(d, b + 12), _r64(d, b + 4), _r64(d, b + 20)];
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
// Local file header data offset (skip local header)
|
|
305
|
-
function _slzh(d, b) {
|
|
306
|
-
return b + 30 + _r16(d, b + 26) + _r16(d, b + 28);
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
// Read central directory entry, return [compression, cSize, uSize, name, nextOffset, localOffset]
|
|
310
|
-
function _readCDE(d, b, zip64) {
|
|
311
|
-
const fnl = _r16(d, b + 28);
|
|
312
|
-
const utf8 = (_r16(d, b + 8) & 0x800) !== 0;
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
const
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
const
|
|
374
|
-
const
|
|
375
|
-
|
|
376
|
-
const
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
let
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
*
|
|
572
|
-
*
|
|
573
|
-
*
|
|
574
|
-
*
|
|
575
|
-
*
|
|
576
|
-
*
|
|
577
|
-
*
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
this.
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
*
|
|
619
|
-
*
|
|
620
|
-
*
|
|
621
|
-
*
|
|
622
|
-
* @
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
const
|
|
631
|
-
|
|
632
|
-
const
|
|
633
|
-
const
|
|
634
|
-
const
|
|
635
|
-
const
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
const
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
const
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
const
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
*
|
|
751
|
-
*
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
*
|
|
780
|
-
*
|
|
781
|
-
*
|
|
782
|
-
*
|
|
783
|
-
*
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
1
|
+
// Copyright (c) 2026 AwaCloud SAS
|
|
2
|
+
// Author: Matthieu Bouilloux
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @fileoverview ZIP archive creation and extraction factory.
|
|
7
|
+
*
|
|
8
|
+
* Supports ZIP and ZIP64 format (for archives > 4 GB) with DEFLATE compression
|
|
9
|
+
* (method 8) and store (method 0) ISO/IEC 21320-1. File entries can be plain `Uint8Array` or
|
|
10
|
+
* `[Uint8Array, PerFileOptions]` tuples. Directory objects are flattened with
|
|
11
|
+
* a trailing `/` path separator.
|
|
12
|
+
*
|
|
13
|
+
* ## API
|
|
14
|
+
*
|
|
15
|
+
* | Method | Returns |
|
|
16
|
+
* |---|---|
|
|
17
|
+
* | `zipSync(files, opts?)` | `Uint8Array` - synchronous archive creation |
|
|
18
|
+
* | `unzipSync(data, opts?)` | `{ [path]: Uint8Array }` - synchronous extraction |
|
|
19
|
+
* | `zip(files, opts?)` | `Promise<Uint8Array>` |
|
|
20
|
+
* | `unzip(data, opts?)` | `Promise<{ [path]: Uint8Array }>` |
|
|
21
|
+
*
|
|
22
|
+
* ## Files argument
|
|
23
|
+
*
|
|
24
|
+
* ```js
|
|
25
|
+
* {
|
|
26
|
+
* 'file.txt': data, // Uint8Array
|
|
27
|
+
* 'archive/big.bin': [data, { level: 0 }], // with per-file options
|
|
28
|
+
* 'subdir/': {}, // directory entry
|
|
29
|
+
* }
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* ## Per-file options
|
|
33
|
+
*
|
|
34
|
+
* `{ level?: 0–9, mtime?: number|Date, comment?: string, extra?: object }`
|
|
35
|
+
*
|
|
36
|
+
* Set `level: 0` to store without compression.
|
|
37
|
+
*
|
|
38
|
+
* ## Deterministic / reproducible archives
|
|
39
|
+
*
|
|
40
|
+
* `opts.mtime` (writer-level default) also accepts `number|Date`, on both
|
|
41
|
+
* write paths: `zipSync`/`zip`'s `opts` argument and `ZipStream`'s
|
|
42
|
+
* constructor `opts`. It seeds every entry that does not supply its own
|
|
43
|
+
* `p.mtime` (per-entry `mtime` always wins). Fixing the writer-level
|
|
44
|
+
* `mtime` makes two writes of an identical payload byte-identical —
|
|
45
|
+
* without it, each entry's timestamp defaults to `Date.now()` and bytes
|
|
46
|
+
* differ run to run. Valid range is 1980-2099 (MS-DOS date/time,
|
|
47
|
+
* 2-second resolution); outside it throws error code 10, fixed mtime
|
|
48
|
+
* included. This module only provides the option — a caller composing on
|
|
49
|
+
* top of `zip` (e.g. a document-format writer) must thread its own fixed
|
|
50
|
+
* `mtime` through to claim reproducible output.
|
|
51
|
+
*
|
|
52
|
+
* ## Extraction options
|
|
53
|
+
*
|
|
54
|
+
* `{ filter?: ({ name, size, originalSize, compression }) => boolean }`
|
|
55
|
+
*
|
|
56
|
+
*/
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Writer returned by `ZipStream.openEntry(...)`.
|
|
60
|
+
* @typedef {object} ZipEntryWriter
|
|
61
|
+
* @property {(chunk: Uint8Array, final?: boolean) => void} push
|
|
62
|
+
*/
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Streaming ZIP archive writer instance shape.
|
|
66
|
+
* @typedef {object} ZipStreamInstance
|
|
67
|
+
* @property {((chunk: Uint8Array, isFinal: boolean) => void)|null} ondata
|
|
68
|
+
* @property {(name: string, data: Uint8Array|[Uint8Array, object], opts?: object) => void} add
|
|
69
|
+
* @property {(name: string, opts?: object) => ZipEntryWriter} openEntry
|
|
70
|
+
* @property {() => void} finalize
|
|
71
|
+
*/
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Constructor for `ZipStream`.
|
|
75
|
+
* @typedef {new (opts?: object|((chunk: Uint8Array, isFinal: boolean) => void), ondata?: (chunk: Uint8Array, isFinal: boolean) => void) => ZipStreamInstance} ZipStreamCtor
|
|
76
|
+
*/
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Streaming ZIP reader instance shape.
|
|
80
|
+
* @typedef {object} ZipStreamReaderInstance
|
|
81
|
+
* @property {((name: string, data: Uint8Array, isFinal: boolean) => void)|null} onfile
|
|
82
|
+
* @property {(chunk: Uint8Array, final?: boolean) => void} push
|
|
83
|
+
*/
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Constructor for `ZipStreamReader`.
|
|
87
|
+
* @typedef {new (opts?: object|((name: string, data: Uint8Array, isFinal: boolean) => void), onfile?: (name: string, data: Uint8Array, isFinal: boolean) => void) => ZipStreamReaderInstance} ZipStreamReaderCtor
|
|
88
|
+
*/
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Public surface of `zip.factory(...)`.
|
|
92
|
+
* @typedef {object} ZipApi
|
|
93
|
+
* @property {(files: object, opts?: object) => Uint8Array} zipSync
|
|
94
|
+
* @property {(data: Uint8Array, opts?: object) => Object<string, Uint8Array>} unzipSync
|
|
95
|
+
* @property {(files: object, opts?: object) => Promise<Uint8Array>} zip
|
|
96
|
+
* @property {(data: Uint8Array, opts?: object) => Promise<Object<string, Uint8Array>>} unzip
|
|
97
|
+
* @property {ZipStreamCtor} ZipStream
|
|
98
|
+
* @property {ZipStreamReaderCtor} ZipStreamReader
|
|
99
|
+
*/
|
|
100
|
+
|
|
101
|
+
import { deflate } from './deflate.js';
|
|
102
|
+
import { crc32 } from '../calc/crc32.js';
|
|
103
|
+
|
|
104
|
+
export const zip = {
|
|
105
|
+
name: 'zip',
|
|
106
|
+
version: '1.0.0',
|
|
107
|
+
type: 'fw.io.compress',
|
|
108
|
+
dependencies: ['deflate', 'crc32'],
|
|
109
|
+
deps: [deflate, crc32],
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* @param {{ deflateSync, inflateSync, deflate, inflate, DeflateStream, InflateStream }} deflateModule
|
|
113
|
+
* @param {new() => {append: function(Uint8Array): void, get: function(): number}} Crc32 - constructor returned by crc32.factory()
|
|
114
|
+
* @returns {ZipApi}
|
|
115
|
+
*/
|
|
116
|
+
factory(deflateModule, Crc32) {
|
|
117
|
+
|
|
118
|
+
const { deflateSync, inflateSync, DeflateStream } = deflateModule;
|
|
119
|
+
|
|
120
|
+
// --- String ↔ Uint8Array helpers ---
|
|
121
|
+
|
|
122
|
+
// Native encoder/decoder (universal in modern environments)
|
|
123
|
+
const _te = typeof TextEncoder !== 'undefined' && new TextEncoder();
|
|
124
|
+
const _td = typeof TextDecoder !== 'undefined' && new TextDecoder();
|
|
125
|
+
|
|
126
|
+
function _strToU8(str) {
|
|
127
|
+
if (_te) return _te.encode(str);
|
|
128
|
+
// Fallback: manual UTF-8 for non-ASCII
|
|
129
|
+
const a = [];
|
|
130
|
+
for (let i = 0; i < str.length; ++i) {
|
|
131
|
+
let c = str.charCodeAt(i);
|
|
132
|
+
if (c < 0x80) {
|
|
133
|
+
a.push(c);
|
|
134
|
+
} else if (c < 0x800) {
|
|
135
|
+
a.push(0xC0 | (c >> 6), 0x80 | (c & 0x3F));
|
|
136
|
+
} else if (c > 0xD7FF && c < 0xE000) {
|
|
137
|
+
c = 0x10000 + (((c & 0x3FF) << 10) | (str.charCodeAt(++i) & 0x3FF));
|
|
138
|
+
a.push(0xF0 | (c >> 18), 0x80 | ((c >> 12) & 0x3F), 0x80 | ((c >> 6) & 0x3F), 0x80 | (c & 0x3F));
|
|
139
|
+
} else {
|
|
140
|
+
a.push(0xE0 | (c >> 12), 0x80 | ((c >> 6) & 0x3F), 0x80 | (c & 0x3F));
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return new Uint8Array(a);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// Decode bytes as UTF-8 (utf8=true) or Latin-1 (utf8=false)
|
|
147
|
+
function _u8ToStr(d, utf8) {
|
|
148
|
+
if (!utf8) {
|
|
149
|
+
// Latin-1: one char per byte
|
|
150
|
+
let r = '';
|
|
151
|
+
for (let i = 0; i < d.length; i += 16384)
|
|
152
|
+
r += String.fromCharCode(...d.subarray(i, i + 16384));
|
|
153
|
+
return r;
|
|
154
|
+
}
|
|
155
|
+
if (_td) return _td.decode(d);
|
|
156
|
+
// Fallback manual decode
|
|
157
|
+
let r = '';
|
|
158
|
+
for (let i = 0; i < d.length;) {
|
|
159
|
+
const b = d[i++];
|
|
160
|
+
if (b < 0x80) { r += String.fromCharCode(b); }
|
|
161
|
+
else if (b < 0xE0) { r += String.fromCharCode(((b & 0x1F) << 6) | (d[i++] & 0x3F)); }
|
|
162
|
+
else if (b < 0xF0) { r += String.fromCharCode(((b & 0x0F) << 12) | ((d[i++] & 0x3F) << 6) | (d[i++] & 0x3F)); }
|
|
163
|
+
else {
|
|
164
|
+
let cp = ((b & 0x07) << 18) | ((d[i++] & 0x3F) << 12) | ((d[i++] & 0x3F) << 6) | (d[i++] & 0x3F);
|
|
165
|
+
cp -= 0x10000;
|
|
166
|
+
r += String.fromCharCode(0xD800 | (cp >> 10), 0xDC00 | (cp & 0x3FF));
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return r;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// True when the string contains no characters outside Latin-1
|
|
173
|
+
function _isUTF8(str) {
|
|
174
|
+
for (let i = 0; i < str.length; ++i) if (str.charCodeAt(i) > 127) return true;
|
|
175
|
+
return false;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// --- Byte-level helpers ---
|
|
179
|
+
|
|
180
|
+
function _r16(d, b) { return d[b] | (d[b + 1] << 8); }
|
|
181
|
+
function _r32(d, b) { return (d[b] | (d[b + 1] << 8) | (d[b + 2] << 16) | (d[b + 3] << 24)) >>> 0; }
|
|
182
|
+
function _r64(d, b) { return _r32(d, b) + _r32(d, b + 4) * 4294967296; }
|
|
183
|
+
|
|
184
|
+
function _w16(d, b, v) { d[b] = v & 0xFF; d[b + 1] = (v >> 8) & 0xFF; }
|
|
185
|
+
function _w32(d, b, v) { d[b] = v & 0xFF; d[b + 1] = (v >> 8) & 0xFF; d[b + 2] = (v >> 16) & 0xFF; d[b + 3] = (v >>> 24) & 0xFF; }
|
|
186
|
+
|
|
187
|
+
// --- MS-DOS date/time encoding ---
|
|
188
|
+
|
|
189
|
+
function _dosDateTime(mtime) {
|
|
190
|
+
const d = new Date(mtime ?? Date.now());
|
|
191
|
+
const y = d.getFullYear() - 1980;
|
|
192
|
+
if (y < 0 || y > 119) {
|
|
193
|
+
const e = new Error('date not in range 1980-2099');
|
|
194
|
+
// @ts-ignore - Error.code is a non-standard but widely-used extension
|
|
195
|
+
e.code = 'EBADDATE'; e.errno = 10;
|
|
196
|
+
throw e;
|
|
197
|
+
}
|
|
198
|
+
return (y << 25) | ((d.getMonth() + 1) << 21) | (d.getDate() << 16)
|
|
199
|
+
| (d.getHours() << 11) | (d.getMinutes() << 5) | (d.getSeconds() >> 1);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// Deflate bit flag from level
|
|
203
|
+
function _dbf(l) { return l === 1 ? 3 : l < 6 ? 2 : l === 9 ? 1 : 0; }
|
|
204
|
+
|
|
205
|
+
// --- Extra field helpers ---
|
|
206
|
+
|
|
207
|
+
function _exfl(ex) {
|
|
208
|
+
let le = 0;
|
|
209
|
+
if (ex) for (const k in ex) {
|
|
210
|
+
const l = ex[k].length;
|
|
211
|
+
// @ts-ignore - Error.code is a non-standard but widely-used extension
|
|
212
|
+
if (l > 65535) { const e = new Error('extra field too long'); e.code = 'EEXTRATOOLONG'; e.errno = 9; throw e; }
|
|
213
|
+
le += l + 4;
|
|
214
|
+
}
|
|
215
|
+
return le;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
function _writeExtra(d, b, ex) {
|
|
219
|
+
if (!ex) return b;
|
|
220
|
+
for (const k in ex) {
|
|
221
|
+
const exf = ex[k];
|
|
222
|
+
_w16(d, b, +k); _w16(d, b + 2, exf.length);
|
|
223
|
+
d.set(exf, b + 4);
|
|
224
|
+
b += 4 + exf.length;
|
|
225
|
+
}
|
|
226
|
+
return b;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// --- Local file header (PK\x03\x04) ---
|
|
230
|
+
|
|
231
|
+
function _localHeaderSize(fnLen, exLen) {
|
|
232
|
+
return 30 + fnLen + exLen;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
function _writeLocalHeader(d, b, fn, fnBytes, u, compression, dosTime, crc, cSize, uSize, ex) {
|
|
236
|
+
_w32(d, b, 0x04034B50); b += 4; // signature
|
|
237
|
+
d[b] = 20; b += 2; // version needed
|
|
238
|
+
d[b] = (compression < 0 && 8); d[b + 1] = u && 8; b += 2; // flags: data descriptor, UTF-8
|
|
239
|
+
_w16(d, b, compression & 0xFFFF); b += 2; // compression method
|
|
240
|
+
_w32(d, b, dosTime); b += 4; // last mod
|
|
241
|
+
if (compression >= 0) {
|
|
242
|
+
_w32(d, b, crc); b += 4; // CRC-32
|
|
243
|
+
_w32(d, b, cSize); b += 4; // compressed size
|
|
244
|
+
_w32(d, b, uSize); b += 4; // uncompressed size
|
|
245
|
+
} else {
|
|
246
|
+
b += 12; // will be filled by data descriptor
|
|
247
|
+
}
|
|
248
|
+
_w16(d, b, fnBytes.length); b += 2; // filename length
|
|
249
|
+
_w16(d, b, _exfl(ex)); b += 2; // extra length
|
|
250
|
+
d.set(fnBytes, b); b += fnBytes.length;
|
|
251
|
+
return _writeExtra(d, b, ex);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
// --- Central directory entry (PK\x01\x02) ---
|
|
255
|
+
|
|
256
|
+
function _centralEntrySize(fnLen, exLen, comLen) {
|
|
257
|
+
return 46 + fnLen + exLen + comLen;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
function _writeCentralEntry(d, b, fnBytes, u, compression, dosTime, crc, cSize, uSize, localOffset, ex, comment) {
|
|
261
|
+
_w32(d, b, 0x02014B50); b += 4; // signature
|
|
262
|
+
d[b] = 20; d[b + 1] = 0; b += 2; // version made by
|
|
263
|
+
d[b] = 20; b += 2; // version needed
|
|
264
|
+
d[b] = _dbf(compression) << 1; d[b + 1] = u && 8; b += 2; // flags
|
|
265
|
+
_w16(d, b, compression < 0 ? 0 : compression & 0xFFFF); b += 2;
|
|
266
|
+
_w32(d, b, dosTime); b += 4;
|
|
267
|
+
_w32(d, b, crc); b += 4;
|
|
268
|
+
_w32(d, b, compression < 0 ? (-compression - 2) : cSize); b += 4;
|
|
269
|
+
_w32(d, b, uSize); b += 4;
|
|
270
|
+
_w16(d, b, fnBytes.length); b += 2;
|
|
271
|
+
const exl = _exfl(ex);
|
|
272
|
+
_w16(d, b, exl); b += 2;
|
|
273
|
+
const coml = comment ? comment.length : 0;
|
|
274
|
+
_w16(d, b, coml); b += 2;
|
|
275
|
+
b += 2; // disk number start
|
|
276
|
+
b += 2; // internal attributes
|
|
277
|
+
b += 4; // external attributes
|
|
278
|
+
_w32(d, b, localOffset); b += 4;
|
|
279
|
+
d.set(fnBytes, b); b += fnBytes.length;
|
|
280
|
+
b = _writeExtra(d, b, ex);
|
|
281
|
+
if (comment) { d.set(comment, b); b += coml; }
|
|
282
|
+
return b;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
// --- End of central directory (PK\x05\x06) ---
|
|
286
|
+
|
|
287
|
+
function _writeEOCD(o, b, entryCount, cdSize, cdOffset) {
|
|
288
|
+
_w32(o, b, 0x06054B50); b += 4;
|
|
289
|
+
b += 4; // disk number + start disk
|
|
290
|
+
_w16(o, b, entryCount); b += 2;
|
|
291
|
+
_w16(o, b, entryCount); b += 2;
|
|
292
|
+
_w32(o, b, cdSize); b += 4;
|
|
293
|
+
_w32(o, b, cdOffset);
|
|
294
|
+
// comment length field (2 bytes, value 0): implicitly zero in output buffer
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
// --- ZIP64 extra field reader ---
|
|
298
|
+
|
|
299
|
+
function _z64e(d, b) {
|
|
300
|
+
while (_r16(d, b) !== 1) b += 4 + _r16(d, b + 2);
|
|
301
|
+
return [_r64(d, b + 12), _r64(d, b + 4), _r64(d, b + 20)];
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
// Local file header data offset (skip local header)
|
|
305
|
+
function _slzh(d, b) {
|
|
306
|
+
return b + 30 + _r16(d, b + 26) + _r16(d, b + 28);
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
// Read central directory entry, return [compression, cSize, uSize, name, nextOffset, localOffset]
|
|
310
|
+
function _readCDE(d, b, zip64) {
|
|
311
|
+
const fnl = _r16(d, b + 28);
|
|
312
|
+
const utf8 = (_r16(d, b + 8) & 0x800) !== 0;
|
|
313
|
+
// `\` becomes `/` (D25): APPNOTE 4.4.17 allows forward slashes only,
|
|
314
|
+
// and .NET Framework's ZipFile.CreateFromDirectory writes `\`;
|
|
315
|
+
// Info-ZIP, 7-Zip and CPython present such names with `/` too.
|
|
316
|
+
const fn = _u8ToStr(d.subarray(b + 46, b + 46 + fnl), utf8).replace(/\\/g, '/');
|
|
317
|
+
const es = b + 46 + fnl;
|
|
318
|
+
const bs = _r32(d, b + 20);
|
|
319
|
+
const [sc, su, off] = zip64 && bs === 0xFFFFFFFF
|
|
320
|
+
? _z64e(d, es)
|
|
321
|
+
: [bs, _r32(d, b + 24), _r32(d, b + 42)];
|
|
322
|
+
return [_r16(d, b + 10), sc, su, fn, es + _r16(d, b + 30) + _r16(d, b + 32), off, _r32(d, b + 16) >>> 0];
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
// --- Flatten nested directory structure ---
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* Set an own enumerable property, `__proto__` included: assigning
|
|
329
|
+
* `obj.__proto__ = v` would replace the object's prototype with a
|
|
330
|
+
* decoded value instead of storing it. Every other key assigns.
|
|
331
|
+
*/
|
|
332
|
+
function _setOwn(obj, key, value) {
|
|
333
|
+
if (key === '__proto__') {
|
|
334
|
+
Object.defineProperty(obj, key, { value, writable: true, enumerable: true, configurable: true });
|
|
335
|
+
} else {
|
|
336
|
+
obj[key] = value;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
function _flatten(d, prefix, out, defaultOpts) {
|
|
341
|
+
for (const k in d) {
|
|
342
|
+
const val = d[k];
|
|
343
|
+
const name = prefix + k;
|
|
344
|
+
let data = val, opts = defaultOpts;
|
|
345
|
+
if (Array.isArray(val)) { opts = Object.assign({}, defaultOpts, val[1]); data = val[0]; }
|
|
346
|
+
if (data instanceof Uint8Array) {
|
|
347
|
+
_setOwn(out, name, [data, opts]);
|
|
348
|
+
} else {
|
|
349
|
+
_setOwn(out, name + '/', [new Uint8Array(0), opts]);
|
|
350
|
+
_flatten(data, name + '/', out, defaultOpts);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
// --- Synchronous API ---
|
|
356
|
+
|
|
357
|
+
/**
|
|
358
|
+
* Create a ZIP archive synchronously.
|
|
359
|
+
*
|
|
360
|
+
* @param {object} files - `{ path: Uint8Array | [Uint8Array, opts] | object }`
|
|
361
|
+
* @param {object} [opts] - default per-file options
|
|
362
|
+
* @returns {Uint8Array}
|
|
363
|
+
*/
|
|
364
|
+
function zipSync(files, opts = {}) {
|
|
365
|
+
const flat = {};
|
|
366
|
+
_flatten(files, '', flat, opts);
|
|
367
|
+
|
|
368
|
+
const entries = [];
|
|
369
|
+
let dataLen = 0;
|
|
370
|
+
let cdLen = 0;
|
|
371
|
+
|
|
372
|
+
for (const fn in flat) {
|
|
373
|
+
const [file, p] = flat[fn];
|
|
374
|
+
const compression = (p.level === 0) ? 0 : 8;
|
|
375
|
+
const fnBytes = _strToU8(fn);
|
|
376
|
+
const fnLen = fnBytes.length;
|
|
377
|
+
// @ts-ignore - Error.code is a non-standard but widely-used extension
|
|
378
|
+
if (fnLen > 65535) { const e = new Error('filename too long'); e.code = 'ENAMETOOLONG'; e.errno = 11; throw e; }
|
|
379
|
+
const comBytes = p.comment ? _strToU8(p.comment) : null;
|
|
380
|
+
const exl = _exfl(p.extra);
|
|
381
|
+
const u = _isUTF8(fn) || (comBytes && _isUTF8(p.comment));
|
|
382
|
+
const dosTime = _dosDateTime(p.mtime);
|
|
383
|
+
|
|
384
|
+
const crc = new Crc32();
|
|
385
|
+
crc.append(file);
|
|
386
|
+
|
|
387
|
+
const compressed = compression ? deflateSync(file, p) : file;
|
|
388
|
+
const cSize = compressed.length;
|
|
389
|
+
const uSize = file.length;
|
|
390
|
+
const crcVal = crc.get();
|
|
391
|
+
|
|
392
|
+
const localHdrLen = _localHeaderSize(fnLen, exl);
|
|
393
|
+
entries.push({ fnBytes, u, compression, dosTime, crcVal, cSize, uSize,
|
|
394
|
+
compressed, localHdrLen, p, comBytes, exl, localOffset: dataLen });
|
|
395
|
+
|
|
396
|
+
dataLen += localHdrLen + cSize;
|
|
397
|
+
cdLen += _centralEntrySize(fnLen, exl, comBytes ? comBytes.length : 0);
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
const out = new Uint8Array(dataLen + cdLen + 22);
|
|
401
|
+
let pos = 0, cdPos = dataLen;
|
|
402
|
+
|
|
403
|
+
for (const e of entries) {
|
|
404
|
+
// Write local header + data
|
|
405
|
+
pos = _writeLocalHeader(out, pos, null, e.fnBytes, e.u, e.compression,
|
|
406
|
+
e.dosTime, e.crcVal, e.cSize, e.uSize, e.p.extra);
|
|
407
|
+
out.set(e.compressed, pos); pos += e.cSize;
|
|
408
|
+
|
|
409
|
+
// Write central directory entry
|
|
410
|
+
cdPos = _writeCentralEntry(out, cdPos, e.fnBytes, e.u, e.compression,
|
|
411
|
+
e.dosTime, e.crcVal, e.cSize, e.uSize, e.localOffset, e.p.extra, e.comBytes);
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
_writeEOCD(out, cdPos, entries.length, cdLen, dataLen);
|
|
415
|
+
return out;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
// Reject paths that would escape the extraction root: any `..`
|
|
419
|
+
// segment or an absolute path (POSIX `/`, Windows drive letter, or
|
|
420
|
+
// Windows UNC `\\`). Default-on per ZIP-slip mitigation; callers can
|
|
421
|
+
// opt out with `{ safe: false }`.
|
|
422
|
+
function _isUnsafePath(name) {
|
|
423
|
+
if (!name) return false;
|
|
424
|
+
// Absolute POSIX
|
|
425
|
+
if (name.charCodeAt(0) === 0x2F) return true;
|
|
426
|
+
// Absolute Windows: `C:` or `\\server`
|
|
427
|
+
if (/^[A-Za-z]:[\\/]/.test(name)) return true;
|
|
428
|
+
if (name.startsWith('\\\\')) return true;
|
|
429
|
+
// Normalise separators then look for `..` segments.
|
|
430
|
+
const segs = name.split(/[\\/]/);
|
|
431
|
+
for (const s of segs) if (s === '..') return true;
|
|
432
|
+
return false;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
/**
|
|
436
|
+
* Extract a ZIP archive synchronously.
|
|
437
|
+
*
|
|
438
|
+
* `maxOutput` caps the bytes extracted over every entry: each entry's
|
|
439
|
+
* declared size is checked against what is left BEFORE its buffer is
|
|
440
|
+
* allocated, and code 7 is thrown past it. Each entry's CRC-32 and
|
|
441
|
+
* size are checked (code 16 on a mismatch); `verify: false` skips
|
|
442
|
+
* the check.
|
|
443
|
+
*
|
|
444
|
+
* @param {Uint8Array} data
|
|
445
|
+
* @param {object} [opts] - `{ filter?: fn, safe?: boolean, verify?: boolean, maxOutput?: number }`
|
|
446
|
+
* @returns {{ [path: string]: Uint8Array }}
|
|
447
|
+
*/
|
|
448
|
+
function unzipSync(data, opts = {}) {
|
|
449
|
+
/** @type {{ [path: string]: Uint8Array }} */
|
|
450
|
+
const result = Object.create(null); // null prototype: no inherited key collides with a decoded one (D9 G7)
|
|
451
|
+
const safe = opts.safe !== false;
|
|
452
|
+
const cap = opts.maxOutput === undefined || opts.maxOutput === null ? Infinity : opts.maxOutput;
|
|
453
|
+
if (cap !== Infinity && !(Number.isSafeInteger(cap) && cap >= 0)) {
|
|
454
|
+
throw new RangeError('maxOutput must be a non-negative integer');
|
|
455
|
+
}
|
|
456
|
+
let extracted = 0;
|
|
457
|
+
|
|
458
|
+
// Locate end-of-central-directory record
|
|
459
|
+
let e = data.length - 22;
|
|
460
|
+
while (_r32(data, e) !== 0x06054B50) {
|
|
461
|
+
if (!e || data.length - e > 65558) {
|
|
462
|
+
const err = new Error('invalid zip data');
|
|
463
|
+
// @ts-ignore - Error.code is a non-standard but widely-used extension
|
|
464
|
+
err.code = 'EBADFORMAT'; err.errno = 13;
|
|
465
|
+
throw err;
|
|
466
|
+
}
|
|
467
|
+
--e;
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
let entryCount = _r16(data, e + 8);
|
|
471
|
+
if (!entryCount) return result;
|
|
472
|
+
|
|
473
|
+
let cdOffset = _r32(data, e + 16);
|
|
474
|
+
let zip64 = cdOffset === 0xFFFFFFFF || entryCount === 0xFFFF;
|
|
475
|
+
|
|
476
|
+
if (zip64) {
|
|
477
|
+
// ZIP64 end-of-central-directory locator at e-12
|
|
478
|
+
const ze = _r32(data, e - 12);
|
|
479
|
+
if (_r32(data, ze) === 0x06064B50) {
|
|
480
|
+
entryCount = _r32(data, ze + 32);
|
|
481
|
+
cdOffset = _r64(data, ze + 48);
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
const fltr = opts.filter;
|
|
486
|
+
let o = cdOffset;
|
|
487
|
+
|
|
488
|
+
for (let i = 0; i < entryCount; ++i) {
|
|
489
|
+
const [cmp, cSize, uSize, fn, nextOff, localOff, crcExpected] = _readCDE(data, o, zip64);
|
|
490
|
+
o = nextOff;
|
|
491
|
+
const dataStart = _slzh(data, localOff);
|
|
492
|
+
|
|
493
|
+
if (safe && _isUnsafePath(fn)) {
|
|
494
|
+
const err = new Error('zip-slip: unsafe entry path "' + fn + '"');
|
|
495
|
+
// @ts-ignore - Error.code is a non-standard but widely-used extension
|
|
496
|
+
err.code = 'EUNSAFEPATH'; err.errno = 15;
|
|
497
|
+
throw err;
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
if (fltr && !fltr({ name: fn, size: cSize, originalSize: uSize, compression: cmp })) continue;
|
|
501
|
+
|
|
502
|
+
const outSize = cmp === 0 ? cSize : uSize;
|
|
503
|
+
if (outSize > cap - extracted) {
|
|
504
|
+
const err = new Error('zip: output limit exceeded (maxOutput) at "' + fn + '"');
|
|
505
|
+
// @ts-ignore - Error.code is a non-standard but widely-used extension
|
|
506
|
+
err.code = 'EMAXOUT'; err.errno = 7;
|
|
507
|
+
throw err;
|
|
508
|
+
}
|
|
509
|
+
extracted += outSize;
|
|
510
|
+
|
|
511
|
+
if (cmp === 0) {
|
|
512
|
+
_setOwn(result, fn, new Uint8Array(data.subarray(dataStart, dataStart + cSize)));
|
|
513
|
+
} else if (cmp === 8) {
|
|
514
|
+
_setOwn(result, fn, inflateSync(data.subarray(dataStart, dataStart + cSize), {
|
|
515
|
+
out: new Uint8Array(uSize),
|
|
516
|
+
}));
|
|
517
|
+
} else {
|
|
518
|
+
const err = new Error('unknown compression type ' + cmp);
|
|
519
|
+
// @ts-ignore - Error.code is a non-standard but widely-used extension
|
|
520
|
+
err.code = 'EBADMETHOD'; err.errno = 14;
|
|
521
|
+
throw err;
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
if (opts.verify !== false) {
|
|
525
|
+
const c = new Crc32();
|
|
526
|
+
c.append(result[fn]);
|
|
527
|
+
if (c.get() !== crcExpected || result[fn].length !== uSize) {
|
|
528
|
+
const err = new Error('zip: incorrect data check (CRC-32 or size mismatch) for "' + fn + '"');
|
|
529
|
+
// @ts-ignore - Error.code is a non-standard but widely-used extension
|
|
530
|
+
err.code = 'ECHECKSUM'; err.errno = 16;
|
|
531
|
+
throw err;
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
return result;
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
// === Streaming ZIP writer helpers ===
|
|
540
|
+
|
|
541
|
+
// Local file header written with data descriptor flag (bit 3).
|
|
542
|
+
// CRC32 / cSize / uSize are 0 - the data descriptor record after the
|
|
543
|
+
// compressed data carries the real values.
|
|
544
|
+
function _writeLocalHeaderDD(d, b, fnBytes, u, method, dosTime, ex) {
|
|
545
|
+
_w32(d, b, 0x04034B50); b += 4;
|
|
546
|
+
d[b] = 20; b += 2; // version needed: 2.0
|
|
547
|
+
d[b] = 8; d[b + 1] = (u ? 8 : 0); b += 2; // flags: bit3=DD, bit11=UTF-8
|
|
548
|
+
_w16(d, b, method); b += 2; // compression method (0 or 8)
|
|
549
|
+
_w32(d, b, dosTime); b += 4; // last mod date/time
|
|
550
|
+
b += 12; // CRC32=0, cSize=0, uSize=0
|
|
551
|
+
_w16(d, b, fnBytes.length); b += 2;
|
|
552
|
+
_w16(d, b, _exfl(ex)); b += 2;
|
|
553
|
+
d.set(fnBytes, b); b += fnBytes.length;
|
|
554
|
+
return _writeExtra(d, b, ex);
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
// Data descriptor record (PK\x07\x08 + CRC32 + cSize + uSize).
|
|
558
|
+
// Written immediately after the compressed data for streaming entries.
|
|
559
|
+
function _writeDataDescriptor(d, b, crc, cSize, uSize) {
|
|
560
|
+
_w32(d, b, 0x08074B50); b += 4;
|
|
561
|
+
_w32(d, b, crc); b += 4;
|
|
562
|
+
_w32(d, b, cSize); b += 4;
|
|
563
|
+
_w32(d, b, uSize); b += 4;
|
|
564
|
+
return b;
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
// === Streaming ZIP Writer ===
|
|
568
|
+
|
|
569
|
+
/**
|
|
570
|
+
* Streaming ZIP archive writer.
|
|
571
|
+
*
|
|
572
|
+
* Emits archive bytes progressively as files are added, enabling
|
|
573
|
+
* download-while-creating use cases without buffering the whole archive.
|
|
574
|
+
* Each file entry (whether added via `add` or `openEntry`) is written as
|
|
575
|
+
* it arrives; the Central Directory and EOCD are emitted by `finalize()`.
|
|
576
|
+
*
|
|
577
|
+
* For entries added via `openEntry`, a data descriptor record
|
|
578
|
+
* (PK\x07\x08) is written after the compressed data so that CRC32 and
|
|
579
|
+
* sizes do not need to be known in advance.
|
|
580
|
+
*
|
|
581
|
+
* ## Usage
|
|
582
|
+
*
|
|
583
|
+
* ```js
|
|
584
|
+
* const zs = new ZipStream({ level: 6 }, (chunk, final) => send(chunk));
|
|
585
|
+
*
|
|
586
|
+
* // Complete file (all bytes available now)
|
|
587
|
+
* zs.add('readme.txt', textBytes);
|
|
588
|
+
*
|
|
589
|
+
* // Large file streamed in chunks
|
|
590
|
+
* const entry = zs.openEntry('big.bin');
|
|
591
|
+
* entry.push(chunk1, false);
|
|
592
|
+
* entry.push(chunk2, true); // ← final chunk of this file
|
|
593
|
+
*
|
|
594
|
+
* zs.finalize(); // emits Central Directory + EOCD
|
|
595
|
+
* ```
|
|
596
|
+
*
|
|
597
|
+
* Only one entry may be open at a time. Do not call `add`, `openEntry`,
|
|
598
|
+
* or `finalize` while an `openEntry` writer is still active.
|
|
599
|
+
*
|
|
600
|
+
* @param {object|function} [opts] - default per-entry options, or `ondata`
|
|
601
|
+
* @param {function} [ondata] - callback(chunk: Uint8Array, isFinal: boolean)
|
|
602
|
+
*/
|
|
603
|
+
function ZipStream(opts, ondata) {
|
|
604
|
+
if (typeof opts === 'function') { ondata = opts; opts = {}; }
|
|
605
|
+
this.ondata = ondata || null;
|
|
606
|
+
this._opts = opts || {};
|
|
607
|
+
this._off = 0; // bytes emitted to the consumer so far
|
|
608
|
+
this._entries = []; // metadata for the Central Directory
|
|
609
|
+
this._active = null; // non-null while an openEntry writer is live
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
ZipStream.prototype._emit = function(chunk, final) {
|
|
613
|
+
this._off += chunk.length;
|
|
614
|
+
if (this.ondata) this.ondata(chunk, !!final);
|
|
615
|
+
};
|
|
616
|
+
|
|
617
|
+
/**
|
|
618
|
+
* Add a complete file entry synchronously.
|
|
619
|
+
*
|
|
620
|
+
* All of the file's bytes must be available at call time.
|
|
621
|
+
*
|
|
622
|
+
* @param {string} name
|
|
623
|
+
* @param {Uint8Array|[Uint8Array, object]} data - file content or `[content, perFileOpts]`
|
|
624
|
+
* @param {object} [opts] - per-entry options (merged with constructor opts)
|
|
625
|
+
*/
|
|
626
|
+
ZipStream.prototype.add = function(name, data, opts) {
|
|
627
|
+
if (this._active) throw new Error('ZipStream: an entry is still open');
|
|
628
|
+
if (Array.isArray(data)) { opts = Object.assign({}, data[1], opts); data = data[0]; }
|
|
629
|
+
const p = Object.assign({}, this._opts, opts);
|
|
630
|
+
const fnBytes = _strToU8(name);
|
|
631
|
+
// @ts-ignore - Error.code is a non-standard but widely-used extension
|
|
632
|
+
if (fnBytes.length > 65535) { const e = new Error('filename too long'); e.code = 'ENAMETOOLONG'; e.errno = 11; throw e; }
|
|
633
|
+
const u = _isUTF8(name);
|
|
634
|
+
const method = p.level === 0 ? 0 : 8;
|
|
635
|
+
const dosTime = _dosDateTime(p.mtime);
|
|
636
|
+
const exl = _exfl(p.extra);
|
|
637
|
+
const localHdrLen = _localHeaderSize(fnBytes.length, exl);
|
|
638
|
+
const localOffset = this._off;
|
|
639
|
+
|
|
640
|
+
const crc = new Crc32(); crc.append(data);
|
|
641
|
+
const crcVal = crc.get();
|
|
642
|
+
const compressed = method ? deflateSync(data, p) : data;
|
|
643
|
+
const cSize = compressed.length;
|
|
644
|
+
const uSize = data.length;
|
|
645
|
+
|
|
646
|
+
const out = new Uint8Array(localHdrLen + cSize);
|
|
647
|
+
_writeLocalHeader(out, 0, null, fnBytes, u, method, dosTime, crcVal, cSize, uSize, p.extra);
|
|
648
|
+
out.set(compressed, localHdrLen);
|
|
649
|
+
this._emit(out, false);
|
|
650
|
+
|
|
651
|
+
const comBytes = p.comment ? _strToU8(p.comment) : null;
|
|
652
|
+
this._entries.push({ fnBytes, u, method, dosTime, crcVal, cSize, uSize, localOffset, extra: p.extra, comBytes });
|
|
653
|
+
};
|
|
654
|
+
|
|
655
|
+
/**
|
|
656
|
+
* Begin a streaming file entry.
|
|
657
|
+
*
|
|
658
|
+
* Returns a writer whose `push(chunk, final)` method accepts file content
|
|
659
|
+
* chunks. The archive stream receives compressed bytes as they are produced.
|
|
660
|
+
* Call `push(lastChunk, true)` to close the entry before using the `ZipStream`
|
|
661
|
+
* again.
|
|
662
|
+
*
|
|
663
|
+
* Because sizes are unknown at header-write time, the local file header has
|
|
664
|
+
* zeros for CRC32/sizes and a data descriptor record is emitted after the
|
|
665
|
+
* compressed data.
|
|
666
|
+
*
|
|
667
|
+
* @param {string} name
|
|
668
|
+
* @param {object} [opts] - per-entry options (merged with constructor opts)
|
|
669
|
+
* @returns {{ push(chunk: Uint8Array, final?: boolean): void }}
|
|
670
|
+
*/
|
|
671
|
+
ZipStream.prototype.openEntry = function(name, opts) {
|
|
672
|
+
if (this._active) throw new Error('ZipStream: an entry is still open');
|
|
673
|
+
const p = Object.assign({}, this._opts, opts);
|
|
674
|
+
const fnBytes = _strToU8(name);
|
|
675
|
+
// @ts-ignore - Error.code is a non-standard but widely-used extension
|
|
676
|
+
if (fnBytes.length > 65535) { const e = new Error('filename too long'); e.code = 'ENAMETOOLONG'; e.errno = 11; throw e; }
|
|
677
|
+
const u = _isUTF8(name);
|
|
678
|
+
const method = p.level === 0 ? 0 : 8;
|
|
679
|
+
const dosTime = _dosDateTime(p.mtime);
|
|
680
|
+
const exl = _exfl(p.extra);
|
|
681
|
+
const localHdrLen = _localHeaderSize(fnBytes.length, exl);
|
|
682
|
+
const localOffset = this._off;
|
|
683
|
+
|
|
684
|
+
// Emit local file header immediately (DD mode - sizes are 0 for now)
|
|
685
|
+
const hdr = new Uint8Array(localHdrLen);
|
|
686
|
+
_writeLocalHeaderDD(hdr, 0, fnBytes, u, method, dosTime, p.extra);
|
|
687
|
+
this._emit(hdr, false);
|
|
688
|
+
|
|
689
|
+
const crc = new Crc32();
|
|
690
|
+
let cSize = 0;
|
|
691
|
+
let uSize = 0;
|
|
692
|
+
const self = this;
|
|
693
|
+
const comBytes = p.comment ? _strToU8(p.comment) : null;
|
|
694
|
+
|
|
695
|
+
// Set up DeflateStream for DEFLATE entries. Called synchronously per push.
|
|
696
|
+
let ds = null;
|
|
697
|
+
if (method === 8) {
|
|
698
|
+
ds = new DeflateStream(p, function(chunk, dfinal) {
|
|
699
|
+
cSize += chunk.length;
|
|
700
|
+
self._emit(chunk, false);
|
|
701
|
+
if (dfinal) {
|
|
702
|
+
// Emit data descriptor (PK\x07\x08) then record the CD entry
|
|
703
|
+
const dd = new Uint8Array(16);
|
|
704
|
+
_writeDataDescriptor(dd, 0, crc.get(), cSize, uSize);
|
|
705
|
+
self._emit(dd, false);
|
|
706
|
+
self._entries.push({ fnBytes, u, method, dosTime, crcVal: crc.get(), cSize, uSize, localOffset, extra: p.extra, comBytes });
|
|
707
|
+
self._active = null;
|
|
708
|
+
}
|
|
709
|
+
});
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
const state = { done: false };
|
|
713
|
+
this._active = state;
|
|
714
|
+
|
|
715
|
+
return {
|
|
716
|
+
/**
|
|
717
|
+
* @param {Uint8Array} chunk
|
|
718
|
+
* @param {boolean} [final=false]
|
|
719
|
+
*/
|
|
720
|
+
push(chunk, final) {
|
|
721
|
+
if (state.done) throw new Error('ZipStream entry already finalized');
|
|
722
|
+
final = !!final;
|
|
723
|
+
crc.append(chunk);
|
|
724
|
+
uSize += chunk.length;
|
|
725
|
+
if (method === 0) {
|
|
726
|
+
// Store mode: emit raw bytes directly
|
|
727
|
+
cSize += chunk.length;
|
|
728
|
+
self._emit(chunk, false);
|
|
729
|
+
if (final) {
|
|
730
|
+
const dd = new Uint8Array(16);
|
|
731
|
+
_writeDataDescriptor(dd, 0, crc.get(), cSize, uSize);
|
|
732
|
+
self._emit(dd, false);
|
|
733
|
+
self._entries.push({ fnBytes, u, method, dosTime, crcVal: crc.get(), cSize, uSize, localOffset, extra: p.extra, comBytes });
|
|
734
|
+
self._active = null;
|
|
735
|
+
state.done = true;
|
|
736
|
+
}
|
|
737
|
+
} else {
|
|
738
|
+
// DEFLATE mode: feed chunk to DeflateStream
|
|
739
|
+
// The DeflateStream callback handles emit + DD + CD entry registration
|
|
740
|
+
ds.push(chunk, final);
|
|
741
|
+
if (final) state.done = true;
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
};
|
|
745
|
+
};
|
|
746
|
+
|
|
747
|
+
/**
|
|
748
|
+
* Finalise the archive.
|
|
749
|
+
*
|
|
750
|
+
* Emits the Central Directory and End-of-Central-Directory record.
|
|
751
|
+
* `ondata` is called with `isFinal = true` on this last chunk.
|
|
752
|
+
*
|
|
753
|
+
* Must be called after all entries have been added and any open `openEntry`
|
|
754
|
+
* writer has received its final `push`.
|
|
755
|
+
*/
|
|
756
|
+
ZipStream.prototype.finalize = function() {
|
|
757
|
+
if (this._active) throw new Error('ZipStream: an entry is still open');
|
|
758
|
+
const cdOffset = this._off;
|
|
759
|
+
let cdLen = 0;
|
|
760
|
+
for (const e of this._entries) {
|
|
761
|
+
cdLen += _centralEntrySize(e.fnBytes.length, _exfl(e.extra), e.comBytes ? e.comBytes.length : 0);
|
|
762
|
+
}
|
|
763
|
+
const out = new Uint8Array(cdLen + 22);
|
|
764
|
+
let pos = 0;
|
|
765
|
+
for (const e of this._entries) {
|
|
766
|
+
pos = _writeCentralEntry(out, pos, e.fnBytes, e.u, e.method, e.dosTime, e.crcVal, e.cSize, e.uSize, e.localOffset, e.extra, e.comBytes);
|
|
767
|
+
}
|
|
768
|
+
_writeEOCD(out, pos, this._entries.length, cdLen, cdOffset);
|
|
769
|
+
this._emit(out, true);
|
|
770
|
+
};
|
|
771
|
+
|
|
772
|
+
// === Streaming ZIP Reader ===
|
|
773
|
+
|
|
774
|
+
/**
|
|
775
|
+
* Streaming ZIP reader.
|
|
776
|
+
*
|
|
777
|
+
* Buffers all pushed chunks and extracts the archive when `push(chunk, true)`
|
|
778
|
+
* is called. The `onfile` callback receives each extracted file.
|
|
779
|
+
*
|
|
780
|
+
* Note: ZIP's Central Directory is at the end of the archive, so extraction
|
|
781
|
+
* cannot begin before the final byte arrives. This class provides a
|
|
782
|
+
* push-based interface consistent with the other streaming APIs while
|
|
783
|
+
* absorbing that constraint internally.
|
|
784
|
+
*
|
|
785
|
+
* @param {object|function} [opts] - extraction options or `onfile` callback
|
|
786
|
+
* @param {function} [onfile] - callback(name: string, data: Uint8Array, isFinal: boolean)
|
|
787
|
+
*/
|
|
788
|
+
function ZipStreamReader(opts, onfile) {
|
|
789
|
+
if (typeof opts === 'function') { onfile = opts; opts = {}; }
|
|
790
|
+
this.onfile = onfile || null;
|
|
791
|
+
this._opts = opts || {};
|
|
792
|
+
this._buf = [];
|
|
793
|
+
this._bufLen = 0;
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
/**
|
|
797
|
+
* @param {Uint8Array} chunk
|
|
798
|
+
* @param {boolean} [final=false]
|
|
799
|
+
*/
|
|
800
|
+
ZipStreamReader.prototype.push = function(chunk, final) {
|
|
801
|
+
this._buf.push(chunk);
|
|
802
|
+
this._bufLen += chunk.length;
|
|
803
|
+
if (!final) return;
|
|
804
|
+
|
|
805
|
+
// Reassemble and extract
|
|
806
|
+
const combined = new Uint8Array(this._bufLen);
|
|
807
|
+
let off = 0;
|
|
808
|
+
for (const c of this._buf) { combined.set(c, off); off += c.length; }
|
|
809
|
+
this._buf = null;
|
|
810
|
+
|
|
811
|
+
const files = unzipSync(combined, this._opts);
|
|
812
|
+
if (this.onfile) {
|
|
813
|
+
const names = Object.keys(files);
|
|
814
|
+
for (let i = 0; i < names.length; ++i) {
|
|
815
|
+
this.onfile(names[i], files[names[i]], i === names.length - 1);
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
};
|
|
819
|
+
|
|
820
|
+
// Async wrappers (microtask-deferred)
|
|
821
|
+
const _mt = typeof queueMicrotask === 'function'
|
|
822
|
+
? queueMicrotask
|
|
823
|
+
: fn => Promise.resolve().then(fn);
|
|
824
|
+
|
|
825
|
+
/**
|
|
826
|
+
* Asynchronously create a ZIP archive.
|
|
827
|
+
*
|
|
828
|
+
* @param {object} files
|
|
829
|
+
* @param {object} [opts]
|
|
830
|
+
* @returns {Promise<Uint8Array>}
|
|
831
|
+
*/
|
|
832
|
+
function zipAsync(files, opts = {}) {
|
|
833
|
+
return new Promise((resolve, reject) => {
|
|
834
|
+
_mt(() => { try { resolve(zipSync(files, opts)); } catch (e) { reject(e); } });
|
|
835
|
+
});
|
|
836
|
+
}
|
|
837
|
+
|
|
838
|
+
/**
|
|
839
|
+
* Asynchronously extract a ZIP archive.
|
|
840
|
+
*
|
|
841
|
+
* @param {Uint8Array} data
|
|
842
|
+
* @param {object} [opts]
|
|
843
|
+
* @returns {Promise<{ [path: string]: Uint8Array }>}
|
|
844
|
+
*/
|
|
845
|
+
function unzipAsync(data, opts = {}) {
|
|
846
|
+
return new Promise((resolve, reject) => {
|
|
847
|
+
_mt(() => { try { resolve(unzipSync(data, opts)); } catch (e) { reject(e); } });
|
|
848
|
+
});
|
|
849
|
+
}
|
|
850
|
+
|
|
851
|
+
return {
|
|
852
|
+
zipSync,
|
|
853
|
+
unzipSync,
|
|
854
|
+
zip: zipAsync,
|
|
855
|
+
unzip: unzipAsync,
|
|
856
|
+
// @ts-ignore - ZipStream is a constructor function matching ZipStreamCtor; TS can't verify function-as-constructor
|
|
857
|
+
ZipStream,
|
|
858
|
+
// @ts-ignore - ZipStreamReader is a constructor function matching ZipStreamReaderCtor; TS can't verify function-as-constructor
|
|
859
|
+
ZipStreamReader,
|
|
860
|
+
};
|
|
861
|
+
}
|
|
862
|
+
};
|