@tonyclaw/llm-inspector 1.6.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/.output/nitro.json +17 -0
- package/.output/public/assets/alibaba-TTwafVwX.svg +1 -0
- package/.output/public/assets/index-B3RwBPLW.css +1 -0
- package/.output/public/assets/index-s4lwsWvq.js +97 -0
- package/.output/public/assets/main-Cp8AM0Pa.js +17 -0
- package/.output/public/assets/minimax-BPMzvuL-.jpeg +0 -0
- package/.output/public/assets/qwen-CONDcHqt.png +0 -0
- package/.output/public/assets/zhipuai-BPNAnxo-.svg +219 -0
- package/.output/server/_chunks/ssr-renderer.mjs +17 -0
- package/.output/server/_libs/@radix-ui/react-accessible-icon+[...].mjs +1 -0
- package/.output/server/_libs/@radix-ui/react-dismissable-layer+[...].mjs +210 -0
- package/.output/server/_libs/@radix-ui/react-navigation-menu+[...].mjs +1 -0
- package/.output/server/_libs/@radix-ui/react-one-time-password-field+[...].mjs +1 -0
- package/.output/server/_libs/@radix-ui/react-password-toggle-field+[...].mjs +1 -0
- package/.output/server/_libs/@radix-ui/react-use-callback-ref+[...].mjs +11 -0
- package/.output/server/_libs/@radix-ui/react-use-controllable-state+[...].mjs +69 -0
- package/.output/server/_libs/@radix-ui/react-use-effect-event+[...].mjs +1 -0
- package/.output/server/_libs/@radix-ui/react-use-escape-keydown+[...].mjs +17 -0
- package/.output/server/_libs/@radix-ui/react-use-is-hydrated+[...].mjs +1 -0
- package/.output/server/_libs/@radix-ui/react-use-layout-effect+[...].mjs +6 -0
- package/.output/server/_libs/@radix-ui/react-visually-hidden+[...].mjs +34 -0
- package/.output/server/_libs/ajv-formats.mjs +330 -0
- package/.output/server/_libs/ajv.mjs +11444 -0
- package/.output/server/_libs/aria-hidden.mjs +122 -0
- package/.output/server/_libs/atomically.mjs +152 -0
- package/.output/server/_libs/bail.mjs +8 -0
- package/.output/server/_libs/character-entities.mjs +2130 -0
- package/.output/server/_libs/class-variance-authority.mjs +44 -0
- package/.output/server/_libs/clsx.mjs +16 -0
- package/.output/server/_libs/comma-separated-tokens.mjs +10 -0
- package/.output/server/_libs/conf.mjs +635 -0
- package/.output/server/_libs/cookie-es.mjs +58 -0
- package/.output/server/_libs/core-util-is.mjs +75 -0
- package/.output/server/_libs/croner.mjs +1 -0
- package/.output/server/_libs/crossws.mjs +1 -0
- package/.output/server/_libs/debounce-fn.mjs +69 -0
- package/.output/server/_libs/decode-named-character-reference+[...].mjs +8 -0
- package/.output/server/_libs/detect-node-es.mjs +1 -0
- package/.output/server/_libs/devlop.mjs +8 -0
- package/.output/server/_libs/dot-prop.mjs +265 -0
- package/.output/server/_libs/env-paths.mjs +57 -0
- package/.output/server/_libs/estree-util-is-identifier-name.mjs +11 -0
- package/.output/server/_libs/extend.mjs +97 -0
- package/.output/server/_libs/fast-deep-equal.mjs +38 -0
- package/.output/server/_libs/fast-uri.mjs +812 -0
- package/.output/server/_libs/floating-ui__core.mjs +725 -0
- package/.output/server/_libs/floating-ui__dom.mjs +622 -0
- package/.output/server/_libs/floating-ui__react-dom.mjs +292 -0
- package/.output/server/_libs/floating-ui__utils.mjs +320 -0
- package/.output/server/_libs/get-nonce.mjs +9 -0
- package/.output/server/_libs/h3-v2.mjs +276 -0
- package/.output/server/_libs/h3.mjs +400 -0
- package/.output/server/_libs/hast-util-to-jsx-runtime.mjs +388 -0
- package/.output/server/_libs/hast-util-whitespace.mjs +10 -0
- package/.output/server/_libs/hookable.mjs +1 -0
- package/.output/server/_libs/html-url-attributes.mjs +26 -0
- package/.output/server/_libs/immediate.mjs +74 -0
- package/.output/server/_libs/inherits.mjs +50 -0
- package/.output/server/_libs/inline-style-parser.mjs +142 -0
- package/.output/server/_libs/is-plain-obj.mjs +10 -0
- package/.output/server/_libs/isarray.mjs +14 -0
- package/.output/server/_libs/isbot.mjs +20 -0
- package/.output/server/_libs/json-schema-traverse.mjs +180 -0
- package/.output/server/_libs/jszip.mjs +3049 -0
- package/.output/server/_libs/lie.mjs +273 -0
- package/.output/server/_libs/lucide-react.mjs +368 -0
- package/.output/server/_libs/mdast-util-from-markdown.mjs +717 -0
- package/.output/server/_libs/mdast-util-to-hast.mjs +710 -0
- package/.output/server/_libs/mdast-util-to-string.mjs +38 -0
- package/.output/server/_libs/micromark-core-commonmark.mjs +2259 -0
- package/.output/server/_libs/micromark-factory-destination.mjs +94 -0
- package/.output/server/_libs/micromark-factory-label.mjs +63 -0
- package/.output/server/_libs/micromark-factory-space.mjs +24 -0
- package/.output/server/_libs/micromark-factory-title.mjs +65 -0
- package/.output/server/_libs/micromark-factory-whitespace.mjs +22 -0
- package/.output/server/_libs/micromark-util-character.mjs +44 -0
- package/.output/server/_libs/micromark-util-chunked.mjs +36 -0
- package/.output/server/_libs/micromark-util-classify-character+[...].mjs +12 -0
- package/.output/server/_libs/micromark-util-combine-extensions+[...].mjs +41 -0
- package/.output/server/_libs/micromark-util-decode-numeric-character-reference+[...].mjs +19 -0
- package/.output/server/_libs/micromark-util-decode-string.mjs +21 -0
- package/.output/server/_libs/micromark-util-encode.mjs +1 -0
- package/.output/server/_libs/micromark-util-html-tag-name.mjs +69 -0
- package/.output/server/_libs/micromark-util-normalize-identifier+[...].mjs +6 -0
- package/.output/server/_libs/micromark-util-resolve-all.mjs +15 -0
- package/.output/server/_libs/micromark-util-sanitize-uri.mjs +41 -0
- package/.output/server/_libs/micromark-util-subtokenize.mjs +346 -0
- package/.output/server/_libs/micromark.mjs +906 -0
- package/.output/server/_libs/mimic-function.mjs +47 -0
- package/.output/server/_libs/ohash.mjs +1 -0
- package/.output/server/_libs/pako.mjs +4223 -0
- package/.output/server/_libs/process-nextick-args.mjs +48 -0
- package/.output/server/_libs/property-information.mjs +1209 -0
- package/.output/server/_libs/radix-ui.mjs +1 -0
- package/.output/server/_libs/radix-ui__number.mjs +6 -0
- package/.output/server/_libs/radix-ui__primitive.mjs +11 -0
- package/.output/server/_libs/radix-ui__react-accordion.mjs +1 -0
- package/.output/server/_libs/radix-ui__react-alert-dialog.mjs +1 -0
- package/.output/server/_libs/radix-ui__react-arrow.mjs +23 -0
- package/.output/server/_libs/radix-ui__react-aspect-ratio.mjs +1 -0
- package/.output/server/_libs/radix-ui__react-avatar.mjs +1 -0
- package/.output/server/_libs/radix-ui__react-checkbox.mjs +1 -0
- package/.output/server/_libs/radix-ui__react-collapsible.mjs +144 -0
- package/.output/server/_libs/radix-ui__react-collection.mjs +69 -0
- package/.output/server/_libs/radix-ui__react-compose-refs.mjs +39 -0
- package/.output/server/_libs/radix-ui__react-context-menu.mjs +1 -0
- package/.output/server/_libs/radix-ui__react-context.mjs +78 -0
- package/.output/server/_libs/radix-ui__react-dialog.mjs +325 -0
- package/.output/server/_libs/radix-ui__react-direction.mjs +9 -0
- package/.output/server/_libs/radix-ui__react-dropdown-menu.mjs +1 -0
- package/.output/server/_libs/radix-ui__react-focus-guards.mjs +29 -0
- package/.output/server/_libs/radix-ui__react-focus-scope.mjs +206 -0
- package/.output/server/_libs/radix-ui__react-form.mjs +1 -0
- package/.output/server/_libs/radix-ui__react-hover-card.mjs +1 -0
- package/.output/server/_libs/radix-ui__react-id.mjs +14 -0
- package/.output/server/_libs/radix-ui__react-label.mjs +1 -0
- package/.output/server/_libs/radix-ui__react-menu.mjs +1 -0
- package/.output/server/_libs/radix-ui__react-menubar.mjs +1 -0
- package/.output/server/_libs/radix-ui__react-popover.mjs +1 -0
- package/.output/server/_libs/radix-ui__react-popper.mjs +286 -0
- package/.output/server/_libs/radix-ui__react-portal.mjs +16 -0
- package/.output/server/_libs/radix-ui__react-presence.mjs +128 -0
- package/.output/server/_libs/radix-ui__react-primitive.mjs +42 -0
- package/.output/server/_libs/radix-ui__react-progress.mjs +1 -0
- package/.output/server/_libs/radix-ui__react-radio-group.mjs +1 -0
- package/.output/server/_libs/radix-ui__react-roving-focus.mjs +224 -0
- package/.output/server/_libs/radix-ui__react-scroll-area.mjs +721 -0
- package/.output/server/_libs/radix-ui__react-select.mjs +1163 -0
- package/.output/server/_libs/radix-ui__react-separator.mjs +28 -0
- package/.output/server/_libs/radix-ui__react-slider.mjs +1 -0
- package/.output/server/_libs/radix-ui__react-slot.mjs +99 -0
- package/.output/server/_libs/radix-ui__react-switch.mjs +1 -0
- package/.output/server/_libs/radix-ui__react-tabs.mjs +189 -0
- package/.output/server/_libs/radix-ui__react-toast.mjs +1 -0
- package/.output/server/_libs/radix-ui__react-toggle-group.mjs +1 -0
- package/.output/server/_libs/radix-ui__react-toggle.mjs +1 -0
- package/.output/server/_libs/radix-ui__react-toolbar.mjs +1 -0
- package/.output/server/_libs/radix-ui__react-tooltip.mjs +495 -0
- package/.output/server/_libs/radix-ui__react-use-previous.mjs +14 -0
- package/.output/server/_libs/radix-ui__react-use-size.mjs +39 -0
- package/.output/server/_libs/react-dom.mjs +9935 -0
- package/.output/server/_libs/react-markdown.mjs +147 -0
- package/.output/server/_libs/react-remove-scroll-bar.mjs +82 -0
- package/.output/server/_libs/react-remove-scroll.mjs +328 -0
- package/.output/server/_libs/react-style-singleton.mjs +69 -0
- package/.output/server/_libs/react.mjs +515 -0
- package/.output/server/_libs/readable-stream.mjs +1518 -0
- package/.output/server/_libs/remark-parse.mjs +19 -0
- package/.output/server/_libs/remark-rehype.mjs +21 -0
- package/.output/server/_libs/rou3.mjs +8 -0
- package/.output/server/_libs/safe-buffer.mjs +64 -0
- package/.output/server/_libs/semver.mjs +1984 -0
- package/.output/server/_libs/seroval-plugins.mjs +58 -0
- package/.output/server/_libs/seroval.mjs +1765 -0
- package/.output/server/_libs/setimmediate.mjs +1 -0
- package/.output/server/_libs/space-separated-tokens.mjs +6 -0
- package/.output/server/_libs/srvx.mjs +334 -0
- package/.output/server/_libs/stubborn-fs.mjs +91 -0
- package/.output/server/_libs/stubborn-utils.mjs +66 -0
- package/.output/server/_libs/style-to-js.mjs +72 -0
- package/.output/server/_libs/style-to-object.mjs +38 -0
- package/.output/server/_libs/tailwind-merge.mjs +3010 -0
- package/.output/server/_libs/tanstack__history.mjs +217 -0
- package/.output/server/_libs/tanstack__react-router.mjs +1480 -0
- package/.output/server/_libs/tanstack__react-store.mjs +1 -0
- package/.output/server/_libs/tanstack__react-virtual.mjs +44 -0
- package/.output/server/_libs/tanstack__router-core.mjs +4827 -0
- package/.output/server/_libs/tanstack__store.mjs +1 -0
- package/.output/server/_libs/tanstack__virtual-core.mjs +1225 -0
- package/.output/server/_libs/tiny-invariant.mjs +12 -0
- package/.output/server/_libs/tiny-warning.mjs +5 -0
- package/.output/server/_libs/trim-lines.mjs +41 -0
- package/.output/server/_libs/trough.mjs +85 -0
- package/.output/server/_libs/tslib.mjs +576 -0
- package/.output/server/_libs/ufo.mjs +54 -0
- package/.output/server/_libs/uint8array-extras.mjs +69 -0
- package/.output/server/_libs/unctx.mjs +1 -0
- package/.output/server/_libs/ungap__structured-clone.mjs +212 -0
- package/.output/server/_libs/unified.mjs +661 -0
- package/.output/server/_libs/unist-util-is.mjs +100 -0
- package/.output/server/_libs/unist-util-position.mjs +27 -0
- package/.output/server/_libs/unist-util-stringify-position.mjs +27 -0
- package/.output/server/_libs/unist-util-visit-parents.mjs +82 -0
- package/.output/server/_libs/unist-util-visit.mjs +24 -0
- package/.output/server/_libs/unstorage.mjs +1 -0
- package/.output/server/_libs/use-callback-ref.mjs +66 -0
- package/.output/server/_libs/use-sidecar.mjs +106 -0
- package/.output/server/_libs/use-sync-external-store.mjs +1 -0
- package/.output/server/_libs/util-deprecate.mjs +12 -0
- package/.output/server/_libs/vfile-message.mjs +138 -0
- package/.output/server/_libs/vfile.mjs +467 -0
- package/.output/server/_libs/when-exit.mjs +53 -0
- package/.output/server/_libs/zod.mjs +4460 -0
- package/.output/server/_ssr/index-ByCLZu7J.mjs +3061 -0
- package/.output/server/_ssr/index.mjs +1176 -0
- package/.output/server/_ssr/router-Bq_mxeNz.mjs +2872 -0
- package/.output/server/_ssr/start-HYkvq4Ni.mjs +4 -0
- package/.output/server/_tanstack-start-manifest_v-C4E0e9my.mjs +4 -0
- package/.output/server/index.mjs +393 -0
- package/README.md +196 -0
- package/package.json +91 -0
- package/src/assets/logos/alibaba.svg +1 -0
- package/src/assets/logos/anthropic.svg +1 -0
- package/src/assets/logos/deepseek.svg +1 -0
- package/src/assets/logos/minimax.jpeg +0 -0
- package/src/assets/logos/openai.svg +1 -0
- package/src/assets/logos/qwen.png +0 -0
- package/src/assets/logos/zhipuai.svg +219 -0
- package/src/cli.ts +68 -0
- package/src/components/ProxyViewer.tsx +325 -0
- package/src/components/ProxyViewerContainer.tsx +211 -0
- package/src/components/providers/ProviderCard.tsx +186 -0
- package/src/components/providers/ProviderForm.tsx +259 -0
- package/src/components/providers/ProviderLogo.tsx +111 -0
- package/src/components/providers/ProvidersPanel.tsx +259 -0
- package/src/components/providers/SettingsDialog.tsx +39 -0
- package/src/components/proxy-viewer/ConversationGroup.tsx +68 -0
- package/src/components/proxy-viewer/ConversationHeader.tsx +141 -0
- package/src/components/proxy-viewer/LogEntry.tsx +225 -0
- package/src/components/proxy-viewer/LogEntryHeader.tsx +250 -0
- package/src/components/proxy-viewer/ReplayDialog.tsx +208 -0
- package/src/components/proxy-viewer/ResponseView.tsx +161 -0
- package/src/components/proxy-viewer/StreamingChunkSequence.tsx +171 -0
- package/src/components/proxy-viewer/formats/anthropic/ContentBlocks.tsx +139 -0
- package/src/components/proxy-viewer/formats/anthropic/ResponseView.tsx +64 -0
- package/src/components/proxy-viewer/formats/index.tsx +24 -0
- package/src/components/proxy-viewer/formats/openai/ResponseView.tsx +80 -0
- package/src/components/proxy-viewer/index.ts +8 -0
- package/src/components/ui/badge.tsx +47 -0
- package/src/components/ui/button.tsx +47 -0
- package/src/components/ui/collapsible.tsx +21 -0
- package/src/components/ui/dialog.tsx +129 -0
- package/src/components/ui/json-viewer.tsx +464 -0
- package/src/components/ui/scroll-area.tsx +54 -0
- package/src/components/ui/select.tsx +178 -0
- package/src/components/ui/separator.tsx +28 -0
- package/src/components/ui/tabs.tsx +88 -0
- package/src/components/ui/tooltip.tsx +51 -0
- package/src/index.css +11 -0
- package/src/lib/export-logs.ts +51 -0
- package/src/lib/utils.ts +22 -0
- package/src/proxy/chunkStorage.ts +118 -0
- package/src/proxy/constants.ts +36 -0
- package/src/proxy/formats/anthropic/anthropicProvider.ts +75 -0
- package/src/proxy/formats/anthropic/handler.ts +74 -0
- package/src/proxy/formats/anthropic/index.ts +14 -0
- package/src/proxy/formats/anthropic/register.ts +4 -0
- package/src/proxy/formats/anthropic/schemas.ts +217 -0
- package/src/proxy/formats/anthropic/stream.ts +167 -0
- package/src/proxy/formats/handler.ts +46 -0
- package/src/proxy/formats/index.ts +12 -0
- package/src/proxy/formats/jsonSchema.ts +24 -0
- package/src/proxy/formats/openai/alibabaProvider.ts +38 -0
- package/src/proxy/formats/openai/handler.ts +70 -0
- package/src/proxy/formats/openai/index.ts +25 -0
- package/src/proxy/formats/openai/provider.ts +50 -0
- package/src/proxy/formats/openai/register.ts +4 -0
- package/src/proxy/formats/openai/schemas.ts +150 -0
- package/src/proxy/formats/openai/stream.ts +153 -0
- package/src/proxy/formats/protocol.ts +50 -0
- package/src/proxy/formats/providerRegistry.ts +51 -0
- package/src/proxy/formats/providers/index.ts +3 -0
- package/src/proxy/formats/registry.ts +61 -0
- package/src/proxy/handler.ts +389 -0
- package/src/proxy/logIndex.ts +187 -0
- package/src/proxy/logger.ts +99 -0
- package/src/proxy/providers.ts +234 -0
- package/src/proxy/schemas.ts +160 -0
- package/src/proxy/socketTracker.ts +158 -0
- package/src/proxy/store.ts +386 -0
- package/src/router.tsx +16 -0
- package/src/routes/__root.tsx +38 -0
- package/src/routes/api/config.paths.ts +14 -0
- package/src/routes/api/health.ts +11 -0
- package/src/routes/api/logs.$id.chunks.ts +36 -0
- package/src/routes/api/logs.$id.replay.ts +262 -0
- package/src/routes/api/logs.$id.ts +22 -0
- package/src/routes/api/logs.stream.ts +64 -0
- package/src/routes/api/logs.ts +30 -0
- package/src/routes/api/models.ts +10 -0
- package/src/routes/api/providers.$providerId.ts +45 -0
- package/src/routes/api/providers.ts +37 -0
- package/src/routes/api/sessions.ts +10 -0
- package/src/routes/index.tsx +6 -0
- package/src/routes/proxy/$.ts +15 -0
- package/styles/globals.css +121 -0
|
@@ -0,0 +1,3049 @@
|
|
|
1
|
+
import { g as getDefaultExportFromCjs } from "./react.mjs";
|
|
2
|
+
import { r as requireReadable } from "./readable-stream.mjs";
|
|
3
|
+
import { r as requireLib$1 } from "./lie.mjs";
|
|
4
|
+
import { r as requirePako } from "./pako.mjs";
|
|
5
|
+
var utf8 = {};
|
|
6
|
+
var utils = {};
|
|
7
|
+
var support = {};
|
|
8
|
+
var hasRequiredSupport;
|
|
9
|
+
function requireSupport() {
|
|
10
|
+
if (hasRequiredSupport) return support;
|
|
11
|
+
hasRequiredSupport = 1;
|
|
12
|
+
support.base64 = true;
|
|
13
|
+
support.array = true;
|
|
14
|
+
support.string = true;
|
|
15
|
+
support.arraybuffer = typeof ArrayBuffer !== "undefined" && typeof Uint8Array !== "undefined";
|
|
16
|
+
support.nodebuffer = typeof Buffer !== "undefined";
|
|
17
|
+
support.uint8array = typeof Uint8Array !== "undefined";
|
|
18
|
+
if (typeof ArrayBuffer === "undefined") {
|
|
19
|
+
support.blob = false;
|
|
20
|
+
} else {
|
|
21
|
+
var buffer = new ArrayBuffer(0);
|
|
22
|
+
try {
|
|
23
|
+
support.blob = new Blob([buffer], {
|
|
24
|
+
type: "application/zip"
|
|
25
|
+
}).size === 0;
|
|
26
|
+
} catch (e) {
|
|
27
|
+
try {
|
|
28
|
+
var Builder = self.BlobBuilder || self.WebKitBlobBuilder || self.MozBlobBuilder || self.MSBlobBuilder;
|
|
29
|
+
var builder = new Builder();
|
|
30
|
+
builder.append(buffer);
|
|
31
|
+
support.blob = builder.getBlob("application/zip").size === 0;
|
|
32
|
+
} catch (e2) {
|
|
33
|
+
support.blob = false;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
try {
|
|
38
|
+
support.nodestream = !!requireReadable().Readable;
|
|
39
|
+
} catch (e) {
|
|
40
|
+
support.nodestream = false;
|
|
41
|
+
}
|
|
42
|
+
return support;
|
|
43
|
+
}
|
|
44
|
+
var base64 = {};
|
|
45
|
+
var hasRequiredBase64;
|
|
46
|
+
function requireBase64() {
|
|
47
|
+
if (hasRequiredBase64) return base64;
|
|
48
|
+
hasRequiredBase64 = 1;
|
|
49
|
+
var utils2 = /* @__PURE__ */ requireUtils();
|
|
50
|
+
var support2 = /* @__PURE__ */ requireSupport();
|
|
51
|
+
var _keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
|
|
52
|
+
base64.encode = function(input) {
|
|
53
|
+
var output = [];
|
|
54
|
+
var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
|
|
55
|
+
var i = 0, len = input.length, remainingBytes = len;
|
|
56
|
+
var isArray = utils2.getTypeOf(input) !== "string";
|
|
57
|
+
while (i < input.length) {
|
|
58
|
+
remainingBytes = len - i;
|
|
59
|
+
if (!isArray) {
|
|
60
|
+
chr1 = input.charCodeAt(i++);
|
|
61
|
+
chr2 = i < len ? input.charCodeAt(i++) : 0;
|
|
62
|
+
chr3 = i < len ? input.charCodeAt(i++) : 0;
|
|
63
|
+
} else {
|
|
64
|
+
chr1 = input[i++];
|
|
65
|
+
chr2 = i < len ? input[i++] : 0;
|
|
66
|
+
chr3 = i < len ? input[i++] : 0;
|
|
67
|
+
}
|
|
68
|
+
enc1 = chr1 >> 2;
|
|
69
|
+
enc2 = (chr1 & 3) << 4 | chr2 >> 4;
|
|
70
|
+
enc3 = remainingBytes > 1 ? (chr2 & 15) << 2 | chr3 >> 6 : 64;
|
|
71
|
+
enc4 = remainingBytes > 2 ? chr3 & 63 : 64;
|
|
72
|
+
output.push(_keyStr.charAt(enc1) + _keyStr.charAt(enc2) + _keyStr.charAt(enc3) + _keyStr.charAt(enc4));
|
|
73
|
+
}
|
|
74
|
+
return output.join("");
|
|
75
|
+
};
|
|
76
|
+
base64.decode = function(input) {
|
|
77
|
+
var chr1, chr2, chr3;
|
|
78
|
+
var enc1, enc2, enc3, enc4;
|
|
79
|
+
var i = 0, resultIndex = 0;
|
|
80
|
+
var dataUrlPrefix = "data:";
|
|
81
|
+
if (input.substr(0, dataUrlPrefix.length) === dataUrlPrefix) {
|
|
82
|
+
throw new Error("Invalid base64 input, it looks like a data url.");
|
|
83
|
+
}
|
|
84
|
+
input = input.replace(/[^A-Za-z0-9+/=]/g, "");
|
|
85
|
+
var totalLength = input.length * 3 / 4;
|
|
86
|
+
if (input.charAt(input.length - 1) === _keyStr.charAt(64)) {
|
|
87
|
+
totalLength--;
|
|
88
|
+
}
|
|
89
|
+
if (input.charAt(input.length - 2) === _keyStr.charAt(64)) {
|
|
90
|
+
totalLength--;
|
|
91
|
+
}
|
|
92
|
+
if (totalLength % 1 !== 0) {
|
|
93
|
+
throw new Error("Invalid base64 input, bad content length.");
|
|
94
|
+
}
|
|
95
|
+
var output;
|
|
96
|
+
if (support2.uint8array) {
|
|
97
|
+
output = new Uint8Array(totalLength | 0);
|
|
98
|
+
} else {
|
|
99
|
+
output = new Array(totalLength | 0);
|
|
100
|
+
}
|
|
101
|
+
while (i < input.length) {
|
|
102
|
+
enc1 = _keyStr.indexOf(input.charAt(i++));
|
|
103
|
+
enc2 = _keyStr.indexOf(input.charAt(i++));
|
|
104
|
+
enc3 = _keyStr.indexOf(input.charAt(i++));
|
|
105
|
+
enc4 = _keyStr.indexOf(input.charAt(i++));
|
|
106
|
+
chr1 = enc1 << 2 | enc2 >> 4;
|
|
107
|
+
chr2 = (enc2 & 15) << 4 | enc3 >> 2;
|
|
108
|
+
chr3 = (enc3 & 3) << 6 | enc4;
|
|
109
|
+
output[resultIndex++] = chr1;
|
|
110
|
+
if (enc3 !== 64) {
|
|
111
|
+
output[resultIndex++] = chr2;
|
|
112
|
+
}
|
|
113
|
+
if (enc4 !== 64) {
|
|
114
|
+
output[resultIndex++] = chr3;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return output;
|
|
118
|
+
};
|
|
119
|
+
return base64;
|
|
120
|
+
}
|
|
121
|
+
var nodejsUtils;
|
|
122
|
+
var hasRequiredNodejsUtils;
|
|
123
|
+
function requireNodejsUtils() {
|
|
124
|
+
if (hasRequiredNodejsUtils) return nodejsUtils;
|
|
125
|
+
hasRequiredNodejsUtils = 1;
|
|
126
|
+
nodejsUtils = {
|
|
127
|
+
/**
|
|
128
|
+
* True if this is running in Nodejs, will be undefined in a browser.
|
|
129
|
+
* In a browser, browserify won't include this file and the whole module
|
|
130
|
+
* will be resolved an empty object.
|
|
131
|
+
*/
|
|
132
|
+
isNode: typeof Buffer !== "undefined",
|
|
133
|
+
/**
|
|
134
|
+
* Create a new nodejs Buffer from an existing content.
|
|
135
|
+
* @param {Object} data the data to pass to the constructor.
|
|
136
|
+
* @param {String} encoding the encoding to use.
|
|
137
|
+
* @return {Buffer} a new Buffer.
|
|
138
|
+
*/
|
|
139
|
+
newBufferFrom: function(data, encoding) {
|
|
140
|
+
if (Buffer.from && Buffer.from !== Uint8Array.from) {
|
|
141
|
+
return Buffer.from(data, encoding);
|
|
142
|
+
} else {
|
|
143
|
+
if (typeof data === "number") {
|
|
144
|
+
throw new Error('The "data" argument must not be a number');
|
|
145
|
+
}
|
|
146
|
+
return new Buffer(data, encoding);
|
|
147
|
+
}
|
|
148
|
+
},
|
|
149
|
+
/**
|
|
150
|
+
* Create a new nodejs Buffer with the specified size.
|
|
151
|
+
* @param {Integer} size the size of the buffer.
|
|
152
|
+
* @return {Buffer} a new Buffer.
|
|
153
|
+
*/
|
|
154
|
+
allocBuffer: function(size) {
|
|
155
|
+
if (Buffer.alloc) {
|
|
156
|
+
return Buffer.alloc(size);
|
|
157
|
+
} else {
|
|
158
|
+
var buf = new Buffer(size);
|
|
159
|
+
buf.fill(0);
|
|
160
|
+
return buf;
|
|
161
|
+
}
|
|
162
|
+
},
|
|
163
|
+
/**
|
|
164
|
+
* Find out if an object is a Buffer.
|
|
165
|
+
* @param {Object} b the object to test.
|
|
166
|
+
* @return {Boolean} true if the object is a Buffer, false otherwise.
|
|
167
|
+
*/
|
|
168
|
+
isBuffer: function(b) {
|
|
169
|
+
return Buffer.isBuffer(b);
|
|
170
|
+
},
|
|
171
|
+
isStream: function(obj) {
|
|
172
|
+
return obj && typeof obj.on === "function" && typeof obj.pause === "function" && typeof obj.resume === "function";
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
return nodejsUtils;
|
|
176
|
+
}
|
|
177
|
+
var external;
|
|
178
|
+
var hasRequiredExternal;
|
|
179
|
+
function requireExternal() {
|
|
180
|
+
if (hasRequiredExternal) return external;
|
|
181
|
+
hasRequiredExternal = 1;
|
|
182
|
+
var ES6Promise = null;
|
|
183
|
+
if (typeof Promise !== "undefined") {
|
|
184
|
+
ES6Promise = Promise;
|
|
185
|
+
} else {
|
|
186
|
+
ES6Promise = /* @__PURE__ */ requireLib$1();
|
|
187
|
+
}
|
|
188
|
+
external = {
|
|
189
|
+
Promise: ES6Promise
|
|
190
|
+
};
|
|
191
|
+
return external;
|
|
192
|
+
}
|
|
193
|
+
var hasRequiredUtils;
|
|
194
|
+
function requireUtils() {
|
|
195
|
+
if (hasRequiredUtils) return utils;
|
|
196
|
+
hasRequiredUtils = 1;
|
|
197
|
+
(function(exports$1) {
|
|
198
|
+
var support2 = /* @__PURE__ */ requireSupport();
|
|
199
|
+
var base642 = /* @__PURE__ */ requireBase64();
|
|
200
|
+
var nodejsUtils2 = /* @__PURE__ */ requireNodejsUtils();
|
|
201
|
+
var external2 = /* @__PURE__ */ requireExternal();
|
|
202
|
+
function string2binary(str) {
|
|
203
|
+
var result = null;
|
|
204
|
+
if (support2.uint8array) {
|
|
205
|
+
result = new Uint8Array(str.length);
|
|
206
|
+
} else {
|
|
207
|
+
result = new Array(str.length);
|
|
208
|
+
}
|
|
209
|
+
return stringToArrayLike(str, result);
|
|
210
|
+
}
|
|
211
|
+
exports$1.newBlob = function(part, type) {
|
|
212
|
+
exports$1.checkSupport("blob");
|
|
213
|
+
try {
|
|
214
|
+
return new Blob([part], {
|
|
215
|
+
type
|
|
216
|
+
});
|
|
217
|
+
} catch (e) {
|
|
218
|
+
try {
|
|
219
|
+
var Builder = self.BlobBuilder || self.WebKitBlobBuilder || self.MozBlobBuilder || self.MSBlobBuilder;
|
|
220
|
+
var builder = new Builder();
|
|
221
|
+
builder.append(part);
|
|
222
|
+
return builder.getBlob(type);
|
|
223
|
+
} catch (e2) {
|
|
224
|
+
throw new Error("Bug : can't construct the Blob.");
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
function identity(input) {
|
|
229
|
+
return input;
|
|
230
|
+
}
|
|
231
|
+
function stringToArrayLike(str, array) {
|
|
232
|
+
for (var i = 0; i < str.length; ++i) {
|
|
233
|
+
array[i] = str.charCodeAt(i) & 255;
|
|
234
|
+
}
|
|
235
|
+
return array;
|
|
236
|
+
}
|
|
237
|
+
var arrayToStringHelper = {
|
|
238
|
+
/**
|
|
239
|
+
* Transform an array of int into a string, chunk by chunk.
|
|
240
|
+
* See the performances notes on arrayLikeToString.
|
|
241
|
+
* @param {Array|ArrayBuffer|Uint8Array|Buffer} array the array to transform.
|
|
242
|
+
* @param {String} type the type of the array.
|
|
243
|
+
* @param {Integer} chunk the chunk size.
|
|
244
|
+
* @return {String} the resulting string.
|
|
245
|
+
* @throws Error if the chunk is too big for the stack.
|
|
246
|
+
*/
|
|
247
|
+
stringifyByChunk: function(array, type, chunk) {
|
|
248
|
+
var result = [], k = 0, len = array.length;
|
|
249
|
+
if (len <= chunk) {
|
|
250
|
+
return String.fromCharCode.apply(null, array);
|
|
251
|
+
}
|
|
252
|
+
while (k < len) {
|
|
253
|
+
if (type === "array" || type === "nodebuffer") {
|
|
254
|
+
result.push(String.fromCharCode.apply(null, array.slice(k, Math.min(k + chunk, len))));
|
|
255
|
+
} else {
|
|
256
|
+
result.push(String.fromCharCode.apply(null, array.subarray(k, Math.min(k + chunk, len))));
|
|
257
|
+
}
|
|
258
|
+
k += chunk;
|
|
259
|
+
}
|
|
260
|
+
return result.join("");
|
|
261
|
+
},
|
|
262
|
+
/**
|
|
263
|
+
* Call String.fromCharCode on every item in the array.
|
|
264
|
+
* This is the naive implementation, which generate A LOT of intermediate string.
|
|
265
|
+
* This should be used when everything else fail.
|
|
266
|
+
* @param {Array|ArrayBuffer|Uint8Array|Buffer} array the array to transform.
|
|
267
|
+
* @return {String} the result.
|
|
268
|
+
*/
|
|
269
|
+
stringifyByChar: function(array) {
|
|
270
|
+
var resultStr = "";
|
|
271
|
+
for (var i = 0; i < array.length; i++) {
|
|
272
|
+
resultStr += String.fromCharCode(array[i]);
|
|
273
|
+
}
|
|
274
|
+
return resultStr;
|
|
275
|
+
},
|
|
276
|
+
applyCanBeUsed: {
|
|
277
|
+
/**
|
|
278
|
+
* true if the browser accepts to use String.fromCharCode on Uint8Array
|
|
279
|
+
*/
|
|
280
|
+
uint8array: (function() {
|
|
281
|
+
try {
|
|
282
|
+
return support2.uint8array && String.fromCharCode.apply(null, new Uint8Array(1)).length === 1;
|
|
283
|
+
} catch (e) {
|
|
284
|
+
return false;
|
|
285
|
+
}
|
|
286
|
+
})(),
|
|
287
|
+
/**
|
|
288
|
+
* true if the browser accepts to use String.fromCharCode on nodejs Buffer.
|
|
289
|
+
*/
|
|
290
|
+
nodebuffer: (function() {
|
|
291
|
+
try {
|
|
292
|
+
return support2.nodebuffer && String.fromCharCode.apply(null, nodejsUtils2.allocBuffer(1)).length === 1;
|
|
293
|
+
} catch (e) {
|
|
294
|
+
return false;
|
|
295
|
+
}
|
|
296
|
+
})()
|
|
297
|
+
}
|
|
298
|
+
};
|
|
299
|
+
function arrayLikeToString(array) {
|
|
300
|
+
var chunk = 65536, type = exports$1.getTypeOf(array), canUseApply = true;
|
|
301
|
+
if (type === "uint8array") {
|
|
302
|
+
canUseApply = arrayToStringHelper.applyCanBeUsed.uint8array;
|
|
303
|
+
} else if (type === "nodebuffer") {
|
|
304
|
+
canUseApply = arrayToStringHelper.applyCanBeUsed.nodebuffer;
|
|
305
|
+
}
|
|
306
|
+
if (canUseApply) {
|
|
307
|
+
while (chunk > 1) {
|
|
308
|
+
try {
|
|
309
|
+
return arrayToStringHelper.stringifyByChunk(array, type, chunk);
|
|
310
|
+
} catch (e) {
|
|
311
|
+
chunk = Math.floor(chunk / 2);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
return arrayToStringHelper.stringifyByChar(array);
|
|
316
|
+
}
|
|
317
|
+
exports$1.applyFromCharCode = arrayLikeToString;
|
|
318
|
+
function arrayLikeToArrayLike(arrayFrom, arrayTo) {
|
|
319
|
+
for (var i = 0; i < arrayFrom.length; i++) {
|
|
320
|
+
arrayTo[i] = arrayFrom[i];
|
|
321
|
+
}
|
|
322
|
+
return arrayTo;
|
|
323
|
+
}
|
|
324
|
+
var transform = {};
|
|
325
|
+
transform["string"] = {
|
|
326
|
+
"string": identity,
|
|
327
|
+
"array": function(input) {
|
|
328
|
+
return stringToArrayLike(input, new Array(input.length));
|
|
329
|
+
},
|
|
330
|
+
"arraybuffer": function(input) {
|
|
331
|
+
return transform["string"]["uint8array"](input).buffer;
|
|
332
|
+
},
|
|
333
|
+
"uint8array": function(input) {
|
|
334
|
+
return stringToArrayLike(input, new Uint8Array(input.length));
|
|
335
|
+
},
|
|
336
|
+
"nodebuffer": function(input) {
|
|
337
|
+
return stringToArrayLike(input, nodejsUtils2.allocBuffer(input.length));
|
|
338
|
+
}
|
|
339
|
+
};
|
|
340
|
+
transform["array"] = {
|
|
341
|
+
"string": arrayLikeToString,
|
|
342
|
+
"array": identity,
|
|
343
|
+
"arraybuffer": function(input) {
|
|
344
|
+
return new Uint8Array(input).buffer;
|
|
345
|
+
},
|
|
346
|
+
"uint8array": function(input) {
|
|
347
|
+
return new Uint8Array(input);
|
|
348
|
+
},
|
|
349
|
+
"nodebuffer": function(input) {
|
|
350
|
+
return nodejsUtils2.newBufferFrom(input);
|
|
351
|
+
}
|
|
352
|
+
};
|
|
353
|
+
transform["arraybuffer"] = {
|
|
354
|
+
"string": function(input) {
|
|
355
|
+
return arrayLikeToString(new Uint8Array(input));
|
|
356
|
+
},
|
|
357
|
+
"array": function(input) {
|
|
358
|
+
return arrayLikeToArrayLike(new Uint8Array(input), new Array(input.byteLength));
|
|
359
|
+
},
|
|
360
|
+
"arraybuffer": identity,
|
|
361
|
+
"uint8array": function(input) {
|
|
362
|
+
return new Uint8Array(input);
|
|
363
|
+
},
|
|
364
|
+
"nodebuffer": function(input) {
|
|
365
|
+
return nodejsUtils2.newBufferFrom(new Uint8Array(input));
|
|
366
|
+
}
|
|
367
|
+
};
|
|
368
|
+
transform["uint8array"] = {
|
|
369
|
+
"string": arrayLikeToString,
|
|
370
|
+
"array": function(input) {
|
|
371
|
+
return arrayLikeToArrayLike(input, new Array(input.length));
|
|
372
|
+
},
|
|
373
|
+
"arraybuffer": function(input) {
|
|
374
|
+
return input.buffer;
|
|
375
|
+
},
|
|
376
|
+
"uint8array": identity,
|
|
377
|
+
"nodebuffer": function(input) {
|
|
378
|
+
return nodejsUtils2.newBufferFrom(input);
|
|
379
|
+
}
|
|
380
|
+
};
|
|
381
|
+
transform["nodebuffer"] = {
|
|
382
|
+
"string": arrayLikeToString,
|
|
383
|
+
"array": function(input) {
|
|
384
|
+
return arrayLikeToArrayLike(input, new Array(input.length));
|
|
385
|
+
},
|
|
386
|
+
"arraybuffer": function(input) {
|
|
387
|
+
return transform["nodebuffer"]["uint8array"](input).buffer;
|
|
388
|
+
},
|
|
389
|
+
"uint8array": function(input) {
|
|
390
|
+
return arrayLikeToArrayLike(input, new Uint8Array(input.length));
|
|
391
|
+
},
|
|
392
|
+
"nodebuffer": identity
|
|
393
|
+
};
|
|
394
|
+
exports$1.transformTo = function(outputType, input) {
|
|
395
|
+
if (!input) {
|
|
396
|
+
input = "";
|
|
397
|
+
}
|
|
398
|
+
if (!outputType) {
|
|
399
|
+
return input;
|
|
400
|
+
}
|
|
401
|
+
exports$1.checkSupport(outputType);
|
|
402
|
+
var inputType = exports$1.getTypeOf(input);
|
|
403
|
+
var result = transform[inputType][outputType](input);
|
|
404
|
+
return result;
|
|
405
|
+
};
|
|
406
|
+
exports$1.resolve = function(path) {
|
|
407
|
+
var parts = path.split("/");
|
|
408
|
+
var result = [];
|
|
409
|
+
for (var index = 0; index < parts.length; index++) {
|
|
410
|
+
var part = parts[index];
|
|
411
|
+
if (part === "." || part === "" && index !== 0 && index !== parts.length - 1) {
|
|
412
|
+
continue;
|
|
413
|
+
} else if (part === "..") {
|
|
414
|
+
result.pop();
|
|
415
|
+
} else {
|
|
416
|
+
result.push(part);
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
return result.join("/");
|
|
420
|
+
};
|
|
421
|
+
exports$1.getTypeOf = function(input) {
|
|
422
|
+
if (typeof input === "string") {
|
|
423
|
+
return "string";
|
|
424
|
+
}
|
|
425
|
+
if (Object.prototype.toString.call(input) === "[object Array]") {
|
|
426
|
+
return "array";
|
|
427
|
+
}
|
|
428
|
+
if (support2.nodebuffer && nodejsUtils2.isBuffer(input)) {
|
|
429
|
+
return "nodebuffer";
|
|
430
|
+
}
|
|
431
|
+
if (support2.uint8array && input instanceof Uint8Array) {
|
|
432
|
+
return "uint8array";
|
|
433
|
+
}
|
|
434
|
+
if (support2.arraybuffer && input instanceof ArrayBuffer) {
|
|
435
|
+
return "arraybuffer";
|
|
436
|
+
}
|
|
437
|
+
};
|
|
438
|
+
exports$1.checkSupport = function(type) {
|
|
439
|
+
var supported = support2[type.toLowerCase()];
|
|
440
|
+
if (!supported) {
|
|
441
|
+
throw new Error(type + " is not supported by this platform");
|
|
442
|
+
}
|
|
443
|
+
};
|
|
444
|
+
exports$1.MAX_VALUE_16BITS = 65535;
|
|
445
|
+
exports$1.MAX_VALUE_32BITS = -1;
|
|
446
|
+
exports$1.pretty = function(str) {
|
|
447
|
+
var res = "", code, i;
|
|
448
|
+
for (i = 0; i < (str || "").length; i++) {
|
|
449
|
+
code = str.charCodeAt(i);
|
|
450
|
+
res += "\\x" + (code < 16 ? "0" : "") + code.toString(16).toUpperCase();
|
|
451
|
+
}
|
|
452
|
+
return res;
|
|
453
|
+
};
|
|
454
|
+
exports$1.delay = function(callback, args, self2) {
|
|
455
|
+
setImmediate(function() {
|
|
456
|
+
callback.apply(self2 || null, args || []);
|
|
457
|
+
});
|
|
458
|
+
};
|
|
459
|
+
exports$1.inherits = function(ctor, superCtor) {
|
|
460
|
+
var Obj = function() {
|
|
461
|
+
};
|
|
462
|
+
Obj.prototype = superCtor.prototype;
|
|
463
|
+
ctor.prototype = new Obj();
|
|
464
|
+
};
|
|
465
|
+
exports$1.extend = function() {
|
|
466
|
+
var result = {}, i, attr;
|
|
467
|
+
for (i = 0; i < arguments.length; i++) {
|
|
468
|
+
for (attr in arguments[i]) {
|
|
469
|
+
if (Object.prototype.hasOwnProperty.call(arguments[i], attr) && typeof result[attr] === "undefined") {
|
|
470
|
+
result[attr] = arguments[i][attr];
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
return result;
|
|
475
|
+
};
|
|
476
|
+
exports$1.prepareContent = function(name, inputData, isBinary, isOptimizedBinaryString, isBase64) {
|
|
477
|
+
var promise = external2.Promise.resolve(inputData).then(function(data) {
|
|
478
|
+
var isBlob = support2.blob && (data instanceof Blob || ["[object File]", "[object Blob]"].indexOf(Object.prototype.toString.call(data)) !== -1);
|
|
479
|
+
if (isBlob && typeof FileReader !== "undefined") {
|
|
480
|
+
return new external2.Promise(function(resolve, reject) {
|
|
481
|
+
var reader = new FileReader();
|
|
482
|
+
reader.onload = function(e) {
|
|
483
|
+
resolve(e.target.result);
|
|
484
|
+
};
|
|
485
|
+
reader.onerror = function(e) {
|
|
486
|
+
reject(e.target.error);
|
|
487
|
+
};
|
|
488
|
+
reader.readAsArrayBuffer(data);
|
|
489
|
+
});
|
|
490
|
+
} else {
|
|
491
|
+
return data;
|
|
492
|
+
}
|
|
493
|
+
});
|
|
494
|
+
return promise.then(function(data) {
|
|
495
|
+
var dataType = exports$1.getTypeOf(data);
|
|
496
|
+
if (!dataType) {
|
|
497
|
+
return external2.Promise.reject(
|
|
498
|
+
new Error("Can't read the data of '" + name + "'. Is it in a supported JavaScript type (String, Blob, ArrayBuffer, etc) ?")
|
|
499
|
+
);
|
|
500
|
+
}
|
|
501
|
+
if (dataType === "arraybuffer") {
|
|
502
|
+
data = exports$1.transformTo("uint8array", data);
|
|
503
|
+
} else if (dataType === "string") {
|
|
504
|
+
if (isBase64) {
|
|
505
|
+
data = base642.decode(data);
|
|
506
|
+
} else if (isBinary) {
|
|
507
|
+
if (isOptimizedBinaryString !== true) {
|
|
508
|
+
data = string2binary(data);
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
return data;
|
|
513
|
+
});
|
|
514
|
+
};
|
|
515
|
+
})(utils);
|
|
516
|
+
return utils;
|
|
517
|
+
}
|
|
518
|
+
var GenericWorker_1;
|
|
519
|
+
var hasRequiredGenericWorker;
|
|
520
|
+
function requireGenericWorker() {
|
|
521
|
+
if (hasRequiredGenericWorker) return GenericWorker_1;
|
|
522
|
+
hasRequiredGenericWorker = 1;
|
|
523
|
+
function GenericWorker(name) {
|
|
524
|
+
this.name = name || "default";
|
|
525
|
+
this.streamInfo = {};
|
|
526
|
+
this.generatedError = null;
|
|
527
|
+
this.extraStreamInfo = {};
|
|
528
|
+
this.isPaused = true;
|
|
529
|
+
this.isFinished = false;
|
|
530
|
+
this.isLocked = false;
|
|
531
|
+
this._listeners = {
|
|
532
|
+
"data": [],
|
|
533
|
+
"end": [],
|
|
534
|
+
"error": []
|
|
535
|
+
};
|
|
536
|
+
this.previous = null;
|
|
537
|
+
}
|
|
538
|
+
GenericWorker.prototype = {
|
|
539
|
+
/**
|
|
540
|
+
* Push a chunk to the next workers.
|
|
541
|
+
* @param {Object} chunk the chunk to push
|
|
542
|
+
*/
|
|
543
|
+
push: function(chunk) {
|
|
544
|
+
this.emit("data", chunk);
|
|
545
|
+
},
|
|
546
|
+
/**
|
|
547
|
+
* End the stream.
|
|
548
|
+
* @return {Boolean} true if this call ended the worker, false otherwise.
|
|
549
|
+
*/
|
|
550
|
+
end: function() {
|
|
551
|
+
if (this.isFinished) {
|
|
552
|
+
return false;
|
|
553
|
+
}
|
|
554
|
+
this.flush();
|
|
555
|
+
try {
|
|
556
|
+
this.emit("end");
|
|
557
|
+
this.cleanUp();
|
|
558
|
+
this.isFinished = true;
|
|
559
|
+
} catch (e) {
|
|
560
|
+
this.emit("error", e);
|
|
561
|
+
}
|
|
562
|
+
return true;
|
|
563
|
+
},
|
|
564
|
+
/**
|
|
565
|
+
* End the stream with an error.
|
|
566
|
+
* @param {Error} e the error which caused the premature end.
|
|
567
|
+
* @return {Boolean} true if this call ended the worker with an error, false otherwise.
|
|
568
|
+
*/
|
|
569
|
+
error: function(e) {
|
|
570
|
+
if (this.isFinished) {
|
|
571
|
+
return false;
|
|
572
|
+
}
|
|
573
|
+
if (this.isPaused) {
|
|
574
|
+
this.generatedError = e;
|
|
575
|
+
} else {
|
|
576
|
+
this.isFinished = true;
|
|
577
|
+
this.emit("error", e);
|
|
578
|
+
if (this.previous) {
|
|
579
|
+
this.previous.error(e);
|
|
580
|
+
}
|
|
581
|
+
this.cleanUp();
|
|
582
|
+
}
|
|
583
|
+
return true;
|
|
584
|
+
},
|
|
585
|
+
/**
|
|
586
|
+
* Add a callback on an event.
|
|
587
|
+
* @param {String} name the name of the event (data, end, error)
|
|
588
|
+
* @param {Function} listener the function to call when the event is triggered
|
|
589
|
+
* @return {GenericWorker} the current object for chainability
|
|
590
|
+
*/
|
|
591
|
+
on: function(name, listener) {
|
|
592
|
+
this._listeners[name].push(listener);
|
|
593
|
+
return this;
|
|
594
|
+
},
|
|
595
|
+
/**
|
|
596
|
+
* Clean any references when a worker is ending.
|
|
597
|
+
*/
|
|
598
|
+
cleanUp: function() {
|
|
599
|
+
this.streamInfo = this.generatedError = this.extraStreamInfo = null;
|
|
600
|
+
this._listeners = [];
|
|
601
|
+
},
|
|
602
|
+
/**
|
|
603
|
+
* Trigger an event. This will call registered callback with the provided arg.
|
|
604
|
+
* @param {String} name the name of the event (data, end, error)
|
|
605
|
+
* @param {Object} arg the argument to call the callback with.
|
|
606
|
+
*/
|
|
607
|
+
emit: function(name, arg) {
|
|
608
|
+
if (this._listeners[name]) {
|
|
609
|
+
for (var i = 0; i < this._listeners[name].length; i++) {
|
|
610
|
+
this._listeners[name][i].call(this, arg);
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
},
|
|
614
|
+
/**
|
|
615
|
+
* Chain a worker with an other.
|
|
616
|
+
* @param {Worker} next the worker receiving events from the current one.
|
|
617
|
+
* @return {worker} the next worker for chainability
|
|
618
|
+
*/
|
|
619
|
+
pipe: function(next) {
|
|
620
|
+
return next.registerPrevious(this);
|
|
621
|
+
},
|
|
622
|
+
/**
|
|
623
|
+
* Same as `pipe` in the other direction.
|
|
624
|
+
* Using an API with `pipe(next)` is very easy.
|
|
625
|
+
* Implementing the API with the point of view of the next one registering
|
|
626
|
+
* a source is easier, see the ZipFileWorker.
|
|
627
|
+
* @param {Worker} previous the previous worker, sending events to this one
|
|
628
|
+
* @return {Worker} the current worker for chainability
|
|
629
|
+
*/
|
|
630
|
+
registerPrevious: function(previous) {
|
|
631
|
+
if (this.isLocked) {
|
|
632
|
+
throw new Error("The stream '" + this + "' has already been used.");
|
|
633
|
+
}
|
|
634
|
+
this.streamInfo = previous.streamInfo;
|
|
635
|
+
this.mergeStreamInfo();
|
|
636
|
+
this.previous = previous;
|
|
637
|
+
var self2 = this;
|
|
638
|
+
previous.on("data", function(chunk) {
|
|
639
|
+
self2.processChunk(chunk);
|
|
640
|
+
});
|
|
641
|
+
previous.on("end", function() {
|
|
642
|
+
self2.end();
|
|
643
|
+
});
|
|
644
|
+
previous.on("error", function(e) {
|
|
645
|
+
self2.error(e);
|
|
646
|
+
});
|
|
647
|
+
return this;
|
|
648
|
+
},
|
|
649
|
+
/**
|
|
650
|
+
* Pause the stream so it doesn't send events anymore.
|
|
651
|
+
* @return {Boolean} true if this call paused the worker, false otherwise.
|
|
652
|
+
*/
|
|
653
|
+
pause: function() {
|
|
654
|
+
if (this.isPaused || this.isFinished) {
|
|
655
|
+
return false;
|
|
656
|
+
}
|
|
657
|
+
this.isPaused = true;
|
|
658
|
+
if (this.previous) {
|
|
659
|
+
this.previous.pause();
|
|
660
|
+
}
|
|
661
|
+
return true;
|
|
662
|
+
},
|
|
663
|
+
/**
|
|
664
|
+
* Resume a paused stream.
|
|
665
|
+
* @return {Boolean} true if this call resumed the worker, false otherwise.
|
|
666
|
+
*/
|
|
667
|
+
resume: function() {
|
|
668
|
+
if (!this.isPaused || this.isFinished) {
|
|
669
|
+
return false;
|
|
670
|
+
}
|
|
671
|
+
this.isPaused = false;
|
|
672
|
+
var withError = false;
|
|
673
|
+
if (this.generatedError) {
|
|
674
|
+
this.error(this.generatedError);
|
|
675
|
+
withError = true;
|
|
676
|
+
}
|
|
677
|
+
if (this.previous) {
|
|
678
|
+
this.previous.resume();
|
|
679
|
+
}
|
|
680
|
+
return !withError;
|
|
681
|
+
},
|
|
682
|
+
/**
|
|
683
|
+
* Flush any remaining bytes as the stream is ending.
|
|
684
|
+
*/
|
|
685
|
+
flush: function() {
|
|
686
|
+
},
|
|
687
|
+
/**
|
|
688
|
+
* Process a chunk. This is usually the method overridden.
|
|
689
|
+
* @param {Object} chunk the chunk to process.
|
|
690
|
+
*/
|
|
691
|
+
processChunk: function(chunk) {
|
|
692
|
+
this.push(chunk);
|
|
693
|
+
},
|
|
694
|
+
/**
|
|
695
|
+
* Add a key/value to be added in the workers chain streamInfo once activated.
|
|
696
|
+
* @param {String} key the key to use
|
|
697
|
+
* @param {Object} value the associated value
|
|
698
|
+
* @return {Worker} the current worker for chainability
|
|
699
|
+
*/
|
|
700
|
+
withStreamInfo: function(key, value) {
|
|
701
|
+
this.extraStreamInfo[key] = value;
|
|
702
|
+
this.mergeStreamInfo();
|
|
703
|
+
return this;
|
|
704
|
+
},
|
|
705
|
+
/**
|
|
706
|
+
* Merge this worker's streamInfo into the chain's streamInfo.
|
|
707
|
+
*/
|
|
708
|
+
mergeStreamInfo: function() {
|
|
709
|
+
for (var key in this.extraStreamInfo) {
|
|
710
|
+
if (!Object.prototype.hasOwnProperty.call(this.extraStreamInfo, key)) {
|
|
711
|
+
continue;
|
|
712
|
+
}
|
|
713
|
+
this.streamInfo[key] = this.extraStreamInfo[key];
|
|
714
|
+
}
|
|
715
|
+
},
|
|
716
|
+
/**
|
|
717
|
+
* Lock the stream to prevent further updates on the workers chain.
|
|
718
|
+
* After calling this method, all calls to pipe will fail.
|
|
719
|
+
*/
|
|
720
|
+
lock: function() {
|
|
721
|
+
if (this.isLocked) {
|
|
722
|
+
throw new Error("The stream '" + this + "' has already been used.");
|
|
723
|
+
}
|
|
724
|
+
this.isLocked = true;
|
|
725
|
+
if (this.previous) {
|
|
726
|
+
this.previous.lock();
|
|
727
|
+
}
|
|
728
|
+
},
|
|
729
|
+
/**
|
|
730
|
+
*
|
|
731
|
+
* Pretty print the workers chain.
|
|
732
|
+
*/
|
|
733
|
+
toString: function() {
|
|
734
|
+
var me = "Worker " + this.name;
|
|
735
|
+
if (this.previous) {
|
|
736
|
+
return this.previous + " -> " + me;
|
|
737
|
+
} else {
|
|
738
|
+
return me;
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
};
|
|
742
|
+
GenericWorker_1 = GenericWorker;
|
|
743
|
+
return GenericWorker_1;
|
|
744
|
+
}
|
|
745
|
+
var hasRequiredUtf8;
|
|
746
|
+
function requireUtf8() {
|
|
747
|
+
if (hasRequiredUtf8) return utf8;
|
|
748
|
+
hasRequiredUtf8 = 1;
|
|
749
|
+
(function(exports$1) {
|
|
750
|
+
var utils2 = /* @__PURE__ */ requireUtils();
|
|
751
|
+
var support2 = /* @__PURE__ */ requireSupport();
|
|
752
|
+
var nodejsUtils2 = /* @__PURE__ */ requireNodejsUtils();
|
|
753
|
+
var GenericWorker = /* @__PURE__ */ requireGenericWorker();
|
|
754
|
+
var _utf8len = new Array(256);
|
|
755
|
+
for (var i = 0; i < 256; i++) {
|
|
756
|
+
_utf8len[i] = i >= 252 ? 6 : i >= 248 ? 5 : i >= 240 ? 4 : i >= 224 ? 3 : i >= 192 ? 2 : 1;
|
|
757
|
+
}
|
|
758
|
+
_utf8len[254] = _utf8len[254] = 1;
|
|
759
|
+
var string2buf = function(str) {
|
|
760
|
+
var buf, c, c2, m_pos, i2, str_len = str.length, buf_len = 0;
|
|
761
|
+
for (m_pos = 0; m_pos < str_len; m_pos++) {
|
|
762
|
+
c = str.charCodeAt(m_pos);
|
|
763
|
+
if ((c & 64512) === 55296 && m_pos + 1 < str_len) {
|
|
764
|
+
c2 = str.charCodeAt(m_pos + 1);
|
|
765
|
+
if ((c2 & 64512) === 56320) {
|
|
766
|
+
c = 65536 + (c - 55296 << 10) + (c2 - 56320);
|
|
767
|
+
m_pos++;
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
buf_len += c < 128 ? 1 : c < 2048 ? 2 : c < 65536 ? 3 : 4;
|
|
771
|
+
}
|
|
772
|
+
if (support2.uint8array) {
|
|
773
|
+
buf = new Uint8Array(buf_len);
|
|
774
|
+
} else {
|
|
775
|
+
buf = new Array(buf_len);
|
|
776
|
+
}
|
|
777
|
+
for (i2 = 0, m_pos = 0; i2 < buf_len; m_pos++) {
|
|
778
|
+
c = str.charCodeAt(m_pos);
|
|
779
|
+
if ((c & 64512) === 55296 && m_pos + 1 < str_len) {
|
|
780
|
+
c2 = str.charCodeAt(m_pos + 1);
|
|
781
|
+
if ((c2 & 64512) === 56320) {
|
|
782
|
+
c = 65536 + (c - 55296 << 10) + (c2 - 56320);
|
|
783
|
+
m_pos++;
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
if (c < 128) {
|
|
787
|
+
buf[i2++] = c;
|
|
788
|
+
} else if (c < 2048) {
|
|
789
|
+
buf[i2++] = 192 | c >>> 6;
|
|
790
|
+
buf[i2++] = 128 | c & 63;
|
|
791
|
+
} else if (c < 65536) {
|
|
792
|
+
buf[i2++] = 224 | c >>> 12;
|
|
793
|
+
buf[i2++] = 128 | c >>> 6 & 63;
|
|
794
|
+
buf[i2++] = 128 | c & 63;
|
|
795
|
+
} else {
|
|
796
|
+
buf[i2++] = 240 | c >>> 18;
|
|
797
|
+
buf[i2++] = 128 | c >>> 12 & 63;
|
|
798
|
+
buf[i2++] = 128 | c >>> 6 & 63;
|
|
799
|
+
buf[i2++] = 128 | c & 63;
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
return buf;
|
|
803
|
+
};
|
|
804
|
+
var utf8border = function(buf, max) {
|
|
805
|
+
var pos;
|
|
806
|
+
max = max || buf.length;
|
|
807
|
+
if (max > buf.length) {
|
|
808
|
+
max = buf.length;
|
|
809
|
+
}
|
|
810
|
+
pos = max - 1;
|
|
811
|
+
while (pos >= 0 && (buf[pos] & 192) === 128) {
|
|
812
|
+
pos--;
|
|
813
|
+
}
|
|
814
|
+
if (pos < 0) {
|
|
815
|
+
return max;
|
|
816
|
+
}
|
|
817
|
+
if (pos === 0) {
|
|
818
|
+
return max;
|
|
819
|
+
}
|
|
820
|
+
return pos + _utf8len[buf[pos]] > max ? pos : max;
|
|
821
|
+
};
|
|
822
|
+
var buf2string = function(buf) {
|
|
823
|
+
var i2, out, c, c_len;
|
|
824
|
+
var len = buf.length;
|
|
825
|
+
var utf16buf = new Array(len * 2);
|
|
826
|
+
for (out = 0, i2 = 0; i2 < len; ) {
|
|
827
|
+
c = buf[i2++];
|
|
828
|
+
if (c < 128) {
|
|
829
|
+
utf16buf[out++] = c;
|
|
830
|
+
continue;
|
|
831
|
+
}
|
|
832
|
+
c_len = _utf8len[c];
|
|
833
|
+
if (c_len > 4) {
|
|
834
|
+
utf16buf[out++] = 65533;
|
|
835
|
+
i2 += c_len - 1;
|
|
836
|
+
continue;
|
|
837
|
+
}
|
|
838
|
+
c &= c_len === 2 ? 31 : c_len === 3 ? 15 : 7;
|
|
839
|
+
while (c_len > 1 && i2 < len) {
|
|
840
|
+
c = c << 6 | buf[i2++] & 63;
|
|
841
|
+
c_len--;
|
|
842
|
+
}
|
|
843
|
+
if (c_len > 1) {
|
|
844
|
+
utf16buf[out++] = 65533;
|
|
845
|
+
continue;
|
|
846
|
+
}
|
|
847
|
+
if (c < 65536) {
|
|
848
|
+
utf16buf[out++] = c;
|
|
849
|
+
} else {
|
|
850
|
+
c -= 65536;
|
|
851
|
+
utf16buf[out++] = 55296 | c >> 10 & 1023;
|
|
852
|
+
utf16buf[out++] = 56320 | c & 1023;
|
|
853
|
+
}
|
|
854
|
+
}
|
|
855
|
+
if (utf16buf.length !== out) {
|
|
856
|
+
if (utf16buf.subarray) {
|
|
857
|
+
utf16buf = utf16buf.subarray(0, out);
|
|
858
|
+
} else {
|
|
859
|
+
utf16buf.length = out;
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
return utils2.applyFromCharCode(utf16buf);
|
|
863
|
+
};
|
|
864
|
+
exports$1.utf8encode = function utf8encode(str) {
|
|
865
|
+
if (support2.nodebuffer) {
|
|
866
|
+
return nodejsUtils2.newBufferFrom(str, "utf-8");
|
|
867
|
+
}
|
|
868
|
+
return string2buf(str);
|
|
869
|
+
};
|
|
870
|
+
exports$1.utf8decode = function utf8decode(buf) {
|
|
871
|
+
if (support2.nodebuffer) {
|
|
872
|
+
return utils2.transformTo("nodebuffer", buf).toString("utf-8");
|
|
873
|
+
}
|
|
874
|
+
buf = utils2.transformTo(support2.uint8array ? "uint8array" : "array", buf);
|
|
875
|
+
return buf2string(buf);
|
|
876
|
+
};
|
|
877
|
+
function Utf8DecodeWorker() {
|
|
878
|
+
GenericWorker.call(this, "utf-8 decode");
|
|
879
|
+
this.leftOver = null;
|
|
880
|
+
}
|
|
881
|
+
utils2.inherits(Utf8DecodeWorker, GenericWorker);
|
|
882
|
+
Utf8DecodeWorker.prototype.processChunk = function(chunk) {
|
|
883
|
+
var data = utils2.transformTo(support2.uint8array ? "uint8array" : "array", chunk.data);
|
|
884
|
+
if (this.leftOver && this.leftOver.length) {
|
|
885
|
+
if (support2.uint8array) {
|
|
886
|
+
var previousData = data;
|
|
887
|
+
data = new Uint8Array(previousData.length + this.leftOver.length);
|
|
888
|
+
data.set(this.leftOver, 0);
|
|
889
|
+
data.set(previousData, this.leftOver.length);
|
|
890
|
+
} else {
|
|
891
|
+
data = this.leftOver.concat(data);
|
|
892
|
+
}
|
|
893
|
+
this.leftOver = null;
|
|
894
|
+
}
|
|
895
|
+
var nextBoundary = utf8border(data);
|
|
896
|
+
var usableData = data;
|
|
897
|
+
if (nextBoundary !== data.length) {
|
|
898
|
+
if (support2.uint8array) {
|
|
899
|
+
usableData = data.subarray(0, nextBoundary);
|
|
900
|
+
this.leftOver = data.subarray(nextBoundary, data.length);
|
|
901
|
+
} else {
|
|
902
|
+
usableData = data.slice(0, nextBoundary);
|
|
903
|
+
this.leftOver = data.slice(nextBoundary, data.length);
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
this.push({
|
|
907
|
+
data: exports$1.utf8decode(usableData),
|
|
908
|
+
meta: chunk.meta
|
|
909
|
+
});
|
|
910
|
+
};
|
|
911
|
+
Utf8DecodeWorker.prototype.flush = function() {
|
|
912
|
+
if (this.leftOver && this.leftOver.length) {
|
|
913
|
+
this.push({
|
|
914
|
+
data: exports$1.utf8decode(this.leftOver),
|
|
915
|
+
meta: {}
|
|
916
|
+
});
|
|
917
|
+
this.leftOver = null;
|
|
918
|
+
}
|
|
919
|
+
};
|
|
920
|
+
exports$1.Utf8DecodeWorker = Utf8DecodeWorker;
|
|
921
|
+
function Utf8EncodeWorker() {
|
|
922
|
+
GenericWorker.call(this, "utf-8 encode");
|
|
923
|
+
}
|
|
924
|
+
utils2.inherits(Utf8EncodeWorker, GenericWorker);
|
|
925
|
+
Utf8EncodeWorker.prototype.processChunk = function(chunk) {
|
|
926
|
+
this.push({
|
|
927
|
+
data: exports$1.utf8encode(chunk.data),
|
|
928
|
+
meta: chunk.meta
|
|
929
|
+
});
|
|
930
|
+
};
|
|
931
|
+
exports$1.Utf8EncodeWorker = Utf8EncodeWorker;
|
|
932
|
+
})(utf8);
|
|
933
|
+
return utf8;
|
|
934
|
+
}
|
|
935
|
+
var ConvertWorker_1;
|
|
936
|
+
var hasRequiredConvertWorker;
|
|
937
|
+
function requireConvertWorker() {
|
|
938
|
+
if (hasRequiredConvertWorker) return ConvertWorker_1;
|
|
939
|
+
hasRequiredConvertWorker = 1;
|
|
940
|
+
var GenericWorker = /* @__PURE__ */ requireGenericWorker();
|
|
941
|
+
var utils2 = /* @__PURE__ */ requireUtils();
|
|
942
|
+
function ConvertWorker(destType) {
|
|
943
|
+
GenericWorker.call(this, "ConvertWorker to " + destType);
|
|
944
|
+
this.destType = destType;
|
|
945
|
+
}
|
|
946
|
+
utils2.inherits(ConvertWorker, GenericWorker);
|
|
947
|
+
ConvertWorker.prototype.processChunk = function(chunk) {
|
|
948
|
+
this.push({
|
|
949
|
+
data: utils2.transformTo(this.destType, chunk.data),
|
|
950
|
+
meta: chunk.meta
|
|
951
|
+
});
|
|
952
|
+
};
|
|
953
|
+
ConvertWorker_1 = ConvertWorker;
|
|
954
|
+
return ConvertWorker_1;
|
|
955
|
+
}
|
|
956
|
+
var NodejsStreamOutputAdapter_1;
|
|
957
|
+
var hasRequiredNodejsStreamOutputAdapter;
|
|
958
|
+
function requireNodejsStreamOutputAdapter() {
|
|
959
|
+
if (hasRequiredNodejsStreamOutputAdapter) return NodejsStreamOutputAdapter_1;
|
|
960
|
+
hasRequiredNodejsStreamOutputAdapter = 1;
|
|
961
|
+
var Readable = requireReadable().Readable;
|
|
962
|
+
var utils2 = /* @__PURE__ */ requireUtils();
|
|
963
|
+
utils2.inherits(NodejsStreamOutputAdapter, Readable);
|
|
964
|
+
function NodejsStreamOutputAdapter(helper, options, updateCb) {
|
|
965
|
+
Readable.call(this, options);
|
|
966
|
+
this._helper = helper;
|
|
967
|
+
var self2 = this;
|
|
968
|
+
helper.on("data", function(data, meta) {
|
|
969
|
+
if (!self2.push(data)) {
|
|
970
|
+
self2._helper.pause();
|
|
971
|
+
}
|
|
972
|
+
if (updateCb) {
|
|
973
|
+
updateCb(meta);
|
|
974
|
+
}
|
|
975
|
+
}).on("error", function(e) {
|
|
976
|
+
self2.emit("error", e);
|
|
977
|
+
}).on("end", function() {
|
|
978
|
+
self2.push(null);
|
|
979
|
+
});
|
|
980
|
+
}
|
|
981
|
+
NodejsStreamOutputAdapter.prototype._read = function() {
|
|
982
|
+
this._helper.resume();
|
|
983
|
+
};
|
|
984
|
+
NodejsStreamOutputAdapter_1 = NodejsStreamOutputAdapter;
|
|
985
|
+
return NodejsStreamOutputAdapter_1;
|
|
986
|
+
}
|
|
987
|
+
var StreamHelper_1;
|
|
988
|
+
var hasRequiredStreamHelper;
|
|
989
|
+
function requireStreamHelper() {
|
|
990
|
+
if (hasRequiredStreamHelper) return StreamHelper_1;
|
|
991
|
+
hasRequiredStreamHelper = 1;
|
|
992
|
+
var utils2 = /* @__PURE__ */ requireUtils();
|
|
993
|
+
var ConvertWorker = /* @__PURE__ */ requireConvertWorker();
|
|
994
|
+
var GenericWorker = /* @__PURE__ */ requireGenericWorker();
|
|
995
|
+
var base642 = /* @__PURE__ */ requireBase64();
|
|
996
|
+
var support2 = /* @__PURE__ */ requireSupport();
|
|
997
|
+
var external2 = /* @__PURE__ */ requireExternal();
|
|
998
|
+
var NodejsStreamOutputAdapter = null;
|
|
999
|
+
if (support2.nodestream) {
|
|
1000
|
+
try {
|
|
1001
|
+
NodejsStreamOutputAdapter = /* @__PURE__ */ requireNodejsStreamOutputAdapter();
|
|
1002
|
+
} catch (e) {
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
function transformZipOutput(type, content, mimeType) {
|
|
1006
|
+
switch (type) {
|
|
1007
|
+
case "blob":
|
|
1008
|
+
return utils2.newBlob(utils2.transformTo("arraybuffer", content), mimeType);
|
|
1009
|
+
case "base64":
|
|
1010
|
+
return base642.encode(content);
|
|
1011
|
+
default:
|
|
1012
|
+
return utils2.transformTo(type, content);
|
|
1013
|
+
}
|
|
1014
|
+
}
|
|
1015
|
+
function concat(type, dataArray) {
|
|
1016
|
+
var i, index = 0, res = null, totalLength = 0;
|
|
1017
|
+
for (i = 0; i < dataArray.length; i++) {
|
|
1018
|
+
totalLength += dataArray[i].length;
|
|
1019
|
+
}
|
|
1020
|
+
switch (type) {
|
|
1021
|
+
case "string":
|
|
1022
|
+
return dataArray.join("");
|
|
1023
|
+
case "array":
|
|
1024
|
+
return Array.prototype.concat.apply([], dataArray);
|
|
1025
|
+
case "uint8array":
|
|
1026
|
+
res = new Uint8Array(totalLength);
|
|
1027
|
+
for (i = 0; i < dataArray.length; i++) {
|
|
1028
|
+
res.set(dataArray[i], index);
|
|
1029
|
+
index += dataArray[i].length;
|
|
1030
|
+
}
|
|
1031
|
+
return res;
|
|
1032
|
+
case "nodebuffer":
|
|
1033
|
+
return Buffer.concat(dataArray);
|
|
1034
|
+
default:
|
|
1035
|
+
throw new Error("concat : unsupported type '" + type + "'");
|
|
1036
|
+
}
|
|
1037
|
+
}
|
|
1038
|
+
function accumulate(helper, updateCallback) {
|
|
1039
|
+
return new external2.Promise(function(resolve, reject) {
|
|
1040
|
+
var dataArray = [];
|
|
1041
|
+
var chunkType = helper._internalType, resultType = helper._outputType, mimeType = helper._mimeType;
|
|
1042
|
+
helper.on("data", function(data, meta) {
|
|
1043
|
+
dataArray.push(data);
|
|
1044
|
+
if (updateCallback) {
|
|
1045
|
+
updateCallback(meta);
|
|
1046
|
+
}
|
|
1047
|
+
}).on("error", function(err) {
|
|
1048
|
+
dataArray = [];
|
|
1049
|
+
reject(err);
|
|
1050
|
+
}).on("end", function() {
|
|
1051
|
+
try {
|
|
1052
|
+
var result = transformZipOutput(resultType, concat(chunkType, dataArray), mimeType);
|
|
1053
|
+
resolve(result);
|
|
1054
|
+
} catch (e) {
|
|
1055
|
+
reject(e);
|
|
1056
|
+
}
|
|
1057
|
+
dataArray = [];
|
|
1058
|
+
}).resume();
|
|
1059
|
+
});
|
|
1060
|
+
}
|
|
1061
|
+
function StreamHelper(worker, outputType, mimeType) {
|
|
1062
|
+
var internalType = outputType;
|
|
1063
|
+
switch (outputType) {
|
|
1064
|
+
case "blob":
|
|
1065
|
+
case "arraybuffer":
|
|
1066
|
+
internalType = "uint8array";
|
|
1067
|
+
break;
|
|
1068
|
+
case "base64":
|
|
1069
|
+
internalType = "string";
|
|
1070
|
+
break;
|
|
1071
|
+
}
|
|
1072
|
+
try {
|
|
1073
|
+
this._internalType = internalType;
|
|
1074
|
+
this._outputType = outputType;
|
|
1075
|
+
this._mimeType = mimeType;
|
|
1076
|
+
utils2.checkSupport(internalType);
|
|
1077
|
+
this._worker = worker.pipe(new ConvertWorker(internalType));
|
|
1078
|
+
worker.lock();
|
|
1079
|
+
} catch (e) {
|
|
1080
|
+
this._worker = new GenericWorker("error");
|
|
1081
|
+
this._worker.error(e);
|
|
1082
|
+
}
|
|
1083
|
+
}
|
|
1084
|
+
StreamHelper.prototype = {
|
|
1085
|
+
/**
|
|
1086
|
+
* Listen a StreamHelper, accumulate its content and concatenate it into a
|
|
1087
|
+
* complete block.
|
|
1088
|
+
* @param {Function} updateCb the update callback.
|
|
1089
|
+
* @return Promise the promise for the accumulation.
|
|
1090
|
+
*/
|
|
1091
|
+
accumulate: function(updateCb) {
|
|
1092
|
+
return accumulate(this, updateCb);
|
|
1093
|
+
},
|
|
1094
|
+
/**
|
|
1095
|
+
* Add a listener on an event triggered on a stream.
|
|
1096
|
+
* @param {String} evt the name of the event
|
|
1097
|
+
* @param {Function} fn the listener
|
|
1098
|
+
* @return {StreamHelper} the current helper.
|
|
1099
|
+
*/
|
|
1100
|
+
on: function(evt, fn) {
|
|
1101
|
+
var self2 = this;
|
|
1102
|
+
if (evt === "data") {
|
|
1103
|
+
this._worker.on(evt, function(chunk) {
|
|
1104
|
+
fn.call(self2, chunk.data, chunk.meta);
|
|
1105
|
+
});
|
|
1106
|
+
} else {
|
|
1107
|
+
this._worker.on(evt, function() {
|
|
1108
|
+
utils2.delay(fn, arguments, self2);
|
|
1109
|
+
});
|
|
1110
|
+
}
|
|
1111
|
+
return this;
|
|
1112
|
+
},
|
|
1113
|
+
/**
|
|
1114
|
+
* Resume the flow of chunks.
|
|
1115
|
+
* @return {StreamHelper} the current helper.
|
|
1116
|
+
*/
|
|
1117
|
+
resume: function() {
|
|
1118
|
+
utils2.delay(this._worker.resume, [], this._worker);
|
|
1119
|
+
return this;
|
|
1120
|
+
},
|
|
1121
|
+
/**
|
|
1122
|
+
* Pause the flow of chunks.
|
|
1123
|
+
* @return {StreamHelper} the current helper.
|
|
1124
|
+
*/
|
|
1125
|
+
pause: function() {
|
|
1126
|
+
this._worker.pause();
|
|
1127
|
+
return this;
|
|
1128
|
+
},
|
|
1129
|
+
/**
|
|
1130
|
+
* Return a nodejs stream for this helper.
|
|
1131
|
+
* @param {Function} updateCb the update callback.
|
|
1132
|
+
* @return {NodejsStreamOutputAdapter} the nodejs stream.
|
|
1133
|
+
*/
|
|
1134
|
+
toNodejsStream: function(updateCb) {
|
|
1135
|
+
utils2.checkSupport("nodestream");
|
|
1136
|
+
if (this._outputType !== "nodebuffer") {
|
|
1137
|
+
throw new Error(this._outputType + " is not supported by this method");
|
|
1138
|
+
}
|
|
1139
|
+
return new NodejsStreamOutputAdapter(this, {
|
|
1140
|
+
objectMode: this._outputType !== "nodebuffer"
|
|
1141
|
+
}, updateCb);
|
|
1142
|
+
}
|
|
1143
|
+
};
|
|
1144
|
+
StreamHelper_1 = StreamHelper;
|
|
1145
|
+
return StreamHelper_1;
|
|
1146
|
+
}
|
|
1147
|
+
var defaults = {};
|
|
1148
|
+
var hasRequiredDefaults;
|
|
1149
|
+
function requireDefaults() {
|
|
1150
|
+
if (hasRequiredDefaults) return defaults;
|
|
1151
|
+
hasRequiredDefaults = 1;
|
|
1152
|
+
defaults.base64 = false;
|
|
1153
|
+
defaults.binary = false;
|
|
1154
|
+
defaults.dir = false;
|
|
1155
|
+
defaults.createFolders = true;
|
|
1156
|
+
defaults.date = null;
|
|
1157
|
+
defaults.compression = null;
|
|
1158
|
+
defaults.compressionOptions = null;
|
|
1159
|
+
defaults.comment = null;
|
|
1160
|
+
defaults.unixPermissions = null;
|
|
1161
|
+
defaults.dosPermissions = null;
|
|
1162
|
+
return defaults;
|
|
1163
|
+
}
|
|
1164
|
+
var DataWorker_1;
|
|
1165
|
+
var hasRequiredDataWorker;
|
|
1166
|
+
function requireDataWorker() {
|
|
1167
|
+
if (hasRequiredDataWorker) return DataWorker_1;
|
|
1168
|
+
hasRequiredDataWorker = 1;
|
|
1169
|
+
var utils2 = /* @__PURE__ */ requireUtils();
|
|
1170
|
+
var GenericWorker = /* @__PURE__ */ requireGenericWorker();
|
|
1171
|
+
var DEFAULT_BLOCK_SIZE = 16 * 1024;
|
|
1172
|
+
function DataWorker(dataP) {
|
|
1173
|
+
GenericWorker.call(this, "DataWorker");
|
|
1174
|
+
var self2 = this;
|
|
1175
|
+
this.dataIsReady = false;
|
|
1176
|
+
this.index = 0;
|
|
1177
|
+
this.max = 0;
|
|
1178
|
+
this.data = null;
|
|
1179
|
+
this.type = "";
|
|
1180
|
+
this._tickScheduled = false;
|
|
1181
|
+
dataP.then(function(data) {
|
|
1182
|
+
self2.dataIsReady = true;
|
|
1183
|
+
self2.data = data;
|
|
1184
|
+
self2.max = data && data.length || 0;
|
|
1185
|
+
self2.type = utils2.getTypeOf(data);
|
|
1186
|
+
if (!self2.isPaused) {
|
|
1187
|
+
self2._tickAndRepeat();
|
|
1188
|
+
}
|
|
1189
|
+
}, function(e) {
|
|
1190
|
+
self2.error(e);
|
|
1191
|
+
});
|
|
1192
|
+
}
|
|
1193
|
+
utils2.inherits(DataWorker, GenericWorker);
|
|
1194
|
+
DataWorker.prototype.cleanUp = function() {
|
|
1195
|
+
GenericWorker.prototype.cleanUp.call(this);
|
|
1196
|
+
this.data = null;
|
|
1197
|
+
};
|
|
1198
|
+
DataWorker.prototype.resume = function() {
|
|
1199
|
+
if (!GenericWorker.prototype.resume.call(this)) {
|
|
1200
|
+
return false;
|
|
1201
|
+
}
|
|
1202
|
+
if (!this._tickScheduled && this.dataIsReady) {
|
|
1203
|
+
this._tickScheduled = true;
|
|
1204
|
+
utils2.delay(this._tickAndRepeat, [], this);
|
|
1205
|
+
}
|
|
1206
|
+
return true;
|
|
1207
|
+
};
|
|
1208
|
+
DataWorker.prototype._tickAndRepeat = function() {
|
|
1209
|
+
this._tickScheduled = false;
|
|
1210
|
+
if (this.isPaused || this.isFinished) {
|
|
1211
|
+
return;
|
|
1212
|
+
}
|
|
1213
|
+
this._tick();
|
|
1214
|
+
if (!this.isFinished) {
|
|
1215
|
+
utils2.delay(this._tickAndRepeat, [], this);
|
|
1216
|
+
this._tickScheduled = true;
|
|
1217
|
+
}
|
|
1218
|
+
};
|
|
1219
|
+
DataWorker.prototype._tick = function() {
|
|
1220
|
+
if (this.isPaused || this.isFinished) {
|
|
1221
|
+
return false;
|
|
1222
|
+
}
|
|
1223
|
+
var size = DEFAULT_BLOCK_SIZE;
|
|
1224
|
+
var data = null, nextIndex = Math.min(this.max, this.index + size);
|
|
1225
|
+
if (this.index >= this.max) {
|
|
1226
|
+
return this.end();
|
|
1227
|
+
} else {
|
|
1228
|
+
switch (this.type) {
|
|
1229
|
+
case "string":
|
|
1230
|
+
data = this.data.substring(this.index, nextIndex);
|
|
1231
|
+
break;
|
|
1232
|
+
case "uint8array":
|
|
1233
|
+
data = this.data.subarray(this.index, nextIndex);
|
|
1234
|
+
break;
|
|
1235
|
+
case "array":
|
|
1236
|
+
case "nodebuffer":
|
|
1237
|
+
data = this.data.slice(this.index, nextIndex);
|
|
1238
|
+
break;
|
|
1239
|
+
}
|
|
1240
|
+
this.index = nextIndex;
|
|
1241
|
+
return this.push({
|
|
1242
|
+
data,
|
|
1243
|
+
meta: {
|
|
1244
|
+
percent: this.max ? this.index / this.max * 100 : 0
|
|
1245
|
+
}
|
|
1246
|
+
});
|
|
1247
|
+
}
|
|
1248
|
+
};
|
|
1249
|
+
DataWorker_1 = DataWorker;
|
|
1250
|
+
return DataWorker_1;
|
|
1251
|
+
}
|
|
1252
|
+
var crc32_1;
|
|
1253
|
+
var hasRequiredCrc32;
|
|
1254
|
+
function requireCrc32() {
|
|
1255
|
+
if (hasRequiredCrc32) return crc32_1;
|
|
1256
|
+
hasRequiredCrc32 = 1;
|
|
1257
|
+
var utils2 = /* @__PURE__ */ requireUtils();
|
|
1258
|
+
function makeTable() {
|
|
1259
|
+
var c, table = [];
|
|
1260
|
+
for (var n = 0; n < 256; n++) {
|
|
1261
|
+
c = n;
|
|
1262
|
+
for (var k = 0; k < 8; k++) {
|
|
1263
|
+
c = c & 1 ? 3988292384 ^ c >>> 1 : c >>> 1;
|
|
1264
|
+
}
|
|
1265
|
+
table[n] = c;
|
|
1266
|
+
}
|
|
1267
|
+
return table;
|
|
1268
|
+
}
|
|
1269
|
+
var crcTable = makeTable();
|
|
1270
|
+
function crc32(crc, buf, len, pos) {
|
|
1271
|
+
var t = crcTable, end = pos + len;
|
|
1272
|
+
crc = crc ^ -1;
|
|
1273
|
+
for (var i = pos; i < end; i++) {
|
|
1274
|
+
crc = crc >>> 8 ^ t[(crc ^ buf[i]) & 255];
|
|
1275
|
+
}
|
|
1276
|
+
return crc ^ -1;
|
|
1277
|
+
}
|
|
1278
|
+
function crc32str(crc, str, len, pos) {
|
|
1279
|
+
var t = crcTable, end = pos + len;
|
|
1280
|
+
crc = crc ^ -1;
|
|
1281
|
+
for (var i = pos; i < end; i++) {
|
|
1282
|
+
crc = crc >>> 8 ^ t[(crc ^ str.charCodeAt(i)) & 255];
|
|
1283
|
+
}
|
|
1284
|
+
return crc ^ -1;
|
|
1285
|
+
}
|
|
1286
|
+
crc32_1 = function crc32wrapper(input, crc) {
|
|
1287
|
+
if (typeof input === "undefined" || !input.length) {
|
|
1288
|
+
return 0;
|
|
1289
|
+
}
|
|
1290
|
+
var isArray = utils2.getTypeOf(input) !== "string";
|
|
1291
|
+
if (isArray) {
|
|
1292
|
+
return crc32(crc | 0, input, input.length, 0);
|
|
1293
|
+
} else {
|
|
1294
|
+
return crc32str(crc | 0, input, input.length, 0);
|
|
1295
|
+
}
|
|
1296
|
+
};
|
|
1297
|
+
return crc32_1;
|
|
1298
|
+
}
|
|
1299
|
+
var Crc32Probe_1;
|
|
1300
|
+
var hasRequiredCrc32Probe;
|
|
1301
|
+
function requireCrc32Probe() {
|
|
1302
|
+
if (hasRequiredCrc32Probe) return Crc32Probe_1;
|
|
1303
|
+
hasRequiredCrc32Probe = 1;
|
|
1304
|
+
var GenericWorker = /* @__PURE__ */ requireGenericWorker();
|
|
1305
|
+
var crc32 = /* @__PURE__ */ requireCrc32();
|
|
1306
|
+
var utils2 = /* @__PURE__ */ requireUtils();
|
|
1307
|
+
function Crc32Probe() {
|
|
1308
|
+
GenericWorker.call(this, "Crc32Probe");
|
|
1309
|
+
this.withStreamInfo("crc32", 0);
|
|
1310
|
+
}
|
|
1311
|
+
utils2.inherits(Crc32Probe, GenericWorker);
|
|
1312
|
+
Crc32Probe.prototype.processChunk = function(chunk) {
|
|
1313
|
+
this.streamInfo.crc32 = crc32(chunk.data, this.streamInfo.crc32 || 0);
|
|
1314
|
+
this.push(chunk);
|
|
1315
|
+
};
|
|
1316
|
+
Crc32Probe_1 = Crc32Probe;
|
|
1317
|
+
return Crc32Probe_1;
|
|
1318
|
+
}
|
|
1319
|
+
var DataLengthProbe_1;
|
|
1320
|
+
var hasRequiredDataLengthProbe;
|
|
1321
|
+
function requireDataLengthProbe() {
|
|
1322
|
+
if (hasRequiredDataLengthProbe) return DataLengthProbe_1;
|
|
1323
|
+
hasRequiredDataLengthProbe = 1;
|
|
1324
|
+
var utils2 = /* @__PURE__ */ requireUtils();
|
|
1325
|
+
var GenericWorker = /* @__PURE__ */ requireGenericWorker();
|
|
1326
|
+
function DataLengthProbe(propName) {
|
|
1327
|
+
GenericWorker.call(this, "DataLengthProbe for " + propName);
|
|
1328
|
+
this.propName = propName;
|
|
1329
|
+
this.withStreamInfo(propName, 0);
|
|
1330
|
+
}
|
|
1331
|
+
utils2.inherits(DataLengthProbe, GenericWorker);
|
|
1332
|
+
DataLengthProbe.prototype.processChunk = function(chunk) {
|
|
1333
|
+
if (chunk) {
|
|
1334
|
+
var length = this.streamInfo[this.propName] || 0;
|
|
1335
|
+
this.streamInfo[this.propName] = length + chunk.data.length;
|
|
1336
|
+
}
|
|
1337
|
+
GenericWorker.prototype.processChunk.call(this, chunk);
|
|
1338
|
+
};
|
|
1339
|
+
DataLengthProbe_1 = DataLengthProbe;
|
|
1340
|
+
return DataLengthProbe_1;
|
|
1341
|
+
}
|
|
1342
|
+
var compressedObject;
|
|
1343
|
+
var hasRequiredCompressedObject;
|
|
1344
|
+
function requireCompressedObject() {
|
|
1345
|
+
if (hasRequiredCompressedObject) return compressedObject;
|
|
1346
|
+
hasRequiredCompressedObject = 1;
|
|
1347
|
+
var external2 = /* @__PURE__ */ requireExternal();
|
|
1348
|
+
var DataWorker = /* @__PURE__ */ requireDataWorker();
|
|
1349
|
+
var Crc32Probe = /* @__PURE__ */ requireCrc32Probe();
|
|
1350
|
+
var DataLengthProbe = /* @__PURE__ */ requireDataLengthProbe();
|
|
1351
|
+
function CompressedObject(compressedSize, uncompressedSize, crc32, compression, data) {
|
|
1352
|
+
this.compressedSize = compressedSize;
|
|
1353
|
+
this.uncompressedSize = uncompressedSize;
|
|
1354
|
+
this.crc32 = crc32;
|
|
1355
|
+
this.compression = compression;
|
|
1356
|
+
this.compressedContent = data;
|
|
1357
|
+
}
|
|
1358
|
+
CompressedObject.prototype = {
|
|
1359
|
+
/**
|
|
1360
|
+
* Create a worker to get the uncompressed content.
|
|
1361
|
+
* @return {GenericWorker} the worker.
|
|
1362
|
+
*/
|
|
1363
|
+
getContentWorker: function() {
|
|
1364
|
+
var worker = new DataWorker(external2.Promise.resolve(this.compressedContent)).pipe(this.compression.uncompressWorker()).pipe(new DataLengthProbe("data_length"));
|
|
1365
|
+
var that = this;
|
|
1366
|
+
worker.on("end", function() {
|
|
1367
|
+
if (this.streamInfo["data_length"] !== that.uncompressedSize) {
|
|
1368
|
+
throw new Error("Bug : uncompressed data size mismatch");
|
|
1369
|
+
}
|
|
1370
|
+
});
|
|
1371
|
+
return worker;
|
|
1372
|
+
},
|
|
1373
|
+
/**
|
|
1374
|
+
* Create a worker to get the compressed content.
|
|
1375
|
+
* @return {GenericWorker} the worker.
|
|
1376
|
+
*/
|
|
1377
|
+
getCompressedWorker: function() {
|
|
1378
|
+
return new DataWorker(external2.Promise.resolve(this.compressedContent)).withStreamInfo("compressedSize", this.compressedSize).withStreamInfo("uncompressedSize", this.uncompressedSize).withStreamInfo("crc32", this.crc32).withStreamInfo("compression", this.compression);
|
|
1379
|
+
}
|
|
1380
|
+
};
|
|
1381
|
+
CompressedObject.createWorkerFrom = function(uncompressedWorker, compression, compressionOptions) {
|
|
1382
|
+
return uncompressedWorker.pipe(new Crc32Probe()).pipe(new DataLengthProbe("uncompressedSize")).pipe(compression.compressWorker(compressionOptions)).pipe(new DataLengthProbe("compressedSize")).withStreamInfo("compression", compression);
|
|
1383
|
+
};
|
|
1384
|
+
compressedObject = CompressedObject;
|
|
1385
|
+
return compressedObject;
|
|
1386
|
+
}
|
|
1387
|
+
var zipObject;
|
|
1388
|
+
var hasRequiredZipObject;
|
|
1389
|
+
function requireZipObject() {
|
|
1390
|
+
if (hasRequiredZipObject) return zipObject;
|
|
1391
|
+
hasRequiredZipObject = 1;
|
|
1392
|
+
var StreamHelper = /* @__PURE__ */ requireStreamHelper();
|
|
1393
|
+
var DataWorker = /* @__PURE__ */ requireDataWorker();
|
|
1394
|
+
var utf82 = /* @__PURE__ */ requireUtf8();
|
|
1395
|
+
var CompressedObject = /* @__PURE__ */ requireCompressedObject();
|
|
1396
|
+
var GenericWorker = /* @__PURE__ */ requireGenericWorker();
|
|
1397
|
+
var ZipObject = function(name, data, options) {
|
|
1398
|
+
this.name = name;
|
|
1399
|
+
this.dir = options.dir;
|
|
1400
|
+
this.date = options.date;
|
|
1401
|
+
this.comment = options.comment;
|
|
1402
|
+
this.unixPermissions = options.unixPermissions;
|
|
1403
|
+
this.dosPermissions = options.dosPermissions;
|
|
1404
|
+
this._data = data;
|
|
1405
|
+
this._dataBinary = options.binary;
|
|
1406
|
+
this.options = {
|
|
1407
|
+
compression: options.compression,
|
|
1408
|
+
compressionOptions: options.compressionOptions
|
|
1409
|
+
};
|
|
1410
|
+
};
|
|
1411
|
+
ZipObject.prototype = {
|
|
1412
|
+
/**
|
|
1413
|
+
* Create an internal stream for the content of this object.
|
|
1414
|
+
* @param {String} type the type of each chunk.
|
|
1415
|
+
* @return StreamHelper the stream.
|
|
1416
|
+
*/
|
|
1417
|
+
internalStream: function(type) {
|
|
1418
|
+
var result = null, outputType = "string";
|
|
1419
|
+
try {
|
|
1420
|
+
if (!type) {
|
|
1421
|
+
throw new Error("No output type specified.");
|
|
1422
|
+
}
|
|
1423
|
+
outputType = type.toLowerCase();
|
|
1424
|
+
var askUnicodeString = outputType === "string" || outputType === "text";
|
|
1425
|
+
if (outputType === "binarystring" || outputType === "text") {
|
|
1426
|
+
outputType = "string";
|
|
1427
|
+
}
|
|
1428
|
+
result = this._decompressWorker();
|
|
1429
|
+
var isUnicodeString = !this._dataBinary;
|
|
1430
|
+
if (isUnicodeString && !askUnicodeString) {
|
|
1431
|
+
result = result.pipe(new utf82.Utf8EncodeWorker());
|
|
1432
|
+
}
|
|
1433
|
+
if (!isUnicodeString && askUnicodeString) {
|
|
1434
|
+
result = result.pipe(new utf82.Utf8DecodeWorker());
|
|
1435
|
+
}
|
|
1436
|
+
} catch (e) {
|
|
1437
|
+
result = new GenericWorker("error");
|
|
1438
|
+
result.error(e);
|
|
1439
|
+
}
|
|
1440
|
+
return new StreamHelper(result, outputType, "");
|
|
1441
|
+
},
|
|
1442
|
+
/**
|
|
1443
|
+
* Prepare the content in the asked type.
|
|
1444
|
+
* @param {String} type the type of the result.
|
|
1445
|
+
* @param {Function} onUpdate a function to call on each internal update.
|
|
1446
|
+
* @return Promise the promise of the result.
|
|
1447
|
+
*/
|
|
1448
|
+
async: function(type, onUpdate) {
|
|
1449
|
+
return this.internalStream(type).accumulate(onUpdate);
|
|
1450
|
+
},
|
|
1451
|
+
/**
|
|
1452
|
+
* Prepare the content as a nodejs stream.
|
|
1453
|
+
* @param {String} type the type of each chunk.
|
|
1454
|
+
* @param {Function} onUpdate a function to call on each internal update.
|
|
1455
|
+
* @return Stream the stream.
|
|
1456
|
+
*/
|
|
1457
|
+
nodeStream: function(type, onUpdate) {
|
|
1458
|
+
return this.internalStream(type || "nodebuffer").toNodejsStream(onUpdate);
|
|
1459
|
+
},
|
|
1460
|
+
/**
|
|
1461
|
+
* Return a worker for the compressed content.
|
|
1462
|
+
* @private
|
|
1463
|
+
* @param {Object} compression the compression object to use.
|
|
1464
|
+
* @param {Object} compressionOptions the options to use when compressing.
|
|
1465
|
+
* @return Worker the worker.
|
|
1466
|
+
*/
|
|
1467
|
+
_compressWorker: function(compression, compressionOptions) {
|
|
1468
|
+
if (this._data instanceof CompressedObject && this._data.compression.magic === compression.magic) {
|
|
1469
|
+
return this._data.getCompressedWorker();
|
|
1470
|
+
} else {
|
|
1471
|
+
var result = this._decompressWorker();
|
|
1472
|
+
if (!this._dataBinary) {
|
|
1473
|
+
result = result.pipe(new utf82.Utf8EncodeWorker());
|
|
1474
|
+
}
|
|
1475
|
+
return CompressedObject.createWorkerFrom(result, compression, compressionOptions);
|
|
1476
|
+
}
|
|
1477
|
+
},
|
|
1478
|
+
/**
|
|
1479
|
+
* Return a worker for the decompressed content.
|
|
1480
|
+
* @private
|
|
1481
|
+
* @return Worker the worker.
|
|
1482
|
+
*/
|
|
1483
|
+
_decompressWorker: function() {
|
|
1484
|
+
if (this._data instanceof CompressedObject) {
|
|
1485
|
+
return this._data.getContentWorker();
|
|
1486
|
+
} else if (this._data instanceof GenericWorker) {
|
|
1487
|
+
return this._data;
|
|
1488
|
+
} else {
|
|
1489
|
+
return new DataWorker(this._data);
|
|
1490
|
+
}
|
|
1491
|
+
}
|
|
1492
|
+
};
|
|
1493
|
+
var removedMethods = ["asText", "asBinary", "asNodeBuffer", "asUint8Array", "asArrayBuffer"];
|
|
1494
|
+
var removedFn = function() {
|
|
1495
|
+
throw new Error("This method has been removed in JSZip 3.0, please check the upgrade guide.");
|
|
1496
|
+
};
|
|
1497
|
+
for (var i = 0; i < removedMethods.length; i++) {
|
|
1498
|
+
ZipObject.prototype[removedMethods[i]] = removedFn;
|
|
1499
|
+
}
|
|
1500
|
+
zipObject = ZipObject;
|
|
1501
|
+
return zipObject;
|
|
1502
|
+
}
|
|
1503
|
+
var generate = {};
|
|
1504
|
+
var compressions = {};
|
|
1505
|
+
var flate = {};
|
|
1506
|
+
var hasRequiredFlate;
|
|
1507
|
+
function requireFlate() {
|
|
1508
|
+
if (hasRequiredFlate) return flate;
|
|
1509
|
+
hasRequiredFlate = 1;
|
|
1510
|
+
var USE_TYPEDARRAY = typeof Uint8Array !== "undefined" && typeof Uint16Array !== "undefined" && typeof Uint32Array !== "undefined";
|
|
1511
|
+
var pako = /* @__PURE__ */ requirePako();
|
|
1512
|
+
var utils2 = /* @__PURE__ */ requireUtils();
|
|
1513
|
+
var GenericWorker = /* @__PURE__ */ requireGenericWorker();
|
|
1514
|
+
var ARRAY_TYPE = USE_TYPEDARRAY ? "uint8array" : "array";
|
|
1515
|
+
flate.magic = "\b\0";
|
|
1516
|
+
function FlateWorker(action, options) {
|
|
1517
|
+
GenericWorker.call(this, "FlateWorker/" + action);
|
|
1518
|
+
this._pako = null;
|
|
1519
|
+
this._pakoAction = action;
|
|
1520
|
+
this._pakoOptions = options;
|
|
1521
|
+
this.meta = {};
|
|
1522
|
+
}
|
|
1523
|
+
utils2.inherits(FlateWorker, GenericWorker);
|
|
1524
|
+
FlateWorker.prototype.processChunk = function(chunk) {
|
|
1525
|
+
this.meta = chunk.meta;
|
|
1526
|
+
if (this._pako === null) {
|
|
1527
|
+
this._createPako();
|
|
1528
|
+
}
|
|
1529
|
+
this._pako.push(utils2.transformTo(ARRAY_TYPE, chunk.data), false);
|
|
1530
|
+
};
|
|
1531
|
+
FlateWorker.prototype.flush = function() {
|
|
1532
|
+
GenericWorker.prototype.flush.call(this);
|
|
1533
|
+
if (this._pako === null) {
|
|
1534
|
+
this._createPako();
|
|
1535
|
+
}
|
|
1536
|
+
this._pako.push([], true);
|
|
1537
|
+
};
|
|
1538
|
+
FlateWorker.prototype.cleanUp = function() {
|
|
1539
|
+
GenericWorker.prototype.cleanUp.call(this);
|
|
1540
|
+
this._pako = null;
|
|
1541
|
+
};
|
|
1542
|
+
FlateWorker.prototype._createPako = function() {
|
|
1543
|
+
this._pako = new pako[this._pakoAction]({
|
|
1544
|
+
raw: true,
|
|
1545
|
+
level: this._pakoOptions.level || -1
|
|
1546
|
+
// default compression
|
|
1547
|
+
});
|
|
1548
|
+
var self2 = this;
|
|
1549
|
+
this._pako.onData = function(data) {
|
|
1550
|
+
self2.push({
|
|
1551
|
+
data,
|
|
1552
|
+
meta: self2.meta
|
|
1553
|
+
});
|
|
1554
|
+
};
|
|
1555
|
+
};
|
|
1556
|
+
flate.compressWorker = function(compressionOptions) {
|
|
1557
|
+
return new FlateWorker("Deflate", compressionOptions);
|
|
1558
|
+
};
|
|
1559
|
+
flate.uncompressWorker = function() {
|
|
1560
|
+
return new FlateWorker("Inflate", {});
|
|
1561
|
+
};
|
|
1562
|
+
return flate;
|
|
1563
|
+
}
|
|
1564
|
+
var hasRequiredCompressions;
|
|
1565
|
+
function requireCompressions() {
|
|
1566
|
+
if (hasRequiredCompressions) return compressions;
|
|
1567
|
+
hasRequiredCompressions = 1;
|
|
1568
|
+
var GenericWorker = /* @__PURE__ */ requireGenericWorker();
|
|
1569
|
+
compressions.STORE = {
|
|
1570
|
+
magic: "\0\0",
|
|
1571
|
+
compressWorker: function() {
|
|
1572
|
+
return new GenericWorker("STORE compression");
|
|
1573
|
+
},
|
|
1574
|
+
uncompressWorker: function() {
|
|
1575
|
+
return new GenericWorker("STORE decompression");
|
|
1576
|
+
}
|
|
1577
|
+
};
|
|
1578
|
+
compressions.DEFLATE = /* @__PURE__ */ requireFlate();
|
|
1579
|
+
return compressions;
|
|
1580
|
+
}
|
|
1581
|
+
var signature = {};
|
|
1582
|
+
var hasRequiredSignature;
|
|
1583
|
+
function requireSignature() {
|
|
1584
|
+
if (hasRequiredSignature) return signature;
|
|
1585
|
+
hasRequiredSignature = 1;
|
|
1586
|
+
signature.LOCAL_FILE_HEADER = "PK";
|
|
1587
|
+
signature.CENTRAL_FILE_HEADER = "PK";
|
|
1588
|
+
signature.CENTRAL_DIRECTORY_END = "PK";
|
|
1589
|
+
signature.ZIP64_CENTRAL_DIRECTORY_LOCATOR = "PK\x07";
|
|
1590
|
+
signature.ZIP64_CENTRAL_DIRECTORY_END = "PK";
|
|
1591
|
+
signature.DATA_DESCRIPTOR = "PK\x07\b";
|
|
1592
|
+
return signature;
|
|
1593
|
+
}
|
|
1594
|
+
var ZipFileWorker_1;
|
|
1595
|
+
var hasRequiredZipFileWorker;
|
|
1596
|
+
function requireZipFileWorker() {
|
|
1597
|
+
if (hasRequiredZipFileWorker) return ZipFileWorker_1;
|
|
1598
|
+
hasRequiredZipFileWorker = 1;
|
|
1599
|
+
var utils2 = /* @__PURE__ */ requireUtils();
|
|
1600
|
+
var GenericWorker = /* @__PURE__ */ requireGenericWorker();
|
|
1601
|
+
var utf82 = /* @__PURE__ */ requireUtf8();
|
|
1602
|
+
var crc32 = /* @__PURE__ */ requireCrc32();
|
|
1603
|
+
var signature2 = /* @__PURE__ */ requireSignature();
|
|
1604
|
+
var decToHex = function(dec, bytes) {
|
|
1605
|
+
var hex = "", i;
|
|
1606
|
+
for (i = 0; i < bytes; i++) {
|
|
1607
|
+
hex += String.fromCharCode(dec & 255);
|
|
1608
|
+
dec = dec >>> 8;
|
|
1609
|
+
}
|
|
1610
|
+
return hex;
|
|
1611
|
+
};
|
|
1612
|
+
var generateUnixExternalFileAttr = function(unixPermissions, isDir) {
|
|
1613
|
+
var result = unixPermissions;
|
|
1614
|
+
if (!unixPermissions) {
|
|
1615
|
+
result = isDir ? 16893 : 33204;
|
|
1616
|
+
}
|
|
1617
|
+
return (result & 65535) << 16;
|
|
1618
|
+
};
|
|
1619
|
+
var generateDosExternalFileAttr = function(dosPermissions) {
|
|
1620
|
+
return (dosPermissions || 0) & 63;
|
|
1621
|
+
};
|
|
1622
|
+
var generateZipParts = function(streamInfo, streamedContent, streamingEnded, offset, platform, encodeFileName) {
|
|
1623
|
+
var file = streamInfo["file"], compression = streamInfo["compression"], useCustomEncoding = encodeFileName !== utf82.utf8encode, encodedFileName = utils2.transformTo("string", encodeFileName(file.name)), utfEncodedFileName = utils2.transformTo("string", utf82.utf8encode(file.name)), comment = file.comment, encodedComment = utils2.transformTo("string", encodeFileName(comment)), utfEncodedComment = utils2.transformTo("string", utf82.utf8encode(comment)), useUTF8ForFileName = utfEncodedFileName.length !== file.name.length, useUTF8ForComment = utfEncodedComment.length !== comment.length, dosTime, dosDate, extraFields = "", unicodePathExtraField = "", unicodeCommentExtraField = "", dir = file.dir, date = file.date;
|
|
1624
|
+
var dataInfo = {
|
|
1625
|
+
crc32: 0,
|
|
1626
|
+
compressedSize: 0,
|
|
1627
|
+
uncompressedSize: 0
|
|
1628
|
+
};
|
|
1629
|
+
if (!streamedContent || streamingEnded) {
|
|
1630
|
+
dataInfo.crc32 = streamInfo["crc32"];
|
|
1631
|
+
dataInfo.compressedSize = streamInfo["compressedSize"];
|
|
1632
|
+
dataInfo.uncompressedSize = streamInfo["uncompressedSize"];
|
|
1633
|
+
}
|
|
1634
|
+
var bitflag = 0;
|
|
1635
|
+
if (streamedContent) {
|
|
1636
|
+
bitflag |= 8;
|
|
1637
|
+
}
|
|
1638
|
+
if (!useCustomEncoding && (useUTF8ForFileName || useUTF8ForComment)) {
|
|
1639
|
+
bitflag |= 2048;
|
|
1640
|
+
}
|
|
1641
|
+
var extFileAttr = 0;
|
|
1642
|
+
var versionMadeBy = 0;
|
|
1643
|
+
if (dir) {
|
|
1644
|
+
extFileAttr |= 16;
|
|
1645
|
+
}
|
|
1646
|
+
if (platform === "UNIX") {
|
|
1647
|
+
versionMadeBy = 798;
|
|
1648
|
+
extFileAttr |= generateUnixExternalFileAttr(file.unixPermissions, dir);
|
|
1649
|
+
} else {
|
|
1650
|
+
versionMadeBy = 20;
|
|
1651
|
+
extFileAttr |= generateDosExternalFileAttr(file.dosPermissions);
|
|
1652
|
+
}
|
|
1653
|
+
dosTime = date.getUTCHours();
|
|
1654
|
+
dosTime = dosTime << 6;
|
|
1655
|
+
dosTime = dosTime | date.getUTCMinutes();
|
|
1656
|
+
dosTime = dosTime << 5;
|
|
1657
|
+
dosTime = dosTime | date.getUTCSeconds() / 2;
|
|
1658
|
+
dosDate = date.getUTCFullYear() - 1980;
|
|
1659
|
+
dosDate = dosDate << 4;
|
|
1660
|
+
dosDate = dosDate | date.getUTCMonth() + 1;
|
|
1661
|
+
dosDate = dosDate << 5;
|
|
1662
|
+
dosDate = dosDate | date.getUTCDate();
|
|
1663
|
+
if (useUTF8ForFileName) {
|
|
1664
|
+
unicodePathExtraField = // Version
|
|
1665
|
+
decToHex(1, 1) + // NameCRC32
|
|
1666
|
+
decToHex(crc32(encodedFileName), 4) + // UnicodeName
|
|
1667
|
+
utfEncodedFileName;
|
|
1668
|
+
extraFields += // Info-ZIP Unicode Path Extra Field
|
|
1669
|
+
"up" + // size
|
|
1670
|
+
decToHex(unicodePathExtraField.length, 2) + // content
|
|
1671
|
+
unicodePathExtraField;
|
|
1672
|
+
}
|
|
1673
|
+
if (useUTF8ForComment) {
|
|
1674
|
+
unicodeCommentExtraField = // Version
|
|
1675
|
+
decToHex(1, 1) + // CommentCRC32
|
|
1676
|
+
decToHex(crc32(encodedComment), 4) + // UnicodeName
|
|
1677
|
+
utfEncodedComment;
|
|
1678
|
+
extraFields += // Info-ZIP Unicode Path Extra Field
|
|
1679
|
+
"uc" + // size
|
|
1680
|
+
decToHex(unicodeCommentExtraField.length, 2) + // content
|
|
1681
|
+
unicodeCommentExtraField;
|
|
1682
|
+
}
|
|
1683
|
+
var header = "";
|
|
1684
|
+
header += "\n\0";
|
|
1685
|
+
header += decToHex(bitflag, 2);
|
|
1686
|
+
header += compression.magic;
|
|
1687
|
+
header += decToHex(dosTime, 2);
|
|
1688
|
+
header += decToHex(dosDate, 2);
|
|
1689
|
+
header += decToHex(dataInfo.crc32, 4);
|
|
1690
|
+
header += decToHex(dataInfo.compressedSize, 4);
|
|
1691
|
+
header += decToHex(dataInfo.uncompressedSize, 4);
|
|
1692
|
+
header += decToHex(encodedFileName.length, 2);
|
|
1693
|
+
header += decToHex(extraFields.length, 2);
|
|
1694
|
+
var fileRecord = signature2.LOCAL_FILE_HEADER + header + encodedFileName + extraFields;
|
|
1695
|
+
var dirRecord = signature2.CENTRAL_FILE_HEADER + // version made by (00: DOS)
|
|
1696
|
+
decToHex(versionMadeBy, 2) + // file header (common to file and central directory)
|
|
1697
|
+
header + // file comment length
|
|
1698
|
+
decToHex(encodedComment.length, 2) + // disk number start
|
|
1699
|
+
"\0\0\0\0" + // external file attributes
|
|
1700
|
+
decToHex(extFileAttr, 4) + // relative offset of local header
|
|
1701
|
+
decToHex(offset, 4) + // file name
|
|
1702
|
+
encodedFileName + // extra field
|
|
1703
|
+
extraFields + // file comment
|
|
1704
|
+
encodedComment;
|
|
1705
|
+
return {
|
|
1706
|
+
fileRecord,
|
|
1707
|
+
dirRecord
|
|
1708
|
+
};
|
|
1709
|
+
};
|
|
1710
|
+
var generateCentralDirectoryEnd = function(entriesCount, centralDirLength, localDirLength, comment, encodeFileName) {
|
|
1711
|
+
var dirEnd = "";
|
|
1712
|
+
var encodedComment = utils2.transformTo("string", encodeFileName(comment));
|
|
1713
|
+
dirEnd = signature2.CENTRAL_DIRECTORY_END + // number of this disk
|
|
1714
|
+
"\0\0\0\0" + // total number of entries in the central directory on this disk
|
|
1715
|
+
decToHex(entriesCount, 2) + // total number of entries in the central directory
|
|
1716
|
+
decToHex(entriesCount, 2) + // size of the central directory 4 bytes
|
|
1717
|
+
decToHex(centralDirLength, 4) + // offset of start of central directory with respect to the starting disk number
|
|
1718
|
+
decToHex(localDirLength, 4) + // .ZIP file comment length
|
|
1719
|
+
decToHex(encodedComment.length, 2) + // .ZIP file comment
|
|
1720
|
+
encodedComment;
|
|
1721
|
+
return dirEnd;
|
|
1722
|
+
};
|
|
1723
|
+
var generateDataDescriptors = function(streamInfo) {
|
|
1724
|
+
var descriptor = "";
|
|
1725
|
+
descriptor = signature2.DATA_DESCRIPTOR + // crc-32 4 bytes
|
|
1726
|
+
decToHex(streamInfo["crc32"], 4) + // compressed size 4 bytes
|
|
1727
|
+
decToHex(streamInfo["compressedSize"], 4) + // uncompressed size 4 bytes
|
|
1728
|
+
decToHex(streamInfo["uncompressedSize"], 4);
|
|
1729
|
+
return descriptor;
|
|
1730
|
+
};
|
|
1731
|
+
function ZipFileWorker(streamFiles, comment, platform, encodeFileName) {
|
|
1732
|
+
GenericWorker.call(this, "ZipFileWorker");
|
|
1733
|
+
this.bytesWritten = 0;
|
|
1734
|
+
this.zipComment = comment;
|
|
1735
|
+
this.zipPlatform = platform;
|
|
1736
|
+
this.encodeFileName = encodeFileName;
|
|
1737
|
+
this.streamFiles = streamFiles;
|
|
1738
|
+
this.accumulate = false;
|
|
1739
|
+
this.contentBuffer = [];
|
|
1740
|
+
this.dirRecords = [];
|
|
1741
|
+
this.currentSourceOffset = 0;
|
|
1742
|
+
this.entriesCount = 0;
|
|
1743
|
+
this.currentFile = null;
|
|
1744
|
+
this._sources = [];
|
|
1745
|
+
}
|
|
1746
|
+
utils2.inherits(ZipFileWorker, GenericWorker);
|
|
1747
|
+
ZipFileWorker.prototype.push = function(chunk) {
|
|
1748
|
+
var currentFilePercent = chunk.meta.percent || 0;
|
|
1749
|
+
var entriesCount = this.entriesCount;
|
|
1750
|
+
var remainingFiles = this._sources.length;
|
|
1751
|
+
if (this.accumulate) {
|
|
1752
|
+
this.contentBuffer.push(chunk);
|
|
1753
|
+
} else {
|
|
1754
|
+
this.bytesWritten += chunk.data.length;
|
|
1755
|
+
GenericWorker.prototype.push.call(this, {
|
|
1756
|
+
data: chunk.data,
|
|
1757
|
+
meta: {
|
|
1758
|
+
currentFile: this.currentFile,
|
|
1759
|
+
percent: entriesCount ? (currentFilePercent + 100 * (entriesCount - remainingFiles - 1)) / entriesCount : 100
|
|
1760
|
+
}
|
|
1761
|
+
});
|
|
1762
|
+
}
|
|
1763
|
+
};
|
|
1764
|
+
ZipFileWorker.prototype.openedSource = function(streamInfo) {
|
|
1765
|
+
this.currentSourceOffset = this.bytesWritten;
|
|
1766
|
+
this.currentFile = streamInfo["file"].name;
|
|
1767
|
+
var streamedContent = this.streamFiles && !streamInfo["file"].dir;
|
|
1768
|
+
if (streamedContent) {
|
|
1769
|
+
var record = generateZipParts(streamInfo, streamedContent, false, this.currentSourceOffset, this.zipPlatform, this.encodeFileName);
|
|
1770
|
+
this.push({
|
|
1771
|
+
data: record.fileRecord,
|
|
1772
|
+
meta: { percent: 0 }
|
|
1773
|
+
});
|
|
1774
|
+
} else {
|
|
1775
|
+
this.accumulate = true;
|
|
1776
|
+
}
|
|
1777
|
+
};
|
|
1778
|
+
ZipFileWorker.prototype.closedSource = function(streamInfo) {
|
|
1779
|
+
this.accumulate = false;
|
|
1780
|
+
var streamedContent = this.streamFiles && !streamInfo["file"].dir;
|
|
1781
|
+
var record = generateZipParts(streamInfo, streamedContent, true, this.currentSourceOffset, this.zipPlatform, this.encodeFileName);
|
|
1782
|
+
this.dirRecords.push(record.dirRecord);
|
|
1783
|
+
if (streamedContent) {
|
|
1784
|
+
this.push({
|
|
1785
|
+
data: generateDataDescriptors(streamInfo),
|
|
1786
|
+
meta: { percent: 100 }
|
|
1787
|
+
});
|
|
1788
|
+
} else {
|
|
1789
|
+
this.push({
|
|
1790
|
+
data: record.fileRecord,
|
|
1791
|
+
meta: { percent: 0 }
|
|
1792
|
+
});
|
|
1793
|
+
while (this.contentBuffer.length) {
|
|
1794
|
+
this.push(this.contentBuffer.shift());
|
|
1795
|
+
}
|
|
1796
|
+
}
|
|
1797
|
+
this.currentFile = null;
|
|
1798
|
+
};
|
|
1799
|
+
ZipFileWorker.prototype.flush = function() {
|
|
1800
|
+
var localDirLength = this.bytesWritten;
|
|
1801
|
+
for (var i = 0; i < this.dirRecords.length; i++) {
|
|
1802
|
+
this.push({
|
|
1803
|
+
data: this.dirRecords[i],
|
|
1804
|
+
meta: { percent: 100 }
|
|
1805
|
+
});
|
|
1806
|
+
}
|
|
1807
|
+
var centralDirLength = this.bytesWritten - localDirLength;
|
|
1808
|
+
var dirEnd = generateCentralDirectoryEnd(this.dirRecords.length, centralDirLength, localDirLength, this.zipComment, this.encodeFileName);
|
|
1809
|
+
this.push({
|
|
1810
|
+
data: dirEnd,
|
|
1811
|
+
meta: { percent: 100 }
|
|
1812
|
+
});
|
|
1813
|
+
};
|
|
1814
|
+
ZipFileWorker.prototype.prepareNextSource = function() {
|
|
1815
|
+
this.previous = this._sources.shift();
|
|
1816
|
+
this.openedSource(this.previous.streamInfo);
|
|
1817
|
+
if (this.isPaused) {
|
|
1818
|
+
this.previous.pause();
|
|
1819
|
+
} else {
|
|
1820
|
+
this.previous.resume();
|
|
1821
|
+
}
|
|
1822
|
+
};
|
|
1823
|
+
ZipFileWorker.prototype.registerPrevious = function(previous) {
|
|
1824
|
+
this._sources.push(previous);
|
|
1825
|
+
var self2 = this;
|
|
1826
|
+
previous.on("data", function(chunk) {
|
|
1827
|
+
self2.processChunk(chunk);
|
|
1828
|
+
});
|
|
1829
|
+
previous.on("end", function() {
|
|
1830
|
+
self2.closedSource(self2.previous.streamInfo);
|
|
1831
|
+
if (self2._sources.length) {
|
|
1832
|
+
self2.prepareNextSource();
|
|
1833
|
+
} else {
|
|
1834
|
+
self2.end();
|
|
1835
|
+
}
|
|
1836
|
+
});
|
|
1837
|
+
previous.on("error", function(e) {
|
|
1838
|
+
self2.error(e);
|
|
1839
|
+
});
|
|
1840
|
+
return this;
|
|
1841
|
+
};
|
|
1842
|
+
ZipFileWorker.prototype.resume = function() {
|
|
1843
|
+
if (!GenericWorker.prototype.resume.call(this)) {
|
|
1844
|
+
return false;
|
|
1845
|
+
}
|
|
1846
|
+
if (!this.previous && this._sources.length) {
|
|
1847
|
+
this.prepareNextSource();
|
|
1848
|
+
return true;
|
|
1849
|
+
}
|
|
1850
|
+
if (!this.previous && !this._sources.length && !this.generatedError) {
|
|
1851
|
+
this.end();
|
|
1852
|
+
return true;
|
|
1853
|
+
}
|
|
1854
|
+
};
|
|
1855
|
+
ZipFileWorker.prototype.error = function(e) {
|
|
1856
|
+
var sources = this._sources;
|
|
1857
|
+
if (!GenericWorker.prototype.error.call(this, e)) {
|
|
1858
|
+
return false;
|
|
1859
|
+
}
|
|
1860
|
+
for (var i = 0; i < sources.length; i++) {
|
|
1861
|
+
try {
|
|
1862
|
+
sources[i].error(e);
|
|
1863
|
+
} catch (e2) {
|
|
1864
|
+
}
|
|
1865
|
+
}
|
|
1866
|
+
return true;
|
|
1867
|
+
};
|
|
1868
|
+
ZipFileWorker.prototype.lock = function() {
|
|
1869
|
+
GenericWorker.prototype.lock.call(this);
|
|
1870
|
+
var sources = this._sources;
|
|
1871
|
+
for (var i = 0; i < sources.length; i++) {
|
|
1872
|
+
sources[i].lock();
|
|
1873
|
+
}
|
|
1874
|
+
};
|
|
1875
|
+
ZipFileWorker_1 = ZipFileWorker;
|
|
1876
|
+
return ZipFileWorker_1;
|
|
1877
|
+
}
|
|
1878
|
+
var hasRequiredGenerate;
|
|
1879
|
+
function requireGenerate() {
|
|
1880
|
+
if (hasRequiredGenerate) return generate;
|
|
1881
|
+
hasRequiredGenerate = 1;
|
|
1882
|
+
var compressions2 = /* @__PURE__ */ requireCompressions();
|
|
1883
|
+
var ZipFileWorker = /* @__PURE__ */ requireZipFileWorker();
|
|
1884
|
+
var getCompression = function(fileCompression, zipCompression) {
|
|
1885
|
+
var compressionName = fileCompression || zipCompression;
|
|
1886
|
+
var compression = compressions2[compressionName];
|
|
1887
|
+
if (!compression) {
|
|
1888
|
+
throw new Error(compressionName + " is not a valid compression method !");
|
|
1889
|
+
}
|
|
1890
|
+
return compression;
|
|
1891
|
+
};
|
|
1892
|
+
generate.generateWorker = function(zip, options, comment) {
|
|
1893
|
+
var zipFileWorker = new ZipFileWorker(options.streamFiles, comment, options.platform, options.encodeFileName);
|
|
1894
|
+
var entriesCount = 0;
|
|
1895
|
+
try {
|
|
1896
|
+
zip.forEach(function(relativePath, file) {
|
|
1897
|
+
entriesCount++;
|
|
1898
|
+
var compression = getCompression(file.options.compression, options.compression);
|
|
1899
|
+
var compressionOptions = file.options.compressionOptions || options.compressionOptions || {};
|
|
1900
|
+
var dir = file.dir, date = file.date;
|
|
1901
|
+
file._compressWorker(compression, compressionOptions).withStreamInfo("file", {
|
|
1902
|
+
name: relativePath,
|
|
1903
|
+
dir,
|
|
1904
|
+
date,
|
|
1905
|
+
comment: file.comment || "",
|
|
1906
|
+
unixPermissions: file.unixPermissions,
|
|
1907
|
+
dosPermissions: file.dosPermissions
|
|
1908
|
+
}).pipe(zipFileWorker);
|
|
1909
|
+
});
|
|
1910
|
+
zipFileWorker.entriesCount = entriesCount;
|
|
1911
|
+
} catch (e) {
|
|
1912
|
+
zipFileWorker.error(e);
|
|
1913
|
+
}
|
|
1914
|
+
return zipFileWorker;
|
|
1915
|
+
};
|
|
1916
|
+
return generate;
|
|
1917
|
+
}
|
|
1918
|
+
var NodejsStreamInputAdapter_1;
|
|
1919
|
+
var hasRequiredNodejsStreamInputAdapter;
|
|
1920
|
+
function requireNodejsStreamInputAdapter() {
|
|
1921
|
+
if (hasRequiredNodejsStreamInputAdapter) return NodejsStreamInputAdapter_1;
|
|
1922
|
+
hasRequiredNodejsStreamInputAdapter = 1;
|
|
1923
|
+
var utils2 = /* @__PURE__ */ requireUtils();
|
|
1924
|
+
var GenericWorker = /* @__PURE__ */ requireGenericWorker();
|
|
1925
|
+
function NodejsStreamInputAdapter(filename, stream) {
|
|
1926
|
+
GenericWorker.call(this, "Nodejs stream input adapter for " + filename);
|
|
1927
|
+
this._upstreamEnded = false;
|
|
1928
|
+
this._bindStream(stream);
|
|
1929
|
+
}
|
|
1930
|
+
utils2.inherits(NodejsStreamInputAdapter, GenericWorker);
|
|
1931
|
+
NodejsStreamInputAdapter.prototype._bindStream = function(stream) {
|
|
1932
|
+
var self2 = this;
|
|
1933
|
+
this._stream = stream;
|
|
1934
|
+
stream.pause();
|
|
1935
|
+
stream.on("data", function(chunk) {
|
|
1936
|
+
self2.push({
|
|
1937
|
+
data: chunk,
|
|
1938
|
+
meta: {
|
|
1939
|
+
percent: 0
|
|
1940
|
+
}
|
|
1941
|
+
});
|
|
1942
|
+
}).on("error", function(e) {
|
|
1943
|
+
if (self2.isPaused) {
|
|
1944
|
+
this.generatedError = e;
|
|
1945
|
+
} else {
|
|
1946
|
+
self2.error(e);
|
|
1947
|
+
}
|
|
1948
|
+
}).on("end", function() {
|
|
1949
|
+
if (self2.isPaused) {
|
|
1950
|
+
self2._upstreamEnded = true;
|
|
1951
|
+
} else {
|
|
1952
|
+
self2.end();
|
|
1953
|
+
}
|
|
1954
|
+
});
|
|
1955
|
+
};
|
|
1956
|
+
NodejsStreamInputAdapter.prototype.pause = function() {
|
|
1957
|
+
if (!GenericWorker.prototype.pause.call(this)) {
|
|
1958
|
+
return false;
|
|
1959
|
+
}
|
|
1960
|
+
this._stream.pause();
|
|
1961
|
+
return true;
|
|
1962
|
+
};
|
|
1963
|
+
NodejsStreamInputAdapter.prototype.resume = function() {
|
|
1964
|
+
if (!GenericWorker.prototype.resume.call(this)) {
|
|
1965
|
+
return false;
|
|
1966
|
+
}
|
|
1967
|
+
if (this._upstreamEnded) {
|
|
1968
|
+
this.end();
|
|
1969
|
+
} else {
|
|
1970
|
+
this._stream.resume();
|
|
1971
|
+
}
|
|
1972
|
+
return true;
|
|
1973
|
+
};
|
|
1974
|
+
NodejsStreamInputAdapter_1 = NodejsStreamInputAdapter;
|
|
1975
|
+
return NodejsStreamInputAdapter_1;
|
|
1976
|
+
}
|
|
1977
|
+
var object;
|
|
1978
|
+
var hasRequiredObject;
|
|
1979
|
+
function requireObject() {
|
|
1980
|
+
if (hasRequiredObject) return object;
|
|
1981
|
+
hasRequiredObject = 1;
|
|
1982
|
+
var utf82 = /* @__PURE__ */ requireUtf8();
|
|
1983
|
+
var utils2 = /* @__PURE__ */ requireUtils();
|
|
1984
|
+
var GenericWorker = /* @__PURE__ */ requireGenericWorker();
|
|
1985
|
+
var StreamHelper = /* @__PURE__ */ requireStreamHelper();
|
|
1986
|
+
var defaults2 = /* @__PURE__ */ requireDefaults();
|
|
1987
|
+
var CompressedObject = /* @__PURE__ */ requireCompressedObject();
|
|
1988
|
+
var ZipObject = /* @__PURE__ */ requireZipObject();
|
|
1989
|
+
var generate2 = /* @__PURE__ */ requireGenerate();
|
|
1990
|
+
var nodejsUtils2 = /* @__PURE__ */ requireNodejsUtils();
|
|
1991
|
+
var NodejsStreamInputAdapter = /* @__PURE__ */ requireNodejsStreamInputAdapter();
|
|
1992
|
+
var fileAdd = function(name, data, originalOptions) {
|
|
1993
|
+
var dataType = utils2.getTypeOf(data), parent;
|
|
1994
|
+
var o = utils2.extend(originalOptions || {}, defaults2);
|
|
1995
|
+
o.date = o.date || /* @__PURE__ */ new Date();
|
|
1996
|
+
if (o.compression !== null) {
|
|
1997
|
+
o.compression = o.compression.toUpperCase();
|
|
1998
|
+
}
|
|
1999
|
+
if (typeof o.unixPermissions === "string") {
|
|
2000
|
+
o.unixPermissions = parseInt(o.unixPermissions, 8);
|
|
2001
|
+
}
|
|
2002
|
+
if (o.unixPermissions && o.unixPermissions & 16384) {
|
|
2003
|
+
o.dir = true;
|
|
2004
|
+
}
|
|
2005
|
+
if (o.dosPermissions && o.dosPermissions & 16) {
|
|
2006
|
+
o.dir = true;
|
|
2007
|
+
}
|
|
2008
|
+
if (o.dir) {
|
|
2009
|
+
name = forceTrailingSlash(name);
|
|
2010
|
+
}
|
|
2011
|
+
if (o.createFolders && (parent = parentFolder(name))) {
|
|
2012
|
+
folderAdd.call(this, parent, true);
|
|
2013
|
+
}
|
|
2014
|
+
var isUnicodeString = dataType === "string" && o.binary === false && o.base64 === false;
|
|
2015
|
+
if (!originalOptions || typeof originalOptions.binary === "undefined") {
|
|
2016
|
+
o.binary = !isUnicodeString;
|
|
2017
|
+
}
|
|
2018
|
+
var isCompressedEmpty = data instanceof CompressedObject && data.uncompressedSize === 0;
|
|
2019
|
+
if (isCompressedEmpty || o.dir || !data || data.length === 0) {
|
|
2020
|
+
o.base64 = false;
|
|
2021
|
+
o.binary = true;
|
|
2022
|
+
data = "";
|
|
2023
|
+
o.compression = "STORE";
|
|
2024
|
+
dataType = "string";
|
|
2025
|
+
}
|
|
2026
|
+
var zipObjectContent = null;
|
|
2027
|
+
if (data instanceof CompressedObject || data instanceof GenericWorker) {
|
|
2028
|
+
zipObjectContent = data;
|
|
2029
|
+
} else if (nodejsUtils2.isNode && nodejsUtils2.isStream(data)) {
|
|
2030
|
+
zipObjectContent = new NodejsStreamInputAdapter(name, data);
|
|
2031
|
+
} else {
|
|
2032
|
+
zipObjectContent = utils2.prepareContent(name, data, o.binary, o.optimizedBinaryString, o.base64);
|
|
2033
|
+
}
|
|
2034
|
+
var object2 = new ZipObject(name, zipObjectContent, o);
|
|
2035
|
+
this.files[name] = object2;
|
|
2036
|
+
};
|
|
2037
|
+
var parentFolder = function(path) {
|
|
2038
|
+
if (path.slice(-1) === "/") {
|
|
2039
|
+
path = path.substring(0, path.length - 1);
|
|
2040
|
+
}
|
|
2041
|
+
var lastSlash = path.lastIndexOf("/");
|
|
2042
|
+
return lastSlash > 0 ? path.substring(0, lastSlash) : "";
|
|
2043
|
+
};
|
|
2044
|
+
var forceTrailingSlash = function(path) {
|
|
2045
|
+
if (path.slice(-1) !== "/") {
|
|
2046
|
+
path += "/";
|
|
2047
|
+
}
|
|
2048
|
+
return path;
|
|
2049
|
+
};
|
|
2050
|
+
var folderAdd = function(name, createFolders) {
|
|
2051
|
+
createFolders = typeof createFolders !== "undefined" ? createFolders : defaults2.createFolders;
|
|
2052
|
+
name = forceTrailingSlash(name);
|
|
2053
|
+
if (!this.files[name]) {
|
|
2054
|
+
fileAdd.call(this, name, null, {
|
|
2055
|
+
dir: true,
|
|
2056
|
+
createFolders
|
|
2057
|
+
});
|
|
2058
|
+
}
|
|
2059
|
+
return this.files[name];
|
|
2060
|
+
};
|
|
2061
|
+
function isRegExp(object2) {
|
|
2062
|
+
return Object.prototype.toString.call(object2) === "[object RegExp]";
|
|
2063
|
+
}
|
|
2064
|
+
var out = {
|
|
2065
|
+
/**
|
|
2066
|
+
* @see loadAsync
|
|
2067
|
+
*/
|
|
2068
|
+
load: function() {
|
|
2069
|
+
throw new Error("This method has been removed in JSZip 3.0, please check the upgrade guide.");
|
|
2070
|
+
},
|
|
2071
|
+
/**
|
|
2072
|
+
* Call a callback function for each entry at this folder level.
|
|
2073
|
+
* @param {Function} cb the callback function:
|
|
2074
|
+
* function (relativePath, file) {...}
|
|
2075
|
+
* It takes 2 arguments : the relative path and the file.
|
|
2076
|
+
*/
|
|
2077
|
+
forEach: function(cb) {
|
|
2078
|
+
var filename, relativePath, file;
|
|
2079
|
+
for (filename in this.files) {
|
|
2080
|
+
file = this.files[filename];
|
|
2081
|
+
relativePath = filename.slice(this.root.length, filename.length);
|
|
2082
|
+
if (relativePath && filename.slice(0, this.root.length) === this.root) {
|
|
2083
|
+
cb(relativePath, file);
|
|
2084
|
+
}
|
|
2085
|
+
}
|
|
2086
|
+
},
|
|
2087
|
+
/**
|
|
2088
|
+
* Filter nested files/folders with the specified function.
|
|
2089
|
+
* @param {Function} search the predicate to use :
|
|
2090
|
+
* function (relativePath, file) {...}
|
|
2091
|
+
* It takes 2 arguments : the relative path and the file.
|
|
2092
|
+
* @return {Array} An array of matching elements.
|
|
2093
|
+
*/
|
|
2094
|
+
filter: function(search) {
|
|
2095
|
+
var result = [];
|
|
2096
|
+
this.forEach(function(relativePath, entry) {
|
|
2097
|
+
if (search(relativePath, entry)) {
|
|
2098
|
+
result.push(entry);
|
|
2099
|
+
}
|
|
2100
|
+
});
|
|
2101
|
+
return result;
|
|
2102
|
+
},
|
|
2103
|
+
/**
|
|
2104
|
+
* Add a file to the zip file, or search a file.
|
|
2105
|
+
* @param {string|RegExp} name The name of the file to add (if data is defined),
|
|
2106
|
+
* the name of the file to find (if no data) or a regex to match files.
|
|
2107
|
+
* @param {String|ArrayBuffer|Uint8Array|Buffer} data The file data, either raw or base64 encoded
|
|
2108
|
+
* @param {Object} o File options
|
|
2109
|
+
* @return {JSZip|Object|Array} this JSZip object (when adding a file),
|
|
2110
|
+
* a file (when searching by string) or an array of files (when searching by regex).
|
|
2111
|
+
*/
|
|
2112
|
+
file: function(name, data, o) {
|
|
2113
|
+
if (arguments.length === 1) {
|
|
2114
|
+
if (isRegExp(name)) {
|
|
2115
|
+
var regexp = name;
|
|
2116
|
+
return this.filter(function(relativePath, file) {
|
|
2117
|
+
return !file.dir && regexp.test(relativePath);
|
|
2118
|
+
});
|
|
2119
|
+
} else {
|
|
2120
|
+
var obj = this.files[this.root + name];
|
|
2121
|
+
if (obj && !obj.dir) {
|
|
2122
|
+
return obj;
|
|
2123
|
+
} else {
|
|
2124
|
+
return null;
|
|
2125
|
+
}
|
|
2126
|
+
}
|
|
2127
|
+
} else {
|
|
2128
|
+
name = this.root + name;
|
|
2129
|
+
fileAdd.call(this, name, data, o);
|
|
2130
|
+
}
|
|
2131
|
+
return this;
|
|
2132
|
+
},
|
|
2133
|
+
/**
|
|
2134
|
+
* Add a directory to the zip file, or search.
|
|
2135
|
+
* @param {String|RegExp} arg The name of the directory to add, or a regex to search folders.
|
|
2136
|
+
* @return {JSZip} an object with the new directory as the root, or an array containing matching folders.
|
|
2137
|
+
*/
|
|
2138
|
+
folder: function(arg) {
|
|
2139
|
+
if (!arg) {
|
|
2140
|
+
return this;
|
|
2141
|
+
}
|
|
2142
|
+
if (isRegExp(arg)) {
|
|
2143
|
+
return this.filter(function(relativePath, file) {
|
|
2144
|
+
return file.dir && arg.test(relativePath);
|
|
2145
|
+
});
|
|
2146
|
+
}
|
|
2147
|
+
var name = this.root + arg;
|
|
2148
|
+
var newFolder = folderAdd.call(this, name);
|
|
2149
|
+
var ret = this.clone();
|
|
2150
|
+
ret.root = newFolder.name;
|
|
2151
|
+
return ret;
|
|
2152
|
+
},
|
|
2153
|
+
/**
|
|
2154
|
+
* Delete a file, or a directory and all sub-files, from the zip
|
|
2155
|
+
* @param {string} name the name of the file to delete
|
|
2156
|
+
* @return {JSZip} this JSZip object
|
|
2157
|
+
*/
|
|
2158
|
+
remove: function(name) {
|
|
2159
|
+
name = this.root + name;
|
|
2160
|
+
var file = this.files[name];
|
|
2161
|
+
if (!file) {
|
|
2162
|
+
if (name.slice(-1) !== "/") {
|
|
2163
|
+
name += "/";
|
|
2164
|
+
}
|
|
2165
|
+
file = this.files[name];
|
|
2166
|
+
}
|
|
2167
|
+
if (file && !file.dir) {
|
|
2168
|
+
delete this.files[name];
|
|
2169
|
+
} else {
|
|
2170
|
+
var kids = this.filter(function(relativePath, file2) {
|
|
2171
|
+
return file2.name.slice(0, name.length) === name;
|
|
2172
|
+
});
|
|
2173
|
+
for (var i = 0; i < kids.length; i++) {
|
|
2174
|
+
delete this.files[kids[i].name];
|
|
2175
|
+
}
|
|
2176
|
+
}
|
|
2177
|
+
return this;
|
|
2178
|
+
},
|
|
2179
|
+
/**
|
|
2180
|
+
* @deprecated This method has been removed in JSZip 3.0, please check the upgrade guide.
|
|
2181
|
+
*/
|
|
2182
|
+
generate: function() {
|
|
2183
|
+
throw new Error("This method has been removed in JSZip 3.0, please check the upgrade guide.");
|
|
2184
|
+
},
|
|
2185
|
+
/**
|
|
2186
|
+
* Generate the complete zip file as an internal stream.
|
|
2187
|
+
* @param {Object} options the options to generate the zip file :
|
|
2188
|
+
* - compression, "STORE" by default.
|
|
2189
|
+
* - type, "base64" by default. Values are : string, base64, uint8array, arraybuffer, blob.
|
|
2190
|
+
* @return {StreamHelper} the streamed zip file.
|
|
2191
|
+
*/
|
|
2192
|
+
generateInternalStream: function(options) {
|
|
2193
|
+
var worker, opts = {};
|
|
2194
|
+
try {
|
|
2195
|
+
opts = utils2.extend(options || {}, {
|
|
2196
|
+
streamFiles: false,
|
|
2197
|
+
compression: "STORE",
|
|
2198
|
+
compressionOptions: null,
|
|
2199
|
+
type: "",
|
|
2200
|
+
platform: "DOS",
|
|
2201
|
+
comment: null,
|
|
2202
|
+
mimeType: "application/zip",
|
|
2203
|
+
encodeFileName: utf82.utf8encode
|
|
2204
|
+
});
|
|
2205
|
+
opts.type = opts.type.toLowerCase();
|
|
2206
|
+
opts.compression = opts.compression.toUpperCase();
|
|
2207
|
+
if (opts.type === "binarystring") {
|
|
2208
|
+
opts.type = "string";
|
|
2209
|
+
}
|
|
2210
|
+
if (!opts.type) {
|
|
2211
|
+
throw new Error("No output type specified.");
|
|
2212
|
+
}
|
|
2213
|
+
utils2.checkSupport(opts.type);
|
|
2214
|
+
if (opts.platform === "darwin" || opts.platform === "freebsd" || opts.platform === "linux" || opts.platform === "sunos") {
|
|
2215
|
+
opts.platform = "UNIX";
|
|
2216
|
+
}
|
|
2217
|
+
if (opts.platform === "win32") {
|
|
2218
|
+
opts.platform = "DOS";
|
|
2219
|
+
}
|
|
2220
|
+
var comment = opts.comment || this.comment || "";
|
|
2221
|
+
worker = generate2.generateWorker(this, opts, comment);
|
|
2222
|
+
} catch (e) {
|
|
2223
|
+
worker = new GenericWorker("error");
|
|
2224
|
+
worker.error(e);
|
|
2225
|
+
}
|
|
2226
|
+
return new StreamHelper(worker, opts.type || "string", opts.mimeType);
|
|
2227
|
+
},
|
|
2228
|
+
/**
|
|
2229
|
+
* Generate the complete zip file asynchronously.
|
|
2230
|
+
* @see generateInternalStream
|
|
2231
|
+
*/
|
|
2232
|
+
generateAsync: function(options, onUpdate) {
|
|
2233
|
+
return this.generateInternalStream(options).accumulate(onUpdate);
|
|
2234
|
+
},
|
|
2235
|
+
/**
|
|
2236
|
+
* Generate the complete zip file asynchronously.
|
|
2237
|
+
* @see generateInternalStream
|
|
2238
|
+
*/
|
|
2239
|
+
generateNodeStream: function(options, onUpdate) {
|
|
2240
|
+
options = options || {};
|
|
2241
|
+
if (!options.type) {
|
|
2242
|
+
options.type = "nodebuffer";
|
|
2243
|
+
}
|
|
2244
|
+
return this.generateInternalStream(options).toNodejsStream(onUpdate);
|
|
2245
|
+
}
|
|
2246
|
+
};
|
|
2247
|
+
object = out;
|
|
2248
|
+
return object;
|
|
2249
|
+
}
|
|
2250
|
+
var DataReader_1;
|
|
2251
|
+
var hasRequiredDataReader;
|
|
2252
|
+
function requireDataReader() {
|
|
2253
|
+
if (hasRequiredDataReader) return DataReader_1;
|
|
2254
|
+
hasRequiredDataReader = 1;
|
|
2255
|
+
var utils2 = /* @__PURE__ */ requireUtils();
|
|
2256
|
+
function DataReader(data) {
|
|
2257
|
+
this.data = data;
|
|
2258
|
+
this.length = data.length;
|
|
2259
|
+
this.index = 0;
|
|
2260
|
+
this.zero = 0;
|
|
2261
|
+
}
|
|
2262
|
+
DataReader.prototype = {
|
|
2263
|
+
/**
|
|
2264
|
+
* Check that the offset will not go too far.
|
|
2265
|
+
* @param {string} offset the additional offset to check.
|
|
2266
|
+
* @throws {Error} an Error if the offset is out of bounds.
|
|
2267
|
+
*/
|
|
2268
|
+
checkOffset: function(offset) {
|
|
2269
|
+
this.checkIndex(this.index + offset);
|
|
2270
|
+
},
|
|
2271
|
+
/**
|
|
2272
|
+
* Check that the specified index will not be too far.
|
|
2273
|
+
* @param {string} newIndex the index to check.
|
|
2274
|
+
* @throws {Error} an Error if the index is out of bounds.
|
|
2275
|
+
*/
|
|
2276
|
+
checkIndex: function(newIndex) {
|
|
2277
|
+
if (this.length < this.zero + newIndex || newIndex < 0) {
|
|
2278
|
+
throw new Error("End of data reached (data length = " + this.length + ", asked index = " + newIndex + "). Corrupted zip ?");
|
|
2279
|
+
}
|
|
2280
|
+
},
|
|
2281
|
+
/**
|
|
2282
|
+
* Change the index.
|
|
2283
|
+
* @param {number} newIndex The new index.
|
|
2284
|
+
* @throws {Error} if the new index is out of the data.
|
|
2285
|
+
*/
|
|
2286
|
+
setIndex: function(newIndex) {
|
|
2287
|
+
this.checkIndex(newIndex);
|
|
2288
|
+
this.index = newIndex;
|
|
2289
|
+
},
|
|
2290
|
+
/**
|
|
2291
|
+
* Skip the next n bytes.
|
|
2292
|
+
* @param {number} n the number of bytes to skip.
|
|
2293
|
+
* @throws {Error} if the new index is out of the data.
|
|
2294
|
+
*/
|
|
2295
|
+
skip: function(n) {
|
|
2296
|
+
this.setIndex(this.index + n);
|
|
2297
|
+
},
|
|
2298
|
+
/**
|
|
2299
|
+
* Get the byte at the specified index.
|
|
2300
|
+
* @param {number} i the index to use.
|
|
2301
|
+
* @return {number} a byte.
|
|
2302
|
+
*/
|
|
2303
|
+
byteAt: function() {
|
|
2304
|
+
},
|
|
2305
|
+
/**
|
|
2306
|
+
* Get the next number with a given byte size.
|
|
2307
|
+
* @param {number} size the number of bytes to read.
|
|
2308
|
+
* @return {number} the corresponding number.
|
|
2309
|
+
*/
|
|
2310
|
+
readInt: function(size) {
|
|
2311
|
+
var result = 0, i;
|
|
2312
|
+
this.checkOffset(size);
|
|
2313
|
+
for (i = this.index + size - 1; i >= this.index; i--) {
|
|
2314
|
+
result = (result << 8) + this.byteAt(i);
|
|
2315
|
+
}
|
|
2316
|
+
this.index += size;
|
|
2317
|
+
return result;
|
|
2318
|
+
},
|
|
2319
|
+
/**
|
|
2320
|
+
* Get the next string with a given byte size.
|
|
2321
|
+
* @param {number} size the number of bytes to read.
|
|
2322
|
+
* @return {string} the corresponding string.
|
|
2323
|
+
*/
|
|
2324
|
+
readString: function(size) {
|
|
2325
|
+
return utils2.transformTo("string", this.readData(size));
|
|
2326
|
+
},
|
|
2327
|
+
/**
|
|
2328
|
+
* Get raw data without conversion, <size> bytes.
|
|
2329
|
+
* @param {number} size the number of bytes to read.
|
|
2330
|
+
* @return {Object} the raw data, implementation specific.
|
|
2331
|
+
*/
|
|
2332
|
+
readData: function() {
|
|
2333
|
+
},
|
|
2334
|
+
/**
|
|
2335
|
+
* Find the last occurrence of a zip signature (4 bytes).
|
|
2336
|
+
* @param {string} sig the signature to find.
|
|
2337
|
+
* @return {number} the index of the last occurrence, -1 if not found.
|
|
2338
|
+
*/
|
|
2339
|
+
lastIndexOfSignature: function() {
|
|
2340
|
+
},
|
|
2341
|
+
/**
|
|
2342
|
+
* Read the signature (4 bytes) at the current position and compare it with sig.
|
|
2343
|
+
* @param {string} sig the expected signature
|
|
2344
|
+
* @return {boolean} true if the signature matches, false otherwise.
|
|
2345
|
+
*/
|
|
2346
|
+
readAndCheckSignature: function() {
|
|
2347
|
+
},
|
|
2348
|
+
/**
|
|
2349
|
+
* Get the next date.
|
|
2350
|
+
* @return {Date} the date.
|
|
2351
|
+
*/
|
|
2352
|
+
readDate: function() {
|
|
2353
|
+
var dostime = this.readInt(4);
|
|
2354
|
+
return new Date(Date.UTC(
|
|
2355
|
+
(dostime >> 25 & 127) + 1980,
|
|
2356
|
+
// year
|
|
2357
|
+
(dostime >> 21 & 15) - 1,
|
|
2358
|
+
// month
|
|
2359
|
+
dostime >> 16 & 31,
|
|
2360
|
+
// day
|
|
2361
|
+
dostime >> 11 & 31,
|
|
2362
|
+
// hour
|
|
2363
|
+
dostime >> 5 & 63,
|
|
2364
|
+
// minute
|
|
2365
|
+
(dostime & 31) << 1
|
|
2366
|
+
));
|
|
2367
|
+
}
|
|
2368
|
+
};
|
|
2369
|
+
DataReader_1 = DataReader;
|
|
2370
|
+
return DataReader_1;
|
|
2371
|
+
}
|
|
2372
|
+
var ArrayReader_1;
|
|
2373
|
+
var hasRequiredArrayReader;
|
|
2374
|
+
function requireArrayReader() {
|
|
2375
|
+
if (hasRequiredArrayReader) return ArrayReader_1;
|
|
2376
|
+
hasRequiredArrayReader = 1;
|
|
2377
|
+
var DataReader = /* @__PURE__ */ requireDataReader();
|
|
2378
|
+
var utils2 = /* @__PURE__ */ requireUtils();
|
|
2379
|
+
function ArrayReader(data) {
|
|
2380
|
+
DataReader.call(this, data);
|
|
2381
|
+
for (var i = 0; i < this.data.length; i++) {
|
|
2382
|
+
data[i] = data[i] & 255;
|
|
2383
|
+
}
|
|
2384
|
+
}
|
|
2385
|
+
utils2.inherits(ArrayReader, DataReader);
|
|
2386
|
+
ArrayReader.prototype.byteAt = function(i) {
|
|
2387
|
+
return this.data[this.zero + i];
|
|
2388
|
+
};
|
|
2389
|
+
ArrayReader.prototype.lastIndexOfSignature = function(sig) {
|
|
2390
|
+
var sig0 = sig.charCodeAt(0), sig1 = sig.charCodeAt(1), sig2 = sig.charCodeAt(2), sig3 = sig.charCodeAt(3);
|
|
2391
|
+
for (var i = this.length - 4; i >= 0; --i) {
|
|
2392
|
+
if (this.data[i] === sig0 && this.data[i + 1] === sig1 && this.data[i + 2] === sig2 && this.data[i + 3] === sig3) {
|
|
2393
|
+
return i - this.zero;
|
|
2394
|
+
}
|
|
2395
|
+
}
|
|
2396
|
+
return -1;
|
|
2397
|
+
};
|
|
2398
|
+
ArrayReader.prototype.readAndCheckSignature = function(sig) {
|
|
2399
|
+
var sig0 = sig.charCodeAt(0), sig1 = sig.charCodeAt(1), sig2 = sig.charCodeAt(2), sig3 = sig.charCodeAt(3), data = this.readData(4);
|
|
2400
|
+
return sig0 === data[0] && sig1 === data[1] && sig2 === data[2] && sig3 === data[3];
|
|
2401
|
+
};
|
|
2402
|
+
ArrayReader.prototype.readData = function(size) {
|
|
2403
|
+
this.checkOffset(size);
|
|
2404
|
+
if (size === 0) {
|
|
2405
|
+
return [];
|
|
2406
|
+
}
|
|
2407
|
+
var result = this.data.slice(this.zero + this.index, this.zero + this.index + size);
|
|
2408
|
+
this.index += size;
|
|
2409
|
+
return result;
|
|
2410
|
+
};
|
|
2411
|
+
ArrayReader_1 = ArrayReader;
|
|
2412
|
+
return ArrayReader_1;
|
|
2413
|
+
}
|
|
2414
|
+
var StringReader_1;
|
|
2415
|
+
var hasRequiredStringReader;
|
|
2416
|
+
function requireStringReader() {
|
|
2417
|
+
if (hasRequiredStringReader) return StringReader_1;
|
|
2418
|
+
hasRequiredStringReader = 1;
|
|
2419
|
+
var DataReader = /* @__PURE__ */ requireDataReader();
|
|
2420
|
+
var utils2 = /* @__PURE__ */ requireUtils();
|
|
2421
|
+
function StringReader(data) {
|
|
2422
|
+
DataReader.call(this, data);
|
|
2423
|
+
}
|
|
2424
|
+
utils2.inherits(StringReader, DataReader);
|
|
2425
|
+
StringReader.prototype.byteAt = function(i) {
|
|
2426
|
+
return this.data.charCodeAt(this.zero + i);
|
|
2427
|
+
};
|
|
2428
|
+
StringReader.prototype.lastIndexOfSignature = function(sig) {
|
|
2429
|
+
return this.data.lastIndexOf(sig) - this.zero;
|
|
2430
|
+
};
|
|
2431
|
+
StringReader.prototype.readAndCheckSignature = function(sig) {
|
|
2432
|
+
var data = this.readData(4);
|
|
2433
|
+
return sig === data;
|
|
2434
|
+
};
|
|
2435
|
+
StringReader.prototype.readData = function(size) {
|
|
2436
|
+
this.checkOffset(size);
|
|
2437
|
+
var result = this.data.slice(this.zero + this.index, this.zero + this.index + size);
|
|
2438
|
+
this.index += size;
|
|
2439
|
+
return result;
|
|
2440
|
+
};
|
|
2441
|
+
StringReader_1 = StringReader;
|
|
2442
|
+
return StringReader_1;
|
|
2443
|
+
}
|
|
2444
|
+
var Uint8ArrayReader_1;
|
|
2445
|
+
var hasRequiredUint8ArrayReader;
|
|
2446
|
+
function requireUint8ArrayReader() {
|
|
2447
|
+
if (hasRequiredUint8ArrayReader) return Uint8ArrayReader_1;
|
|
2448
|
+
hasRequiredUint8ArrayReader = 1;
|
|
2449
|
+
var ArrayReader = /* @__PURE__ */ requireArrayReader();
|
|
2450
|
+
var utils2 = /* @__PURE__ */ requireUtils();
|
|
2451
|
+
function Uint8ArrayReader(data) {
|
|
2452
|
+
ArrayReader.call(this, data);
|
|
2453
|
+
}
|
|
2454
|
+
utils2.inherits(Uint8ArrayReader, ArrayReader);
|
|
2455
|
+
Uint8ArrayReader.prototype.readData = function(size) {
|
|
2456
|
+
this.checkOffset(size);
|
|
2457
|
+
if (size === 0) {
|
|
2458
|
+
return new Uint8Array(0);
|
|
2459
|
+
}
|
|
2460
|
+
var result = this.data.subarray(this.zero + this.index, this.zero + this.index + size);
|
|
2461
|
+
this.index += size;
|
|
2462
|
+
return result;
|
|
2463
|
+
};
|
|
2464
|
+
Uint8ArrayReader_1 = Uint8ArrayReader;
|
|
2465
|
+
return Uint8ArrayReader_1;
|
|
2466
|
+
}
|
|
2467
|
+
var NodeBufferReader_1;
|
|
2468
|
+
var hasRequiredNodeBufferReader;
|
|
2469
|
+
function requireNodeBufferReader() {
|
|
2470
|
+
if (hasRequiredNodeBufferReader) return NodeBufferReader_1;
|
|
2471
|
+
hasRequiredNodeBufferReader = 1;
|
|
2472
|
+
var Uint8ArrayReader = /* @__PURE__ */ requireUint8ArrayReader();
|
|
2473
|
+
var utils2 = /* @__PURE__ */ requireUtils();
|
|
2474
|
+
function NodeBufferReader(data) {
|
|
2475
|
+
Uint8ArrayReader.call(this, data);
|
|
2476
|
+
}
|
|
2477
|
+
utils2.inherits(NodeBufferReader, Uint8ArrayReader);
|
|
2478
|
+
NodeBufferReader.prototype.readData = function(size) {
|
|
2479
|
+
this.checkOffset(size);
|
|
2480
|
+
var result = this.data.slice(this.zero + this.index, this.zero + this.index + size);
|
|
2481
|
+
this.index += size;
|
|
2482
|
+
return result;
|
|
2483
|
+
};
|
|
2484
|
+
NodeBufferReader_1 = NodeBufferReader;
|
|
2485
|
+
return NodeBufferReader_1;
|
|
2486
|
+
}
|
|
2487
|
+
var readerFor;
|
|
2488
|
+
var hasRequiredReaderFor;
|
|
2489
|
+
function requireReaderFor() {
|
|
2490
|
+
if (hasRequiredReaderFor) return readerFor;
|
|
2491
|
+
hasRequiredReaderFor = 1;
|
|
2492
|
+
var utils2 = /* @__PURE__ */ requireUtils();
|
|
2493
|
+
var support2 = /* @__PURE__ */ requireSupport();
|
|
2494
|
+
var ArrayReader = /* @__PURE__ */ requireArrayReader();
|
|
2495
|
+
var StringReader = /* @__PURE__ */ requireStringReader();
|
|
2496
|
+
var NodeBufferReader = /* @__PURE__ */ requireNodeBufferReader();
|
|
2497
|
+
var Uint8ArrayReader = /* @__PURE__ */ requireUint8ArrayReader();
|
|
2498
|
+
readerFor = function(data) {
|
|
2499
|
+
var type = utils2.getTypeOf(data);
|
|
2500
|
+
utils2.checkSupport(type);
|
|
2501
|
+
if (type === "string" && !support2.uint8array) {
|
|
2502
|
+
return new StringReader(data);
|
|
2503
|
+
}
|
|
2504
|
+
if (type === "nodebuffer") {
|
|
2505
|
+
return new NodeBufferReader(data);
|
|
2506
|
+
}
|
|
2507
|
+
if (support2.uint8array) {
|
|
2508
|
+
return new Uint8ArrayReader(utils2.transformTo("uint8array", data));
|
|
2509
|
+
}
|
|
2510
|
+
return new ArrayReader(utils2.transformTo("array", data));
|
|
2511
|
+
};
|
|
2512
|
+
return readerFor;
|
|
2513
|
+
}
|
|
2514
|
+
var zipEntry;
|
|
2515
|
+
var hasRequiredZipEntry;
|
|
2516
|
+
function requireZipEntry() {
|
|
2517
|
+
if (hasRequiredZipEntry) return zipEntry;
|
|
2518
|
+
hasRequiredZipEntry = 1;
|
|
2519
|
+
var readerFor2 = /* @__PURE__ */ requireReaderFor();
|
|
2520
|
+
var utils2 = /* @__PURE__ */ requireUtils();
|
|
2521
|
+
var CompressedObject = /* @__PURE__ */ requireCompressedObject();
|
|
2522
|
+
var crc32fn = /* @__PURE__ */ requireCrc32();
|
|
2523
|
+
var utf82 = /* @__PURE__ */ requireUtf8();
|
|
2524
|
+
var compressions2 = /* @__PURE__ */ requireCompressions();
|
|
2525
|
+
var support2 = /* @__PURE__ */ requireSupport();
|
|
2526
|
+
var MADE_BY_DOS = 0;
|
|
2527
|
+
var MADE_BY_UNIX = 3;
|
|
2528
|
+
var findCompression = function(compressionMethod) {
|
|
2529
|
+
for (var method in compressions2) {
|
|
2530
|
+
if (!Object.prototype.hasOwnProperty.call(compressions2, method)) {
|
|
2531
|
+
continue;
|
|
2532
|
+
}
|
|
2533
|
+
if (compressions2[method].magic === compressionMethod) {
|
|
2534
|
+
return compressions2[method];
|
|
2535
|
+
}
|
|
2536
|
+
}
|
|
2537
|
+
return null;
|
|
2538
|
+
};
|
|
2539
|
+
function ZipEntry(options, loadOptions) {
|
|
2540
|
+
this.options = options;
|
|
2541
|
+
this.loadOptions = loadOptions;
|
|
2542
|
+
}
|
|
2543
|
+
ZipEntry.prototype = {
|
|
2544
|
+
/**
|
|
2545
|
+
* say if the file is encrypted.
|
|
2546
|
+
* @return {boolean} true if the file is encrypted, false otherwise.
|
|
2547
|
+
*/
|
|
2548
|
+
isEncrypted: function() {
|
|
2549
|
+
return (this.bitFlag & 1) === 1;
|
|
2550
|
+
},
|
|
2551
|
+
/**
|
|
2552
|
+
* say if the file has utf-8 filename/comment.
|
|
2553
|
+
* @return {boolean} true if the filename/comment is in utf-8, false otherwise.
|
|
2554
|
+
*/
|
|
2555
|
+
useUTF8: function() {
|
|
2556
|
+
return (this.bitFlag & 2048) === 2048;
|
|
2557
|
+
},
|
|
2558
|
+
/**
|
|
2559
|
+
* Read the local part of a zip file and add the info in this object.
|
|
2560
|
+
* @param {DataReader} reader the reader to use.
|
|
2561
|
+
*/
|
|
2562
|
+
readLocalPart: function(reader) {
|
|
2563
|
+
var compression, localExtraFieldsLength;
|
|
2564
|
+
reader.skip(22);
|
|
2565
|
+
this.fileNameLength = reader.readInt(2);
|
|
2566
|
+
localExtraFieldsLength = reader.readInt(2);
|
|
2567
|
+
this.fileName = reader.readData(this.fileNameLength);
|
|
2568
|
+
reader.skip(localExtraFieldsLength);
|
|
2569
|
+
if (this.compressedSize === -1 || this.uncompressedSize === -1) {
|
|
2570
|
+
throw new Error("Bug or corrupted zip : didn't get enough information from the central directory (compressedSize === -1 || uncompressedSize === -1)");
|
|
2571
|
+
}
|
|
2572
|
+
compression = findCompression(this.compressionMethod);
|
|
2573
|
+
if (compression === null) {
|
|
2574
|
+
throw new Error("Corrupted zip : compression " + utils2.pretty(this.compressionMethod) + " unknown (inner file : " + utils2.transformTo("string", this.fileName) + ")");
|
|
2575
|
+
}
|
|
2576
|
+
this.decompressed = new CompressedObject(this.compressedSize, this.uncompressedSize, this.crc32, compression, reader.readData(this.compressedSize));
|
|
2577
|
+
},
|
|
2578
|
+
/**
|
|
2579
|
+
* Read the central part of a zip file and add the info in this object.
|
|
2580
|
+
* @param {DataReader} reader the reader to use.
|
|
2581
|
+
*/
|
|
2582
|
+
readCentralPart: function(reader) {
|
|
2583
|
+
this.versionMadeBy = reader.readInt(2);
|
|
2584
|
+
reader.skip(2);
|
|
2585
|
+
this.bitFlag = reader.readInt(2);
|
|
2586
|
+
this.compressionMethod = reader.readString(2);
|
|
2587
|
+
this.date = reader.readDate();
|
|
2588
|
+
this.crc32 = reader.readInt(4);
|
|
2589
|
+
this.compressedSize = reader.readInt(4);
|
|
2590
|
+
this.uncompressedSize = reader.readInt(4);
|
|
2591
|
+
var fileNameLength = reader.readInt(2);
|
|
2592
|
+
this.extraFieldsLength = reader.readInt(2);
|
|
2593
|
+
this.fileCommentLength = reader.readInt(2);
|
|
2594
|
+
this.diskNumberStart = reader.readInt(2);
|
|
2595
|
+
this.internalFileAttributes = reader.readInt(2);
|
|
2596
|
+
this.externalFileAttributes = reader.readInt(4);
|
|
2597
|
+
this.localHeaderOffset = reader.readInt(4);
|
|
2598
|
+
if (this.isEncrypted()) {
|
|
2599
|
+
throw new Error("Encrypted zip are not supported");
|
|
2600
|
+
}
|
|
2601
|
+
reader.skip(fileNameLength);
|
|
2602
|
+
this.readExtraFields(reader);
|
|
2603
|
+
this.parseZIP64ExtraField(reader);
|
|
2604
|
+
this.fileComment = reader.readData(this.fileCommentLength);
|
|
2605
|
+
},
|
|
2606
|
+
/**
|
|
2607
|
+
* Parse the external file attributes and get the unix/dos permissions.
|
|
2608
|
+
*/
|
|
2609
|
+
processAttributes: function() {
|
|
2610
|
+
this.unixPermissions = null;
|
|
2611
|
+
this.dosPermissions = null;
|
|
2612
|
+
var madeBy = this.versionMadeBy >> 8;
|
|
2613
|
+
this.dir = this.externalFileAttributes & 16 ? true : false;
|
|
2614
|
+
if (madeBy === MADE_BY_DOS) {
|
|
2615
|
+
this.dosPermissions = this.externalFileAttributes & 63;
|
|
2616
|
+
}
|
|
2617
|
+
if (madeBy === MADE_BY_UNIX) {
|
|
2618
|
+
this.unixPermissions = this.externalFileAttributes >> 16 & 65535;
|
|
2619
|
+
}
|
|
2620
|
+
if (!this.dir && this.fileNameStr.slice(-1) === "/") {
|
|
2621
|
+
this.dir = true;
|
|
2622
|
+
}
|
|
2623
|
+
},
|
|
2624
|
+
/**
|
|
2625
|
+
* Parse the ZIP64 extra field and merge the info in the current ZipEntry.
|
|
2626
|
+
* @param {DataReader} reader the reader to use.
|
|
2627
|
+
*/
|
|
2628
|
+
parseZIP64ExtraField: function() {
|
|
2629
|
+
if (!this.extraFields[1]) {
|
|
2630
|
+
return;
|
|
2631
|
+
}
|
|
2632
|
+
var extraReader = readerFor2(this.extraFields[1].value);
|
|
2633
|
+
if (this.uncompressedSize === utils2.MAX_VALUE_32BITS) {
|
|
2634
|
+
this.uncompressedSize = extraReader.readInt(8);
|
|
2635
|
+
}
|
|
2636
|
+
if (this.compressedSize === utils2.MAX_VALUE_32BITS) {
|
|
2637
|
+
this.compressedSize = extraReader.readInt(8);
|
|
2638
|
+
}
|
|
2639
|
+
if (this.localHeaderOffset === utils2.MAX_VALUE_32BITS) {
|
|
2640
|
+
this.localHeaderOffset = extraReader.readInt(8);
|
|
2641
|
+
}
|
|
2642
|
+
if (this.diskNumberStart === utils2.MAX_VALUE_32BITS) {
|
|
2643
|
+
this.diskNumberStart = extraReader.readInt(4);
|
|
2644
|
+
}
|
|
2645
|
+
},
|
|
2646
|
+
/**
|
|
2647
|
+
* Read the central part of a zip file and add the info in this object.
|
|
2648
|
+
* @param {DataReader} reader the reader to use.
|
|
2649
|
+
*/
|
|
2650
|
+
readExtraFields: function(reader) {
|
|
2651
|
+
var end = reader.index + this.extraFieldsLength, extraFieldId, extraFieldLength, extraFieldValue;
|
|
2652
|
+
if (!this.extraFields) {
|
|
2653
|
+
this.extraFields = {};
|
|
2654
|
+
}
|
|
2655
|
+
while (reader.index + 4 < end) {
|
|
2656
|
+
extraFieldId = reader.readInt(2);
|
|
2657
|
+
extraFieldLength = reader.readInt(2);
|
|
2658
|
+
extraFieldValue = reader.readData(extraFieldLength);
|
|
2659
|
+
this.extraFields[extraFieldId] = {
|
|
2660
|
+
id: extraFieldId,
|
|
2661
|
+
length: extraFieldLength,
|
|
2662
|
+
value: extraFieldValue
|
|
2663
|
+
};
|
|
2664
|
+
}
|
|
2665
|
+
reader.setIndex(end);
|
|
2666
|
+
},
|
|
2667
|
+
/**
|
|
2668
|
+
* Apply an UTF8 transformation if needed.
|
|
2669
|
+
*/
|
|
2670
|
+
handleUTF8: function() {
|
|
2671
|
+
var decodeParamType = support2.uint8array ? "uint8array" : "array";
|
|
2672
|
+
if (this.useUTF8()) {
|
|
2673
|
+
this.fileNameStr = utf82.utf8decode(this.fileName);
|
|
2674
|
+
this.fileCommentStr = utf82.utf8decode(this.fileComment);
|
|
2675
|
+
} else {
|
|
2676
|
+
var upath = this.findExtraFieldUnicodePath();
|
|
2677
|
+
if (upath !== null) {
|
|
2678
|
+
this.fileNameStr = upath;
|
|
2679
|
+
} else {
|
|
2680
|
+
var fileNameByteArray = utils2.transformTo(decodeParamType, this.fileName);
|
|
2681
|
+
this.fileNameStr = this.loadOptions.decodeFileName(fileNameByteArray);
|
|
2682
|
+
}
|
|
2683
|
+
var ucomment = this.findExtraFieldUnicodeComment();
|
|
2684
|
+
if (ucomment !== null) {
|
|
2685
|
+
this.fileCommentStr = ucomment;
|
|
2686
|
+
} else {
|
|
2687
|
+
var commentByteArray = utils2.transformTo(decodeParamType, this.fileComment);
|
|
2688
|
+
this.fileCommentStr = this.loadOptions.decodeFileName(commentByteArray);
|
|
2689
|
+
}
|
|
2690
|
+
}
|
|
2691
|
+
},
|
|
2692
|
+
/**
|
|
2693
|
+
* Find the unicode path declared in the extra field, if any.
|
|
2694
|
+
* @return {String} the unicode path, null otherwise.
|
|
2695
|
+
*/
|
|
2696
|
+
findExtraFieldUnicodePath: function() {
|
|
2697
|
+
var upathField = this.extraFields[28789];
|
|
2698
|
+
if (upathField) {
|
|
2699
|
+
var extraReader = readerFor2(upathField.value);
|
|
2700
|
+
if (extraReader.readInt(1) !== 1) {
|
|
2701
|
+
return null;
|
|
2702
|
+
}
|
|
2703
|
+
if (crc32fn(this.fileName) !== extraReader.readInt(4)) {
|
|
2704
|
+
return null;
|
|
2705
|
+
}
|
|
2706
|
+
return utf82.utf8decode(extraReader.readData(upathField.length - 5));
|
|
2707
|
+
}
|
|
2708
|
+
return null;
|
|
2709
|
+
},
|
|
2710
|
+
/**
|
|
2711
|
+
* Find the unicode comment declared in the extra field, if any.
|
|
2712
|
+
* @return {String} the unicode comment, null otherwise.
|
|
2713
|
+
*/
|
|
2714
|
+
findExtraFieldUnicodeComment: function() {
|
|
2715
|
+
var ucommentField = this.extraFields[25461];
|
|
2716
|
+
if (ucommentField) {
|
|
2717
|
+
var extraReader = readerFor2(ucommentField.value);
|
|
2718
|
+
if (extraReader.readInt(1) !== 1) {
|
|
2719
|
+
return null;
|
|
2720
|
+
}
|
|
2721
|
+
if (crc32fn(this.fileComment) !== extraReader.readInt(4)) {
|
|
2722
|
+
return null;
|
|
2723
|
+
}
|
|
2724
|
+
return utf82.utf8decode(extraReader.readData(ucommentField.length - 5));
|
|
2725
|
+
}
|
|
2726
|
+
return null;
|
|
2727
|
+
}
|
|
2728
|
+
};
|
|
2729
|
+
zipEntry = ZipEntry;
|
|
2730
|
+
return zipEntry;
|
|
2731
|
+
}
|
|
2732
|
+
var zipEntries;
|
|
2733
|
+
var hasRequiredZipEntries;
|
|
2734
|
+
function requireZipEntries() {
|
|
2735
|
+
if (hasRequiredZipEntries) return zipEntries;
|
|
2736
|
+
hasRequiredZipEntries = 1;
|
|
2737
|
+
var readerFor2 = /* @__PURE__ */ requireReaderFor();
|
|
2738
|
+
var utils2 = /* @__PURE__ */ requireUtils();
|
|
2739
|
+
var sig = /* @__PURE__ */ requireSignature();
|
|
2740
|
+
var ZipEntry = /* @__PURE__ */ requireZipEntry();
|
|
2741
|
+
var support2 = /* @__PURE__ */ requireSupport();
|
|
2742
|
+
function ZipEntries(loadOptions) {
|
|
2743
|
+
this.files = [];
|
|
2744
|
+
this.loadOptions = loadOptions;
|
|
2745
|
+
}
|
|
2746
|
+
ZipEntries.prototype = {
|
|
2747
|
+
/**
|
|
2748
|
+
* Check that the reader is on the specified signature.
|
|
2749
|
+
* @param {string} expectedSignature the expected signature.
|
|
2750
|
+
* @throws {Error} if it is an other signature.
|
|
2751
|
+
*/
|
|
2752
|
+
checkSignature: function(expectedSignature) {
|
|
2753
|
+
if (!this.reader.readAndCheckSignature(expectedSignature)) {
|
|
2754
|
+
this.reader.index -= 4;
|
|
2755
|
+
var signature2 = this.reader.readString(4);
|
|
2756
|
+
throw new Error("Corrupted zip or bug: unexpected signature (" + utils2.pretty(signature2) + ", expected " + utils2.pretty(expectedSignature) + ")");
|
|
2757
|
+
}
|
|
2758
|
+
},
|
|
2759
|
+
/**
|
|
2760
|
+
* Check if the given signature is at the given index.
|
|
2761
|
+
* @param {number} askedIndex the index to check.
|
|
2762
|
+
* @param {string} expectedSignature the signature to expect.
|
|
2763
|
+
* @return {boolean} true if the signature is here, false otherwise.
|
|
2764
|
+
*/
|
|
2765
|
+
isSignature: function(askedIndex, expectedSignature) {
|
|
2766
|
+
var currentIndex = this.reader.index;
|
|
2767
|
+
this.reader.setIndex(askedIndex);
|
|
2768
|
+
var signature2 = this.reader.readString(4);
|
|
2769
|
+
var result = signature2 === expectedSignature;
|
|
2770
|
+
this.reader.setIndex(currentIndex);
|
|
2771
|
+
return result;
|
|
2772
|
+
},
|
|
2773
|
+
/**
|
|
2774
|
+
* Read the end of the central directory.
|
|
2775
|
+
*/
|
|
2776
|
+
readBlockEndOfCentral: function() {
|
|
2777
|
+
this.diskNumber = this.reader.readInt(2);
|
|
2778
|
+
this.diskWithCentralDirStart = this.reader.readInt(2);
|
|
2779
|
+
this.centralDirRecordsOnThisDisk = this.reader.readInt(2);
|
|
2780
|
+
this.centralDirRecords = this.reader.readInt(2);
|
|
2781
|
+
this.centralDirSize = this.reader.readInt(4);
|
|
2782
|
+
this.centralDirOffset = this.reader.readInt(4);
|
|
2783
|
+
this.zipCommentLength = this.reader.readInt(2);
|
|
2784
|
+
var zipComment = this.reader.readData(this.zipCommentLength);
|
|
2785
|
+
var decodeParamType = support2.uint8array ? "uint8array" : "array";
|
|
2786
|
+
var decodeContent = utils2.transformTo(decodeParamType, zipComment);
|
|
2787
|
+
this.zipComment = this.loadOptions.decodeFileName(decodeContent);
|
|
2788
|
+
},
|
|
2789
|
+
/**
|
|
2790
|
+
* Read the end of the Zip 64 central directory.
|
|
2791
|
+
* Not merged with the method readEndOfCentral :
|
|
2792
|
+
* The end of central can coexist with its Zip64 brother,
|
|
2793
|
+
* I don't want to read the wrong number of bytes !
|
|
2794
|
+
*/
|
|
2795
|
+
readBlockZip64EndOfCentral: function() {
|
|
2796
|
+
this.zip64EndOfCentralSize = this.reader.readInt(8);
|
|
2797
|
+
this.reader.skip(4);
|
|
2798
|
+
this.diskNumber = this.reader.readInt(4);
|
|
2799
|
+
this.diskWithCentralDirStart = this.reader.readInt(4);
|
|
2800
|
+
this.centralDirRecordsOnThisDisk = this.reader.readInt(8);
|
|
2801
|
+
this.centralDirRecords = this.reader.readInt(8);
|
|
2802
|
+
this.centralDirSize = this.reader.readInt(8);
|
|
2803
|
+
this.centralDirOffset = this.reader.readInt(8);
|
|
2804
|
+
this.zip64ExtensibleData = {};
|
|
2805
|
+
var extraDataSize = this.zip64EndOfCentralSize - 44, index = 0, extraFieldId, extraFieldLength, extraFieldValue;
|
|
2806
|
+
while (index < extraDataSize) {
|
|
2807
|
+
extraFieldId = this.reader.readInt(2);
|
|
2808
|
+
extraFieldLength = this.reader.readInt(4);
|
|
2809
|
+
extraFieldValue = this.reader.readData(extraFieldLength);
|
|
2810
|
+
this.zip64ExtensibleData[extraFieldId] = {
|
|
2811
|
+
id: extraFieldId,
|
|
2812
|
+
length: extraFieldLength,
|
|
2813
|
+
value: extraFieldValue
|
|
2814
|
+
};
|
|
2815
|
+
}
|
|
2816
|
+
},
|
|
2817
|
+
/**
|
|
2818
|
+
* Read the end of the Zip 64 central directory locator.
|
|
2819
|
+
*/
|
|
2820
|
+
readBlockZip64EndOfCentralLocator: function() {
|
|
2821
|
+
this.diskWithZip64CentralDirStart = this.reader.readInt(4);
|
|
2822
|
+
this.relativeOffsetEndOfZip64CentralDir = this.reader.readInt(8);
|
|
2823
|
+
this.disksCount = this.reader.readInt(4);
|
|
2824
|
+
if (this.disksCount > 1) {
|
|
2825
|
+
throw new Error("Multi-volumes zip are not supported");
|
|
2826
|
+
}
|
|
2827
|
+
},
|
|
2828
|
+
/**
|
|
2829
|
+
* Read the local files, based on the offset read in the central part.
|
|
2830
|
+
*/
|
|
2831
|
+
readLocalFiles: function() {
|
|
2832
|
+
var i, file;
|
|
2833
|
+
for (i = 0; i < this.files.length; i++) {
|
|
2834
|
+
file = this.files[i];
|
|
2835
|
+
this.reader.setIndex(file.localHeaderOffset);
|
|
2836
|
+
this.checkSignature(sig.LOCAL_FILE_HEADER);
|
|
2837
|
+
file.readLocalPart(this.reader);
|
|
2838
|
+
file.handleUTF8();
|
|
2839
|
+
file.processAttributes();
|
|
2840
|
+
}
|
|
2841
|
+
},
|
|
2842
|
+
/**
|
|
2843
|
+
* Read the central directory.
|
|
2844
|
+
*/
|
|
2845
|
+
readCentralDir: function() {
|
|
2846
|
+
var file;
|
|
2847
|
+
this.reader.setIndex(this.centralDirOffset);
|
|
2848
|
+
while (this.reader.readAndCheckSignature(sig.CENTRAL_FILE_HEADER)) {
|
|
2849
|
+
file = new ZipEntry({
|
|
2850
|
+
zip64: this.zip64
|
|
2851
|
+
}, this.loadOptions);
|
|
2852
|
+
file.readCentralPart(this.reader);
|
|
2853
|
+
this.files.push(file);
|
|
2854
|
+
}
|
|
2855
|
+
if (this.centralDirRecords !== this.files.length) {
|
|
2856
|
+
if (this.centralDirRecords !== 0 && this.files.length === 0) {
|
|
2857
|
+
throw new Error("Corrupted zip or bug: expected " + this.centralDirRecords + " records in central dir, got " + this.files.length);
|
|
2858
|
+
}
|
|
2859
|
+
}
|
|
2860
|
+
},
|
|
2861
|
+
/**
|
|
2862
|
+
* Read the end of central directory.
|
|
2863
|
+
*/
|
|
2864
|
+
readEndOfCentral: function() {
|
|
2865
|
+
var offset = this.reader.lastIndexOfSignature(sig.CENTRAL_DIRECTORY_END);
|
|
2866
|
+
if (offset < 0) {
|
|
2867
|
+
var isGarbage = !this.isSignature(0, sig.LOCAL_FILE_HEADER);
|
|
2868
|
+
if (isGarbage) {
|
|
2869
|
+
throw new Error("Can't find end of central directory : is this a zip file ? If it is, see https://stuk.github.io/jszip/documentation/howto/read_zip.html");
|
|
2870
|
+
} else {
|
|
2871
|
+
throw new Error("Corrupted zip: can't find end of central directory");
|
|
2872
|
+
}
|
|
2873
|
+
}
|
|
2874
|
+
this.reader.setIndex(offset);
|
|
2875
|
+
var endOfCentralDirOffset = offset;
|
|
2876
|
+
this.checkSignature(sig.CENTRAL_DIRECTORY_END);
|
|
2877
|
+
this.readBlockEndOfCentral();
|
|
2878
|
+
if (this.diskNumber === utils2.MAX_VALUE_16BITS || this.diskWithCentralDirStart === utils2.MAX_VALUE_16BITS || this.centralDirRecordsOnThisDisk === utils2.MAX_VALUE_16BITS || this.centralDirRecords === utils2.MAX_VALUE_16BITS || this.centralDirSize === utils2.MAX_VALUE_32BITS || this.centralDirOffset === utils2.MAX_VALUE_32BITS) {
|
|
2879
|
+
this.zip64 = true;
|
|
2880
|
+
offset = this.reader.lastIndexOfSignature(sig.ZIP64_CENTRAL_DIRECTORY_LOCATOR);
|
|
2881
|
+
if (offset < 0) {
|
|
2882
|
+
throw new Error("Corrupted zip: can't find the ZIP64 end of central directory locator");
|
|
2883
|
+
}
|
|
2884
|
+
this.reader.setIndex(offset);
|
|
2885
|
+
this.checkSignature(sig.ZIP64_CENTRAL_DIRECTORY_LOCATOR);
|
|
2886
|
+
this.readBlockZip64EndOfCentralLocator();
|
|
2887
|
+
if (!this.isSignature(this.relativeOffsetEndOfZip64CentralDir, sig.ZIP64_CENTRAL_DIRECTORY_END)) {
|
|
2888
|
+
this.relativeOffsetEndOfZip64CentralDir = this.reader.lastIndexOfSignature(sig.ZIP64_CENTRAL_DIRECTORY_END);
|
|
2889
|
+
if (this.relativeOffsetEndOfZip64CentralDir < 0) {
|
|
2890
|
+
throw new Error("Corrupted zip: can't find the ZIP64 end of central directory");
|
|
2891
|
+
}
|
|
2892
|
+
}
|
|
2893
|
+
this.reader.setIndex(this.relativeOffsetEndOfZip64CentralDir);
|
|
2894
|
+
this.checkSignature(sig.ZIP64_CENTRAL_DIRECTORY_END);
|
|
2895
|
+
this.readBlockZip64EndOfCentral();
|
|
2896
|
+
}
|
|
2897
|
+
var expectedEndOfCentralDirOffset = this.centralDirOffset + this.centralDirSize;
|
|
2898
|
+
if (this.zip64) {
|
|
2899
|
+
expectedEndOfCentralDirOffset += 20;
|
|
2900
|
+
expectedEndOfCentralDirOffset += 12 + this.zip64EndOfCentralSize;
|
|
2901
|
+
}
|
|
2902
|
+
var extraBytes = endOfCentralDirOffset - expectedEndOfCentralDirOffset;
|
|
2903
|
+
if (extraBytes > 0) {
|
|
2904
|
+
if (this.isSignature(endOfCentralDirOffset, sig.CENTRAL_FILE_HEADER)) ;
|
|
2905
|
+
else {
|
|
2906
|
+
this.reader.zero = extraBytes;
|
|
2907
|
+
}
|
|
2908
|
+
} else if (extraBytes < 0) {
|
|
2909
|
+
throw new Error("Corrupted zip: missing " + Math.abs(extraBytes) + " bytes.");
|
|
2910
|
+
}
|
|
2911
|
+
},
|
|
2912
|
+
prepareReader: function(data) {
|
|
2913
|
+
this.reader = readerFor2(data);
|
|
2914
|
+
},
|
|
2915
|
+
/**
|
|
2916
|
+
* Read a zip file and create ZipEntries.
|
|
2917
|
+
* @param {String|ArrayBuffer|Uint8Array|Buffer} data the binary string representing a zip file.
|
|
2918
|
+
*/
|
|
2919
|
+
load: function(data) {
|
|
2920
|
+
this.prepareReader(data);
|
|
2921
|
+
this.readEndOfCentral();
|
|
2922
|
+
this.readCentralDir();
|
|
2923
|
+
this.readLocalFiles();
|
|
2924
|
+
}
|
|
2925
|
+
};
|
|
2926
|
+
zipEntries = ZipEntries;
|
|
2927
|
+
return zipEntries;
|
|
2928
|
+
}
|
|
2929
|
+
var load;
|
|
2930
|
+
var hasRequiredLoad;
|
|
2931
|
+
function requireLoad() {
|
|
2932
|
+
if (hasRequiredLoad) return load;
|
|
2933
|
+
hasRequiredLoad = 1;
|
|
2934
|
+
var utils2 = /* @__PURE__ */ requireUtils();
|
|
2935
|
+
var external2 = /* @__PURE__ */ requireExternal();
|
|
2936
|
+
var utf82 = /* @__PURE__ */ requireUtf8();
|
|
2937
|
+
var ZipEntries = /* @__PURE__ */ requireZipEntries();
|
|
2938
|
+
var Crc32Probe = /* @__PURE__ */ requireCrc32Probe();
|
|
2939
|
+
var nodejsUtils2 = /* @__PURE__ */ requireNodejsUtils();
|
|
2940
|
+
function checkEntryCRC32(zipEntry2) {
|
|
2941
|
+
return new external2.Promise(function(resolve, reject) {
|
|
2942
|
+
var worker = zipEntry2.decompressed.getContentWorker().pipe(new Crc32Probe());
|
|
2943
|
+
worker.on("error", function(e) {
|
|
2944
|
+
reject(e);
|
|
2945
|
+
}).on("end", function() {
|
|
2946
|
+
if (worker.streamInfo.crc32 !== zipEntry2.decompressed.crc32) {
|
|
2947
|
+
reject(new Error("Corrupted zip : CRC32 mismatch"));
|
|
2948
|
+
} else {
|
|
2949
|
+
resolve();
|
|
2950
|
+
}
|
|
2951
|
+
}).resume();
|
|
2952
|
+
});
|
|
2953
|
+
}
|
|
2954
|
+
load = function(data, options) {
|
|
2955
|
+
var zip = this;
|
|
2956
|
+
options = utils2.extend(options || {}, {
|
|
2957
|
+
base64: false,
|
|
2958
|
+
checkCRC32: false,
|
|
2959
|
+
optimizedBinaryString: false,
|
|
2960
|
+
createFolders: false,
|
|
2961
|
+
decodeFileName: utf82.utf8decode
|
|
2962
|
+
});
|
|
2963
|
+
if (nodejsUtils2.isNode && nodejsUtils2.isStream(data)) {
|
|
2964
|
+
return external2.Promise.reject(new Error("JSZip can't accept a stream when loading a zip file."));
|
|
2965
|
+
}
|
|
2966
|
+
return utils2.prepareContent("the loaded zip file", data, true, options.optimizedBinaryString, options.base64).then(function(data2) {
|
|
2967
|
+
var zipEntries2 = new ZipEntries(options);
|
|
2968
|
+
zipEntries2.load(data2);
|
|
2969
|
+
return zipEntries2;
|
|
2970
|
+
}).then(function checkCRC32(zipEntries2) {
|
|
2971
|
+
var promises = [external2.Promise.resolve(zipEntries2)];
|
|
2972
|
+
var files = zipEntries2.files;
|
|
2973
|
+
if (options.checkCRC32) {
|
|
2974
|
+
for (var i = 0; i < files.length; i++) {
|
|
2975
|
+
promises.push(checkEntryCRC32(files[i]));
|
|
2976
|
+
}
|
|
2977
|
+
}
|
|
2978
|
+
return external2.Promise.all(promises);
|
|
2979
|
+
}).then(function addFiles(results) {
|
|
2980
|
+
var zipEntries2 = results.shift();
|
|
2981
|
+
var files = zipEntries2.files;
|
|
2982
|
+
for (var i = 0; i < files.length; i++) {
|
|
2983
|
+
var input = files[i];
|
|
2984
|
+
var unsafeName = input.fileNameStr;
|
|
2985
|
+
var safeName = utils2.resolve(input.fileNameStr);
|
|
2986
|
+
zip.file(safeName, input.decompressed, {
|
|
2987
|
+
binary: true,
|
|
2988
|
+
optimizedBinaryString: true,
|
|
2989
|
+
date: input.date,
|
|
2990
|
+
dir: input.dir,
|
|
2991
|
+
comment: input.fileCommentStr.length ? input.fileCommentStr : null,
|
|
2992
|
+
unixPermissions: input.unixPermissions,
|
|
2993
|
+
dosPermissions: input.dosPermissions,
|
|
2994
|
+
createFolders: options.createFolders
|
|
2995
|
+
});
|
|
2996
|
+
if (!input.dir) {
|
|
2997
|
+
zip.file(safeName).unsafeOriginalName = unsafeName;
|
|
2998
|
+
}
|
|
2999
|
+
}
|
|
3000
|
+
if (zipEntries2.zipComment.length) {
|
|
3001
|
+
zip.comment = zipEntries2.zipComment;
|
|
3002
|
+
}
|
|
3003
|
+
return zip;
|
|
3004
|
+
});
|
|
3005
|
+
};
|
|
3006
|
+
return load;
|
|
3007
|
+
}
|
|
3008
|
+
var lib;
|
|
3009
|
+
var hasRequiredLib;
|
|
3010
|
+
function requireLib() {
|
|
3011
|
+
if (hasRequiredLib) return lib;
|
|
3012
|
+
hasRequiredLib = 1;
|
|
3013
|
+
function JSZip2() {
|
|
3014
|
+
if (!(this instanceof JSZip2)) {
|
|
3015
|
+
return new JSZip2();
|
|
3016
|
+
}
|
|
3017
|
+
if (arguments.length) {
|
|
3018
|
+
throw new Error("The constructor with parameters has been removed in JSZip 3.0, please check the upgrade guide.");
|
|
3019
|
+
}
|
|
3020
|
+
this.files = /* @__PURE__ */ Object.create(null);
|
|
3021
|
+
this.comment = null;
|
|
3022
|
+
this.root = "";
|
|
3023
|
+
this.clone = function() {
|
|
3024
|
+
var newObj = new JSZip2();
|
|
3025
|
+
for (var i in this) {
|
|
3026
|
+
if (typeof this[i] !== "function") {
|
|
3027
|
+
newObj[i] = this[i];
|
|
3028
|
+
}
|
|
3029
|
+
}
|
|
3030
|
+
return newObj;
|
|
3031
|
+
};
|
|
3032
|
+
}
|
|
3033
|
+
JSZip2.prototype = /* @__PURE__ */ requireObject();
|
|
3034
|
+
JSZip2.prototype.loadAsync = /* @__PURE__ */ requireLoad();
|
|
3035
|
+
JSZip2.support = /* @__PURE__ */ requireSupport();
|
|
3036
|
+
JSZip2.defaults = /* @__PURE__ */ requireDefaults();
|
|
3037
|
+
JSZip2.version = "3.10.1";
|
|
3038
|
+
JSZip2.loadAsync = function(content, options) {
|
|
3039
|
+
return new JSZip2().loadAsync(content, options);
|
|
3040
|
+
};
|
|
3041
|
+
JSZip2.external = /* @__PURE__ */ requireExternal();
|
|
3042
|
+
lib = JSZip2;
|
|
3043
|
+
return lib;
|
|
3044
|
+
}
|
|
3045
|
+
var libExports = /* @__PURE__ */ requireLib();
|
|
3046
|
+
const JSZip = /* @__PURE__ */ getDefaultExportFromCjs(libExports);
|
|
3047
|
+
export {
|
|
3048
|
+
JSZip as J
|
|
3049
|
+
};
|