Comparing version 0.13.1 to 0.13.2
12
cfb.js
@@ -164,3 +164,3 @@ /* cfb.js (C) 2013-present SheetJS -- http://sheetjs.com */ | ||
var exports = {}; | ||
exports.version = '0.13.1'; | ||
exports.version = '0.13.2'; | ||
/* [MS-CFB] 2.6.4 */ | ||
@@ -186,2 +186,4 @@ function namecmp(l, r) { | ||
} | ||
var fs; | ||
function get_fs() { return fs || (fs = require('fs')); } | ||
function parse(file, options) { | ||
@@ -484,5 +486,4 @@ var mver = 3; | ||
var fs; | ||
function read_file(filename, options) { | ||
if(fs == null) fs = require('fs'); | ||
get_fs(); | ||
return parse(fs.readFileSync(filename), options); | ||
@@ -762,2 +763,3 @@ } | ||
function write_file(cfb, filename, options) { | ||
get_fs(); | ||
var o = _write(cfb, options); | ||
@@ -776,3 +778,3 @@ fs.writeFileSync(filename, o); | ||
switch(options && options.type) { | ||
case "file": fs.writeFileSync(options.filename, (o)); return o; | ||
case "file": get_fs(); fs.writeFileSync(options.filename, (o)); return o; | ||
case "binary": return a2s(o); | ||
@@ -799,3 +801,3 @@ case "base64": return Base64.encode(a2s(o)); | ||
} | ||
file = ({name: filename(name)}); | ||
file = ({name: filename(name), type: 2}); | ||
cfb.FileIndex.push(file); | ||
@@ -802,0 +804,0 @@ cfb.FullPaths.push(fpath); |
@@ -164,3 +164,3 @@ /* cfb.js (C) 2013-present SheetJS -- http://sheetjs.com */ | ||
var exports = {}; | ||
exports.version = '0.13.1'; | ||
exports.version = '0.13.2'; | ||
/* [MS-CFB] 2.6.4 */ | ||
@@ -186,2 +186,4 @@ function namecmp(l, r) { | ||
} | ||
var fs; | ||
function get_fs() { return fs || (fs = require('fs')); } | ||
function parse(file, options) { | ||
@@ -484,5 +486,4 @@ var mver = 3; | ||
var fs; | ||
function read_file(filename, options) { | ||
if(fs == null) fs = require('fs'); | ||
get_fs(); | ||
return parse(fs.readFileSync(filename), options); | ||
@@ -762,2 +763,3 @@ } | ||
function write_file(cfb, filename, options) { | ||
get_fs(); | ||
var o = _write(cfb, options); | ||
@@ -776,3 +778,3 @@ fs.writeFileSync(filename, o); | ||
switch(options && options.type) { | ||
case "file": fs.writeFileSync(options.filename, (o)); return o; | ||
case "file": get_fs(); fs.writeFileSync(options.filename, (o)); return o; | ||
case "binary": return a2s(o); | ||
@@ -799,3 +801,3 @@ case "base64": return Base64.encode(a2s(o)); | ||
} | ||
file = ({name: filename(name)}); | ||
file = ({name: filename(name), type: 2}); | ||
cfb.FileIndex.push(file); | ||
@@ -802,0 +804,0 @@ cfb.FullPaths.push(fpath); |
/* cfb.js (C) 2013-present SheetJS -- http://sheetjs.com */ | ||
var Base64=function e(){var e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";return{encode:function(r){var t="";var i,n,a;var f,s,h,l;for(var o=0;o<r.length;){i=r.charCodeAt(o++);f=i>>2;n=r.charCodeAt(o++);s=(i&3)<<4|n>>4;a=r.charCodeAt(o++);h=(n&15)<<2|a>>6;l=a&63;if(isNaN(n)){h=l=64}else if(isNaN(a)){l=64}t+=e.charAt(f)+e.charAt(s)+e.charAt(h)+e.charAt(l)}return t},decode:function r(t){var i="";var n,a,f;var s,h,l,o;t=t.replace(/[^\w\+\/\=]/g,"");for(var c=0;c<t.length;){s=e.indexOf(t.charAt(c++));h=e.indexOf(t.charAt(c++));n=s<<2|h>>4;i+=String.fromCharCode(n);l=e.indexOf(t.charAt(c++));a=(h&15)<<4|l>>2;if(l!==64){i+=String.fromCharCode(a)}o=e.indexOf(t.charAt(c++));f=(l&3)<<6|o;if(o!==64){i+=String.fromCharCode(f)}}return i}}}();var has_buf=typeof Buffer!=="undefined"&&typeof process!=="undefined"&&typeof process.versions!=="undefined"&&process.versions.node;function new_raw_buf(e){return new(has_buf?Buffer:Array)(e)}var s2a=function r(e){if(has_buf)return new Buffer(e,"binary");return e.split("").map(function(e){return e.charCodeAt(0)&255})};var chr0=/\u0000/g,chr1=/[\u0001-\u0006]/;var __toBuffer=function(e){var r=[];for(var t=0;t<e[0].length;++t){r.push.apply(r,e[0][t])}return r};var ___toBuffer=__toBuffer;var __utf16le=function(e,r,t){var i=[];for(var n=r;n<t;n+=2)i.push(String.fromCharCode(__readUInt16LE(e,n)));return i.join("").replace(chr0,"")};var ___utf16le=__utf16le;var __hexlify=function(e,r,t){var i=[];for(var n=r;n<r+t;++n)i.push(("0"+e[n].toString(16)).slice(-2));return i.join("")};var ___hexlify=__hexlify;var __bconcat=function(e){if(Array.isArray(e[0]))return[].concat.apply([],e);var r=0,t=0;for(t=0;t<e.length;++t)r+=e[t].length;var i=new Uint8Array(r);for(t=0,r=0;t<e.length;r+=e[t].length,++t)i.set(e[t],r);return i};var bconcat=__bconcat;if(has_buf){__utf16le=function(e,r,t){if(!Buffer.isBuffer(e))return ___utf16le(e,r,t);return e.toString("utf16le",r,t).replace(chr0,"")};__hexlify=function(e,r,t){return Buffer.isBuffer(e)?e.toString("hex",r,r+t):___hexlify(e,r,t)};__toBuffer=function(e){return e[0].length>0&&Buffer.isBuffer(e[0][0])?Buffer.concat(e[0]):___toBuffer(e)};s2a=function(e){return new Buffer(e,"binary")};bconcat=function(e){return Buffer.isBuffer(e[0])?Buffer.concat(e):__bconcat(e)}}var __readUInt8=function(e,r){return e[r]};var __readUInt16LE=function(e,r){return e[r+1]*(1<<8)+e[r]};var __readInt16LE=function(e,r){var t=e[r+1]*(1<<8)+e[r];return t<32768?t:(65535-t+1)*-1};var __readUInt32LE=function(e,r){return e[r+3]*(1<<24)+(e[r+2]<<16)+(e[r+1]<<8)+e[r]};var __readInt32LE=function(e,r){return(e[r+3]<<24)+(e[r+2]<<16)+(e[r+1]<<8)+e[r]};function ReadShift(e,r){var t,i,n=0;switch(e){case 1:t=__readUInt8(this,this.l);break;case 2:t=(r!=="i"?__readUInt16LE:__readInt16LE)(this,this.l);break;case 4:t=__readInt32LE(this,this.l);break;case 16:n=2;i=__hexlify(this,this.l,e);}this.l+=e;if(n===0)return t;return i}var __writeUInt32LE=function(e,r,t){e[t]=r&255;e[t+1]=r>>>8&255;e[t+2]=r>>>16&255;e[t+3]=r>>>24&255};var __writeInt32LE=function(e,r,t){e[t]=r&255;e[t+1]=r>>8&255;e[t+2]=r>>16&255;e[t+3]=r>>24&255};function WriteShift(e,r,t){var i=0,n=0;switch(t){case"hex":for(;n<e;++n){this[this.l++]=parseInt(r.slice(2*n,2*n+2),16)||0}return this;case"utf16le":var a=this.l+e;for(n=0;n<Math.min(r.length,e);++n){var f=r.charCodeAt(n);this[this.l++]=f&255;this[this.l++]=f>>8}while(this.l<a)this[this.l++]=0;return this;}switch(e){case 1:i=1;this[this.l]=r&255;break;case 2:i=2;this[this.l]=r&255;r>>>=8;this[this.l+1]=r&255;break;case 4:i=4;__writeUInt32LE(this,r,this.l);break;case-4:i=4;__writeInt32LE(this,r,this.l);break;}this.l+=i;return this}function CheckField(e,r){var t=__hexlify(this,this.l,e.length>>1);if(t!==e)throw new Error(r+"Expected "+e+" saw "+t);this.l+=e.length>>1}function prep_blob(e,r){e.l=r;e.read_shift=ReadShift;e.chk=CheckField;e.write_shift=WriteShift}function new_buf(e){var r=new_raw_buf(e);prep_blob(r,0);return r}var CFB=function t(){var e={};e.version="0.13.1";function r(e,r){var t=e.split("/"),i=r.split("/");for(var n=0,a=0,f=Math.min(t.length,i.length);n<f;++n){if(a=t[n].length-i[n].length)return a;if(t[n]!=i[n])return t[n]<i[n]?-1:1}return t.length-i.length}function t(e){if(e.charAt(e.length-1)=="/")return e.slice(0,-1).indexOf("/")===-1?e:t(e.slice(0,-1));var r=e.lastIndexOf("/");return r===-1?e:e.slice(0,r+1)}function i(e){if(e.charAt(e.length-1)=="/")return i(e.slice(0,-1));var r=e.lastIndexOf("/");return r===-1?e:e.slice(r+1)}function n(e,r){var t=3;var i=512;var n=0;var o=0;var _=0;var d=0;var v=0;var w=[];var p=e.slice(0,512);prep_blob(p,0);var F=a(p);t=F[0];switch(t){case 3:i=512;break;case 4:i=4096;break;default:throw new Error("Major Version: Expected 3 or 4 saw "+t);}if(i!==512){p=e.slice(0,i);prep_blob(p,28)}var g=e.slice(0,i);f(p,t);var I=p.read_shift(4,"i");if(t===3&&I!==0)throw new Error("# Directory Sectors: Expected 0 saw "+I);p.l+=4;_=p.read_shift(4,"i");p.l+=4;p.chk("00100000","Mini Stream Cutoff Size: ");d=p.read_shift(4,"i");n=p.read_shift(4,"i");v=p.read_shift(4,"i");o=p.read_shift(4,"i");for(var b=-1,x=0;x<109;++x){b=p.read_shift(4,"i");if(b<0)break;w[x]=b}var C=s(e,i);l(v,o,C,i,w);var y=c(C,_,w,i);y[_].name="!Directory";if(n>0&&d!==E)y[d].name="!MiniFAT";y[w[0]].name="!FAT";y.fat_addrs=w;y.ssz=i;var S={},A=[],m=[],B=[],k={};u(_,y,C,A,n,S,m);h(m,k,B,A);A.shift();var L={FileIndex:m,FullPaths:B,FullPathDir:k};if(r&&r.raw)L.raw={header:g,sectors:C};return L}function a(e){e.chk(C,"Header Signature: ");e.chk(S,"CLSID: ");var r=e.read_shift(2,"u");return[e.read_shift(2,"u"),r]}function f(e,r){var t=9;e.l+=2;switch(t=e.read_shift(2)){case 9:if(r!=3)throw new Error("Sector Shift: Expected 9 saw "+t);break;case 12:if(r!=4)throw new Error("Sector Shift: Expected 12 saw "+t);break;default:throw new Error("Sector Shift: Expected 9 or 12 saw "+t);}e.chk("0600","Mini Sector Shift: ");e.chk("000000000000","Reserved: ")}function s(e,r){var t=Math.ceil(e.length/r)-1;var i=[];for(var n=1;n<t;++n)i[n-1]=e.slice(n*r,(n+1)*r);i[t-1]=e.slice(t*r);return i}function h(e,r,t,i){var n=0,a=0,f=0,s=0,h=0,l=i.length;var o=[],c=[];for(;n<l;++n){o[n]=c[n]=n;t[n]=i[n]}for(;h<c.length;++h){n=c[h];a=e[n].L;f=e[n].R;s=e[n].C;if(o[n]===n){if(a!==-1&&o[a]!==a)o[n]=o[a];if(f!==-1&&o[f]!==f)o[n]=o[f]}if(s!==-1)o[s]=n;if(a!==-1){o[a]=o[n];c.push(a)}if(f!==-1){o[f]=o[n];c.push(f)}}for(n=1;n!==l;++n)if(o[n]===n){if(f!==-1&&o[f]!==f)o[n]=o[f];else if(a!==-1&&o[a]!==a)o[n]=o[a]}for(n=1;n<l;++n){if(e[n].type===0)continue;h=o[n];if(h===0)t[n]=t[0]+"/"+t[n];else while(h!==0&&h!==o[h]){t[n]=t[h]+"/"+t[n];h=o[h]}o[n]=0}t[0]+="/";for(n=1;n<l;++n){if(e[n].type!==2)t[n]+="/";r[t[n]]=e[n]}}function l(e,r,t,i,n){var a=E;if(e===E){if(r!==0)throw new Error("DIFAT chain shorter than expected")}else if(e!==-1){var f=t[e],s=(i>>>2)-1;if(!f)return;for(var h=0;h<s;++h){if((a=__readInt32LE(f,h*4))===E)break;n.push(a)}l(__readInt32LE(f,i-4),r-1,t,i,n)}}function o(e,r,t,i,n){var a=[],f=[];if(!n)n=[];var s=i-1,h=0,l=0;for(h=r;h>=0;){n[h]=true;a[a.length]=h;f.push(e[h]);var o=t[Math.floor(h*4/i)];l=h*4&s;if(i<4+l)throw new Error("FAT boundary crossed: "+h+" 4 "+i);if(!e[o])break;h=__readInt32LE(e[o],l)}return{nodes:a,data:__toBuffer([f])}}function c(e,r,t,i){var n=e.length,a=[];var f=[],s=[],h=[];var l=i-1,o=0,c=0,u=0,_=0;for(o=0;o<n;++o){s=[];u=o+r;if(u>=n)u-=n;if(f[u])continue;h=[];for(c=u;c>=0;){f[c]=true;s[s.length]=c;h.push(e[c]);var d=t[Math.floor(c*4/i)];_=c*4&l;if(i<4+_)throw new Error("FAT boundary crossed: "+c+" 4 "+i);if(!e[d])break;c=__readInt32LE(e[d],_)}a[u]={nodes:s,data:__toBuffer([h])}}return a}function u(e,r,t,i,n,a,f){var s=0,h=i.length?2:0;var l=r[e].data;var c=0,u=0,d;for(;c<l.length;c+=128){var v=l.slice(c,c+128);prep_blob(v,64);u=v.read_shift(2);d=__utf16le(v,0,u-h);i.push(d);var w={name:d,type:v.read_shift(1),color:v.read_shift(1),L:v.read_shift(4,"i"),R:v.read_shift(4,"i"),C:v.read_shift(4,"i"),clsid:v.read_shift(16),state:v.read_shift(4,"i"),start:0,size:0};var p=v.read_shift(2)+v.read_shift(2)+v.read_shift(2)+v.read_shift(2);if(p!==0)w.ct=_(v,v.l-8);var F=v.read_shift(2)+v.read_shift(2)+v.read_shift(2)+v.read_shift(2);if(F!==0)w.mt=_(v,v.l-8);w.start=v.read_shift(4,"i");w.size=v.read_shift(4,"i");if(w.size<0&&w.start<0){w.size=w.type=0;w.start=E;w.name=""}if(w.type===5){s=w.start;if(n>0&&s!==E)r[s].name="!StreamData"}else if(w.size>=4096){w.storage="fat";if(r[w.start]===undefined)r[w.start]=o(t,w.start,r.fat_addrs,r.ssz);r[w.start].name=w.name;w.content=r[w.start].data.slice(0,w.size);prep_blob(w.content,0)}else{w.storage="minifat";if(s!==E&&w.start!==E&&r[s]){w.content=r[s].data.slice(w.start*x,w.start*x+w.size);prep_blob(w.content,0)}}a[d]=w;f.push(w)}}function _(e,r){return new Date((__readUInt32LE(e,r+4)/1e7*Math.pow(2,32)+__readUInt32LE(e,r)/1e7-11644473600)*1e3)}var d;function v(e,r){if(d==null)d=require("fs");return n(d.readFileSync(e),r)}function w(e,r){switch(r&&r.type||"base64"){case"file":return v(e,r);case"base64":return n(s2a(Base64.decode(e)),r);case"binary":return n(s2a(e),r);}return n(e,r)}function p(e,r){var t=r||{},i=t.root||"Root Entry";if(!e.FullPaths)e.FullPaths=[];if(!e.FileIndex)e.FileIndex=[];if(e.FullPaths.length!==e.FileIndex.length)throw new Error("inconsistent CFB structure");if(e.FullPaths.length===0){e.FullPaths[0]=i+"/";e.FileIndex[0]={name:i,type:5}}if(t.CLSID)e.FileIndex[0].clsid=t.CLSID;F(e)}function F(e){var r="Sh33tJ5";if(CFB.find(e,"/"+r))return;var t=new_buf(4);t[0]=55;t[1]=t[3]=50;t[2]=54;e.FileIndex.push({name:r,type:2,content:t,size:4,L:69,R:69,C:69});e.FullPaths.push(e.FullPaths[0]+r);g(e)}function g(e,n){p(e);var a=false,f=false;for(var s=e.FullPaths.length-1;s>=0;--s){var h=e.FileIndex[s];switch(h.type){case 0:if(f)a=true;else{e.FileIndex.pop();e.FullPaths.pop()}break;case 1:;case 2:;case 5:f=true;if(isNaN(h.R*h.L*h.C))a=true;if(h.R>-1&&h.L>-1&&h.R==h.L)a=true;break;default:a=true;break;}}if(!a&&!n)return;var l=new Date(1987,1,19),o=0;var c=[];for(s=0;s<e.FullPaths.length;++s){if(e.FileIndex[s].type===0)continue;c.push([e.FullPaths[s],e.FileIndex[s]])}for(s=0;s<c.length;++s){var u=t(c[s][0]);f=false;for(o=0;o<c.length;++o)if(c[o][0]===u)f=true;if(!f)c.push([u,{name:i(u).replace("/",""),type:1,clsid:S,ct:l,mt:l,content:null}])}c.sort(function(e,t){return r(e[0],t[0])});e.FullPaths=[];e.FileIndex=[];for(s=0;s<c.length;++s){e.FullPaths[s]=c[s][0];e.FileIndex[s]=c[s][1]}for(s=0;s<c.length;++s){var _=e.FileIndex[s];var d=e.FullPaths[s];_.name=i(d).replace("/","");_.L=_.R=_.C=-(_.color=1);_.size=_.content?_.content.length:0;_.start=0;_.clsid=_.clsid||S;if(s===0){_.C=c.length>1?1:-1;_.size=0;_.type=5}else if(d.slice(-1)=="/"){for(o=s+1;o<c.length;++o)if(t(e.FullPaths[o])==d)break;_.C=o>=c.length?-1:o;for(o=s+1;o<c.length;++o)if(t(e.FullPaths[o])==t(d))break;_.R=o>=c.length?-1:o;_.type=1}else{if(t(e.FullPaths[s+1]||"")==t(d))_.R=s+1;_.type=2}}}function I(e,r){g(e);var t=function(e){var r=0,t=0;for(var i=0;i<e.FileIndex.length;++i){var n=e.FileIndex[i];if(!n.content)continue;var a=n.content.length;if(a===0){}else if(a<4096)r+=a+63>>6;else t+=a+511>>9}var f=e.FullPaths.length+3>>2;var s=r+7>>3;var h=r+127>>7;var l=s+t+f+h;var o=l+127>>7;var c=o<=109?0:Math.ceil((o-109)/127);while(l+o+c+127>>7>o)c=++o<=109?0:Math.ceil((o-109)/127);var u=[1,c,o,h,f,t,r,0];e.FileIndex[0].size=r<<6;u[7]=(e.FileIndex[0].start=u[0]+u[1]+u[2]+u[3]+u[4]+u[5])+(u[6]+7>>3);return u}(e);var i=new_buf(t[7]<<9);var n=0,a=0;{for(n=0;n<8;++n)i.write_shift(1,y[n]);for(n=0;n<8;++n)i.write_shift(2,0);i.write_shift(2,62);i.write_shift(2,3);i.write_shift(2,65534);i.write_shift(2,9);i.write_shift(2,6);for(n=0;n<3;++n)i.write_shift(2,0);i.write_shift(4,0);i.write_shift(4,t[2]);i.write_shift(4,t[0]+t[1]+t[2]+t[3]-1);i.write_shift(4,0);i.write_shift(4,1<<12);i.write_shift(4,t[3]?t[0]+t[1]+t[2]-1:E);i.write_shift(4,t[3]);i.write_shift(-4,t[1]?t[0]-1:E);i.write_shift(4,t[1]);for(n=0;n<109;++n)i.write_shift(-4,n<t[2]?t[1]+n:-1)}if(t[1]){for(a=0;a<t[1];++a){for(;n<236+a*127;++n)i.write_shift(-4,n<t[2]?t[1]+n:-1);i.write_shift(-4,a===t[1]-1?E:a+1)}}var f=function(e){for(a+=e;n<a-1;++n)i.write_shift(-4,n+1);if(e){++n;i.write_shift(-4,E)}};a=n=0;for(a+=t[1];n<a;++n)i.write_shift(-4,A.DIFSECT);for(a+=t[2];n<a;++n)i.write_shift(-4,A.FATSECT);f(t[3]);f(t[4]);var s=0,h=0;var l=e.FileIndex[0];for(;s<e.FileIndex.length;++s){l=e.FileIndex[s];if(!l.content)continue;h=l.content.length;if(h<4096)continue;l.start=a;f(h+511>>9)}f(t[6]+7>>3);while(i.l&511)i.write_shift(-4,A.ENDOFCHAIN);a=n=0;for(s=0;s<e.FileIndex.length;++s){l=e.FileIndex[s];if(!l.content)continue;h=l.content.length;if(!h||h>=4096)continue;l.start=a;f(h+63>>6)}while(i.l&511)i.write_shift(-4,A.ENDOFCHAIN);for(n=0;n<t[4]<<2;++n){var o=e.FullPaths[n];if(!o||o.length===0){for(s=0;s<17;++s)i.write_shift(4,0);for(s=0;s<3;++s)i.write_shift(4,-1);for(s=0;s<12;++s)i.write_shift(4,0);continue}l=e.FileIndex[n];if(n===0)l.start=l.size?l.start-1:E;h=2*(l.name.length+1);i.write_shift(64,l.name,"utf16le");i.write_shift(2,h);i.write_shift(1,l.type);i.write_shift(1,l.color);i.write_shift(-4,l.L);i.write_shift(-4,l.R);i.write_shift(-4,l.C);if(!l.clsid)for(s=0;s<4;++s)i.write_shift(4,0);else i.write_shift(16,l.clsid,"hex");i.write_shift(4,l.state||0);i.write_shift(4,0);i.write_shift(4,0);i.write_shift(4,0);i.write_shift(4,0);i.write_shift(4,l.start);i.write_shift(4,l.size);i.write_shift(4,0)}for(n=1;n<e.FileIndex.length;++n){l=e.FileIndex[n];if(l.size>=4096){i.l=l.start+1<<9;for(s=0;s<l.size;++s)i.write_shift(1,l.content[s]);for(;s&511;++s)i.write_shift(1,0)}}for(n=1;n<e.FileIndex.length;++n){l=e.FileIndex[n];if(l.size>0&&l.size<4096){for(s=0;s<l.size;++s)i.write_shift(1,l.content[s]);for(;s&63;++s)i.write_shift(1,0)}}while(i.l<i.length)i.write_shift(1,0);return i}function b(e,r){var t=e.FullPaths.map(function(e){return e.toUpperCase()});var i=t.map(function(e){var r=e.split("/");return r[r.length-(e.slice(-1)=="/"?2:1)]});var n=false;if(r.charCodeAt(0)===47){n=true;r=t[0].slice(0,-1)+r}else n=r.indexOf("/")!==-1;var a=r.toUpperCase();var f=n===true?t.indexOf(a):i.indexOf(a);if(f!==-1)return e.FileIndex[f];a=a.replace(chr0,"").replace(chr1,"!");for(f=0;f<t.length;++f){if(t[f].replace(chr0,"").replace(chr1,"!")==a)return e.FileIndex[f];if(i[f].replace(chr0,"").replace(chr1,"!")==a)return e.FileIndex[f]}return null}var x=64;var E=-2;var C="d0cf11e0a1b11ae1";var y=[208,207,17,224,161,177,26,225];var S="00000000000000000000000000000000";var A={MAXREGSECT:-6,DIFSECT:-4,FATSECT:-3,ENDOFCHAIN:E,FREESECT:-1,HEADER_SIGNATURE:C,HEADER_MINOR_VERSION:"3e00",MAXREGSID:-6,NOSTREAM:-1,HEADER_CLSID:S,EntryTypes:["unknown","storage","stream","lockbytes","property","root"]};function m(e,r,t){var i=I(e,t);d.writeFileSync(r,i)}function B(e){var r=new Array(e.length);for(var t=0;t<e.length;++t)r[t]=String.fromCharCode(e[t]);return r.join("")}function k(e,r){var t=I(e,r);switch(r&&r.type){case"file":d.writeFileSync(r.filename,t);return t;case"binary":return B(t);case"base64":return Base64.encode(B(t));}return t}function L(e){var r={};p(r,e);return r}function P(e,r,t,n){p(e);var a=CFB.find(e,r);if(!a){var f=e.FullPaths[0];if(r.slice(0,f.length)==f)f=r;else{if(f.slice(-1)!="/")f+="/";f=(f+r).replace("//","/")}a={name:i(r)};e.FileIndex.push(a);e.FullPaths.push(f);CFB.utils.cfb_gc(e)}a.content=t;a.size=t?t.length:0;if(n){if(n.CLSID)a.clsid=n.CLSID}return a}function R(e,r){p(e);var t=CFB.find(e,r);if(t)for(var i=0;i<e.FileIndex.length;++i)if(e.FileIndex[i]==t){e.FileIndex.splice(i,1);e.FullPaths.splice(i,1);return true}return false}function D(e,r,t){p(e);var n=CFB.find(e,r);if(n)for(var a=0;a<e.FileIndex.length;++a)if(e.FileIndex[a]==n){e.FileIndex[a].name=i(t);e.FullPaths[a]=t;return true}return false}function z(e){g(e,true)}e.find=b;e.read=w;e.parse=n;e.write=k;e.writeFile=m;e.utils={cfb_new:L,cfb_add:P,cfb_del:R,cfb_mov:D,cfb_gc:z,ReadShift:ReadShift,CheckField:CheckField,prep_blob:prep_blob,bconcat:bconcat,consts:A};return e}();if(typeof require!=="undefined"&&typeof module!=="undefined"&&typeof DO_NOT_EXPORT_CFB==="undefined"){module.exports=CFB} | ||
var Base64=function e(){var e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";return{encode:function(r){var t="";var i,n,a;var f,s,h,l;for(var o=0;o<r.length;){i=r.charCodeAt(o++);f=i>>2;n=r.charCodeAt(o++);s=(i&3)<<4|n>>4;a=r.charCodeAt(o++);h=(n&15)<<2|a>>6;l=a&63;if(isNaN(n)){h=l=64}else if(isNaN(a)){l=64}t+=e.charAt(f)+e.charAt(s)+e.charAt(h)+e.charAt(l)}return t},decode:function r(t){var i="";var n,a,f;var s,h,l,o;t=t.replace(/[^\w\+\/\=]/g,"");for(var c=0;c<t.length;){s=e.indexOf(t.charAt(c++));h=e.indexOf(t.charAt(c++));n=s<<2|h>>4;i+=String.fromCharCode(n);l=e.indexOf(t.charAt(c++));a=(h&15)<<4|l>>2;if(l!==64){i+=String.fromCharCode(a)}o=e.indexOf(t.charAt(c++));f=(l&3)<<6|o;if(o!==64){i+=String.fromCharCode(f)}}return i}}}();var has_buf=typeof Buffer!=="undefined"&&typeof process!=="undefined"&&typeof process.versions!=="undefined"&&process.versions.node;function new_raw_buf(e){return new(has_buf?Buffer:Array)(e)}var s2a=function r(e){if(has_buf)return new Buffer(e,"binary");return e.split("").map(function(e){return e.charCodeAt(0)&255})};var chr0=/\u0000/g,chr1=/[\u0001-\u0006]/;var __toBuffer=function(e){var r=[];for(var t=0;t<e[0].length;++t){r.push.apply(r,e[0][t])}return r};var ___toBuffer=__toBuffer;var __utf16le=function(e,r,t){var i=[];for(var n=r;n<t;n+=2)i.push(String.fromCharCode(__readUInt16LE(e,n)));return i.join("").replace(chr0,"")};var ___utf16le=__utf16le;var __hexlify=function(e,r,t){var i=[];for(var n=r;n<r+t;++n)i.push(("0"+e[n].toString(16)).slice(-2));return i.join("")};var ___hexlify=__hexlify;var __bconcat=function(e){if(Array.isArray(e[0]))return[].concat.apply([],e);var r=0,t=0;for(t=0;t<e.length;++t)r+=e[t].length;var i=new Uint8Array(r);for(t=0,r=0;t<e.length;r+=e[t].length,++t)i.set(e[t],r);return i};var bconcat=__bconcat;if(has_buf){__utf16le=function(e,r,t){if(!Buffer.isBuffer(e))return ___utf16le(e,r,t);return e.toString("utf16le",r,t).replace(chr0,"")};__hexlify=function(e,r,t){return Buffer.isBuffer(e)?e.toString("hex",r,r+t):___hexlify(e,r,t)};__toBuffer=function(e){return e[0].length>0&&Buffer.isBuffer(e[0][0])?Buffer.concat(e[0]):___toBuffer(e)};s2a=function(e){return new Buffer(e,"binary")};bconcat=function(e){return Buffer.isBuffer(e[0])?Buffer.concat(e):__bconcat(e)}}var __readUInt8=function(e,r){return e[r]};var __readUInt16LE=function(e,r){return e[r+1]*(1<<8)+e[r]};var __readInt16LE=function(e,r){var t=e[r+1]*(1<<8)+e[r];return t<32768?t:(65535-t+1)*-1};var __readUInt32LE=function(e,r){return e[r+3]*(1<<24)+(e[r+2]<<16)+(e[r+1]<<8)+e[r]};var __readInt32LE=function(e,r){return(e[r+3]<<24)+(e[r+2]<<16)+(e[r+1]<<8)+e[r]};function ReadShift(e,r){var t,i,n=0;switch(e){case 1:t=__readUInt8(this,this.l);break;case 2:t=(r!=="i"?__readUInt16LE:__readInt16LE)(this,this.l);break;case 4:t=__readInt32LE(this,this.l);break;case 16:n=2;i=__hexlify(this,this.l,e);}this.l+=e;if(n===0)return t;return i}var __writeUInt32LE=function(e,r,t){e[t]=r&255;e[t+1]=r>>>8&255;e[t+2]=r>>>16&255;e[t+3]=r>>>24&255};var __writeInt32LE=function(e,r,t){e[t]=r&255;e[t+1]=r>>8&255;e[t+2]=r>>16&255;e[t+3]=r>>24&255};function WriteShift(e,r,t){var i=0,n=0;switch(t){case"hex":for(;n<e;++n){this[this.l++]=parseInt(r.slice(2*n,2*n+2),16)||0}return this;case"utf16le":var a=this.l+e;for(n=0;n<Math.min(r.length,e);++n){var f=r.charCodeAt(n);this[this.l++]=f&255;this[this.l++]=f>>8}while(this.l<a)this[this.l++]=0;return this;}switch(e){case 1:i=1;this[this.l]=r&255;break;case 2:i=2;this[this.l]=r&255;r>>>=8;this[this.l+1]=r&255;break;case 4:i=4;__writeUInt32LE(this,r,this.l);break;case-4:i=4;__writeInt32LE(this,r,this.l);break;}this.l+=i;return this}function CheckField(e,r){var t=__hexlify(this,this.l,e.length>>1);if(t!==e)throw new Error(r+"Expected "+e+" saw "+t);this.l+=e.length>>1}function prep_blob(e,r){e.l=r;e.read_shift=ReadShift;e.chk=CheckField;e.write_shift=WriteShift}function new_buf(e){var r=new_raw_buf(e);prep_blob(r,0);return r}var CFB=function t(){var e={};e.version="0.13.2";function r(e,r){var t=e.split("/"),i=r.split("/");for(var n=0,a=0,f=Math.min(t.length,i.length);n<f;++n){if(a=t[n].length-i[n].length)return a;if(t[n]!=i[n])return t[n]<i[n]?-1:1}return t.length-i.length}function t(e){if(e.charAt(e.length-1)=="/")return e.slice(0,-1).indexOf("/")===-1?e:t(e.slice(0,-1));var r=e.lastIndexOf("/");return r===-1?e:e.slice(0,r+1)}function i(e){if(e.charAt(e.length-1)=="/")return i(e.slice(0,-1));var r=e.lastIndexOf("/");return r===-1?e:e.slice(r+1)}var n;function a(){return n||(n=require("fs"))}function f(e,r){var t=3;var i=512;var n=0;var a=0;var f=0;var u=0;var v=0;var w=[];var p=e.slice(0,512);prep_blob(p,0);var F=s(p);t=F[0];switch(t){case 3:i=512;break;case 4:i=4096;break;default:throw new Error("Major Version: Expected 3 or 4 saw "+t);}if(i!==512){p=e.slice(0,i);prep_blob(p,28)}var g=e.slice(0,i);h(p,t);var I=p.read_shift(4,"i");if(t===3&&I!==0)throw new Error("# Directory Sectors: Expected 0 saw "+I);p.l+=4;f=p.read_shift(4,"i");p.l+=4;p.chk("00100000","Mini Stream Cutoff Size: ");u=p.read_shift(4,"i");n=p.read_shift(4,"i");v=p.read_shift(4,"i");a=p.read_shift(4,"i");for(var b=-1,x=0;x<109;++x){b=p.read_shift(4,"i");if(b<0)break;w[x]=b}var E=l(e,i);c(v,a,E,i,w);var y=_(E,f,w,i);y[f].name="!Directory";if(n>0&&u!==C)y[u].name="!MiniFAT";y[w[0]].name="!FAT";y.fat_addrs=w;y.ssz=i;var S={},A=[],m=[],B=[],k={};d(f,y,E,A,n,S,m);o(m,k,B,A);A.shift();var L={FileIndex:m,FullPaths:B,FullPathDir:k};if(r&&r.raw)L.raw={header:g,sectors:E};return L}function s(e){e.chk(y,"Header Signature: ");e.chk(A,"CLSID: ");var r=e.read_shift(2,"u");return[e.read_shift(2,"u"),r]}function h(e,r){var t=9;e.l+=2;switch(t=e.read_shift(2)){case 9:if(r!=3)throw new Error("Sector Shift: Expected 9 saw "+t);break;case 12:if(r!=4)throw new Error("Sector Shift: Expected 12 saw "+t);break;default:throw new Error("Sector Shift: Expected 9 or 12 saw "+t);}e.chk("0600","Mini Sector Shift: ");e.chk("000000000000","Reserved: ")}function l(e,r){var t=Math.ceil(e.length/r)-1;var i=[];for(var n=1;n<t;++n)i[n-1]=e.slice(n*r,(n+1)*r);i[t-1]=e.slice(t*r);return i}function o(e,r,t,i){var n=0,a=0,f=0,s=0,h=0,l=i.length;var o=[],c=[];for(;n<l;++n){o[n]=c[n]=n;t[n]=i[n]}for(;h<c.length;++h){n=c[h];a=e[n].L;f=e[n].R;s=e[n].C;if(o[n]===n){if(a!==-1&&o[a]!==a)o[n]=o[a];if(f!==-1&&o[f]!==f)o[n]=o[f]}if(s!==-1)o[s]=n;if(a!==-1){o[a]=o[n];c.push(a)}if(f!==-1){o[f]=o[n];c.push(f)}}for(n=1;n!==l;++n)if(o[n]===n){if(f!==-1&&o[f]!==f)o[n]=o[f];else if(a!==-1&&o[a]!==a)o[n]=o[a]}for(n=1;n<l;++n){if(e[n].type===0)continue;h=o[n];if(h===0)t[n]=t[0]+"/"+t[n];else while(h!==0&&h!==o[h]){t[n]=t[h]+"/"+t[n];h=o[h]}o[n]=0}t[0]+="/";for(n=1;n<l;++n){if(e[n].type!==2)t[n]+="/";r[t[n]]=e[n]}}function c(e,r,t,i,n){var a=C;if(e===C){if(r!==0)throw new Error("DIFAT chain shorter than expected")}else if(e!==-1){var f=t[e],s=(i>>>2)-1;if(!f)return;for(var h=0;h<s;++h){if((a=__readInt32LE(f,h*4))===C)break;n.push(a)}c(__readInt32LE(f,i-4),r-1,t,i,n)}}function u(e,r,t,i,n){var a=[],f=[];if(!n)n=[];var s=i-1,h=0,l=0;for(h=r;h>=0;){n[h]=true;a[a.length]=h;f.push(e[h]);var o=t[Math.floor(h*4/i)];l=h*4&s;if(i<4+l)throw new Error("FAT boundary crossed: "+h+" 4 "+i);if(!e[o])break;h=__readInt32LE(e[o],l)}return{nodes:a,data:__toBuffer([f])}}function _(e,r,t,i){var n=e.length,a=[];var f=[],s=[],h=[];var l=i-1,o=0,c=0,u=0,_=0;for(o=0;o<n;++o){s=[];u=o+r;if(u>=n)u-=n;if(f[u])continue;h=[];for(c=u;c>=0;){f[c]=true;s[s.length]=c;h.push(e[c]);var d=t[Math.floor(c*4/i)];_=c*4&l;if(i<4+_)throw new Error("FAT boundary crossed: "+c+" 4 "+i);if(!e[d])break;c=__readInt32LE(e[d],_)}a[u]={nodes:s,data:__toBuffer([h])}}return a}function d(e,r,t,i,n,a,f){var s=0,h=i.length?2:0;var l=r[e].data;var o=0,c=0,_;for(;o<l.length;o+=128){var d=l.slice(o,o+128);prep_blob(d,64);c=d.read_shift(2);_=__utf16le(d,0,c-h);i.push(_);var w={name:_,type:d.read_shift(1),color:d.read_shift(1),L:d.read_shift(4,"i"),R:d.read_shift(4,"i"),C:d.read_shift(4,"i"),clsid:d.read_shift(16),state:d.read_shift(4,"i"),start:0,size:0};var p=d.read_shift(2)+d.read_shift(2)+d.read_shift(2)+d.read_shift(2);if(p!==0)w.ct=v(d,d.l-8);var F=d.read_shift(2)+d.read_shift(2)+d.read_shift(2)+d.read_shift(2);if(F!==0)w.mt=v(d,d.l-8);w.start=d.read_shift(4,"i");w.size=d.read_shift(4,"i");if(w.size<0&&w.start<0){w.size=w.type=0;w.start=C;w.name=""}if(w.type===5){s=w.start;if(n>0&&s!==C)r[s].name="!StreamData"}else if(w.size>=4096){w.storage="fat";if(r[w.start]===undefined)r[w.start]=u(t,w.start,r.fat_addrs,r.ssz);r[w.start].name=w.name;w.content=r[w.start].data.slice(0,w.size);prep_blob(w.content,0)}else{w.storage="minifat";if(s!==C&&w.start!==C&&r[s]){w.content=r[s].data.slice(w.start*E,w.start*E+w.size);prep_blob(w.content,0)}}a[_]=w;f.push(w)}}function v(e,r){return new Date((__readUInt32LE(e,r+4)/1e7*Math.pow(2,32)+__readUInt32LE(e,r)/1e7-11644473600)*1e3)}function w(e,r){a();return f(n.readFileSync(e),r)}function p(e,r){switch(r&&r.type||"base64"){case"file":return w(e,r);case"base64":return f(s2a(Base64.decode(e)),r);case"binary":return f(s2a(e),r);}return f(e,r)}function F(e,r){var t=r||{},i=t.root||"Root Entry";if(!e.FullPaths)e.FullPaths=[];if(!e.FileIndex)e.FileIndex=[];if(e.FullPaths.length!==e.FileIndex.length)throw new Error("inconsistent CFB structure");if(e.FullPaths.length===0){e.FullPaths[0]=i+"/";e.FileIndex[0]={name:i,type:5}}if(t.CLSID)e.FileIndex[0].clsid=t.CLSID;g(e)}function g(e){var r="Sh33tJ5";if(CFB.find(e,"/"+r))return;var t=new_buf(4);t[0]=55;t[1]=t[3]=50;t[2]=54;e.FileIndex.push({name:r,type:2,content:t,size:4,L:69,R:69,C:69});e.FullPaths.push(e.FullPaths[0]+r);I(e)}function I(e,n){F(e);var a=false,f=false;for(var s=e.FullPaths.length-1;s>=0;--s){var h=e.FileIndex[s];switch(h.type){case 0:if(f)a=true;else{e.FileIndex.pop();e.FullPaths.pop()}break;case 1:;case 2:;case 5:f=true;if(isNaN(h.R*h.L*h.C))a=true;if(h.R>-1&&h.L>-1&&h.R==h.L)a=true;break;default:a=true;break;}}if(!a&&!n)return;var l=new Date(1987,1,19),o=0;var c=[];for(s=0;s<e.FullPaths.length;++s){if(e.FileIndex[s].type===0)continue;c.push([e.FullPaths[s],e.FileIndex[s]])}for(s=0;s<c.length;++s){var u=t(c[s][0]);f=false;for(o=0;o<c.length;++o)if(c[o][0]===u)f=true;if(!f)c.push([u,{name:i(u).replace("/",""),type:1,clsid:A,ct:l,mt:l,content:null}])}c.sort(function(e,t){return r(e[0],t[0])});e.FullPaths=[];e.FileIndex=[];for(s=0;s<c.length;++s){e.FullPaths[s]=c[s][0];e.FileIndex[s]=c[s][1]}for(s=0;s<c.length;++s){var _=e.FileIndex[s];var d=e.FullPaths[s];_.name=i(d).replace("/","");_.L=_.R=_.C=-(_.color=1);_.size=_.content?_.content.length:0;_.start=0;_.clsid=_.clsid||A;if(s===0){_.C=c.length>1?1:-1;_.size=0;_.type=5}else if(d.slice(-1)=="/"){for(o=s+1;o<c.length;++o)if(t(e.FullPaths[o])==d)break;_.C=o>=c.length?-1:o;for(o=s+1;o<c.length;++o)if(t(e.FullPaths[o])==t(d))break;_.R=o>=c.length?-1:o;_.type=1}else{if(t(e.FullPaths[s+1]||"")==t(d))_.R=s+1;_.type=2}}}function b(e,r){I(e);var t=function(e){var r=0,t=0;for(var i=0;i<e.FileIndex.length;++i){var n=e.FileIndex[i];if(!n.content)continue;var a=n.content.length;if(a===0){}else if(a<4096)r+=a+63>>6;else t+=a+511>>9}var f=e.FullPaths.length+3>>2;var s=r+7>>3;var h=r+127>>7;var l=s+t+f+h;var o=l+127>>7;var c=o<=109?0:Math.ceil((o-109)/127);while(l+o+c+127>>7>o)c=++o<=109?0:Math.ceil((o-109)/127);var u=[1,c,o,h,f,t,r,0];e.FileIndex[0].size=r<<6;u[7]=(e.FileIndex[0].start=u[0]+u[1]+u[2]+u[3]+u[4]+u[5])+(u[6]+7>>3);return u}(e);var i=new_buf(t[7]<<9);var n=0,a=0;{for(n=0;n<8;++n)i.write_shift(1,S[n]);for(n=0;n<8;++n)i.write_shift(2,0);i.write_shift(2,62);i.write_shift(2,3);i.write_shift(2,65534);i.write_shift(2,9);i.write_shift(2,6);for(n=0;n<3;++n)i.write_shift(2,0);i.write_shift(4,0);i.write_shift(4,t[2]);i.write_shift(4,t[0]+t[1]+t[2]+t[3]-1);i.write_shift(4,0);i.write_shift(4,1<<12);i.write_shift(4,t[3]?t[0]+t[1]+t[2]-1:C);i.write_shift(4,t[3]);i.write_shift(-4,t[1]?t[0]-1:C);i.write_shift(4,t[1]);for(n=0;n<109;++n)i.write_shift(-4,n<t[2]?t[1]+n:-1)}if(t[1]){for(a=0;a<t[1];++a){for(;n<236+a*127;++n)i.write_shift(-4,n<t[2]?t[1]+n:-1);i.write_shift(-4,a===t[1]-1?C:a+1)}}var f=function(e){for(a+=e;n<a-1;++n)i.write_shift(-4,n+1);if(e){++n;i.write_shift(-4,C)}};a=n=0;for(a+=t[1];n<a;++n)i.write_shift(-4,m.DIFSECT);for(a+=t[2];n<a;++n)i.write_shift(-4,m.FATSECT);f(t[3]);f(t[4]);var s=0,h=0;var l=e.FileIndex[0];for(;s<e.FileIndex.length;++s){l=e.FileIndex[s];if(!l.content)continue;h=l.content.length;if(h<4096)continue;l.start=a;f(h+511>>9)}f(t[6]+7>>3);while(i.l&511)i.write_shift(-4,m.ENDOFCHAIN);a=n=0;for(s=0;s<e.FileIndex.length;++s){l=e.FileIndex[s];if(!l.content)continue;h=l.content.length;if(!h||h>=4096)continue;l.start=a;f(h+63>>6)}while(i.l&511)i.write_shift(-4,m.ENDOFCHAIN);for(n=0;n<t[4]<<2;++n){var o=e.FullPaths[n];if(!o||o.length===0){for(s=0;s<17;++s)i.write_shift(4,0);for(s=0;s<3;++s)i.write_shift(4,-1);for(s=0;s<12;++s)i.write_shift(4,0);continue}l=e.FileIndex[n];if(n===0)l.start=l.size?l.start-1:C;h=2*(l.name.length+1);i.write_shift(64,l.name,"utf16le");i.write_shift(2,h);i.write_shift(1,l.type);i.write_shift(1,l.color);i.write_shift(-4,l.L);i.write_shift(-4,l.R);i.write_shift(-4,l.C);if(!l.clsid)for(s=0;s<4;++s)i.write_shift(4,0);else i.write_shift(16,l.clsid,"hex");i.write_shift(4,l.state||0);i.write_shift(4,0);i.write_shift(4,0);i.write_shift(4,0);i.write_shift(4,0);i.write_shift(4,l.start);i.write_shift(4,l.size);i.write_shift(4,0)}for(n=1;n<e.FileIndex.length;++n){l=e.FileIndex[n];if(l.size>=4096){i.l=l.start+1<<9;for(s=0;s<l.size;++s)i.write_shift(1,l.content[s]);for(;s&511;++s)i.write_shift(1,0)}}for(n=1;n<e.FileIndex.length;++n){l=e.FileIndex[n];if(l.size>0&&l.size<4096){for(s=0;s<l.size;++s)i.write_shift(1,l.content[s]);for(;s&63;++s)i.write_shift(1,0)}}while(i.l<i.length)i.write_shift(1,0);return i}function x(e,r){var t=e.FullPaths.map(function(e){return e.toUpperCase()});var i=t.map(function(e){var r=e.split("/");return r[r.length-(e.slice(-1)=="/"?2:1)]});var n=false;if(r.charCodeAt(0)===47){n=true;r=t[0].slice(0,-1)+r}else n=r.indexOf("/")!==-1;var a=r.toUpperCase();var f=n===true?t.indexOf(a):i.indexOf(a);if(f!==-1)return e.FileIndex[f];a=a.replace(chr0,"").replace(chr1,"!");for(f=0;f<t.length;++f){if(t[f].replace(chr0,"").replace(chr1,"!")==a)return e.FileIndex[f];if(i[f].replace(chr0,"").replace(chr1,"!")==a)return e.FileIndex[f]}return null}var E=64;var C=-2;var y="d0cf11e0a1b11ae1";var S=[208,207,17,224,161,177,26,225];var A="00000000000000000000000000000000";var m={MAXREGSECT:-6,DIFSECT:-4,FATSECT:-3,ENDOFCHAIN:C,FREESECT:-1,HEADER_SIGNATURE:y,HEADER_MINOR_VERSION:"3e00",MAXREGSID:-6,NOSTREAM:-1,HEADER_CLSID:A,EntryTypes:["unknown","storage","stream","lockbytes","property","root"]};function B(e,r,t){a();var i=b(e,t);n.writeFileSync(r,i)}function k(e){var r=new Array(e.length);for(var t=0;t<e.length;++t)r[t]=String.fromCharCode(e[t]);return r.join("")}function L(e,r){var t=b(e,r);switch(r&&r.type){case"file":a();n.writeFileSync(r.filename,t);return t;case"binary":return k(t);case"base64":return Base64.encode(k(t));}return t}function P(e){var r={};F(r,e);return r}function R(e,r,t,n){F(e);var a=CFB.find(e,r);if(!a){var f=e.FullPaths[0];if(r.slice(0,f.length)==f)f=r;else{if(f.slice(-1)!="/")f+="/";f=(f+r).replace("//","/")}a={name:i(r),type:2};e.FileIndex.push(a);e.FullPaths.push(f);CFB.utils.cfb_gc(e)}a.content=t;a.size=t?t.length:0;if(n){if(n.CLSID)a.clsid=n.CLSID}return a}function D(e,r){F(e);var t=CFB.find(e,r);if(t)for(var i=0;i<e.FileIndex.length;++i)if(e.FileIndex[i]==t){e.FileIndex.splice(i,1);e.FullPaths.splice(i,1);return true}return false}function z(e,r,t){F(e);var n=CFB.find(e,r);if(n)for(var a=0;a<e.FileIndex.length;++a)if(e.FileIndex[a]==n){e.FileIndex[a].name=i(t);e.FullPaths[a]=t;return true}return false}function O(e){I(e,true)}e.find=x;e.read=p;e.parse=f;e.write=L;e.writeFile=B;e.utils={cfb_new:P,cfb_add:R,cfb_del:D,cfb_mov:z,cfb_gc:O,ReadShift:ReadShift,CheckField:CheckField,prep_blob:prep_blob,bconcat:bconcat,consts:m};return e}();if(typeof require!=="undefined"&&typeof module!=="undefined"&&typeof DO_NOT_EXPORT_CFB==="undefined"){module.exports=CFB} |
@@ -41,3 +41,3 @@ var DO_NOT_EXPORT_CFB = true; | ||
var exports/*:CFBModule*/ = /*::(*/{}/*:: :any)*/; | ||
exports.version = '0.13.1'; | ||
exports.version = '0.13.2'; | ||
/* [MS-CFB] 2.6.4 */ | ||
@@ -63,2 +63,4 @@ function namecmp(l/*:string*/, r/*:string*/)/*:number*/ { | ||
} | ||
var fs/*:: = require('fs'); */; | ||
function get_fs() { return fs || (fs = require('fs')); } | ||
function parse(file/*:RawBytes*/, options/*:CFBReadOpts*/)/*:CFBContainer*/ { | ||
@@ -361,5 +363,4 @@ var mver = 3; | ||
var fs/*:: = require('fs'); */; | ||
function read_file(filename/*:string*/, options/*:CFBReadOpts*/) { | ||
if(fs == null) fs = require('fs'); | ||
get_fs(); | ||
return parse(fs.readFileSync(filename), options); | ||
@@ -644,2 +645,3 @@ } | ||
function write_file(cfb/*:CFBContainer*/, filename/*:string*/, options/*:CFBWriteOpts*/)/*:void*/ { | ||
get_fs(); | ||
var o = _write(cfb, options); | ||
@@ -659,3 +661,3 @@ /*:: if(typeof Buffer == 'undefined' || !Buffer.isBuffer(o) || !(o instanceof Buffer)) throw new Error("unreachable"); */ | ||
switch(options && options.type) { | ||
case "file": fs.writeFileSync(options.filename, (o/*:any*/)); return o; | ||
case "file": get_fs(); fs.writeFileSync(options.filename, (o/*:any*/)); return o; | ||
case "binary": return a2s(o); | ||
@@ -676,3 +678,3 @@ case "base64": return Base64.encode(a2s(o)); | ||
if(!file) { | ||
var fpath = cfb.FullPaths[0]; | ||
var fpath/*:string*/ = cfb.FullPaths[0]; | ||
if(name.slice(0, fpath.length) == fpath) fpath = name; | ||
@@ -683,3 +685,3 @@ else { | ||
} | ||
file = ({name: filename(name)}/*:any*/); | ||
file = ({name: filename(name), type: 2}/*:any*/); | ||
cfb.FileIndex.push(file); | ||
@@ -686,0 +688,0 @@ cfb.FullPaths.push(fpath); |
{ | ||
"name": "cfb", | ||
"version": "0.13.1", | ||
"version": "0.13.2", | ||
"author": "sheetjs", | ||
@@ -5,0 +5,0 @@ "description": "Compound File Binary File Format extractor", |
# Compound File Binary Format | ||
Pure-JS implementation of MS-CFB: Compound File Binary File Format, a container | ||
Pure JS implementation of MS-CFB: Compound File Binary File Format, a container | ||
format used in many Microsoft file types (XLS, DOC, VBA blobs in XLSX and XLSB) | ||
@@ -38,3 +38,3 @@ | ||
For example, to get the Workbook content from an XLS file: | ||
For example, to get the Workbook content from an Excel 2003 XLS file: | ||
@@ -56,12 +56,20 @@ ```js | ||
The global installation adds a command `cfb` which can work with existing files: | ||
The global installation adds a command `cfb` which can work with files: | ||
- `cfb file` will extract the contents of the file to the current directory. | ||
It will make the corresponding subdirectories. | ||
- `cfb --list-files file` will show a listing of the contained files. | ||
The format follows the `unzip -l` "short format". | ||
- `cfb --repair file` will attempt to repair by reading and re-writing the file. | ||
- `cfb file [names...]` extracts the contents of the file. If additional names | ||
are supplied, only the listed files will be extracted. | ||
- `cfb -l file` lists the contained files (following `unzip -l` "short format") | ||
- `cfb -r file` attempts to repair by reading and re-writing the file. | ||
This fixes some issues with files generated by non-standard tools. | ||
- `cfb -c file [files...]` creates a new file containing the listed files. | ||
The default root entry name is `Root Entry`. | ||
- `cfb -a file [files...]` adds the listed files to the original file. | ||
- `cfb -d file [files...]` deletes the listed files from the original file. | ||
## JS API | ||
@@ -78,6 +86,8 @@ | ||
- `file`: `blob` is interpreted as a file name that will be read | ||
- `base64`: `blob` is interpreted as base64 string | ||
- `binary`: `blob` is interpreted as binary string | ||
- default: `blob` is interpreted as nodejs buffer or array of bytes | ||
| `type` | expected input | | ||
|------------|-----------------------------------------------------------------| | ||
| `"base64"` | string: Base64 encoding of the file | | ||
| `"binary"` | string: binary string (byte `n` is `data.charCodeAt(n)`) | | ||
| `"file"` | string: path of file that will be read (nodejs only) | | ||
| (default) | buffer or array of 8-bit unsigned int (byte `n` is `data[n]`) | | ||
@@ -90,5 +100,7 @@ `CFB.find(cfb, path)` performs a case-insensitive match for the path (or file | ||
- `base64`: returns a base64 string | ||
- `binary`: returns a binary string | ||
- default: returns a nodejs buffer or array of bytes | ||
| `type` | output | | ||
|------------|-----------------------------------------------------------------| | ||
| `"base64"` | string: Base64 encoding of the file | | ||
| `"binary"` | string: binary string (byte `n` is `data.charCodeAt(n)`) | | ||
| (default) | buffer if available, array of 8-bit unsigned int otherwise | | ||
@@ -117,16 +129,5 @@ `CFB.writeFile(cfb, filename, opts)` creates a file with the specified name. | ||
- `.FullPathDir` is an object whose keys are entries in `.FullPaths` and whose | ||
values are objects with metadata and content (described below) | ||
- `.FileIndex` is an array, in the same order as `.FullPaths`, whose values are | ||
objects following the schema: | ||
- `.FileIndex` is an array of the objects from `.FullPathDir`, in the same order | ||
as `.FullPaths`. | ||
- `.raw` contains the raw header and sectors | ||
## Entry Object Description | ||
The entry objects are available from `FullPathDir` and `FileIndex` elements of | ||
the container object: | ||
```typescript | ||
@@ -159,2 +160,1 @@ interface CFBEntry { | ||
@@ -41,3 +41,3 @@ var DO_NOT_EXPORT_CFB = true; | ||
var exports/*:CFBModule*/ = /*::(*/{}/*:: :any)*/; | ||
exports.version = '0.13.1'; | ||
exports.version = '0.13.2'; | ||
/* [MS-CFB] 2.6.4 */ | ||
@@ -63,2 +63,4 @@ function namecmp(l/*:string*/, r/*:string*/)/*:number*/ { | ||
} | ||
var fs/*:: = require('fs'); */; | ||
function get_fs() { return fs || (fs = require('fs')); } | ||
function parse(file/*:RawBytes*/, options/*:CFBReadOpts*/)/*:CFBContainer*/ { | ||
@@ -361,5 +363,4 @@ var mver = 3; | ||
var fs/*:: = require('fs'); */; | ||
function read_file(filename/*:string*/, options/*:CFBReadOpts*/) { | ||
if(fs == null) fs = require('fs'); | ||
get_fs(); | ||
return parse(fs.readFileSync(filename), options); | ||
@@ -644,2 +645,3 @@ } | ||
function write_file(cfb/*:CFBContainer*/, filename/*:string*/, options/*:CFBWriteOpts*/)/*:void*/ { | ||
get_fs(); | ||
var o = _write(cfb, options); | ||
@@ -659,3 +661,3 @@ /*:: if(typeof Buffer == 'undefined' || !Buffer.isBuffer(o) || !(o instanceof Buffer)) throw new Error("unreachable"); */ | ||
switch(options && options.type) { | ||
case "file": fs.writeFileSync(options.filename, (o/*:any*/)); return o; | ||
case "file": get_fs(); fs.writeFileSync(options.filename, (o/*:any*/)); return o; | ||
case "binary": return a2s(o); | ||
@@ -676,3 +678,3 @@ case "base64": return Base64.encode(a2s(o)); | ||
if(!file) { | ||
var fpath = cfb.FullPaths[0]; | ||
var fpath/*:string*/ = cfb.FullPaths[0]; | ||
if(name.slice(0, fpath.length) == fpath) fpath = name; | ||
@@ -683,3 +685,3 @@ else { | ||
} | ||
file = ({name: filename(name)}/*:any*/); | ||
file = ({name: filename(name), type: 2}/*:any*/); | ||
cfb.FileIndex.push(file); | ||
@@ -686,0 +688,0 @@ cfb.FullPaths.push(fpath); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
162045
3058