@@ -20,6 +20,12 @@ const fetchProgressDecorator = (total, fn) => {
2020const isFetchSupported = typeof fetch !== 'undefined' ;
2121const isReadableStreamSupported = isFetchSupported && typeof ReadableStream !== 'undefined' ;
2222
23+ // used only inside the fetch adapter
24+ const encodeText = isFetchSupported && ( typeof TextEncoder !== 'undefined' ?
25+ ( ( encoder ) => ( str ) => encoder . encode ( str ) ) ( new TextEncoder ( ) ) :
26+ async ( str ) => new Uint8Array ( await new Response ( str ) . arrayBuffer ( ) )
27+ ) ;
28+
2329const supportsRequestStream = isReadableStreamSupported && ( ( ) => {
2430 let duplexAccessed = false ;
2531
@@ -80,7 +86,7 @@ const getBodyLength = async (body) => {
8086 }
8187
8288 if ( utils . isString ( body ) ) {
83- return ( await new TextEncoder ( ) . encode ( body ) ) . byteLength ;
89+ return ( await encodeText ( body ) ) . byteLength ;
8490 }
8591}
8692
@@ -144,7 +150,7 @@ export default isFetchSupported && (async (config) => {
144150 data = trackStream ( _request . body , DEFAULT_CHUNK_SIZE , fetchProgressDecorator (
145151 requestContentLength ,
146152 progressEventReducer ( onUploadProgress )
147- ) ) ;
153+ ) , null , encodeText ) ;
148154 }
149155 }
150156
@@ -179,7 +185,7 @@ export default isFetchSupported && (async (config) => {
179185 trackStream ( response . body , DEFAULT_CHUNK_SIZE , onDownloadProgress && fetchProgressDecorator (
180186 responseContentLength ,
181187 progressEventReducer ( onDownloadProgress , true )
182- ) , isStreamResponse && onFinish ) ,
188+ ) , isStreamResponse && onFinish , encodeText ) ,
183189 options
184190 ) ;
185191 }
0 commit comments