@mininglamp-oss/octo-runtime 1.1.6 → 1.1.7
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/apps/cli/dist/build-info.json +2 -2
- package/dist/public/dsh.d.ts +1 -1
- package/dist/public/dsh.js +1 -1
- package/node_modules/@mininglamp-oss/octo-runtime-acp-client/package.json +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-acp/dist/index.d.ts +9 -1
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-acp/dist/index.js +17 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-acp/package.json +4 -4
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-antigravity/dist/index.d.ts +20 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-antigravity/package.json +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-claude-code/dist/index.d.ts +32 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-claude-code/dist/index.js +3 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-claude-code/package.json +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-codebuddy/dist/index.d.ts +16 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-codebuddy/package.json +4 -4
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/app-server.js +5 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/index.d.ts +32 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/package.json +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/{chunk-IW62UM3C.js → chunk-CFKMMCO6.js} +5 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/{chunk-FWAPYRV2.js → chunk-LO34KB7D.js} +1 -1
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/{chunk-3GXX5VD5.js → chunk-V5W6ZTYC.js} +14 -6
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/errors.d.ts +4 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/errors.js +3 -1
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/index.d.ts +17 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/index.js +8 -6
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/launch.d.ts +1 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/launch.js +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/trajectory.js +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/package.json +4 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-grok-build/dist/adapter.d.ts +9 -1
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-grok-build/dist/index.d.ts +10 -6
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-grok-build/package.json +5 -5
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-hermes/dist/index.d.ts +9 -1
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-hermes/package.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-kimi-code/dist/index.d.ts +9 -1
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-kimi-code/package.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-mcode/dist/index.d.ts +9 -1
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-mcode/package.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-openclaw/dist/compatibility.d.ts +2 -1
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-openclaw/dist/compatibility.js +12 -40
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-openclaw/dist/index.d.ts +22 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-openclaw/dist/index.js +422 -135
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-openclaw/package.json +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-opencode/dist/index.d.ts +6 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-opencode/dist/index.js +2 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-opencode/package.json +4 -4
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-qodercli/dist/index.d.ts +9 -1
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-qodercli/package.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-qoderclicn/dist/index.d.ts +9 -1
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-qoderclicn/package.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/index.d.ts +18 -4
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/index.js +7 -4
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/package.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-zcode-gui/dist/index.d.ts +20 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-zcode-gui/package.json +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/build-info.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-cli/package.json +24 -24
- package/node_modules/@mininglamp-oss/octo-runtime-cross-service/dist/runner.d.ts +2 -1
- package/node_modules/@mininglamp-oss/octo-runtime-cross-service/dist/runner.js +102 -52
- package/node_modules/@mininglamp-oss/octo-runtime-cross-service/dist/windows-task.js +8 -3
- package/node_modules/@mininglamp-oss/octo-runtime-cross-service/package.json +5 -3
- package/node_modules/@mininglamp-oss/octo-runtime-executor-core/dist/index.d.ts +4 -3
- package/node_modules/@mininglamp-oss/octo-runtime-executor-core/dist/index.js +1 -1
- package/node_modules/@mininglamp-oss/octo-runtime-executor-core/dist/invoke-input.js +2 -0
- package/node_modules/@mininglamp-oss/octo-runtime-executor-core/dist/model-input.d.ts +1 -1
- package/node_modules/@mininglamp-oss/octo-runtime-executor-core/dist/model-input.js +9 -6
- package/node_modules/@mininglamp-oss/octo-runtime-executor-core/package.json +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/package.json +4 -4
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/config-schema.json +8 -1
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/application/context-gap.d.ts +17 -1
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/application/context-gap.js +22 -6
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/application/history-context.d.ts +3 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/application/history-context.js +27 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/application/im-channel.js +444 -226
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/application/rules-context.d.ts +5 -2
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/application/rules-context.js +42 -4
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/application/session-store.d.ts +5 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/application/stable-context.d.ts +15 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/application/stable-context.js +28 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/contracts.d.ts +16 -5
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/delivery/artifact-policy.d.ts +4 -5
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/delivery/artifact-policy.js +12 -9
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/delivery/artifacts.d.ts +1 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/delivery/artifacts.js +7 -5
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/delivery/identity.d.ts +15 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/delivery/identity.js +36 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/delivery/scheduler.d.ts +2 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/delivery/scheduler.js +10 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/execution/dispatcher.d.ts +5 -2
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/execution/dispatcher.js +36 -22
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/extra.js +14 -1
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/lifecycle/configuration.js +4 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/presentation/run-projector.d.ts +5 -1
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/presentation/run-projector.js +265 -38
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/cards.d.ts +4 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/cards.js +5 -5
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/client.d.ts +7 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/client.js +19 -2
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/conversations.d.ts +3 -1
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/conversations.js +4 -3
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/errors.d.ts +0 -12
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/errors.js +5 -3
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/files.d.ts +2 -1
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/files.js +8 -6
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/messages.d.ts +3 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/messages.js +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/card-session.d.ts +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/card-session.js +27 -15
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/channel.d.ts +17 -1
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/channel.js +217 -50
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/connection-error.js +2 -4
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/connector.d.ts +3 -2
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/connector.js +41 -12
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/contexts.d.ts +2 -6
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/contexts.js +53 -82
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/history-content.d.ts +12 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/history-content.js +133 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/history-messages.d.ts +21 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/history-messages.js +76 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/mentions.d.ts +0 -2
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/mentions.js +0 -2
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/message-identities.d.ts +16 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/message-identities.js +74 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/message-time.d.ts +4 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/message-time.js +19 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/message-trigger.d.ts +7 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/message-trigger.js +90 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/reasoning-frame.js +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/retry-after.d.ts +6 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/retry-after.js +60 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/wukong.d.ts +2 -1
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/wukong.js +20 -8
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/package.json +6 -6
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-wecom/dist/application/im-channel.js +10 -2
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-wecom/dist/extra.js +14 -1
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-wecom/dist/transport/channel.js +2 -3
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-wecom/package.json +5 -5
- package/node_modules/@mininglamp-oss/octo-runtime-extra-webui/package.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/context-loader.d.ts +3 -2
- package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/context-loader.js +11 -4
- package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/package.json +4 -4
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/context.js +8 -1
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/generated/protocol-types.d.ts +9 -0
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/index.js +3 -0
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/invoke-input.d.ts +6 -0
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/invoke-input.js +14 -0
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/package.json +1 -1
- package/node_modules/iconv-lite/LICENSE +21 -0
- package/node_modules/iconv-lite/README.md +138 -0
- package/node_modules/iconv-lite/encodings/dbcs-codec.js +532 -0
- package/node_modules/iconv-lite/encodings/dbcs-data.js +185 -0
- package/node_modules/iconv-lite/encodings/index.js +23 -0
- package/node_modules/iconv-lite/encodings/internal.js +218 -0
- package/node_modules/iconv-lite/encodings/sbcs-codec.js +75 -0
- package/node_modules/iconv-lite/encodings/sbcs-data-generated.js +451 -0
- package/node_modules/iconv-lite/encodings/sbcs-data.js +180 -0
- package/node_modules/iconv-lite/encodings/tables/big5-added.json +122 -0
- package/node_modules/iconv-lite/encodings/tables/cp936.json +264 -0
- package/node_modules/iconv-lite/encodings/tables/cp949.json +273 -0
- package/node_modules/iconv-lite/encodings/tables/cp950.json +177 -0
- package/node_modules/iconv-lite/encodings/tables/eucjp.json +182 -0
- package/node_modules/iconv-lite/encodings/tables/gb18030-ranges.json +1 -0
- package/node_modules/iconv-lite/encodings/tables/gbk-added.json +56 -0
- package/node_modules/iconv-lite/encodings/tables/shiftjis.json +125 -0
- package/node_modules/iconv-lite/encodings/utf16.js +187 -0
- package/node_modules/iconv-lite/encodings/utf32.js +314 -0
- package/node_modules/iconv-lite/encodings/utf7.js +283 -0
- package/node_modules/iconv-lite/lib/bom-handling.js +48 -0
- package/node_modules/iconv-lite/lib/helpers/merge-exports.js +13 -0
- package/node_modules/iconv-lite/lib/index.d.ts +129 -0
- package/node_modules/iconv-lite/lib/index.js +182 -0
- package/node_modules/iconv-lite/lib/streams.js +105 -0
- package/node_modules/iconv-lite/package.json +70 -0
- package/node_modules/iconv-lite/types/encodings.d.ts +425 -0
- package/node_modules/safer-buffer/LICENSE +21 -0
- package/node_modules/safer-buffer/Porting-Buffer.md +268 -0
- package/node_modules/safer-buffer/Readme.md +156 -0
- package/node_modules/safer-buffer/dangerous.js +58 -0
- package/node_modules/safer-buffer/package.json +34 -0
- package/node_modules/safer-buffer/safer.js +77 -0
- package/node_modules/safer-buffer/tests.js +406 -0
- package/node_modules/semver/LICENSE +15 -0
- package/node_modules/semver/README.md +680 -0
- package/node_modules/semver/bin/semver.js +195 -0
- package/node_modules/semver/classes/comparator.js +143 -0
- package/node_modules/semver/classes/index.js +7 -0
- package/node_modules/semver/classes/range.js +577 -0
- package/node_modules/semver/classes/semver.js +350 -0
- package/node_modules/semver/functions/clean.js +8 -0
- package/node_modules/semver/functions/cmp.js +54 -0
- package/node_modules/semver/functions/coerce.js +62 -0
- package/node_modules/semver/functions/compare-build.js +9 -0
- package/node_modules/semver/functions/compare-loose.js +5 -0
- package/node_modules/semver/functions/compare.js +7 -0
- package/node_modules/semver/functions/diff.js +60 -0
- package/node_modules/semver/functions/eq.js +5 -0
- package/node_modules/semver/functions/gt.js +5 -0
- package/node_modules/semver/functions/gte.js +5 -0
- package/node_modules/semver/functions/inc.js +21 -0
- package/node_modules/semver/functions/lt.js +5 -0
- package/node_modules/semver/functions/lte.js +5 -0
- package/node_modules/semver/functions/major.js +5 -0
- package/node_modules/semver/functions/minor.js +5 -0
- package/node_modules/semver/functions/neq.js +5 -0
- package/node_modules/semver/functions/parse.js +18 -0
- package/node_modules/semver/functions/patch.js +5 -0
- package/node_modules/semver/functions/prerelease.js +8 -0
- package/node_modules/semver/functions/rcompare.js +5 -0
- package/node_modules/semver/functions/rsort.js +5 -0
- package/node_modules/semver/functions/satisfies.js +12 -0
- package/node_modules/semver/functions/sort.js +5 -0
- package/node_modules/semver/functions/truncate.js +48 -0
- package/node_modules/semver/functions/valid.js +8 -0
- package/node_modules/semver/index.js +93 -0
- package/node_modules/semver/internal/constants.js +37 -0
- package/node_modules/semver/internal/debug.js +11 -0
- package/node_modules/semver/internal/identifiers.js +29 -0
- package/node_modules/semver/internal/lrucache.js +42 -0
- package/node_modules/semver/internal/parse-options.js +17 -0
- package/node_modules/semver/internal/re.js +223 -0
- package/node_modules/semver/package.json +78 -0
- package/node_modules/semver/preload.js +4 -0
- package/node_modules/semver/range.bnf +17 -0
- package/node_modules/semver/ranges/gtr.js +6 -0
- package/node_modules/semver/ranges/intersects.js +9 -0
- package/node_modules/semver/ranges/ltr.js +6 -0
- package/node_modules/semver/ranges/max-satisfying.js +27 -0
- package/node_modules/semver/ranges/min-satisfying.js +26 -0
- package/node_modules/semver/ranges/min-version.js +63 -0
- package/node_modules/semver/ranges/outside.js +82 -0
- package/node_modules/semver/ranges/simplify.js +49 -0
- package/node_modules/semver/ranges/subset.js +249 -0
- package/node_modules/semver/ranges/to-comparators.js +10 -0
- package/node_modules/semver/ranges/valid.js +13 -0
- package/package.json +33 -27
- package/packages/octo-runtime-extra-channel-gateway/config-schema.json +8 -1
- package/packages/octo-runtime-protocol/schema/protocol.schema.json +43 -1
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
"use strict"
|
|
2
|
+
var Buffer = require("safer-buffer").Buffer
|
|
3
|
+
|
|
4
|
+
// Note: UTF16-LE (or UCS2) codec is Node.js native. See encodings/internal.js
|
|
5
|
+
|
|
6
|
+
// == UTF16-BE codec. ==========================================================
|
|
7
|
+
|
|
8
|
+
exports.utf16be = Utf16BECodec
|
|
9
|
+
function Utf16BECodec () {
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
Utf16BECodec.prototype.encoder = Utf16BEEncoder
|
|
13
|
+
Utf16BECodec.prototype.decoder = Utf16BEDecoder
|
|
14
|
+
Utf16BECodec.prototype.bomAware = true
|
|
15
|
+
|
|
16
|
+
// -- Encoding
|
|
17
|
+
|
|
18
|
+
function Utf16BEEncoder () {
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
Utf16BEEncoder.prototype.write = function (str) {
|
|
22
|
+
var buf = Buffer.from(str, "ucs2")
|
|
23
|
+
for (var i = 0; i < buf.length; i += 2) {
|
|
24
|
+
var tmp = buf[i]; buf[i] = buf[i + 1]; buf[i + 1] = tmp
|
|
25
|
+
}
|
|
26
|
+
return buf
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
Utf16BEEncoder.prototype.end = function () {
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// -- Decoding
|
|
33
|
+
|
|
34
|
+
function Utf16BEDecoder () {
|
|
35
|
+
this.overflowByte = -1
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
Utf16BEDecoder.prototype.write = function (buf) {
|
|
39
|
+
if (buf.length == 0) { return "" }
|
|
40
|
+
|
|
41
|
+
var buf2 = Buffer.alloc(buf.length + 1)
|
|
42
|
+
var i = 0; var j = 0
|
|
43
|
+
|
|
44
|
+
if (this.overflowByte !== -1) {
|
|
45
|
+
buf2[0] = buf[0]
|
|
46
|
+
buf2[1] = this.overflowByte
|
|
47
|
+
i = 1; j = 2
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
for (; i < buf.length - 1; i += 2, j += 2) {
|
|
51
|
+
buf2[j] = buf[i + 1]
|
|
52
|
+
buf2[j + 1] = buf[i]
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
this.overflowByte = (i == buf.length - 1) ? buf[buf.length - 1] : -1
|
|
56
|
+
|
|
57
|
+
return buf2.slice(0, j).toString("ucs2")
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
Utf16BEDecoder.prototype.end = function () {
|
|
61
|
+
this.overflowByte = -1
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// == UTF-16 codec =============================================================
|
|
65
|
+
// Decoder chooses automatically from UTF-16LE and UTF-16BE using BOM and space-based heuristic.
|
|
66
|
+
// Defaults to UTF-16LE, as it's prevalent and default in Node.
|
|
67
|
+
// http://en.wikipedia.org/wiki/UTF-16 and http://encoding.spec.whatwg.org/#utf-16le
|
|
68
|
+
// Decoder default can be changed: iconv.decode(buf, 'utf16', {defaultEncoding: 'utf-16be'});
|
|
69
|
+
|
|
70
|
+
// Encoder uses UTF-16LE and prepends BOM (which can be overridden with addBOM: false).
|
|
71
|
+
|
|
72
|
+
exports.utf16 = Utf16Codec
|
|
73
|
+
function Utf16Codec (codecOptions, iconv) {
|
|
74
|
+
this.iconv = iconv
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
Utf16Codec.prototype.encoder = Utf16Encoder
|
|
78
|
+
Utf16Codec.prototype.decoder = Utf16Decoder
|
|
79
|
+
|
|
80
|
+
// -- Encoding (pass-through)
|
|
81
|
+
|
|
82
|
+
function Utf16Encoder (options, codec) {
|
|
83
|
+
options = options || {}
|
|
84
|
+
if (options.addBOM === undefined) { options.addBOM = true }
|
|
85
|
+
this.encoder = codec.iconv.getEncoder("utf-16le", options)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
Utf16Encoder.prototype.write = function (str) {
|
|
89
|
+
return this.encoder.write(str)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
Utf16Encoder.prototype.end = function () {
|
|
93
|
+
return this.encoder.end()
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// -- Decoding
|
|
97
|
+
|
|
98
|
+
function Utf16Decoder (options, codec) {
|
|
99
|
+
this.decoder = null
|
|
100
|
+
this.initialBufs = []
|
|
101
|
+
this.initialBufsLen = 0
|
|
102
|
+
|
|
103
|
+
this.options = options || {}
|
|
104
|
+
this.iconv = codec.iconv
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
Utf16Decoder.prototype.write = function (buf) {
|
|
108
|
+
if (!this.decoder) {
|
|
109
|
+
// Codec is not chosen yet. Accumulate initial bytes.
|
|
110
|
+
this.initialBufs.push(buf)
|
|
111
|
+
this.initialBufsLen += buf.length
|
|
112
|
+
|
|
113
|
+
if (this.initialBufsLen < 16) // We need more bytes to use space heuristic (see below)
|
|
114
|
+
{ return "" }
|
|
115
|
+
|
|
116
|
+
// We have enough bytes -> detect endianness.
|
|
117
|
+
var encoding = detectEncoding(this.initialBufs, this.options.defaultEncoding)
|
|
118
|
+
this.decoder = this.iconv.getDecoder(encoding, this.options)
|
|
119
|
+
|
|
120
|
+
var resStr = ""
|
|
121
|
+
for (var i = 0; i < this.initialBufs.length; i++) { resStr += this.decoder.write(this.initialBufs[i]) }
|
|
122
|
+
|
|
123
|
+
this.initialBufs.length = this.initialBufsLen = 0
|
|
124
|
+
return resStr
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return this.decoder.write(buf)
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
Utf16Decoder.prototype.end = function () {
|
|
131
|
+
if (!this.decoder) {
|
|
132
|
+
var encoding = detectEncoding(this.initialBufs, this.options.defaultEncoding)
|
|
133
|
+
this.decoder = this.iconv.getDecoder(encoding, this.options)
|
|
134
|
+
|
|
135
|
+
var resStr = ""
|
|
136
|
+
for (var i = 0; i < this.initialBufs.length; i++) { resStr += this.decoder.write(this.initialBufs[i]) }
|
|
137
|
+
|
|
138
|
+
var trail = this.decoder.end()
|
|
139
|
+
if (trail) { resStr += trail }
|
|
140
|
+
|
|
141
|
+
this.initialBufs.length = this.initialBufsLen = 0
|
|
142
|
+
return resStr
|
|
143
|
+
}
|
|
144
|
+
return this.decoder.end()
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function detectEncoding (bufs, defaultEncoding) {
|
|
148
|
+
var b = []
|
|
149
|
+
var charsProcessed = 0
|
|
150
|
+
// Number of ASCII chars when decoded as LE or BE.
|
|
151
|
+
var asciiCharsLE = 0
|
|
152
|
+
var asciiCharsBE = 0
|
|
153
|
+
|
|
154
|
+
outerLoop:
|
|
155
|
+
for (var i = 0; i < bufs.length; i++) {
|
|
156
|
+
var buf = bufs[i]
|
|
157
|
+
for (var j = 0; j < buf.length; j++) {
|
|
158
|
+
b.push(buf[j])
|
|
159
|
+
if (b.length === 2) {
|
|
160
|
+
if (charsProcessed === 0) {
|
|
161
|
+
// Check BOM first.
|
|
162
|
+
if (b[0] === 0xFF && b[1] === 0xFE) return "utf-16le"
|
|
163
|
+
if (b[0] === 0xFE && b[1] === 0xFF) return "utf-16be"
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
if (b[0] === 0 && b[1] !== 0) asciiCharsBE++
|
|
167
|
+
if (b[0] !== 0 && b[1] === 0) asciiCharsLE++
|
|
168
|
+
|
|
169
|
+
b.length = 0
|
|
170
|
+
charsProcessed++
|
|
171
|
+
|
|
172
|
+
if (charsProcessed >= 100) {
|
|
173
|
+
break outerLoop
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// Make decisions.
|
|
180
|
+
// Most of the time, the content has ASCII chars (U+00**), but the opposite (U+**00) is uncommon.
|
|
181
|
+
// So, we count ASCII as if it was LE or BE, and decide from that.
|
|
182
|
+
if (asciiCharsBE > asciiCharsLE) return "utf-16be"
|
|
183
|
+
if (asciiCharsBE < asciiCharsLE) return "utf-16le"
|
|
184
|
+
|
|
185
|
+
// Couldn't decide (likely all zeros or not enough data).
|
|
186
|
+
return defaultEncoding || "utf-16le"
|
|
187
|
+
}
|
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
"use strict"
|
|
2
|
+
|
|
3
|
+
var Buffer = require("safer-buffer").Buffer
|
|
4
|
+
|
|
5
|
+
// == UTF32-LE/BE codec. ==========================================================
|
|
6
|
+
|
|
7
|
+
exports._utf32 = Utf32Codec
|
|
8
|
+
|
|
9
|
+
function Utf32Codec (codecOptions, iconv) {
|
|
10
|
+
this.iconv = iconv
|
|
11
|
+
this.bomAware = true
|
|
12
|
+
this.isLE = codecOptions.isLE
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
exports.utf32le = { type: "_utf32", isLE: true }
|
|
16
|
+
exports.utf32be = { type: "_utf32", isLE: false }
|
|
17
|
+
|
|
18
|
+
// Aliases
|
|
19
|
+
exports.ucs4le = "utf32le"
|
|
20
|
+
exports.ucs4be = "utf32be"
|
|
21
|
+
|
|
22
|
+
Utf32Codec.prototype.encoder = Utf32Encoder
|
|
23
|
+
Utf32Codec.prototype.decoder = Utf32Decoder
|
|
24
|
+
|
|
25
|
+
// -- Encoding
|
|
26
|
+
|
|
27
|
+
function Utf32Encoder (options, codec) {
|
|
28
|
+
this.isLE = codec.isLE
|
|
29
|
+
this.highSurrogate = 0
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
Utf32Encoder.prototype.write = function (str) {
|
|
33
|
+
var src = Buffer.from(str, "ucs2")
|
|
34
|
+
// src.length * 2 covers this chunk's code units (4 bytes each); the extra 4 bytes leave room for a
|
|
35
|
+
// high surrogate held over from a previous chunk, which is flushed ahead of this chunk's units.
|
|
36
|
+
var dst = Buffer.alloc(src.length * 2 + 4)
|
|
37
|
+
var write32 = this.isLE ? dst.writeUInt32LE : dst.writeUInt32BE
|
|
38
|
+
var offset = 0
|
|
39
|
+
|
|
40
|
+
for (var i = 0; i < src.length; i += 2) {
|
|
41
|
+
var code = src.readUInt16LE(i)
|
|
42
|
+
var isHighSurrogate = (code >= 0xD800 && code < 0xDC00)
|
|
43
|
+
var isLowSurrogate = (code >= 0xDC00 && code < 0xE000)
|
|
44
|
+
|
|
45
|
+
if (this.highSurrogate) {
|
|
46
|
+
if (isHighSurrogate || !isLowSurrogate) {
|
|
47
|
+
// There shouldn't be two high surrogates in a row, nor a high surrogate which isn't followed by a low
|
|
48
|
+
// surrogate. If this happens, keep the pending high surrogate as a stand-alone semi-invalid character
|
|
49
|
+
// (technically wrong, but expected by some applications, like Windows file names).
|
|
50
|
+
write32.call(dst, this.highSurrogate, offset)
|
|
51
|
+
offset += 4
|
|
52
|
+
} else {
|
|
53
|
+
// Create 32-bit value from high and low surrogates;
|
|
54
|
+
var codepoint = (((this.highSurrogate - 0xD800) << 10) | (code - 0xDC00)) + 0x10000
|
|
55
|
+
|
|
56
|
+
write32.call(dst, codepoint, offset)
|
|
57
|
+
offset += 4
|
|
58
|
+
this.highSurrogate = 0
|
|
59
|
+
|
|
60
|
+
continue
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (isHighSurrogate) { this.highSurrogate = code } else {
|
|
65
|
+
// Even if the current character is a low surrogate, with no previous high surrogate, we'll
|
|
66
|
+
// encode it as a semi-invalid stand-alone character for the same reasons expressed above for
|
|
67
|
+
// unpaired high surrogates.
|
|
68
|
+
write32.call(dst, code, offset)
|
|
69
|
+
offset += 4
|
|
70
|
+
this.highSurrogate = 0
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (offset < dst.length) { dst = dst.slice(0, offset) }
|
|
75
|
+
|
|
76
|
+
return dst
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
Utf32Encoder.prototype.end = function () {
|
|
80
|
+
// Treat any leftover high surrogate as a semi-valid independent character.
|
|
81
|
+
if (!this.highSurrogate) { return }
|
|
82
|
+
|
|
83
|
+
var buf = Buffer.alloc(4)
|
|
84
|
+
|
|
85
|
+
if (this.isLE) { buf.writeUInt32LE(this.highSurrogate, 0) } else { buf.writeUInt32BE(this.highSurrogate, 0) }
|
|
86
|
+
|
|
87
|
+
this.highSurrogate = 0
|
|
88
|
+
|
|
89
|
+
return buf
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// -- Decoding
|
|
93
|
+
|
|
94
|
+
function Utf32Decoder (options, codec) {
|
|
95
|
+
this.isLE = codec.isLE
|
|
96
|
+
this.badChar = codec.iconv.defaultCharUnicode.charCodeAt(0)
|
|
97
|
+
this.overflow = []
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
Utf32Decoder.prototype.write = function (src) {
|
|
101
|
+
if (src.length === 0) { return "" }
|
|
102
|
+
|
|
103
|
+
var i = 0
|
|
104
|
+
var codepoint = 0
|
|
105
|
+
var dst = Buffer.alloc(src.length + 4)
|
|
106
|
+
var offset = 0
|
|
107
|
+
var isLE = this.isLE
|
|
108
|
+
var overflow = this.overflow
|
|
109
|
+
var badChar = this.badChar
|
|
110
|
+
|
|
111
|
+
if (overflow.length > 0) {
|
|
112
|
+
for (; i < src.length && overflow.length < 4; i++) { overflow.push(src[i]) }
|
|
113
|
+
|
|
114
|
+
if (overflow.length === 4) {
|
|
115
|
+
// NOTE: codepoint is a signed int32 and can be negative.
|
|
116
|
+
// NOTE: We copied this block from below to help V8 optimize it (it works with array, not buffer).
|
|
117
|
+
if (isLE) {
|
|
118
|
+
codepoint = overflow[0] | (overflow[1] << 8) | (overflow[2] << 16) | (overflow[3] << 24)
|
|
119
|
+
} else {
|
|
120
|
+
codepoint = overflow[3] | (overflow[2] << 8) | (overflow[1] << 16) | (overflow[0] << 24)
|
|
121
|
+
}
|
|
122
|
+
overflow.length = 0
|
|
123
|
+
|
|
124
|
+
offset = _writeCodepoint(dst, offset, codepoint, badChar)
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// Main loop. Should be as optimized as possible.
|
|
129
|
+
for (; i < src.length - 3; i += 4) {
|
|
130
|
+
// NOTE: codepoint is a signed int32 and can be negative.
|
|
131
|
+
if (isLE) {
|
|
132
|
+
codepoint = src[i] | (src[i + 1] << 8) | (src[i + 2] << 16) | (src[i + 3] << 24)
|
|
133
|
+
} else {
|
|
134
|
+
codepoint = src[i + 3] | (src[i + 2] << 8) | (src[i + 1] << 16) | (src[i] << 24)
|
|
135
|
+
}
|
|
136
|
+
offset = _writeCodepoint(dst, offset, codepoint, badChar)
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// Keep overflowing bytes.
|
|
140
|
+
for (; i < src.length; i++) {
|
|
141
|
+
overflow.push(src[i])
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return dst.slice(0, offset).toString("ucs2")
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function _writeCodepoint (dst, offset, codepoint, badChar) {
|
|
148
|
+
// NOTE: codepoint is signed int32 and can be negative. We keep it that way to help V8 with optimizations.
|
|
149
|
+
if (codepoint < 0 || codepoint > 0x10FFFF) {
|
|
150
|
+
// Not a valid Unicode codepoint
|
|
151
|
+
codepoint = badChar
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// Ephemeral Planes: Write high surrogate.
|
|
155
|
+
if (codepoint >= 0x10000) {
|
|
156
|
+
codepoint -= 0x10000
|
|
157
|
+
|
|
158
|
+
var high = 0xD800 | (codepoint >> 10)
|
|
159
|
+
dst[offset++] = high & 0xff
|
|
160
|
+
dst[offset++] = high >> 8
|
|
161
|
+
|
|
162
|
+
// Low surrogate is written below.
|
|
163
|
+
var codepoint = 0xDC00 | (codepoint & 0x3FF)
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// Write BMP char or low surrogate.
|
|
167
|
+
dst[offset++] = codepoint & 0xff
|
|
168
|
+
dst[offset++] = codepoint >> 8
|
|
169
|
+
|
|
170
|
+
return offset
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
Utf32Decoder.prototype.end = function () {
|
|
174
|
+
if (this.overflow.length === 0) { return }
|
|
175
|
+
|
|
176
|
+
// A leftover, incomplete 4-byte code unit at the end of the input is ill-formed. Substitute a
|
|
177
|
+
// single U+FFFD (Unicode Standard conformance clause C10) instead of silently dropping the bytes.
|
|
178
|
+
this.overflow.length = 0
|
|
179
|
+
return String.fromCharCode(this.badChar)
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// == UTF-32 Auto codec =============================================================
|
|
183
|
+
// Decoder chooses automatically from UTF-32LE and UTF-32BE using BOM and space-based heuristic.
|
|
184
|
+
// Defaults to UTF-32LE. http://en.wikipedia.org/wiki/UTF-32
|
|
185
|
+
// Encoder/decoder default can be changed: iconv.decode(buf, 'utf32', {defaultEncoding: 'utf-32be'});
|
|
186
|
+
|
|
187
|
+
// Encoder prepends BOM (which can be overridden with (addBOM: false}).
|
|
188
|
+
|
|
189
|
+
exports.utf32 = Utf32AutoCodec
|
|
190
|
+
exports.ucs4 = "utf32"
|
|
191
|
+
|
|
192
|
+
function Utf32AutoCodec (options, iconv) {
|
|
193
|
+
this.iconv = iconv
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
Utf32AutoCodec.prototype.encoder = Utf32AutoEncoder
|
|
197
|
+
Utf32AutoCodec.prototype.decoder = Utf32AutoDecoder
|
|
198
|
+
|
|
199
|
+
// -- Encoding
|
|
200
|
+
|
|
201
|
+
function Utf32AutoEncoder (options, codec) {
|
|
202
|
+
options = options || {}
|
|
203
|
+
|
|
204
|
+
if (options.addBOM === undefined) {
|
|
205
|
+
options.addBOM = true
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
this.encoder = codec.iconv.getEncoder(options.defaultEncoding || "utf-32le", options)
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
Utf32AutoEncoder.prototype.write = function (str) {
|
|
212
|
+
return this.encoder.write(str)
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
Utf32AutoEncoder.prototype.end = function () {
|
|
216
|
+
return this.encoder.end()
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// -- Decoding
|
|
220
|
+
|
|
221
|
+
function Utf32AutoDecoder (options, codec) {
|
|
222
|
+
this.decoder = null
|
|
223
|
+
this.initialBufs = []
|
|
224
|
+
this.initialBufsLen = 0
|
|
225
|
+
this.options = options || {}
|
|
226
|
+
this.iconv = codec.iconv
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
Utf32AutoDecoder.prototype.write = function (buf) {
|
|
230
|
+
if (!this.decoder) {
|
|
231
|
+
// Codec is not chosen yet. Accumulate initial bytes.
|
|
232
|
+
this.initialBufs.push(buf)
|
|
233
|
+
this.initialBufsLen += buf.length
|
|
234
|
+
|
|
235
|
+
if (this.initialBufsLen < 32) // We need more bytes to use space heuristic (see below)
|
|
236
|
+
{ return "" }
|
|
237
|
+
|
|
238
|
+
// We have enough bytes -> detect endianness.
|
|
239
|
+
var encoding = detectEncoding(this.initialBufs, this.options.defaultEncoding)
|
|
240
|
+
this.decoder = this.iconv.getDecoder(encoding, this.options)
|
|
241
|
+
|
|
242
|
+
var resStr = ""
|
|
243
|
+
for (var i = 0; i < this.initialBufs.length; i++) { resStr += this.decoder.write(this.initialBufs[i]) }
|
|
244
|
+
|
|
245
|
+
this.initialBufs.length = this.initialBufsLen = 0
|
|
246
|
+
return resStr
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
return this.decoder.write(buf)
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
Utf32AutoDecoder.prototype.end = function () {
|
|
253
|
+
if (!this.decoder) {
|
|
254
|
+
var encoding = detectEncoding(this.initialBufs, this.options.defaultEncoding)
|
|
255
|
+
this.decoder = this.iconv.getDecoder(encoding, this.options)
|
|
256
|
+
|
|
257
|
+
var resStr = ""
|
|
258
|
+
for (var i = 0; i < this.initialBufs.length; i++) { resStr += this.decoder.write(this.initialBufs[i]) }
|
|
259
|
+
|
|
260
|
+
var trail = this.decoder.end()
|
|
261
|
+
if (trail) { resStr += trail }
|
|
262
|
+
|
|
263
|
+
this.initialBufs.length = this.initialBufsLen = 0
|
|
264
|
+
return resStr
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
return this.decoder.end()
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
function detectEncoding (bufs, defaultEncoding) {
|
|
271
|
+
var b = []
|
|
272
|
+
var charsProcessed = 0
|
|
273
|
+
var invalidLE = 0; var invalidBE = 0 // Number of invalid chars when decoded as LE or BE.
|
|
274
|
+
var bmpCharsLE = 0; var bmpCharsBE = 0 // Number of BMP chars when decoded as LE or BE.
|
|
275
|
+
|
|
276
|
+
outerLoop:
|
|
277
|
+
for (var i = 0; i < bufs.length; i++) {
|
|
278
|
+
var buf = bufs[i]
|
|
279
|
+
for (var j = 0; j < buf.length; j++) {
|
|
280
|
+
b.push(buf[j])
|
|
281
|
+
if (b.length === 4) {
|
|
282
|
+
if (charsProcessed === 0) {
|
|
283
|
+
// Check BOM first.
|
|
284
|
+
if (b[0] === 0xFF && b[1] === 0xFE && b[2] === 0 && b[3] === 0) {
|
|
285
|
+
return "utf-32le"
|
|
286
|
+
}
|
|
287
|
+
if (b[0] === 0 && b[1] === 0 && b[2] === 0xFE && b[3] === 0xFF) {
|
|
288
|
+
return "utf-32be"
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
if (b[0] !== 0 || b[1] > 0x10) invalidBE++
|
|
293
|
+
if (b[3] !== 0 || b[2] > 0x10) invalidLE++
|
|
294
|
+
|
|
295
|
+
if (b[0] === 0 && b[1] === 0 && (b[2] !== 0 || b[3] !== 0)) bmpCharsBE++
|
|
296
|
+
if ((b[0] !== 0 || b[1] !== 0) && b[2] === 0 && b[3] === 0) bmpCharsLE++
|
|
297
|
+
|
|
298
|
+
b.length = 0
|
|
299
|
+
charsProcessed++
|
|
300
|
+
|
|
301
|
+
if (charsProcessed >= 100) {
|
|
302
|
+
break outerLoop
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
// Make decisions.
|
|
309
|
+
if (bmpCharsBE - invalidBE > bmpCharsLE - invalidLE) return "utf-32be"
|
|
310
|
+
if (bmpCharsBE - invalidBE < bmpCharsLE - invalidLE) return "utf-32le"
|
|
311
|
+
|
|
312
|
+
// Couldn't decide (likely all zeros or not enough data).
|
|
313
|
+
return defaultEncoding || "utf-32le"
|
|
314
|
+
}
|