Bladeren bron

added debug logs

Gildas 7 jaren geleden
bovenliggende
commit
e0dffe69d7
1 gewijzigde bestanden met toevoegingen van 16 en 0 verwijderingen
  1. 16 0
      lib/single-file/single-file-browser.js

+ 16 - 0
lib/single-file/single-file-browser.js

@@ -23,6 +23,7 @@
 this.SingleFile = this.SingleFile || (() => {
 
 	const ONE_MB = 1024 * 1024;
+	const DEBUG = false;
 
 	// --------
 	// Download
@@ -53,6 +54,11 @@ this.SingleFile = this.SingleFile || (() => {
 
 	class Download {
 		static async getContent(resourceURL, options) {
+			let startTime;
+			if (DEBUG) {
+				startTime = Date.now();
+				log("  // STARTED download", resourceURL, options.asDataURI);
+			}
 			let resourceContent;
 			if (!fetchResource) {
 				fetchResource = typeof superFetch == "undefined" ? fetch : superFetch.fetch;
@@ -79,6 +85,9 @@ this.SingleFile = this.SingleFile || (() => {
 			if (options && options.asDataURI) {
 				try {
 					const buffer = await resourceContent.arrayBuffer();
+					if (DEBUG) {
+						log("  // ENDED   download", resourceURL, Date.now() - startTime);
+					}
 					const dataURI = "data:" + (contentType || "") + ";" + "base64," + base64.fromByteArray(new Uint8Array(buffer));
 					if (options.maxResourceSizeEnabled && buffer.byteLength > options.maxResourceSize * ONE_MB) {
 						return "data:base64,";
@@ -99,6 +108,9 @@ this.SingleFile = this.SingleFile || (() => {
 				}
 				try {
 					const arrayBuffer = await resourceContent.arrayBuffer();
+					if (DEBUG) {
+						log("  // ENDED   download", resourceURL, Date.now() - startTime);
+					}
 					const textContent = (new TextDecoder(charSet)).decode(arrayBuffer);
 					if (options.maxResourceSizeEnabled && textContent.length > options.maxResourceSize * ONE_MB) {
 						return "";
@@ -237,6 +249,10 @@ this.SingleFile = this.SingleFile || (() => {
 		}
 	}
 
+	function log(...args) {
+		console.log("S-File <browser>", ...args); // eslint-disable-line no-console
+	}
+
 	return { getClass: () => SingleFileCore.getClass(Download, DOM, URL) };
 
 })();