2014-10-10 02:22:38 +00:00
|
|
|
function getdata(data) {
|
|
|
|
if(!data) return null;
|
|
|
|
if(data.data) return data.data;
|
|
|
|
if(data.asNodeBuffer && has_buf) return data.asNodeBuffer().toString('binary');
|
|
|
|
if(data.asBinary) return data.asBinary();
|
|
|
|
if(data._data && data._data.getContent) return cc2str(Array.prototype.slice.call(data._data.getContent(),0));
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
function safegetzipfile(zip, file) {
|
|
|
|
var f = file; if(zip.files[f]) return zip.files[f];
|
|
|
|
f = file.toLowerCase(); if(zip.files[f]) return zip.files[f];
|
|
|
|
f = f.replace(/\//g,'\\'); if(zip.files[f]) return zip.files[f];
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getzipfile(zip, file) {
|
|
|
|
var o = safegetzipfile(zip, file);
|
|
|
|
if(o == null) throw new Error("Cannot find file " + file + " in zip");
|
|
|
|
return o;
|
|
|
|
}
|
|
|
|
|
2017-02-03 20:50:45 +00:00
|
|
|
function getzipdata(zip, file, safe/*:?boolean*/) {
|
2014-10-10 02:22:38 +00:00
|
|
|
if(!safe) return getdata(getzipfile(zip, file));
|
|
|
|
if(!file) return null;
|
|
|
|
try { return getzipdata(zip, file); } catch(e) { return null; }
|
|
|
|
}
|
|
|
|
|
|
|
|
var _fs, jszip;
|
2017-02-03 20:50:45 +00:00
|
|
|
/*:: declare var JSZip:any; */
|
2014-10-10 02:22:38 +00:00
|
|
|
if(typeof JSZip !== 'undefined') jszip = JSZip;
|
|
|
|
if (typeof exports !== 'undefined') {
|
|
|
|
if (typeof module !== 'undefined' && module.exports) {
|
2017-02-10 19:23:01 +00:00
|
|
|
if(typeof jszip === 'undefined') jszip = require('./js'+'zip');
|
2014-10-10 02:22:38 +00:00
|
|
|
_fs = require('f'+'s');
|
|
|
|
}
|
|
|
|
}
|