js-cfb/dist/cfb.min.js

3 lines
10 KiB
JavaScript
Raw Normal View History

/* cfb.js (C) 2013-2014 SheetJS -- http://sheetjs.com */
var Base64=function(){var map="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";return{decode:function(input,utf8){var o="";var c1,c2,c3;var e1,e2,e3,e4;input=input.replace(/[^A-Za-z0-9\+\/\=]/g,"");for(var i=0;i<input.length;){e1=map.indexOf(input.charAt(i++));e2=map.indexOf(input.charAt(i++));e3=map.indexOf(input.charAt(i++));e4=map.indexOf(input.charAt(i++));c1=e1<<2|e2>>4;c2=(e2&15)<<4|e3>>2;c3=(e3&3)<<6|e4;o+=String.fromCharCode(c1);if(e3!=64){o+=String.fromCharCode(c2)}if(e4!=64){o+=String.fromCharCode(c3)}}return o}}}();function s2a(s){if(typeof Buffer!=="undefined")return new Buffer(s,"binary");var w=s.split("").map(function(x){return x.charCodeAt(0)&255});return w}var __toBuffer;if(typeof Buffer!=="undefined"){Buffer.prototype.hexlify=function(){return this.toString("hex")};Buffer.prototype.utf16le=function(s,e){return this.toString("utf16le",s,e).replace(/\u0000/,"").replace(/[\u0001-\u0006]/,"!")};Buffer.prototype.utf8=function(s,e){return this.toString("utf8",s,e)};__toBuffer=function(bufs){return Buffer.concat(bufs[0])}}else{__toBuffer=function(bufs){var x=[];for(var i=0;i!=bufs[0].length;++i){x=x.concat(bufs[0][i])}return x}}var __readUInt8=function(b,idx){return b.readUInt8?b.readUInt8(idx):b[idx]};var __readUInt16LE=function(b,idx){return b.readUInt16LE?b.readUInt16LE(idx):b[idx+1]*(1<<8)+b[idx]};var __readInt16LE=function(b,idx){var u=__readUInt16LE(b,idx);if(!(u&32768))return u;return(65535-u+1)*-1};var __readUInt32LE=function(b,idx){return b.readUInt32LE?b.readUInt32LE(idx):b[idx+3]*(1<<24)+b[idx+2]*(1<<16)+b[idx+1]*(1<<8)+b[idx]};var __readInt32LE=function(b,idx){if(b.readInt32LE)return b.readInt32LE(idx);var u=__readUInt32LE(b,idx);if(!(u&2147483648))return u;return(4294967295-u+1)*-1};var __hexlify=function(b){return b.map(function(x){return(x<16?"0":"")+x.toString(16)}).join("")};var __utf16le=function(b,s,e){if(b.utf16le)return b.utf16le(s,e);var ss=[];for(var i=s;i<e;i+=2)ss.push(String.fromCharCode(__readUInt16LE(b,i)));return ss.join("").replace(/\u0000/,"").replace(/[\u0001-\u0006]/,"!")};var __utf8=function(b,s,e){if(b.utf8)return b.utf8(s,e);var ss=[];for(var i=s;i<e;i++)ss.push(String.fromCharCode(__readUInt8(b,i)));return ss.join("")};function bconcat(bufs){return typeof Buffer!=="undefined"?Buffer.concat(bufs):[].concat.apply([],bufs)}function ReadShift(size,t){var o,oo=[],w,vv;t=t||"u";switch(size){case 1:o=__readUInt8(this,this.l);break;case 2:o=(t==="u"?__readUInt16LE:__readInt16LE)(this,this.l);break;case 4:o=__readUInt32LE(this,this.l);break;case 8:case 16:o=this.toString("hex",this.l,this.l+size);break;case"utf8":size=t;o=__utf8(this,this.l,this.l+size);break;case"utf16le":size=2*t;o=__utf16le(this,this.l,this.l+size);break;case"cstr":size=0;o="";while((w=__readUInt8(this,this.l+size++))!==0)oo.push(String.fromCharCode(w));o=oo.join("");break;case"wstr":size=0;o="";while((w=__readUInt16LE(this,this.l+size))!==0){oo.push(String.fromCharCode(w));size+=2}size+=2;break}this.l+=size;return o}function CheckField(hexstr,fld){var b=this.slice(this.l,this.l+hexstr.length/2);var m=b.hexlify?b.hexlify():__hexlify(b);if(m!==hexstr)throw(fld||"")+"Expected "+hexstr+" saw "+m;this.l+=hexstr.length/2}function prep_blob(blob,pos){blob.read_shift=ReadShift.bind(blob);blob.chk=CheckField;blob.l=pos||0;var read=ReadShift.bind(blob),chk=CheckField.bind(blob);return[read,chk]}var CFB=function(){this.version="0.9.1";function parse(file){var mver=3;var ssz=512;var mssz=64;var nds=0;var nfs=0;var nmfs=0;var ndfs=0;var dir_start=0;var minifat_start=0;var difat_start=0;var ms_cutoff_size=4096;var minifat_store=0;var minifat_size=0;var fat_addrs=[];var blob=file.slice(0,512);prep_blob(blob);var read=ReadShift.bind(blob),chk=CheckField.bind(blob);var j=0,q;chk(HEADER_SIGNATURE,"Header Signature: ");chk(HEADER_CLSID,"CLSID: ");read(2);mver=read(2);switch(mver){case 3:ssz=512;break;case 4:ssz=4096;break;default:throw"Major Version: Expected 3 or 4 saw "+mver}var pos=blob.l;blob=file.slice(0,ssz);prep_blob(blob,pos);read=ReadShift.bind(blob);chk=CheckField.bind(blob);var header=file.slice(0,ssz
//# sourceMappingURL=dist/cfb.min.map