Re-factor the fetchData
helper function, in src/display/display_utils.js
to be asynchronous
This commit is contained in:
parent
b05a22d01b
commit
7b17dc8bfd
@ -46,23 +46,18 @@ class DOMCanvasFactory extends BaseCanvasFactory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function fetchData(url, asTypedArray) {
|
async function fetchData(url, asTypedArray = false) {
|
||||||
if (
|
if (
|
||||||
(typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) ||
|
(typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) ||
|
||||||
(isFetchSupported() && isValidFetchUrl(url, document.baseURI))
|
(isFetchSupported() && isValidFetchUrl(url, document.baseURI))
|
||||||
) {
|
) {
|
||||||
return fetch(url).then(async response => {
|
const response = await fetch(url);
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error(response.statusText);
|
throw new Error(response.statusText);
|
||||||
}
|
}
|
||||||
let data;
|
return asTypedArray
|
||||||
if (asTypedArray) {
|
? new Uint8Array(await response.arrayBuffer())
|
||||||
data = new Uint8Array(await response.arrayBuffer());
|
: stringToBytes(await response.text());
|
||||||
} else {
|
|
||||||
data = stringToBytes(await response.text());
|
|
||||||
}
|
|
||||||
return data;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// The Fetch API is not supported.
|
// The Fetch API is not supported.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user