indentation
This commit is contained in:
parent
458ae0c70c
commit
081f62d099
1 changed files with 48 additions and 48 deletions
96
lib/xlsx.js
96
lib/xlsx.js
|
|
@ -3226,54 +3226,54 @@ function blobify(data) {
|
||||||
if(Array.isArray(data)) return a2u(data);
|
if(Array.isArray(data)) return a2u(data);
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
/* write or download file */
|
/* write or download file */
|
||||||
function write_dl(fname, payload, enc) {
|
function write_dl(fname, payload, enc) {
|
||||||
/*global IE_SaveFile, Blob, navigator, saveAs, document, File, chrome */
|
/*global IE_SaveFile, Blob, navigator, saveAs, document, File, chrome */
|
||||||
if(typeof _fs !== 'undefined' && _fs.writeFileSync) return enc ? _fs.writeFileSync(fname, payload, enc) : _fs.writeFileSync(fname, payload);
|
if(typeof _fs !== 'undefined' && _fs.writeFileSync) return enc ? _fs.writeFileSync(fname, payload, enc) : _fs.writeFileSync(fname, payload);
|
||||||
if(typeof Deno !== 'undefined') {
|
if(typeof Deno !== 'undefined') {
|
||||||
/* in this spot, it's safe to assume typed arrays and TextEncoder/TextDecoder exist */
|
/* in this spot, it's safe to assume typed arrays and TextEncoder/TextDecoder exist */
|
||||||
if(enc && typeof payload == "string") switch(enc) {
|
if(enc && typeof payload == "string") switch(enc) {
|
||||||
case "utf8": payload = new TextEncoder(enc).encode(payload); break;
|
case "utf8": payload = new TextEncoder(enc).encode(payload); break;
|
||||||
case "binary": payload = s2ab(payload); break;
|
case "binary": payload = s2ab(payload); break;
|
||||||
/* TODO: binary equivalent */
|
/* TODO: binary equivalent */
|
||||||
default: throw new Error("Unsupported encoding " + enc);
|
default: throw new Error("Unsupported encoding " + enc);
|
||||||
}
|
}
|
||||||
return Deno.writeFileSync(fname, payload);
|
return Deno.writeFileSync(fname, payload);
|
||||||
}
|
}
|
||||||
var data = (enc == "utf8") ? utf8write(payload) : payload;
|
var data = (enc == "utf8") ? utf8write(payload) : payload;
|
||||||
if(typeof IE_SaveFile !== 'undefined') return IE_SaveFile(data, fname);
|
if(typeof IE_SaveFile !== 'undefined') return IE_SaveFile(data, fname);
|
||||||
if(typeof Blob !== 'undefined') {
|
if(typeof Blob !== 'undefined') {
|
||||||
var blob = new Blob([blobify(data)], {type:"application/octet-stream"});
|
var blob = new Blob([blobify(data)], {type:"application/octet-stream"});
|
||||||
if(typeof navigator !== 'undefined' && navigator.msSaveBlob) return navigator.msSaveBlob(blob, fname);
|
if(typeof navigator !== 'undefined' && navigator.msSaveBlob) return navigator.msSaveBlob(blob, fname);
|
||||||
if(typeof saveAs !== 'undefined') return saveAs(blob, fname);
|
if(typeof saveAs !== 'undefined') return saveAs(blob, fname);
|
||||||
if(typeof URL !== 'undefined' && typeof document !== 'undefined' && document.createElement && URL.createObjectURL) {
|
if(typeof URL !== 'undefined' && typeof document !== 'undefined' && document.createElement && URL.createObjectURL) {
|
||||||
var url = URL.createObjectURL(blob);
|
var url = URL.createObjectURL(blob);
|
||||||
if(typeof chrome === 'object' && typeof (chrome.downloads||{}).download == "function") {
|
if(typeof chrome === 'object' && typeof (chrome.downloads||{}).download == "function") {
|
||||||
if(URL.revokeObjectURL && typeof setTimeout !== 'undefined') setTimeout(function() { URL.revokeObjectURL(url); }, 60000);
|
if(URL.revokeObjectURL && typeof setTimeout !== 'undefined') setTimeout(function() { URL.revokeObjectURL(url); }, 60000);
|
||||||
return chrome.downloads.download({ url: url, filename: fname, saveAs: true });
|
return chrome.downloads.download({ url: url, filename: fname, saveAs: true });
|
||||||
}
|
}
|
||||||
var a = document.createElement("a");
|
var a = document.createElement("a");
|
||||||
if(a.download != null) {
|
if(a.download != null) {
|
||||||
a.download = fname; a.href = url; document.body.appendChild(a); a.click();
|
a.download = fname; a.href = url; document.body.appendChild(a); a.click();
|
||||||
document.body.removeChild(a);
|
document.body.removeChild(a);
|
||||||
if(URL.revokeObjectURL && typeof setTimeout !== 'undefined') setTimeout(function() { URL.revokeObjectURL(url); }, 60000);
|
if(URL.revokeObjectURL && typeof setTimeout !== 'undefined') setTimeout(function() { URL.revokeObjectURL(url); }, 60000);
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
} else if(typeof URL !== 'undefined' && !URL.createObjectURL && typeof chrome === 'object') {
|
} else if(typeof URL !== 'undefined' && !URL.createObjectURL && typeof chrome === 'object') {
|
||||||
/* manifest v3 extensions -- no URL.createObjectURL */
|
/* manifest v3 extensions -- no URL.createObjectURL */
|
||||||
var b64 = "data:application/octet-stream;base64," + Base64_encode_arr(new Uint8Array(blobify(data)));
|
var b64 = "data:application/octet-stream;base64," + Base64_encode_arr(new Uint8Array(blobify(data)));
|
||||||
return chrome.downloads.download({ url: b64, filename: fname, saveAs: true });
|
return chrome.downloads.download({ url: b64, filename: fname, saveAs: true });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// $FlowIgnore
|
// $FlowIgnore
|
||||||
if(typeof $ !== 'undefined' && typeof File !== 'undefined' && typeof Folder !== 'undefined') try { // extendscript
|
if(typeof $ !== 'undefined' && typeof File !== 'undefined' && typeof Folder !== 'undefined') try { // extendscript
|
||||||
// $FlowIgnore
|
// $FlowIgnore
|
||||||
var out = File(fname); out.open("w"); out.encoding = "binary";
|
var out = File(fname); out.open("w"); out.encoding = "binary";
|
||||||
if(Array.isArray(payload)) payload = a2s(payload);
|
if(Array.isArray(payload)) payload = a2s(payload);
|
||||||
out.write(payload); out.close(); return payload;
|
out.write(payload); out.close(); return payload;
|
||||||
} catch(e) { if(!e.message || e.message.indexOf("onstruct") == -1) throw e; }
|
} catch(e) { if(!e.message || e.message.indexOf("onstruct") == -1) throw e; }
|
||||||
throw new Error("cannot save file " + fname);
|
throw new Error("cannot save file " + fname);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* read binary data from file */
|
/* read binary data from file */
|
||||||
function read_binary(path) {
|
function read_binary(path) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue