Skip to content

Commit 27a1c42

Browse files
committed
Readability.
1 parent e78ac48 commit 27a1c42

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

tools/file_packager.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -960,34 +960,32 @@ def generate_js(data_target, data_files, metadata):
960960
fetch(packageName)
961961
.catch((cause) => Promise.reject(new Error(`Network Error: ${packageName}`, {cause}))) // If fetch fails, rewrite the error to include the failing URL & the cause.
962962
.then((response) => {
963-
964-
let loaded = 0;
965-
966963
if (!response.ok) {
967964
return Promise.reject(new Error(`${response.status}: ${response.url}`));
968965
}
969966
970-
// If we're using the polyfill, readers won't be available...
971-
if (!response.body && response.arrayBuffer) {
967+
if (!response.body && response.arrayBuffer) { // If we're using the polyfill, readers won't be available...
972968
response.arrayBuffer().then(callback);
973969
return;
974970
}
975971
976972
const reader = response.body.getReader();
977-
const headers = response.headers;
978-
979-
const size = Number(headers.get('Content-Length') ?? packageSize);
980-
const chunks = [];
981973
982974
const iterate = () => reader.read().then(handleChunk).catch((cause) => {
983975
return Promise.reject(new Error(`Unexpected error while handling : ${response.url} ${cause}`, {cause}));
984976
});
985977
978+
const chunks = [];
979+
const headers = response.headers;
980+
const total = Number(headers.get('Content-Length') ?? packageSize);
981+
982+
let loaded = 0;
983+
986984
const handleChunk = ({done, value}) => {
987985
if (!done) {
988986
chunks.push(value);
989987
loaded += value.length;
990-
Module['dataFileDownloads'][packageName] = {loaded, total: size};
988+
Module['dataFileDownloads'][packageName] = {loaded, total};
991989
992990
let totalLoaded = 0;
993991
let totalSize = 0;

0 commit comments

Comments
 (0)