forked from sheetjs/sheetjs
demos avoid readAsBinaryString [ci skip]
This commit is contained in:
parent
37624cf990
commit
82d0faa183
@ -11,12 +11,11 @@ Template.sheetjs.events({
|
||||
/* "Browser file upload form element" from SheetJS README */
|
||||
const file = event.currentTarget.files[0];
|
||||
const reader = new FileReader();
|
||||
const rABS = !!reader.readAsBinaryString;
|
||||
reader.onload = function(e) {
|
||||
const data = e.target.result;
|
||||
const name = file.name;
|
||||
/* Meteor magic */
|
||||
Meteor.call(rABS ? 'uploadS' : 'uploadU', rABS ? data : new Uint8Array(data), name, function(err, wb) {
|
||||
Meteor.call('uploadU', new Uint8Array(data), name, function(err, wb) {
|
||||
if (err) throw err;
|
||||
/* load the first worksheet */
|
||||
const ws = wb.Sheets[wb.SheetNames[0]];
|
||||
@ -26,7 +25,7 @@ Template.sheetjs.events({
|
||||
document.getElementById('dnload').disabled = false;
|
||||
});
|
||||
};
|
||||
if(rABS) reader.readAsBinaryString(file); else reader.readAsArrayBuffer(file);
|
||||
reader.readAsArrayBuffer(file);
|
||||
},
|
||||
'click button' () {
|
||||
const html = document.getElementById('out').innerHTML;
|
||||
|
@ -5,11 +5,6 @@ import XLSX from 'xlsx';
|
||||
|
||||
Meteor.methods({
|
||||
/* read the data and return the workbook object to the frontend */
|
||||
uploadS: (bstr, name) => {
|
||||
check(bstr, String);
|
||||
check(name, String);
|
||||
return XLSX.read(bstr, { type: 'binary' });
|
||||
},
|
||||
uploadU: (ab, name) => {
|
||||
check(ab, Uint8Array);
|
||||
check(name, String);
|
||||
|
@ -39,8 +39,6 @@ Output Format: <select name="format" onchange="setfmt()">
|
||||
|
||||
<textarea id="b64data">... or paste a base64-encoding here</textarea>
|
||||
<input type="button" id="dotext" value="Click here to process the base64 text" onclick="b64it();"/><br />
|
||||
<b>Advanced Demo Options:</b>
|
||||
Use readAsBinaryString: (when available) <input type="checkbox" name="userabs" checked>
|
||||
</pre>
|
||||
<pre id="out"></pre>
|
||||
<div id="htmlout"></div>
|
||||
|
@ -88,22 +88,16 @@ 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);
|
||||
|
||||
return function do_file(files) {
|
||||
rABS = domrabs.checked;
|
||||
var f = files[0];
|
||||
var reader = new FileReader();
|
||||
reader.onload = function(e) {
|
||||
if(typeof console !== 'undefined') console.log("onload", new Date(), rABS);
|
||||
if(typeof console !== 'undefined') console.log("onload", new Date());
|
||||
var data = e.target.result;
|
||||
if(!rABS) data = new Uint8Array(data);
|
||||
process_wb(X.read(data, {type: rABS ? 'binary' : 'array'}));
|
||||
data = new Uint8Array(data);
|
||||
process_wb(X.read(data, {type: 'array'}));
|
||||
};
|
||||
if(rABS) reader.readAsBinaryString(f);
|
||||
else reader.readAsArrayBuffer(f);
|
||||
reader.readAsArrayBuffer(f);
|
||||
};
|
||||
})();
|
||||
|
||||
|
@ -88,10 +88,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);
|
||||
@ -105,23 +101,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>
|
||||
|
@ -88,22 +88,16 @@ 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);
|
||||
|
||||
return function do_file(files) {
|
||||
rABS = domrabs.checked;
|
||||
var f = files[0];
|
||||
var reader = new FileReader();
|
||||
reader.onload = function(e) {
|
||||
if(typeof console !== 'undefined') console.log("onload", new Date(), rABS);
|
||||
if(typeof console !== 'undefined') console.log("onload", new Date());
|
||||
var data = e.target.result;
|
||||
if(!rABS) data = new Uint8Array(data);
|
||||
process_wb(X.read(data, {type: rABS ? 'binary' : 'array'}));
|
||||
data = new Uint8Array(data);
|
||||
process_wb(X.read(data, {type: 'array'}));
|
||||
};
|
||||
if(rABS) reader.readAsBinaryString(f);
|
||||
else reader.readAsArrayBuffer(f);
|
||||
reader.readAsArrayBuffer(f);
|
||||
};
|
||||
})();
|
||||
|
||||
|
@ -40,7 +40,6 @@ Output Format: <select name="format" onchange="setfmt()">
|
||||
<textarea id="b64data">... or paste a base64-encoding here</textarea>
|
||||
<input type="button" id="dotext" value="Click here to process the base64 text" onclick="b64it();"/><br />
|
||||
<b>Advanced Demo Options:</b>
|
||||
Use readAsBinaryString: (when available) <input type="checkbox" name="userabs" checked>
|
||||
</pre>
|
||||
<pre id="out"></pre>
|
||||
<div id="htmlout"></div>
|
||||
|
Loading…
Reference in New Issue
Block a user