From 82d0faa18379701ba713ba27e123a90e2a214cb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jimmy=20Wa=CC=88rting?= Date: Mon, 20 Sep 2021 09:37:16 +0200 Subject: [PATCH] demos avoid readAsBinaryString [ci skip] --- demos/meteor/client/main.js | 5 ++--- demos/meteor/server/main.js | 5 ----- demos/parcel/index.html | 2 -- demos/parcel/index.js | 14 ++++---------- demos/rollup/app.js | 16 +++++----------- demos/rollup/rollup.html | 1 - demos/systemjs/main.js | 14 ++++---------- demos/systemjs/systemjs.html | 1 - 8 files changed, 15 insertions(+), 43 deletions(-) diff --git a/demos/meteor/client/main.js b/demos/meteor/client/main.js index 75b7e40..ac5adfc 100644 --- a/demos/meteor/client/main.js +++ b/demos/meteor/client/main.js @@ -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; diff --git a/demos/meteor/server/main.js b/demos/meteor/server/main.js index ea30a72..da4ab43 100644 --- a/demos/meteor/server/main.js +++ b/demos/meteor/server/main.js @@ -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); diff --git a/demos/parcel/index.html b/demos/parcel/index.html index 50ee3d0..11467f6 100644 --- a/demos/parcel/index.html +++ b/demos/parcel/index.html @@ -39,8 +39,6 @@ Output Format:
-Advanced Demo Options: -Use readAsBinaryString: (when available)

 
diff --git a/demos/parcel/index.js b/demos/parcel/index.js index 6e39000..5841528 100644 --- a/demos/parcel/index.js +++ b/demos/parcel/index.js @@ -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); }; })(); diff --git a/demos/rollup/app.js b/demos/rollup/app.js index 573e126..73f9158 100644 --- a/demos/rollup/app.js +++ b/demos/rollup/app.js @@ -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); }; })(); diff --git a/demos/rollup/rollup.html b/demos/rollup/rollup.html index f898fe4..86692f9 100644 --- a/demos/rollup/rollup.html +++ b/demos/rollup/rollup.html @@ -41,7 +41,6 @@ Output Format:
Advanced Demo Options: Use Web Workers: (when available) -Use readAsBinaryString: (when available)

 
diff --git a/demos/systemjs/main.js b/demos/systemjs/main.js index ecaa841..eb17fcd 100644 --- a/demos/systemjs/main.js +++ b/demos/systemjs/main.js @@ -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); }; })(); diff --git a/demos/systemjs/systemjs.html b/demos/systemjs/systemjs.html index 05fbde3..131032b 100644 --- a/demos/systemjs/systemjs.html +++ b/demos/systemjs/systemjs.html @@ -40,7 +40,6 @@ Output Format:
Advanced Demo Options: -Use readAsBinaryString: (when available)