@@ -283,13 +283,48 @@ assert.throws(() => new Blob({}), {
283283} ) ( ) . then ( common . mustCall ( ) ) ;
284284
285285( async ( ) => {
286- const file = new Blob ( [ '<svg></svg>' ] , { type : 'image/svg+xml' } ) ;
287- const url = URL . createObjectURL ( file ) ;
288- const res = await fetch ( url ) ;
289- const blob = await res . blob ( ) ;
290- assert . strictEqual ( blob . size , 11 ) ;
291- assert . strictEqual ( blob . type , 'image/svg+xml' ) ;
292- assert . strictEqual ( await blob . text ( ) , '<svg></svg>' ) ;
286+ const b = new Blob ( [ 'A' , 'B' , 'C' ] ) ;
287+ const stream = b . stream ( ) ;
288+ const chunks = [ ] ;
289+ const decoder = new TextDecoder ( ) ;
290+ await stream . pipeTo (
291+ new WritableStream ( {
292+ write ( chunk ) {
293+ chunks . push ( decoder . decode ( chunk , { stream : true } ) ) ;
294+ } ,
295+ } )
296+ ) ;
297+ assert . strictEqual ( chunks . join ( '' ) , 'ABC' ) ;
298+ } ) ( ) . then ( common . mustCall ( ) ) ;
299+
300+ ( async ( ) => {
301+ // Ref: https://github.com/nodejs/node/issues/48668
302+ const chunks = [ ] ;
303+ const stream = new Blob ( [ 'Hello world' ] ) . stream ( ) ;
304+ const decoder = new TextDecoder ( ) ;
305+ await Promise . resolve ( ) ;
306+ await stream . pipeTo (
307+ new WritableStream ( {
308+ write ( chunk ) {
309+ chunks . push ( decoder . decode ( chunk , { stream : true } ) ) ;
310+ } ,
311+ } )
312+ ) ;
313+ assert . strictEqual ( chunks . join ( '' ) , 'Hello world' ) ;
314+ } ) ( ) . then ( common . mustCall ( ) ) ;
315+
316+ ( async ( ) => {
317+ // Ref: https://github.com/nodejs/node/issues/48668
318+ if ( common . hasCrypto ) {
319+ // Can only do this test if we have node built with crypto
320+ const file = new Blob ( [ '<svg></svg>' ] , { type : 'image/svg+xml' } ) ;
321+ const url = URL . createObjectURL ( file ) ;
322+ const res = await fetch ( url ) ;
323+ const blob = await res . blob ( ) ;
324+ assert . strictEqual ( blob . size , 11 ) ;
325+ assert . strictEqual ( blob . type , 'image/svg+xml' ) ;
326+ assert . strictEqual ( await blob . text ( ) , '<svg></svg>' ) ;
327+ }
293328} ) ( ) . then ( common . mustCall ( ) ) ;
294329
295330( async ( ) => {
0 commit comments