js-cfb/bits/38_extrafield.js

28 lines
690 B
JavaScript

function parse_extra_field(blob/*:CFBlob*/)/*:any*/ {
prep_blob(blob, 0);
var o = /*::(*/{}/*:: :any)*/;
var flags = 0;
while(blob.l <= blob.length - 4) {
var type = blob.read_shift(2);
var sz = blob.read_shift(2), tgt = blob.l + sz;
var p = {};
switch(type) {
/* UNIX-style Timestamps */
case 0x5455: {
flags = blob.read_shift(1);
if(flags & 1) p.mtime = blob.read_shift(4);
/* for some reason, CD flag corresponds to LFH */
if(sz > 5) {
if(flags & 2) p.atime = blob.read_shift(4);
if(flags & 4) p.ctime = blob.read_shift(4);
}
if(p.mtime) p.mt = new Date(p.mtime*1000);
}
break;
}
blob.l = tgt;
o[type] = p;
}
return o;
}