()
| 173 | } |
| 174 | |
| 175 | function createOutputDecoder() { |
| 176 | let decoder: TextDecoder | undefined |
| 177 | return { |
| 178 | decode(chunk: Buffer) { |
| 179 | decoder ??= new TextDecoder(detectOutputEncoding(chunk)) |
| 180 | return decoder.decode(chunk, { stream: true }) |
| 181 | }, |
| 182 | flush() { |
| 183 | return decoder?.decode() ?? "" |
| 184 | }, |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | function detectOutputEncoding(chunk: Uint8Array) { |
| 189 | if (chunk[0] === 0xff && chunk[1] === 0xfe) return "utf-16le" |