MCPcopy
hub / github.com/anomalyco/opencode / detectOutputEncoding

Function detectOutputEncoding

packages/desktop/src/main/wsl/runtime.ts:188–195  ·  view source on GitHub ↗
(chunk: Uint8Array)

Source from the content-addressed store, hash-verified

186}
187
188function detectOutputEncoding(chunk: Uint8Array) {
189 if (chunk[0] === 0xff && chunk[1] === 0xfe) return "utf-16le"
190 const pairs = Math.floor(chunk.length / 2)
191 if (pairs < 2) return "utf-8"
192 const oddZeroes = Array.from({ length: pairs }).filter((_, index) => chunk[index * 2 + 1] === 0).length
193 const evenZeroes = Array.from({ length: pairs }).filter((_, index) => chunk[index * 2] === 0).length
194 return oddZeroes >= Math.ceil(pairs / 3) && evenZeroes * 2 <= oddZeroes ? "utf-16le" : "utf-8"
195}
196
197export function runWslInDistro(args: string[], distro?: string | null, opts?: RunWslOptions) {
198 return runWsl(wslArgs(args, distro), opts)

Callers 1

decodeFunction · 0.85

Calls 1

fromMethod · 0.45

Tested by

no test coverage detected