Skip to content

Commit

Permalink
Re-factor the fetchData helper function, in `src/display/display_ut…
Browse files Browse the repository at this point in the history
…ils.js` to be asynchronous
  • Loading branch information
Snuffleupagus authored and bh213 committed Jun 3, 2022
1 parent 0dd6c30 commit 6643042
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions src/display/display_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,18 @@ class DOMCanvasFactory extends BaseCanvasFactory {
}
}

function fetchData(url, asTypedArray) {
async function fetchData(url, asTypedArray = false) {
if (
(typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) ||
(isFetchSupported() && isValidFetchUrl(url, document.baseURI))
) {
return fetch(url).then(async response => {
if (!response.ok) {
throw new Error(response.statusText);
}
let data;
if (asTypedArray) {
data = new Uint8Array(await response.arrayBuffer());
} else {
data = stringToBytes(await response.text());
}
return data;
});
const response = await fetch(url);
if (!response.ok) {
throw new Error(response.statusText);
}
return asTypedArray
? new Uint8Array(await response.arrayBuffer())
: stringToBytes(await response.text());
}

// The Fetch API is not supported.
Expand Down

0 comments on commit 6643042

Please sign in to comment.