@@ -85,6 +85,7 @@ const kNotCloneable = Symbol('kNotCloneable');
8585const disallowedTypeCharacters = / [ ^ \u{0020} - \u{007E} ] / u;
8686
8787let ReadableStream ;
88+ let TextDecoderStream ;
8889
8990const enc = new TextEncoder ( ) ;
9091let dec ;
@@ -100,6 +101,13 @@ function lazyReadableStream(options) {
100101 return new ReadableStream ( options ) ;
101102}
102103
104+ function lazyTextDecoderStream ( ) {
105+ // eslint-disable-next-line no-global-assign
106+ TextDecoderStream ??=
107+ require ( 'internal/webstreams/encoding' ) . TextDecoderStream ;
108+ return new TextDecoderStream ( ) ;
109+ }
110+
103111const { EOL } = require ( 'internal/constants' ) ;
104112
105113function isBlob ( object ) {
@@ -331,6 +339,17 @@ class Blob {
331339 throw new ERR_INVALID_THIS ( 'Blob' ) ;
332340 return createBlobReaderStream ( this [ kHandle ] . getReader ( ) ) ;
333341 }
342+
343+ /**
344+ * @returns {ReadableStream }
345+ */
346+ textStream ( ) {
347+ if ( ! isBlob ( this ) )
348+ throw new ERR_INVALID_THIS ( 'Blob' ) ;
349+ const stream = createBlobReaderStream ( this [ kHandle ] . getReader ( ) ) ;
350+ const decoder = lazyTextDecoderStream ( ) ;
351+ return stream . pipeThrough ( decoder ) ;
352+ }
334353}
335354
336355function TransferableBlob ( handle , length , type = '' ) {
@@ -364,6 +383,7 @@ ObjectDefineProperties(Blob.prototype, {
364383 type : kEnumerableProperty ,
365384 slice : kEnumerableProperty ,
366385 stream : kEnumerableProperty ,
386+ textStream : kEnumerableProperty ,
367387 text : kEnumerableProperty ,
368388 arrayBuffer : kEnumerableProperty ,
369389 bytes : kEnumerableProperty ,
0 commit comments