sheetjs-clone/bits/21_ziputils.js
SheetJS 54b528eaed version bump 0.9.0: merged ODS into XLSX
The optional ODS module has been completely merged into xlsx.js and the
corresponding scripts have been removed.  The new xlsx.js file provides
appropriate ODS exports, so fixing is a matter of removing ods.js refs.
2017-03-09 20:09:18 -05:00

63 lines
2.1 KiB
JavaScript

function getdatastr(data)/*:?string*/ {
if(!data) return null;
if(data.data) return debom(data.data);
if(data.asNodeBuffer && has_buf) return debom(data.asNodeBuffer().toString('binary'));
if(data.asBinary) return debom(data.asBinary());
if(data._data && data._data.getContent) return debom(cc2str(Array.prototype.slice.call(data._data.getContent(),0)));
return null;
}
function getdatabin(data) {
if(!data) return null;
if(data.data) return char_codes(data.data);
if(data.asNodeBuffer && has_buf) return data.asNodeBuffer();
if(data._data && data._data.getContent) {
var o = data._data.getContent();
if(typeof o == "string") return str2cc(o);
return Array.prototype.slice.call(o);
}
return null;
}
function getdata(data) { return (data && data.name.slice(-4) === ".bin") ? getdatabin(data) : getdatastr(data); }
/* Part 2 Section 10.1.2 "Mapping Content Types" Names are case-insensitive */
/* OASIS does not comment on filename case sensitivity */
function safegetzipfile(zip, file/*:string*/) {
var k = keys(zip.files);
var f = file.toLowerCase(), g = f.replace(/\//g,'\\');
for(var i=0; i<k.length; ++i) {
var n = k[i].toLowerCase();
if(f == n || g == n) return zip.files[k[i]];
}
return null;
}
function getzipfile(zip, file/*:string*/) {
var o = safegetzipfile(zip, file);
if(o == null) throw new Error("Cannot find file " + file + " in zip");
return o;
}
function getzipdata(zip, file/*:string*/, safe/*:?boolean*/) {
if(!safe) return getdata(getzipfile(zip, file));
if(!file) return null;
try { return getzipdata(zip, file); } catch(e) { return null; }
}
function getzipstr(zip, file/*:string*/, safe/*:?boolean*/)/*:?string*/ {
if(!safe) return getdatastr(getzipfile(zip, file));
if(!file) return null;
try { return getzipstr(zip, file); } catch(e) { return null; }
}
var _fs, jszip;
/*:: declare var JSZip:any; */
if(typeof JSZip !== 'undefined') jszip = JSZip;
if (typeof exports !== 'undefined') {
if (typeof module !== 'undefined' && module.exports) {
if(typeof jszip === 'undefined') jszip = require('./jszip.js');
_fs = require('fs');
}
}