Skip to content

Commit 735cf65

Browse files
committed
fix: flush TextDecoder on stream end to prevent silent data loss
When using decoder.decode(value, { stream: true }), the TextDecoder may hold incomplete multi-byte UTF-8 bytes internally. Without flushing on EOF, those trailing bytes were silently dropped — a regression from the previous behavior which would at minimum emit replacement characters.
1 parent 9d91e76 commit 735cf65

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

js/src/utils.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ export async function* readLines(stream: ReadableStream<Uint8Array>) {
3030
const { done, value } = await reader.read()
3131

3232
if (done) {
33+
const trailing = decoder.decode()
34+
if (trailing) pending.push(trailing)
3335
if (pending.length > 0) {
3436
yield pending.join('')
3537
}

0 commit comments

Comments
 (0)