fix(ps-encoded.sh): Python fallback when iconv.exe absent (Git-for-Windows ships libiconv DLL only, no pacman)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-07-07 20:51:17 -07:00
parent 840b0ce9d6
commit e548f63605

View File

@@ -38,7 +38,20 @@ read_script() { # $1 = file path or "-"
}
encode_b64() { # stdin: UTF-8 script -> stdout: UTF-16LE base64 (no BOM, no wraps)
iconv -f UTF-8 -t UTF-16LE | base64 -w0
if command -v iconv >/dev/null 2>&1; then
iconv -f UTF-8 -t UTF-16LE | base64 -w0
else
# Git-for-Windows ships the iconv *library* (msys-iconv-2.dll) but NOT iconv.exe,
# and has no pacman to install it. Fall back to Python (present fleet-wide) for the
# UTF-16LE -> base64 encode. Binary stdin/stdout so no CRLF translation.
local py
py="$(command -v py || command -v python3 || command -v python || true)"
if [ -z "$py" ]; then
echo "[ERROR] neither iconv nor python available for UTF-16LE encoding" >&2
return 1
fi
"$py" -c "import sys,base64; sys.stdout.write(base64.b64encode(sys.stdin.buffer.read().decode('utf-8').encode('utf-16-le')).decode())"
fi
}
size_gate() { # $1 = encoded string, $2 = force flag (0/1)