xsheetjs/bits/43_sstbin.js

49 lines
1.2 KiB
JavaScript
Raw Normal View History

/* [MS-XLSB] 2.4.221 BrtBeginSst */
function parse_BrtBeginSst(data) {
return [data.read_shift(4), data.read_shift(4)];
}
/* [MS-XLSB] 2.1.7.45 Shared Strings */
function parse_sst_bin(data, opts)/*:SST*/ {
var s/*:SST*/ = ([]/*:any*/);
var pass = false;
2022-03-12 14:05:57 +00:00
recordhopper(data, function hopper_sst(val, R, RT) {
switch(RT) {
2022-03-12 14:05:57 +00:00
case 0x009F: /* BrtBeginSst */
s.Count = val[0]; s.Unique = val[1]; break;
2022-03-12 14:05:57 +00:00
case 0x0013: /* BrtSSTItem */
s.push(val); break;
2022-03-12 14:05:57 +00:00
case 0x00A0: /* BrtEndSst */
return true;
2022-03-12 14:05:57 +00:00
case 0x0023: /* BrtFRTBegin */
pass = true; break;
2022-03-12 14:05:57 +00:00
case 0x0024: /* BrtFRTEnd */
pass = false; break;
default:
2022-03-12 14:05:57 +00:00
if(R.T){}
if(!pass || opts.WTF) throw new Error("Unexpected record 0x" + RT.toString(16));
}
});
return s;
}
function write_BrtBeginSst(sst, o) {
if(!o) o = new_buf(8);
o.write_shift(4, sst.Count);
o.write_shift(4, sst.Unique);
return o;
}
var write_BrtSSTItem = write_RichStr;
function write_sst_bin(sst/*::, opts*/) {
var ba = buf_array();
2022-03-12 14:05:57 +00:00
write_record(ba, 0x009F /* BrtBeginSst */, write_BrtBeginSst(sst));
for(var i = 0; i < sst.length; ++i) write_record(ba, 0x0013 /* BrtSSTItem */, write_BrtSSTItem(sst[i]));
/* FRTSST */
2022-03-12 14:05:57 +00:00
write_record(ba, 0x00A0 /* BrtEndSst */);
return ba.end();
}