2017-09-14 21:14:22 +00:00
|
|
|
function cfb_new(opts/*:?any*/)/*:CFBContainer*/ {
|
|
|
|
var o/*:CFBContainer*/ = ({}/*:any*/);
|
|
|
|
init_cfb(o, opts);
|
|
|
|
return o;
|
|
|
|
}
|
|
|
|
|
|
|
|
function cfb_add(cfb/*:CFBContainer*/, name/*:string*/, content/*:?RawBytes*/, opts/*:?any*/)/*:CFBEntry*/ {
|
2018-04-09 06:33:22 +00:00
|
|
|
var unsafe = opts && opts.unsafe;
|
|
|
|
if(!unsafe) init_cfb(cfb);
|
|
|
|
var file = !unsafe && CFB.find(cfb, name);
|
2017-09-14 21:14:22 +00:00
|
|
|
if(!file) {
|
2017-10-20 20:36:54 +00:00
|
|
|
var fpath/*:string*/ = cfb.FullPaths[0];
|
2017-09-20 23:33:03 +00:00
|
|
|
if(name.slice(0, fpath.length) == fpath) fpath = name;
|
|
|
|
else {
|
|
|
|
if(fpath.slice(-1) != "/") fpath += "/";
|
|
|
|
fpath = (fpath + name).replace("//","/");
|
|
|
|
}
|
2017-10-20 20:36:54 +00:00
|
|
|
file = ({name: filename(name), type: 2}/*:any*/);
|
2017-09-14 21:14:22 +00:00
|
|
|
cfb.FileIndex.push(file);
|
2017-09-20 23:33:03 +00:00
|
|
|
cfb.FullPaths.push(fpath);
|
2018-04-09 06:33:22 +00:00
|
|
|
if(!unsafe) CFB.utils.cfb_gc(cfb);
|
2017-09-14 21:14:22 +00:00
|
|
|
}
|
|
|
|
/*:: if(!file) throw new Error("unreachable"); */
|
|
|
|
file.content = (content/*:any*/);
|
|
|
|
file.size = content ? content.length : 0;
|
|
|
|
if(opts) {
|
|
|
|
if(opts.CLSID) file.clsid = opts.CLSID;
|
|
|
|
}
|
|
|
|
return file;
|
|
|
|
}
|
|
|
|
|
|
|
|
function cfb_del(cfb/*:CFBContainer*/, name/*:string*/)/*:boolean*/ {
|
|
|
|
init_cfb(cfb);
|
|
|
|
var file = CFB.find(cfb, name);
|
|
|
|
if(file) for(var j = 0; j < cfb.FileIndex.length; ++j) if(cfb.FileIndex[j] == file) {
|
|
|
|
cfb.FileIndex.splice(j, 1);
|
|
|
|
cfb.FullPaths.splice(j, 1);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
function cfb_mov(cfb/*:CFBContainer*/, old_name/*:string*/, new_name/*:string*/)/*:boolean*/ {
|
|
|
|
init_cfb(cfb);
|
|
|
|
var file = CFB.find(cfb, old_name);
|
|
|
|
if(file) for(var j = 0; j < cfb.FileIndex.length; ++j) if(cfb.FileIndex[j] == file) {
|
|
|
|
cfb.FileIndex[j].name = filename(new_name);
|
|
|
|
cfb.FullPaths[j] = new_name;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
function cfb_gc(cfb/*:CFBContainer*/)/*:void*/ { rebuild_cfb(cfb, true); }
|
|
|
|
|