File tree 2 files changed +17
-0
lines changed
2 files changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -63,6 +63,9 @@ async function text(stream) {
63
63
else
64
64
str += dec . decode ( chunk , { stream : true } ) ;
65
65
}
66
+ // Flush the streaming TextDecoder so that any pending
67
+ // incomplete multibyte characters are handled.
68
+ str += dec . decode ( undefined , { stream : false } ) ;
66
69
return str ;
67
70
}
68
71
Original file line number Diff line number Diff line change @@ -232,3 +232,17 @@ const kArrayBuffer =
232
232
stream . write ( { } ) ;
233
233
stream . end ( { } ) ;
234
234
}
235
+
236
+ {
237
+ const stream = new TransformStream ( ) ;
238
+ text ( stream . readable ) . then ( common . mustCall ( ( str ) => {
239
+ // Incomplete utf8 character is flushed as a replacement char
240
+ assert . strictEqual ( str . charCodeAt ( 0 ) , 0xfffd ) ;
241
+ } ) ) ;
242
+ const writer = stream . writable . getWriter ( ) ;
243
+ Promise . all ( [
244
+ writer . write ( new Uint8Array ( [ 0xe2 ] ) ) ,
245
+ writer . write ( new Uint8Array ( [ 0x82 ] ) ) ,
246
+ writer . close ( ) ,
247
+ ] ) . then ( common . mustCall ( ) ) ;
248
+ }
You can’t perform that action at this time.
0 commit comments