@@ -50,6 +50,10 @@ const {
5050 pull : pullWithTransforms ,
5151} = require ( 'internal/streams/new/pull' ) ;
5252
53+ const {
54+ allUint8Array,
55+ } = require ( 'internal/streams/new/utils' ) ;
56+
5357const encoder = new TextEncoder ( ) ;
5458
5559// Non-exported symbol for internal cancel notification from BroadcastImpl
@@ -400,8 +404,10 @@ class BroadcastWriter {
400404 throw new ERR_INVALID_STATE ( 'Writer is closed' ) ;
401405 }
402406
403- const converted = ArrayPrototypeMap ( chunks , ( c ) =>
404- ( typeof c === 'string' ? encoder . encode ( c ) : c ) ) ;
407+ const converted = allUint8Array ( chunks )
408+ ? ArrayPrototypeSlice ( chunks )
409+ : ArrayPrototypeMap ( chunks , ( c ) =>
410+ ( typeof c === 'string' ? encoder . encode ( c ) : c ) ) ;
405411
406412 if ( this . _broadcast . _write ( converted ) ) {
407413 for ( let i = 0 ; i < converted . length ; i ++ ) {
@@ -441,8 +447,10 @@ class BroadcastWriter {
441447 writevSync ( chunks ) {
442448 if ( this . _closed || this . _aborted ) return false ;
443449 if ( ! this . _broadcast . _canWrite ( ) ) return false ;
444- const converted = ArrayPrototypeMap ( chunks , ( c ) =>
445- ( typeof c === 'string' ? encoder . encode ( c ) : c ) ) ;
450+ const converted = allUint8Array ( chunks )
451+ ? ArrayPrototypeSlice ( chunks )
452+ : ArrayPrototypeMap ( chunks , ( c ) =>
453+ ( typeof c === 'string' ? encoder . encode ( c ) : c ) ) ;
446454 if ( this . _broadcast . _write ( converted ) ) {
447455 for ( let i = 0 ; i < converted . length ; i ++ ) {
448456 this . _totalBytes += converted [ i ] . byteLength ;
0 commit comments