@@ -453,27 +453,52 @@ export class DataObjects {
453
453
for ( var link_msg of link_msgs ) {
454
454
let offset = link_msg . get ( 'offset_to_message' ) ;
455
455
var [ version , flags ] = struct . unpack_from ( '<BB' , this . fh , offset ) ;
456
- offset += 2
456
+ offset += 2 ;
457
457
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 ) ;
462
470
if ( flags & 0b00000100 ) {
463
471
//# creation order present
464
472
offset += 8 ;
465
473
}
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
+ }
466
482
467
- var encoding = 'ascii' ;
483
+ let encoding = ( link_name_character_set == 0 ) ? 'ascii' : 'utf-8 ';
468
484
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 ) ) ;
473
489
offset += name_size ;
474
490
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
+ }
477
502
}
478
503
return links
479
504
}
0 commit comments