Skip to content

Commit

Permalink
FileLoader: Support environments without ReadableStream (#23032)
Browse files Browse the repository at this point in the history
  • Loading branch information
gkjohnson authored Dec 21, 2021
1 parent e44441a commit 483cf30
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/loaders/FileLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ class FileLoader extends Loader {

}

if ( typeof ReadableStream === 'undefined' || response.body.getReader === undefined ) {

return response;

}

const callbacks = loading[ url ];
const reader = response.body.getReader();
const contentLength = response.headers.get( 'Content-Length' );
Expand All @@ -92,7 +98,7 @@ class FileLoader extends Loader {
let loaded = 0;

// periodically read data into the new stream tracking while download progress
return new ReadableStream( {
const stream = new ReadableStream( {
start( controller ) {

readData();
Expand Down Expand Up @@ -130,16 +136,16 @@ class FileLoader extends Loader {

} );

return new Response( stream );

} else {

throw Error( `fetch for "${response.url}" responded with ${response.status}: ${response.statusText}` );

}

} )
.then( stream => {

const response = new Response( stream );
.then( response => {

switch ( this.responseType ) {

Expand Down

0 comments on commit 483cf30

Please sign in to comment.