browserify demo avoid readAsBinaryString [ci skip]

This commit is contained in:
Jimmy Wärting 2021-09-11 11:13:50 +02:00
parent 96eee3c7eb
commit 50754f02be
2 changed files with 5 additions and 12 deletions

@ -95,10 +95,6 @@ var b64it = window.b64it = (function() {
})();
var do_file = (function() {
var rABS = typeof FileReader !== "undefined" && (FileReader.prototype||{}).readAsBinaryString;
var domrabs = document.getElementsByName("userabs")[0];
if(!rABS) domrabs.disabled = !(domrabs.checked = false);
var use_worker = typeof Worker !== 'undefined';
var domwork = document.getElementsByName("useworker")[0];
if(!use_worker) domwork.disabled = !(domwork.checked = false);
@ -112,23 +108,21 @@ var do_file = (function() {
case XW.msg: cb(JSON.parse(e.data.d)); break;
}
};
worker.postMessage({d:data,b:rABS?'binary':'array'});
worker.postMessage({d:data,b:'array'});
};
return function do_file(files) {
rABS = domrabs.checked;
use_worker = domwork.checked;
var f = files[0];
var reader = new FileReader();
reader.onload = function(e) {
if(typeof console !== 'undefined') console.log("onload", new Date(), rABS, use_worker);
if(typeof console !== 'undefined') console.log("onload", new Date(), use_worker);
var data = e.target.result;
if(!rABS) data = new Uint8Array(data);
data = new Uint8Array(data);
if(use_worker) xw(data, process_wb);
else process_wb(X.read(data, {type: rABS ? 'binary' : 'array'}));
else process_wb(X.read(data, {type: 'array'}));
};
if(rABS) reader.readAsBinaryString(f);
else reader.readAsArrayBuffer(f);
reader.readAsArrayBuffer(f);
};
})();

@ -41,7 +41,6 @@ Output Format: <select name="format" onchange="setfmt()">
<input type="button" id="dotext" value="Click here to process the base64 text" onclick="b64it();"/><br />
<b>Advanced Demo Options:</b>
Use Web Workers: (when available) <input type="checkbox" name="useworker" checked>
Use readAsBinaryString: (when available) <input type="checkbox" name="userabs" checked>
</pre>
<pre id="out"></pre>
<div id="htmlout"></div>