2022-03-03 08:35:39 +00:00
|
|
|
function parse_BrtMdtinfo(data, length) {
|
|
|
|
return {
|
|
|
|
flags: data.read_shift(4),
|
|
|
|
version: data.read_shift(4),
|
|
|
|
name: parse_XLWideString(data, length - 8)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
function write_BrtMdtinfo(data) {
|
|
|
|
var o = new_buf(12 + 2 * data.name.length);
|
|
|
|
o.write_shift(4, data.flags);
|
|
|
|
o.write_shift(4, data.version);
|
|
|
|
write_XLWideString(data.name, o);
|
|
|
|
return o.slice(0, o.l);
|
|
|
|
}
|
2022-03-14 06:51:33 +00:00
|
|
|
function parse_BrtMdb(data, length) {
|
|
|
|
var out = [];
|
|
|
|
var cnt = data.read_shift(4);
|
|
|
|
while (cnt-- > 0)
|
|
|
|
out.push([data.read_shift(4), data.read_shift(4)]);
|
|
|
|
return out;
|
|
|
|
}
|
2022-03-03 08:35:39 +00:00
|
|
|
function write_BrtMdb(mdb) {
|
|
|
|
var o = new_buf(4 + 8 * mdb.length);
|
|
|
|
o.write_shift(4, mdb.length);
|
|
|
|
for (var i = 0; i < mdb.length; ++i) {
|
|
|
|
o.write_shift(4, mdb[i][0]);
|
|
|
|
o.write_shift(4, mdb[i][1]);
|
|
|
|
}
|
|
|
|
return o;
|
|
|
|
}
|
|
|
|
function write_BrtBeginEsfmd(cnt, name) {
|
|
|
|
var o = new_buf(8 + 2 * name.length);
|
|
|
|
o.write_shift(4, cnt);
|
|
|
|
write_XLWideString(name, o);
|
|
|
|
return o.slice(0, o.l);
|
|
|
|
}
|
2022-03-14 06:51:33 +00:00
|
|
|
function parse_BrtBeginEsmdb(data, length) {
|
|
|
|
data.l += 4;
|
|
|
|
return data.read_shift(4) != 0;
|
|
|
|
}
|
2022-03-03 08:35:39 +00:00
|
|
|
function write_BrtBeginEsmdb(cnt, cm) {
|
|
|
|
var o = new_buf(8);
|
|
|
|
o.write_shift(4, cnt);
|
|
|
|
o.write_shift(4, cm ? 1 : 0);
|
|
|
|
return o;
|
|
|
|
}
|
|
|
|
function parse_xlmeta_bin(data, name, _opts) {
|
2022-03-14 06:51:33 +00:00
|
|
|
var out = { Types: [], Cell: [], Value: [] };
|
2022-03-03 08:35:39 +00:00
|
|
|
var opts = _opts || {};
|
|
|
|
var state = [];
|
|
|
|
var pass = false;
|
2022-03-14 06:51:33 +00:00
|
|
|
var esmdb = 0;
|
2022-03-12 14:05:57 +00:00
|
|
|
recordhopper(data, function(val, R, RT) {
|
2022-03-03 08:35:39 +00:00
|
|
|
switch (RT) {
|
|
|
|
case 335:
|
|
|
|
out.Types.push({ name: val.name });
|
|
|
|
break;
|
|
|
|
case 51:
|
2022-03-14 06:51:33 +00:00
|
|
|
val.forEach(function(r) {
|
|
|
|
(esmdb == 1 ? out.Cell : out.Value).push({ type: out.Types[r[0] - 1].name, index: r[1] });
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
case 337:
|
|
|
|
esmdb = val ? 1 : 0;
|
2022-03-03 08:35:39 +00:00
|
|
|
break;
|
|
|
|
case 35:
|
2022-03-12 14:05:57 +00:00
|
|
|
state.push(RT);
|
2022-03-03 08:35:39 +00:00
|
|
|
pass = true;
|
|
|
|
break;
|
|
|
|
case 36:
|
|
|
|
state.pop();
|
|
|
|
pass = false;
|
|
|
|
break;
|
|
|
|
default:
|
2022-03-12 14:05:57 +00:00
|
|
|
if (R.T) {
|
|
|
|
} else if (!pass || opts.WTF && state[state.length - 1] != 35)
|
|
|
|
throw new Error("Unexpected record 0x" + RT.toString(16));
|
2022-03-03 08:35:39 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
function write_xlmeta_bin() {
|
|
|
|
var ba = buf_array();
|
2022-03-12 14:05:57 +00:00
|
|
|
write_record(ba, 332);
|
|
|
|
write_record(ba, 334, write_UInt32LE(1));
|
|
|
|
write_record(ba, 335, write_BrtMdtinfo({
|
2022-03-03 08:35:39 +00:00
|
|
|
name: "XLDAPR",
|
|
|
|
version: 12e4,
|
|
|
|
flags: 3496657072
|
|
|
|
}));
|
2022-03-12 14:05:57 +00:00
|
|
|
write_record(ba, 336);
|
|
|
|
write_record(ba, 339, write_BrtBeginEsfmd(1, "XLDAPR"));
|
|
|
|
write_record(ba, 52);
|
|
|
|
write_record(ba, 35, write_UInt32LE(514));
|
|
|
|
write_record(ba, 4096, write_UInt32LE(0));
|
|
|
|
write_record(ba, 4097, writeuint16(1));
|
|
|
|
write_record(ba, 36);
|
|
|
|
write_record(ba, 53);
|
|
|
|
write_record(ba, 340);
|
|
|
|
write_record(ba, 337, write_BrtBeginEsmdb(1, true));
|
|
|
|
write_record(ba, 51, write_BrtMdb([[1, 0]]));
|
|
|
|
write_record(ba, 338);
|
|
|
|
write_record(ba, 333);
|
2022-03-03 08:35:39 +00:00
|
|
|
return ba.end();
|
|
|
|
}
|