24 lines
1.1 KiB
JavaScript
24 lines
1.1 KiB
JavaScript
var L = (function(cfb/*:CFBContainer*/)/*:Array<number>*/{
|
|
var mini_size = 0, fat_size = 0;
|
|
for(var i = 0; i < cfb.FileIndex.length; ++i) {
|
|
var file = cfb.FileIndex[i];
|
|
if(!file.content) continue;
|
|
/*:: if(file.content == null) throw new Error("unreachable"); */
|
|
var flen = file.content.length;
|
|
if(flen === 0){}
|
|
else if(flen < 0x1000) mini_size += (flen + 0x3F) >> 6;
|
|
else fat_size += (flen + 0x01FF) >> 9;
|
|
}
|
|
var dir_cnt = (cfb.FullPaths.length +3) >> 2;
|
|
var mini_cnt = (mini_size + 7) >> 3;
|
|
var mfat_cnt = (mini_size + 0x7F) >> 7;
|
|
var fat_base = mini_cnt + fat_size + dir_cnt + mfat_cnt;
|
|
var fat_cnt = (fat_base + 0x7F) >> 7;
|
|
var difat_cnt = fat_cnt <= 109 ? 0 : Math.ceil((fat_cnt-109)/0x7F);
|
|
while(((fat_base + fat_cnt + difat_cnt + 0x7F) >> 7) > fat_cnt) difat_cnt = ++fat_cnt <= 109 ? 0 : Math.ceil((fat_cnt-109)/0x7F);
|
|
var L = [1, difat_cnt, fat_cnt, mfat_cnt, dir_cnt, fat_size, mini_size, 0];
|
|
cfb.FileIndex[0].size = mini_size << 6;
|
|
L[7] = (cfb.FileIndex[0].start=L[0]+L[1]+L[2]+L[3]+L[4]+L[5])+((L[6]+7) >> 3);
|
|
return L;
|
|
})(cfb);
|