fix(exec): preserve UTF-8 across streaming output chunks

This commit is contained in:
Booty Destroyer 6969 authored and chengyongru committed 2026-09-10 11:36:33 +08:00
1 parent 8ea683679d
commit dfed706bc0
2 files changed
+32 -3

No files matched your search

+5 -3
View File
@@ -3,6 +3,7 @@
from __future__ import annotations
import asyncio
import codecs
import time
import uuid
from collections import deque
@@ -149,13 +150,14 @@ class _ExecSession:
) -> None:
if stream is None:
return
decoder = codecs.getincrementaldecoder("utf-8")(errors="replace")
while True:
chunk = await stream.read(4096)
if not chunk:
break
text = chunk.decode("utf-8", errors="replace")
text = decoder.decode(chunk, final=not chunk)
async with self._lock:
buffer.append(text)
if not chunk:
break
async def write(self, chars: str) -> str | None:
if self.process.returncode is not None: