}
async function openURL(url) {
+ freeDocument();
try {
let response = await fetch(url);
if (!response.ok)
}
function openFile(file) {
+ freeDocument();
if (file instanceof File) {
initDocument(file, file.name)
.catch(error => showDocumentError("initDocument", error));
}
}
-async function initDocument(blob, magic) {
+function freeDocument() {
if (doc) {
mupdf.freeDocument(doc);
doc = 0;
dirty = [];
searchDirty = [];
}
-
emptyNode(document.getElementById("pages"));
emptyNode(document.getElementById("outline"));
+}
+async function initDocument(blob, magic) {
let data = await blob.arrayBuffer();
doc = await mupdf.openDocument(data, magic);
pageCount = await mupdf.countPages(doc);