@pnpm/exe 11.0.0-beta.0 → 11.0.0-beta.1
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/dist/node_modules/@gar/promise-retry/lib/index.js +28 -0
- package/dist/node_modules/@gar/promise-retry/package.json +48 -0
- package/dist/node_modules/@npmcli/agent/package.json +7 -7
- package/dist/node_modules/@npmcli/fs/package.json +4 -4
- package/dist/node_modules/abbrev/package.json +11 -15
- package/dist/node_modules/cacache/package.json +10 -11
- package/dist/node_modules/glob/dist/commonjs/glob.js +2 -1
- package/dist/node_modules/glob/dist/commonjs/index.min.js +4 -0
- package/dist/node_modules/glob/dist/commonjs/pattern.js +4 -0
- package/dist/node_modules/glob/dist/esm/glob.js +2 -1
- package/dist/node_modules/glob/dist/esm/index.min.js +4 -0
- package/dist/node_modules/glob/dist/esm/pattern.js +4 -0
- package/dist/node_modules/glob/package.json +38 -37
- package/dist/node_modules/graceful-fs/graceful-fs.js +1 -1
- package/dist/node_modules/iconv-lite/encodings/dbcs-codec.js +460 -525
- package/dist/node_modules/iconv-lite/encodings/dbcs-data.js +179 -182
- package/dist/node_modules/iconv-lite/encodings/index.js +15 -15
- package/dist/node_modules/iconv-lite/encodings/internal.js +168 -148
- package/dist/node_modules/iconv-lite/encodings/sbcs-codec.js +55 -52
- package/dist/node_modules/iconv-lite/encodings/sbcs-data.js +174 -175
- package/dist/node_modules/iconv-lite/encodings/utf16.js +121 -131
- package/dist/node_modules/iconv-lite/encodings/utf32.js +226 -238
- package/dist/node_modules/iconv-lite/encodings/utf7.js +208 -215
- package/dist/node_modules/iconv-lite/lib/bom-handling.js +30 -34
- package/dist/node_modules/iconv-lite/lib/helpers/merge-exports.js +13 -0
- package/dist/node_modules/iconv-lite/lib/index.js +125 -123
- package/dist/node_modules/iconv-lite/lib/streams.js +92 -96
- package/dist/node_modules/iconv-lite/package.json +34 -8
- package/dist/node_modules/isexe/package.json +65 -18
- package/dist/node_modules/lru-cache/dist/commonjs/index.js +134 -85
- package/dist/node_modules/lru-cache/dist/commonjs/index.min.js +1 -1
- package/dist/node_modules/lru-cache/dist/esm/index.js +134 -85
- package/dist/node_modules/lru-cache/dist/esm/index.min.js +1 -1
- package/dist/node_modules/lru-cache/package.json +18 -41
- package/dist/node_modules/make-fetch-happen/lib/remote.js +1 -1
- package/dist/node_modules/make-fetch-happen/package.json +10 -10
- package/dist/node_modules/minipass-fetch/lib/body.js +25 -15
- package/dist/node_modules/minipass-fetch/package.json +7 -7
- package/dist/node_modules/minipass-sized/dist/commonjs/index.js +69 -0
- package/dist/node_modules/minipass-sized/dist/esm/index.js +64 -0
- package/dist/node_modules/minipass-sized/package.json +39 -9
- package/dist/node_modules/node-gyp/.release-please-manifest.json +1 -1
- package/dist/node_modules/node-gyp/bin/node-gyp.js +7 -0
- package/dist/node_modules/node-gyp/gyp/.release-please-manifest.json +1 -1
- package/dist/node_modules/node-gyp/gyp/pylib/gyp/MSVSNew.py +3 -3
- package/dist/node_modules/node-gyp/gyp/pylib/gyp/MSVSVersion.py +26 -1
- package/dist/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py +1 -1
- package/dist/node_modules/node-gyp/gyp/pylib/gyp/generator/ninja.py +3 -4
- package/dist/node_modules/node-gyp/gyp/pylib/gyp/xcodeproj_file.py +1 -1
- package/dist/node_modules/node-gyp/gyp/pyproject.toml +1 -1
- package/dist/node_modules/node-gyp/lib/build.js +2 -2
- package/dist/node_modules/node-gyp/lib/find-python.js +2 -8
- package/dist/node_modules/node-gyp/lib/find-visualstudio.js +11 -5
- package/dist/node_modules/node-gyp/lib/install.js +1 -1
- package/dist/node_modules/node-gyp/lib/process-release.js +3 -3
- package/dist/node_modules/node-gyp/package.json +13 -13
- package/dist/node_modules/nopt/package.json +5 -5
- package/dist/node_modules/proc-log/lib/index.js +10 -5
- package/dist/node_modules/proc-log/package.json +5 -5
- package/dist/node_modules/retry/lib/retry.js +2 -2
- package/dist/node_modules/retry/lib/retry_operation.js +10 -6
- package/dist/node_modules/retry/package.json +6 -2
- package/dist/node_modules/ssri/lib/index.js +33 -63
- package/dist/node_modules/ssri/package.json +17 -17
- package/dist/node_modules/unique-filename/package.json +5 -5
- package/dist/node_modules/unique-slug/package.json +4 -4
- package/dist/node_modules/which/package.json +29 -20
- package/dist/pnpm.mjs +63952 -54674
- package/dist/worker.js +601 -2162
- package/package.json +8 -8
- package/dist/node_modules/@isaacs/cliui/dist/commonjs/ansi-regex/index.js +0 -16
- package/dist/node_modules/@isaacs/cliui/dist/commonjs/ansi-styles/index.js +0 -170
- package/dist/node_modules/@isaacs/cliui/dist/commonjs/eastasianwidth/index.js +0 -307
- package/dist/node_modules/@isaacs/cliui/dist/commonjs/emoji-regex/index.js +0 -7
- package/dist/node_modules/@isaacs/cliui/dist/commonjs/index.js +0 -322
- package/dist/node_modules/@isaacs/cliui/dist/commonjs/index.min.js +0 -12
- package/dist/node_modules/@isaacs/cliui/dist/commonjs/string-width/index.js +0 -49
- package/dist/node_modules/@isaacs/cliui/dist/commonjs/strip-ansi/index.js +0 -8
- package/dist/node_modules/@isaacs/cliui/dist/commonjs/wrap-ansi/index.js +0 -176
- package/dist/node_modules/@isaacs/cliui/dist/esm/ansi-regex/index.js +0 -12
- package/dist/node_modules/@isaacs/cliui/dist/esm/ansi-styles/index.js +0 -167
- package/dist/node_modules/@isaacs/cliui/dist/esm/eastasianwidth/index.js +0 -299
- package/dist/node_modules/@isaacs/cliui/dist/esm/emoji-regex/index.js +0 -3
- package/dist/node_modules/@isaacs/cliui/dist/esm/index.js +0 -317
- package/dist/node_modules/@isaacs/cliui/dist/esm/index.min.js +0 -12
- package/dist/node_modules/@isaacs/cliui/dist/esm/string-width/index.js +0 -46
- package/dist/node_modules/@isaacs/cliui/dist/esm/strip-ansi/index.js +0 -4
- package/dist/node_modules/@isaacs/cliui/dist/esm/wrap-ansi/index.js +0 -172
- package/dist/node_modules/@isaacs/cliui/package.json +0 -163
- package/dist/node_modules/cross-spawn/LICENSE +0 -21
- package/dist/node_modules/cross-spawn/index.js +0 -39
- package/dist/node_modules/cross-spawn/lib/enoent.js +0 -59
- package/dist/node_modules/cross-spawn/lib/parse.js +0 -91
- package/dist/node_modules/cross-spawn/lib/util/escape.js +0 -47
- package/dist/node_modules/cross-spawn/lib/util/readShebang.js +0 -23
- package/dist/node_modules/cross-spawn/lib/util/resolveCommand.js +0 -52
- package/dist/node_modules/cross-spawn/package.json +0 -73
- package/dist/node_modules/encoding/.prettierrc.js +0 -8
- package/dist/node_modules/encoding/LICENSE +0 -16
- package/dist/node_modules/encoding/lib/encoding.js +0 -83
- package/dist/node_modules/encoding/package.json +0 -18
- package/dist/node_modules/err-code/.eslintrc.json +0 -7
- package/dist/node_modules/err-code/bower.json +0 -30
- package/dist/node_modules/err-code/index.js +0 -47
- package/dist/node_modules/err-code/index.umd.js +0 -51
- package/dist/node_modules/err-code/package.json +0 -34
- package/dist/node_modules/foreground-child/LICENSE +0 -15
- package/dist/node_modules/foreground-child/dist/commonjs/all-signals.js +0 -58
- package/dist/node_modules/foreground-child/dist/commonjs/index.js +0 -123
- package/dist/node_modules/foreground-child/dist/commonjs/proxy-signals.js +0 -38
- package/dist/node_modules/foreground-child/dist/commonjs/watchdog.js +0 -50
- package/dist/node_modules/foreground-child/dist/esm/all-signals.js +0 -52
- package/dist/node_modules/foreground-child/dist/esm/index.js +0 -115
- package/dist/node_modules/foreground-child/dist/esm/proxy-signals.js +0 -34
- package/dist/node_modules/foreground-child/dist/esm/watchdog.js +0 -46
- package/dist/node_modules/foreground-child/package.json +0 -106
- package/dist/node_modules/glob/dist/esm/bin.d.mts +0 -3
- package/dist/node_modules/glob/dist/esm/bin.mjs +0 -346
- package/dist/node_modules/iconv-lite/.github/dependabot.yml +0 -11
- package/dist/node_modules/iconv-lite/.idea/codeStyles/Project.xml +0 -47
- package/dist/node_modules/iconv-lite/.idea/codeStyles/codeStyleConfig.xml +0 -5
- package/dist/node_modules/iconv-lite/.idea/iconv-lite.iml +0 -12
- package/dist/node_modules/iconv-lite/.idea/inspectionProfiles/Project_Default.xml +0 -6
- package/dist/node_modules/iconv-lite/.idea/modules.xml +0 -8
- package/dist/node_modules/iconv-lite/.idea/vcs.xml +0 -6
- package/dist/node_modules/isexe/LICENSE +0 -15
- package/dist/node_modules/isexe/index.js +0 -57
- package/dist/node_modules/isexe/mode.js +0 -41
- package/dist/node_modules/isexe/windows.js +0 -42
- package/dist/node_modules/jackspeak/dist/commonjs/index.js +0 -944
- package/dist/node_modules/jackspeak/dist/commonjs/index.min.js +0 -33
- package/dist/node_modules/jackspeak/dist/commonjs/package.json +0 -3
- package/dist/node_modules/jackspeak/dist/esm/index.js +0 -936
- package/dist/node_modules/jackspeak/dist/esm/index.min.js +0 -33
- package/dist/node_modules/jackspeak/dist/esm/package.json +0 -3
- package/dist/node_modules/jackspeak/package.json +0 -115
- package/dist/node_modules/lru-cache/LICENSE +0 -15
- package/dist/node_modules/minipass-sized/index.js +0 -67
- package/dist/node_modules/minipass-sized/node_modules/minipass/LICENSE +0 -15
- package/dist/node_modules/minipass-sized/node_modules/minipass/index.js +0 -649
- package/dist/node_modules/minipass-sized/node_modules/minipass/package.json +0 -56
- package/dist/node_modules/minipass-sized/package-lock.json +0 -3464
- package/dist/node_modules/node-gyp/node_modules/isexe/dist/commonjs/package.json +0 -3
- package/dist/node_modules/node-gyp/node_modules/isexe/dist/esm/package.json +0 -3
- package/dist/node_modules/node-gyp/node_modules/isexe/package.json +0 -78
- package/dist/node_modules/node-gyp/node_modules/which/LICENSE +0 -15
- package/dist/node_modules/node-gyp/node_modules/which/package.json +0 -52
- package/dist/node_modules/package-json-from-dist/dist/commonjs/index.js +0 -134
- package/dist/node_modules/package-json-from-dist/dist/commonjs/package.json +0 -3
- package/dist/node_modules/package-json-from-dist/dist/esm/index.js +0 -129
- package/dist/node_modules/package-json-from-dist/dist/esm/package.json +0 -3
- package/dist/node_modules/package-json-from-dist/package.json +0 -68
- package/dist/node_modules/path-key/index.js +0 -16
- package/dist/node_modules/path-key/license +0 -9
- package/dist/node_modules/path-key/package.json +0 -39
- package/dist/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/index.js +0 -1589
- package/dist/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/index.min.js +0 -2
- package/dist/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/package.json +0 -3
- package/dist/node_modules/path-scurry/node_modules/lru-cache/dist/esm/index.js +0 -1585
- package/dist/node_modules/path-scurry/node_modules/lru-cache/dist/esm/index.min.js +0 -2
- package/dist/node_modules/path-scurry/node_modules/lru-cache/dist/esm/package.json +0 -3
- package/dist/node_modules/path-scurry/node_modules/lru-cache/package.json +0 -101
- package/dist/node_modules/promise-retry/index.js +0 -52
- package/dist/node_modules/promise-retry/package.json +0 -37
- package/dist/node_modules/retry/equation.gif +0 -0
- package/dist/node_modules/shebang-command/index.js +0 -19
- package/dist/node_modules/shebang-command/license +0 -9
- package/dist/node_modules/shebang-command/package.json +0 -34
- package/dist/node_modules/shebang-regex/index.js +0 -2
- package/dist/node_modules/shebang-regex/license +0 -9
- package/dist/node_modules/shebang-regex/package.json +0 -35
- package/dist/node_modules/signal-exit/LICENSE.txt +0 -16
- package/dist/node_modules/signal-exit/dist/cjs/browser.js +0 -10
- package/dist/node_modules/signal-exit/dist/cjs/index.js +0 -279
- package/dist/node_modules/signal-exit/dist/cjs/package.json +0 -3
- package/dist/node_modules/signal-exit/dist/cjs/signals.js +0 -42
- package/dist/node_modules/signal-exit/dist/mjs/browser.js +0 -4
- package/dist/node_modules/signal-exit/dist/mjs/index.js +0 -275
- package/dist/node_modules/signal-exit/dist/mjs/package.json +0 -3
- package/dist/node_modules/signal-exit/dist/mjs/signals.js +0 -39
- package/dist/node_modules/signal-exit/package.json +0 -106
- package/dist/node_modules/which/bin/node-which +0 -52
- package/dist/node_modules/which/which.js +0 -125
- /package/dist/node_modules/{promise-retry → @gar/promise-retry}/LICENSE +0 -0
- /package/dist/node_modules/{node-gyp/node_modules/isexe → isexe}/dist/commonjs/index.js +0 -0
- /package/dist/node_modules/{node-gyp/node_modules/isexe → isexe}/dist/commonjs/index.min.js +0 -0
- /package/dist/node_modules/{node-gyp/node_modules/isexe → isexe}/dist/commonjs/options.js +0 -0
- /package/dist/node_modules/{@isaacs/cliui → isexe}/dist/commonjs/package.json +0 -0
- /package/dist/node_modules/{node-gyp/node_modules/isexe → isexe}/dist/commonjs/posix.js +0 -0
- /package/dist/node_modules/{node-gyp/node_modules/isexe → isexe}/dist/commonjs/win32.js +0 -0
- /package/dist/node_modules/{node-gyp/node_modules/isexe → isexe}/dist/esm/index.js +0 -0
- /package/dist/node_modules/{node-gyp/node_modules/isexe → isexe}/dist/esm/index.min.js +0 -0
- /package/dist/node_modules/{node-gyp/node_modules/isexe → isexe}/dist/esm/options.js +0 -0
- /package/dist/node_modules/{@isaacs/cliui → isexe}/dist/esm/package.json +0 -0
- /package/dist/node_modules/{node-gyp/node_modules/isexe → isexe}/dist/esm/posix.js +0 -0
- /package/dist/node_modules/{node-gyp/node_modules/isexe → isexe}/dist/esm/win32.js +0 -0
- /package/dist/node_modules/{foreground-child → minipass-sized}/dist/commonjs/package.json +0 -0
- /package/dist/node_modules/{foreground-child → minipass-sized}/dist/esm/package.json +0 -0
- /package/dist/node_modules/{node-gyp/node_modules/which → which}/bin/which.js +0 -0
- /package/dist/node_modules/{node-gyp/node_modules/which → which}/lib/index.js +0 -0
|
@@ -1,70 +1,66 @@
|
|
|
1
|
-
"use strict"
|
|
2
|
-
var Buffer = require("safer-buffer").Buffer
|
|
1
|
+
"use strict"
|
|
2
|
+
var Buffer = require("safer-buffer").Buffer
|
|
3
3
|
|
|
4
4
|
// Note: UTF16-LE (or UCS2) codec is Node.js native. See encodings/internal.js
|
|
5
5
|
|
|
6
6
|
// == UTF16-BE codec. ==========================================================
|
|
7
7
|
|
|
8
|
-
exports.utf16be = Utf16BECodec
|
|
9
|
-
function Utf16BECodec() {
|
|
8
|
+
exports.utf16be = Utf16BECodec
|
|
9
|
+
function Utf16BECodec () {
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
Utf16BECodec.prototype.encoder = Utf16BEEncoder
|
|
13
|
-
Utf16BECodec.prototype.decoder = Utf16BEDecoder
|
|
14
|
-
Utf16BECodec.prototype.bomAware = true
|
|
15
|
-
|
|
12
|
+
Utf16BECodec.prototype.encoder = Utf16BEEncoder
|
|
13
|
+
Utf16BECodec.prototype.decoder = Utf16BEDecoder
|
|
14
|
+
Utf16BECodec.prototype.bomAware = true
|
|
16
15
|
|
|
17
16
|
// -- Encoding
|
|
18
17
|
|
|
19
|
-
function Utf16BEEncoder() {
|
|
18
|
+
function Utf16BEEncoder () {
|
|
20
19
|
}
|
|
21
20
|
|
|
22
|
-
Utf16BEEncoder.prototype.write = function(str) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
|
28
27
|
}
|
|
29
28
|
|
|
30
|
-
Utf16BEEncoder.prototype.end = function() {
|
|
29
|
+
Utf16BEEncoder.prototype.end = function () {
|
|
31
30
|
}
|
|
32
31
|
|
|
33
|
-
|
|
34
32
|
// -- Decoding
|
|
35
33
|
|
|
36
|
-
function Utf16BEDecoder() {
|
|
37
|
-
|
|
34
|
+
function Utf16BEDecoder () {
|
|
35
|
+
this.overflowByte = -1
|
|
38
36
|
}
|
|
39
37
|
|
|
40
|
-
Utf16BEDecoder.prototype.write = function(buf) {
|
|
41
|
-
|
|
42
|
-
return '';
|
|
38
|
+
Utf16BEDecoder.prototype.write = function (buf) {
|
|
39
|
+
if (buf.length == 0) { return "" }
|
|
43
40
|
|
|
44
|
-
|
|
45
|
-
|
|
41
|
+
var buf2 = Buffer.alloc(buf.length + 1)
|
|
42
|
+
var i = 0; var j = 0
|
|
46
43
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
44
|
+
if (this.overflowByte !== -1) {
|
|
45
|
+
buf2[0] = buf[0]
|
|
46
|
+
buf2[1] = this.overflowByte
|
|
47
|
+
i = 1; j = 2
|
|
48
|
+
}
|
|
52
49
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
50
|
+
for (; i < buf.length - 1; i += 2, j += 2) {
|
|
51
|
+
buf2[j] = buf[i + 1]
|
|
52
|
+
buf2[j + 1] = buf[i]
|
|
53
|
+
}
|
|
57
54
|
|
|
58
|
-
|
|
55
|
+
this.overflowByte = (i == buf.length - 1) ? buf[buf.length - 1] : -1
|
|
59
56
|
|
|
60
|
-
|
|
57
|
+
return buf2.slice(0, j).toString("ucs2")
|
|
61
58
|
}
|
|
62
59
|
|
|
63
|
-
Utf16BEDecoder.prototype.end = function() {
|
|
64
|
-
|
|
60
|
+
Utf16BEDecoder.prototype.end = function () {
|
|
61
|
+
this.overflowByte = -1
|
|
65
62
|
}
|
|
66
63
|
|
|
67
|
-
|
|
68
64
|
// == UTF-16 codec =============================================================
|
|
69
65
|
// Decoder chooses automatically from UTF-16LE and UTF-16BE using BOM and space-based heuristic.
|
|
70
66
|
// Defaults to UTF-16LE, as it's prevalent and default in Node.
|
|
@@ -73,125 +69,119 @@ Utf16BEDecoder.prototype.end = function() {
|
|
|
73
69
|
|
|
74
70
|
// Encoder uses UTF-16LE and prepends BOM (which can be overridden with addBOM: false).
|
|
75
71
|
|
|
76
|
-
exports.utf16 = Utf16Codec
|
|
77
|
-
function Utf16Codec(codecOptions, iconv) {
|
|
78
|
-
|
|
72
|
+
exports.utf16 = Utf16Codec
|
|
73
|
+
function Utf16Codec (codecOptions, iconv) {
|
|
74
|
+
this.iconv = iconv
|
|
79
75
|
}
|
|
80
76
|
|
|
81
|
-
Utf16Codec.prototype.encoder = Utf16Encoder
|
|
82
|
-
Utf16Codec.prototype.decoder = Utf16Decoder
|
|
83
|
-
|
|
77
|
+
Utf16Codec.prototype.encoder = Utf16Encoder
|
|
78
|
+
Utf16Codec.prototype.decoder = Utf16Decoder
|
|
84
79
|
|
|
85
80
|
// -- Encoding (pass-through)
|
|
86
81
|
|
|
87
|
-
function Utf16Encoder(options, codec) {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
this.encoder = codec.iconv.getEncoder('utf-16le', options);
|
|
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)
|
|
92
86
|
}
|
|
93
87
|
|
|
94
|
-
Utf16Encoder.prototype.write = function(str) {
|
|
95
|
-
|
|
88
|
+
Utf16Encoder.prototype.write = function (str) {
|
|
89
|
+
return this.encoder.write(str)
|
|
96
90
|
}
|
|
97
91
|
|
|
98
|
-
Utf16Encoder.prototype.end = function() {
|
|
99
|
-
|
|
92
|
+
Utf16Encoder.prototype.end = function () {
|
|
93
|
+
return this.encoder.end()
|
|
100
94
|
}
|
|
101
95
|
|
|
102
|
-
|
|
103
96
|
// -- Decoding
|
|
104
97
|
|
|
105
|
-
function Utf16Decoder(options, codec) {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
98
|
+
function Utf16Decoder (options, codec) {
|
|
99
|
+
this.decoder = null
|
|
100
|
+
this.initialBufs = []
|
|
101
|
+
this.initialBufsLen = 0
|
|
109
102
|
|
|
110
|
-
|
|
111
|
-
|
|
103
|
+
this.options = options || {}
|
|
104
|
+
this.iconv = codec.iconv
|
|
112
105
|
}
|
|
113
106
|
|
|
114
|
-
Utf16Decoder.prototype.write = function(buf) {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
// We have enough bytes -> detect endianness.
|
|
124
|
-
var encoding = detectEncoding(this.initialBufs, this.options.defaultEncoding);
|
|
125
|
-
this.decoder = this.iconv.getDecoder(encoding, this.options);
|
|
126
|
-
|
|
127
|
-
var resStr = '';
|
|
128
|
-
for (var i = 0; i < this.initialBufs.length; i++)
|
|
129
|
-
resStr += this.decoder.write(this.initialBufs[i]);
|
|
130
|
-
|
|
131
|
-
this.initialBufs.length = this.initialBufsLen = 0;
|
|
132
|
-
return resStr;
|
|
133
|
-
}
|
|
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 "" }
|
|
134
115
|
|
|
135
|
-
|
|
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)
|
|
136
128
|
}
|
|
137
129
|
|
|
138
|
-
Utf16Decoder.prototype.end = function() {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
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)
|
|
142
134
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
resStr += this.decoder.write(this.initialBufs[i]);
|
|
135
|
+
var resStr = ""
|
|
136
|
+
for (var i = 0; i < this.initialBufs.length; i++) { resStr += this.decoder.write(this.initialBufs[i]) }
|
|
146
137
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
resStr += trail;
|
|
138
|
+
var trail = this.decoder.end()
|
|
139
|
+
if (trail) { resStr += trail }
|
|
150
140
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
141
|
+
this.initialBufs.length = this.initialBufsLen = 0
|
|
142
|
+
return resStr
|
|
143
|
+
}
|
|
144
|
+
return this.decoder.end()
|
|
155
145
|
}
|
|
156
146
|
|
|
157
|
-
function detectEncoding(bufs, defaultEncoding) {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
if (b[0] === 0 && b[1] !== 0) asciiCharsBE++;
|
|
175
|
-
if (b[0] !== 0 && b[1] === 0) asciiCharsLE++;
|
|
176
|
-
|
|
177
|
-
b.length = 0;
|
|
178
|
-
charsProcessed++;
|
|
179
|
-
|
|
180
|
-
if (charsProcessed >= 100) {
|
|
181
|
-
break outer_loop;
|
|
182
|
-
}
|
|
183
|
-
}
|
|
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"
|
|
184
164
|
}
|
|
185
|
-
}
|
|
186
165
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
// So, we count ASCII as if it was LE or BE, and decide from that.
|
|
190
|
-
if (asciiCharsBE > asciiCharsLE) return 'utf-16be';
|
|
191
|
-
if (asciiCharsBE < asciiCharsLE) return 'utf-16le';
|
|
166
|
+
if (b[0] === 0 && b[1] !== 0) asciiCharsBE++
|
|
167
|
+
if (b[0] !== 0 && b[1] === 0) asciiCharsLE++
|
|
192
168
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
}
|
|
169
|
+
b.length = 0
|
|
170
|
+
charsProcessed++
|
|
196
171
|
|
|
172
|
+
if (charsProcessed >= 100) {
|
|
173
|
+
break outerLoop
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
197
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
|
+
}
|