Skip to content

Commit 36895ef

Browse files
committed
adding softlink to get_links_from_link_msgs (I don't have a test for this)
1 parent 4468de1 commit 36895ef

File tree

1 file changed

+37
-12
lines changed

1 file changed

+37
-12
lines changed

esm/dataobjects.js

+37-12
Original file line numberDiff line numberDiff line change
@@ -453,27 +453,52 @@ export class DataObjects {
453453
for (var link_msg of link_msgs) {
454454
let offset = link_msg.get('offset_to_message');
455455
var [version, flags] = struct.unpack_from('<BB', this.fh, offset);
456-
offset += 2
456+
offset += 2;
457457
assert(version == 1);
458-
assert((flags & 0b00000001) == 0);
459-
assert((flags & 0b00000010) == 0);
460-
assert((flags & 0b00001000) == 0);
461-
assert((flags & 0b00010000) == 0);
458+
let size_of_length_of_link_name = Math.pow((flags & 0b00000011), 2);
459+
let link_type_field_present = flags & 0b00000100;
460+
let link_name_character_set_field_present = flags & 0b00010000;
461+
var link_type;
462+
if (link_type_field_present) {
463+
link_type = struct.unpack_from('<B', this.fh, offset)[0];
464+
offset += 1;
465+
}
466+
else {
467+
link_type = 0;
468+
}
469+
assert (link_type == 0 || link_type == 1);
462470
if (flags & 0b00000100) {
463471
//# creation order present
464472
offset += 8;
465473
}
474+
var link_name_character_set;
475+
if (link_name_character_set_field_present) {
476+
link_name_character_set = struct.unpack_from('<B', this.fh, offset)[0];
477+
offset += 1;
478+
}
479+
else {
480+
link_name_character_set = 0;
481+
}
466482

467-
var encoding = 'ascii';
483+
let encoding = (link_name_character_set == 0) ? 'ascii' : 'utf-8';
468484

469-
let name_size = struct.unpack_from('<B', this.fh, offset)[0];
470-
offset += 1;
471-
//let name = this.fh.slice(offset, offset + name_size).decode(encoding)
472-
let name = struct.unpack_from('<' + name_size.toFixed() + 's', this.fh, offset);
485+
let name_size_fmt = ["<B", "<H", "<I", "<Q"][flags & 3]
486+
let name_size = struct.unpack_from(name_size_fmt, this.fh, offset)[0]
487+
offset += size_of_length_of_link_name;
488+
let name = new TextDecoder(encoding).decode(this.fh.slice(offset, offset+name_size));
473489
offset += name_size;
474490

475-
let address = struct.unpack_from('<Q', this.fh, offset)[0];
476-
links[name] = address;
491+
if (link_type == 0) {
492+
//# hard link
493+
let address = struct.unpack_from('<Q', this.fh, offset)[0];
494+
links[name] = address;
495+
}
496+
else if (link_type == 1) {
497+
//# soft link
498+
let length_of_soft_link_value = struct.unpack_from('<H', this.fh, offset)[0];
499+
offset += 2;
500+
links[name] = new TextDecoder('utf-8').decode(this.fh.slice(offset, offset+length_of_soft_link_value));
501+
}
477502
}
478503
return links
479504
}

0 commit comments

Comments
 (0)