|
|
@@ -65,17 +65,17 @@ this.SingleFile = this.SingleFile || (() => {
|
|
|
try {
|
|
|
resourceContent = await fetchResource(resourceURL);
|
|
|
} catch (error) {
|
|
|
- return options && options.asDataURI ? { empty: true } : { content: "" };
|
|
|
+ return options && options.asDataURI ? "data:base64," : "";
|
|
|
}
|
|
|
if (resourceContent.status >= 400 && superFetch.hostFetch) {
|
|
|
try {
|
|
|
resourceContent = await superFetch.hostFetch(resourceURL);
|
|
|
} catch (error) {
|
|
|
- return options && options.asDataURI ? { empty: true } : { content: "" };
|
|
|
+ return options && options.asDataURI ? "data:base64," : "";
|
|
|
}
|
|
|
}
|
|
|
if (resourceContent.status >= 400) {
|
|
|
- return options && options.asDataURI ? { empty: true } : "";
|
|
|
+ return options && options.asDataURI ? "data:base64," : "";
|
|
|
}
|
|
|
let contentType = resourceContent.headers && resourceContent.headers.get("content-type");
|
|
|
let charSet;
|
|
|
@@ -99,16 +99,14 @@ this.SingleFile = this.SingleFile || (() => {
|
|
|
if (DEBUG) {
|
|
|
log(" // ENDED download url =", resourceURL, "delay =", Date.now() - startTime);
|
|
|
}
|
|
|
- const uInt8Array = new Uint8Array(buffer);
|
|
|
- const dataURI = "data:" + (contentType || "") + ";" + "base64," + base64.fromByteArray(uInt8Array);
|
|
|
+ const dataURI = "data:" + (contentType || "") + ";" + "base64," + base64.fromByteArray(new Uint8Array(buffer));
|
|
|
if (options.maxResourceSizeEnabled && buffer.byteLength > options.maxResourceSize * ONE_MB) {
|
|
|
- return { empty: true };
|
|
|
+ return "data:base64,";
|
|
|
} else {
|
|
|
- const hash = hex(await crypto.subtle.digest("SHA-256", uInt8Array));
|
|
|
- return { content: dataURI, hash };
|
|
|
+ return dataURI;
|
|
|
}
|
|
|
} catch (error) {
|
|
|
- return { empty: true };
|
|
|
+ return "data:base64,";
|
|
|
}
|
|
|
} else {
|
|
|
if (!charSet) {
|
|
|
@@ -127,13 +125,12 @@ this.SingleFile = this.SingleFile || (() => {
|
|
|
}
|
|
|
const textContent = (new TextDecoder(charSet)).decode(arrayBuffer);
|
|
|
if (options.maxResourceSizeEnabled && textContent.length > options.maxResourceSize * ONE_MB) {
|
|
|
- return { content: "" };
|
|
|
+ return "";
|
|
|
} else {
|
|
|
- const hash = hex(await crypto.subtle.digest("SHA-256", arrayBuffer));
|
|
|
- return { content: textContent, hash };
|
|
|
+ return textContent;
|
|
|
}
|
|
|
} catch (error) {
|
|
|
- return { content: "" };
|
|
|
+ return "";
|
|
|
}
|
|
|
}
|
|
|
}
|