From ca22658b8c04d11a5210ab3b0ad526d4a26c595c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jimmy=20W=C3=A4rting?= Date: Mon, 19 Nov 2018 21:44:54 +0100 Subject: [PATCH] README use typed array (fixes #1362) > The use of readAsArrayBuffer() is preferred over readAsBinaryString(), > which is provided for backwards compatibility. --- README.md | 20 +++++++------------- docbits/20_import.md | 20 +++++++------------- misc/docs/README.md | 20 +++++++------------- 3 files changed, 21 insertions(+), 39 deletions(-) diff --git a/README.md b/README.md index 3b784a6..1e3586c 100644 --- a/README.md +++ b/README.md @@ -413,24 +413,20 @@ req.send();
Browser drag-and-drop (click to show) -Drag-and-drop uses the HTML5 `FileReader` API, loading the data with -`readAsBinaryString` or `readAsArrayBuffer`. Since not all browsers support the -full `FileReader` API, dynamic feature tests are highly recommended. +Drag-and-drop uses the HTML5 `FileReader` API. ```js -var rABS = true; // true: readAsBinaryString ; false: readAsArrayBuffer function handleDrop(e) { e.stopPropagation(); e.preventDefault(); var files = e.dataTransfer.files, f = files[0]; var reader = new FileReader(); reader.onload = function(e) { - var data = e.target.result; - if(!rABS) data = new Uint8Array(data); - var workbook = XLSX.read(data, {type: rABS ? 'binary' : 'array'}); + var data = new Uint8Array(e.target.result); + var workbook = XLSX.read(data, {type: 'array'}); /* DO SOMETHING WITH workbook HERE */ }; - if(rABS) reader.readAsBinaryString(f); else reader.readAsArrayBuffer(f); + reader.readAsArrayBuffer(f); } drop_dom_element.addEventListener('drop', handleDrop, false); ``` @@ -444,18 +440,16 @@ Data from file input elements can be processed using the same `FileReader` API as in the drag-and-drop example: ```js -var rABS = true; // true: readAsBinaryString ; false: readAsArrayBuffer function handleFile(e) { var files = e.target.files, f = files[0]; var reader = new FileReader(); reader.onload = function(e) { - var data = e.target.result; - if(!rABS) data = new Uint8Array(data); - var workbook = XLSX.read(data, {type: rABS ? 'binary' : 'array'}); + var data = new Uint8Array(e.target.result); + var workbook = XLSX.read(data, {type: 'array'}); /* DO SOMETHING WITH workbook HERE */ }; - if(rABS) reader.readAsBinaryString(f); else reader.readAsArrayBuffer(f); + reader.readAsArrayBuffer(f); } input_dom_element.addEventListener('change', handleFile, false); ``` diff --git a/docbits/20_import.md b/docbits/20_import.md index 9b9a9a1..08dc1f8 100644 --- a/docbits/20_import.md +++ b/docbits/20_import.md @@ -101,24 +101,20 @@ req.send();
Browser drag-and-drop (click to show) -Drag-and-drop uses the HTML5 `FileReader` API, loading the data with -`readAsBinaryString` or `readAsArrayBuffer`. Since not all browsers support the -full `FileReader` API, dynamic feature tests are highly recommended. +Drag-and-drop uses the HTML5 `FileReader` API. ```js -var rABS = true; // true: readAsBinaryString ; false: readAsArrayBuffer function handleDrop(e) { e.stopPropagation(); e.preventDefault(); var files = e.dataTransfer.files, f = files[0]; var reader = new FileReader(); reader.onload = function(e) { - var data = e.target.result; - if(!rABS) data = new Uint8Array(data); - var workbook = XLSX.read(data, {type: rABS ? 'binary' : 'array'}); + var data = new Uint8Array(e.target.result); + var workbook = XLSX.read(data, {type: 'array'}); /* DO SOMETHING WITH workbook HERE */ }; - if(rABS) reader.readAsBinaryString(f); else reader.readAsArrayBuffer(f); + reader.readAsArrayBuffer(f); } drop_dom_element.addEventListener('drop', handleDrop, false); ``` @@ -132,18 +128,16 @@ Data from file input elements can be processed using the same `FileReader` API as in the drag-and-drop example: ```js -var rABS = true; // true: readAsBinaryString ; false: readAsArrayBuffer function handleFile(e) { var files = e.target.files, f = files[0]; var reader = new FileReader(); reader.onload = function(e) { - var data = e.target.result; - if(!rABS) data = new Uint8Array(data); - var workbook = XLSX.read(data, {type: rABS ? 'binary' : 'array'}); + var data = new Uint8Array(e.target.result); + var workbook = XLSX.read(data, {type: 'array'}); /* DO SOMETHING WITH workbook HERE */ }; - if(rABS) reader.readAsBinaryString(f); else reader.readAsArrayBuffer(f); + reader.readAsArrayBuffer(f); } input_dom_element.addEventListener('change', handleFile, false); ``` diff --git a/misc/docs/README.md b/misc/docs/README.md index e0bbb8c..3bc4945 100644 --- a/misc/docs/README.md +++ b/misc/docs/README.md @@ -384,24 +384,20 @@ req.send(); -Drag-and-drop uses the HTML5 `FileReader` API, loading the data with -`readAsBinaryString` or `readAsArrayBuffer`. Since not all browsers support the -full `FileReader` API, dynamic feature tests are highly recommended. +Drag-and-drop uses the HTML5 `FileReader` API. ```js -var rABS = true; // true: readAsBinaryString ; false: readAsArrayBuffer function handleDrop(e) { e.stopPropagation(); e.preventDefault(); var files = e.dataTransfer.files, f = files[0]; var reader = new FileReader(); reader.onload = function(e) { - var data = e.target.result; - if(!rABS) data = new Uint8Array(data); - var workbook = XLSX.read(data, {type: rABS ? 'binary' : 'array'}); + var data = new Uint8Array(e.target.result); + var workbook = XLSX.read(data, {type: 'array'}); /* DO SOMETHING WITH workbook HERE */ }; - if(rABS) reader.readAsBinaryString(f); else reader.readAsArrayBuffer(f); + reader.readAsArrayBuffer(f); } drop_dom_element.addEventListener('drop', handleDrop, false); ``` @@ -412,18 +408,16 @@ Data from file input elements can be processed using the same `FileReader` API as in the drag-and-drop example: ```js -var rABS = true; // true: readAsBinaryString ; false: readAsArrayBuffer function handleFile(e) { var files = e.target.files, f = files[0]; var reader = new FileReader(); reader.onload = function(e) { - var data = e.target.result; - if(!rABS) data = new Uint8Array(data); - var workbook = XLSX.read(data, {type: rABS ? 'binary' : 'array'}); + var data = new Uint8Array(e.target.result); + var workbook = XLSX.read(data, {type: 'array'}); /* DO SOMETHING WITH workbook HERE */ }; - if(rABS) reader.readAsBinaryString(f); else reader.readAsArrayBuffer(f); + reader.readAsArrayBuffer(f); } input_dom_element.addEventListener('change', handleFile, false); ```