mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 13:48:44 +02:00
stream: ensure text() stream consumer flushes correctly
Signed-off-by: James M Snell <jasnell@gmail.com> PR-URL: https://github.com/nodejs/node/pull/39737 Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
This commit is contained in:
parent
394c99118d
commit
ca19775d0e
2 changed files with 17 additions and 0 deletions
|
@ -63,6 +63,9 @@ async function text(stream) {
|
||||||
else
|
else
|
||||||
str += dec.decode(chunk, { stream: true });
|
str += dec.decode(chunk, { stream: true });
|
||||||
}
|
}
|
||||||
|
// Flush the streaming TextDecoder so that any pending
|
||||||
|
// incomplete multibyte characters are handled.
|
||||||
|
str += dec.decode(undefined, { stream: false });
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -232,3 +232,17 @@ const kArrayBuffer =
|
||||||
stream.write({});
|
stream.write({});
|
||||||
stream.end({});
|
stream.end({});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
const stream = new TransformStream();
|
||||||
|
text(stream.readable).then(common.mustCall((str) => {
|
||||||
|
// Incomplete utf8 character is flushed as a replacement char
|
||||||
|
assert.strictEqual(str.charCodeAt(0), 0xfffd);
|
||||||
|
}));
|
||||||
|
const writer = stream.writable.getWriter();
|
||||||
|
Promise.all([
|
||||||
|
writer.write(new Uint8Array([0xe2])),
|
||||||
|
writer.write(new Uint8Array([0x82])),
|
||||||
|
writer.close(),
|
||||||
|
]).then(common.mustCall());
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue