bireader 1.0.19 → 1.0.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -103,9 +103,11 @@ export function remove(_this, startOffset, endOffset, consume, remove, fillValue
103
103
  if (consume == true) {
104
104
  if (remove != true) {
105
105
  _this.offset = new_offset;
106
+ _this.bitoffset = 0;
106
107
  }
107
108
  else {
108
109
  _this.offset = new_start;
110
+ _this.bitoffset = 0;
109
111
  }
110
112
  }
111
113
  return data_removed;
@@ -160,6 +162,7 @@ export function addData(_this, data, consume, offset, repalce) {
160
162
  }
161
163
  if (consume) {
162
164
  _this.offset = needed_size;
165
+ _this.bitoffset = 0;
163
166
  }
164
167
  }
165
168
  export function hexDump(_this, options) {
@@ -344,7 +347,7 @@ export function hexDump(_this, options) {
344
347
  }
345
348
  console.log(rows.join("\n"));
346
349
  }
347
- export function AND(_this, xor_key, start, end, consume) {
350
+ export function AND(_this, and_key, start, end, consume) {
348
351
  const input = _this.data;
349
352
  if ((end || 0) > _this.size) {
350
353
  if (_this.strict == false) {
@@ -355,27 +358,29 @@ export function AND(_this, xor_key, start, end, consume) {
355
358
  throw new Error("\x1b[33m[Strict mode]\x1b[0m: End offset outside of data: endOffset" + (end || 0) + " of " + _this.size);
356
359
  }
357
360
  }
358
- if (typeof xor_key == "number") {
361
+ if (typeof and_key == "number") {
359
362
  for (let i = (start || 0); i < Math.min(end || _this.size, _this.size); i++) {
360
- input[i] = input[i] & (xor_key & 0xff);
363
+ input[i] = input[i] & (and_key & 0xff);
361
364
  if (consume) {
362
365
  _this.offset = i;
366
+ _this.bitoffset = 0;
363
367
  }
364
368
  }
365
369
  }
366
370
  else {
367
- if (_this.isBufferOrUint8Array(xor_key)) {
371
+ if (_this.isBufferOrUint8Array(and_key)) {
368
372
  let number = -1;
369
373
  for (let i = (start || 0); i < Math.min(end || _this.size, _this.size); i++) {
370
- if (number != xor_key.length - 1) {
374
+ if (number != and_key.length - 1) {
371
375
  number = number + 1;
372
376
  }
373
377
  else {
374
378
  number = 0;
375
379
  }
376
- input[i] = input[i] & xor_key[number];
380
+ input[i] = input[i] & and_key[number];
377
381
  if (consume) {
378
382
  _this.offset = i;
383
+ _this.bitoffset = 0;
379
384
  }
380
385
  }
381
386
  }
@@ -384,7 +389,7 @@ export function AND(_this, xor_key, start, end, consume) {
384
389
  }
385
390
  }
386
391
  }
387
- export function OR(_this, xor_key, start, end, consume) {
392
+ export function OR(_this, or_key, start, end, consume) {
388
393
  const input = _this.data;
389
394
  if ((end || 0) > _this.size) {
390
395
  if (_this.strict == false) {
@@ -395,27 +400,29 @@ export function OR(_this, xor_key, start, end, consume) {
395
400
  throw new Error("\x1b[33m[Strict mode]\x1b[0m: End offset outside of data: endOffset" + (end || 0) + " of " + _this.size);
396
401
  }
397
402
  }
398
- if (typeof xor_key == "number") {
403
+ if (typeof or_key == "number") {
399
404
  for (let i = (start || 0); i < Math.min(end || _this.size, _this.size); i++) {
400
- input[i] = input[i] | (xor_key & 0xff);
405
+ input[i] = input[i] | (or_key & 0xff);
401
406
  if (consume) {
402
407
  _this.offset = i;
408
+ _this.bitoffset = 0;
403
409
  }
404
410
  }
405
411
  }
406
412
  else {
407
- if (_this.isBufferOrUint8Array(xor_key)) {
413
+ if (_this.isBufferOrUint8Array(or_key)) {
408
414
  let number = -1;
409
415
  for (let i = (start || 0); i < Math.min(end || _this.size, _this.size); i++) {
410
- if (number != xor_key.length - 1) {
416
+ if (number != or_key.length - 1) {
411
417
  number = number + 1;
412
418
  }
413
419
  else {
414
420
  number = 0;
415
421
  }
416
- input[i] = input[i] | xor_key[number];
422
+ input[i] = input[i] | or_key[number];
417
423
  if (consume) {
418
424
  _this.offset = i;
425
+ _this.bitoffset = 0;
419
426
  }
420
427
  }
421
428
  }
@@ -440,6 +447,7 @@ export function XOR(_this, xor_key, start, end, consume) {
440
447
  input[i] = input[i] ^ (xor_key & 0xff);
441
448
  if (consume) {
442
449
  _this.offset = i;
450
+ _this.bitoffset = 0;
443
451
  }
444
452
  }
445
453
  }
@@ -456,6 +464,7 @@ export function XOR(_this, xor_key, start, end, consume) {
456
464
  input[i] = input[i] ^ xor_key[number];
457
465
  if (consume) {
458
466
  _this.offset = i;
467
+ _this.bitoffset = 0;
459
468
  }
460
469
  }
461
470
  }
@@ -478,10 +487,12 @@ export function NOT(_this, start, end, consume) {
478
487
  _this.data[i] = ~_this.data[i];
479
488
  if (consume) {
480
489
  _this.offset = i;
490
+ _this.bitoffset = 0;
481
491
  }
482
492
  }
483
493
  }
484
- export function LSHIFT(_this, value, start, end, consume) {
494
+ export function LSHIFT(_this, shift_key, start, end, consume) {
495
+ const input = _this.data;
485
496
  if ((end || 0) > _this.size) {
486
497
  if (_this.strict == false) {
487
498
  _this.extendArray((end || 0) - _this.size);
@@ -491,14 +502,39 @@ export function LSHIFT(_this, value, start, end, consume) {
491
502
  throw new Error("\x1b[33m[Strict mode]\x1b[0m: End offset outside of data: endOffset" + (end || 0) + " of " + _this.size);
492
503
  }
493
504
  }
494
- for (let i = (start || 0); i < Math.min(end || _this.size, _this.size); i++) {
495
- _this.data[i] = _this.data[i] << value;
496
- if (consume) {
497
- _this.offset = i;
505
+ if (typeof shift_key == "number") {
506
+ for (let i = (start || 0); i < Math.min(end || _this.size, _this.size); i++) {
507
+ input[i] = input[i] << shift_key;
508
+ if (consume) {
509
+ _this.offset = i;
510
+ _this.bitoffset = 0;
511
+ }
512
+ }
513
+ }
514
+ else {
515
+ if (_this.isBufferOrUint8Array(shift_key)) {
516
+ let number = -1;
517
+ for (let i = (start || 0); i < Math.min(end || _this.size, _this.size); i++) {
518
+ if (number != shift_key.length - 1) {
519
+ number = number + 1;
520
+ }
521
+ else {
522
+ number = 0;
523
+ }
524
+ input[i] = input[i] << shift_key[number];
525
+ if (consume) {
526
+ _this.offset = i;
527
+ _this.bitoffset = 0;
528
+ }
529
+ }
530
+ }
531
+ else {
532
+ throw new Error("XOR key must be a byte value, string, Uint8Array or Buffer");
498
533
  }
499
534
  }
500
535
  }
501
- export function RSHIFT(_this, value, start, end, consume) {
536
+ export function RSHIFT(_this, shift_key, start, end, consume) {
537
+ const input = _this.data;
502
538
  if ((end || 0) > _this.size) {
503
539
  if (_this.strict == false) {
504
540
  _this.extendArray((end || 0) - _this.size);
@@ -508,14 +544,39 @@ export function RSHIFT(_this, value, start, end, consume) {
508
544
  throw new Error("\x1b[33m[Strict mode]\x1b[0m: End offset outside of data: endOffset" + (end || 0) + " of " + _this.size);
509
545
  }
510
546
  }
511
- for (let i = (start || 0); i < Math.min(end || _this.size, _this.size); i++) {
512
- _this.data[i] = _this.data[i] >> value;
513
- if (consume) {
514
- _this.offset = i;
547
+ if (typeof shift_key == "number") {
548
+ for (let i = (start || 0); i < Math.min(end || _this.size, _this.size); i++) {
549
+ input[i] = input[i] >> shift_key;
550
+ if (consume) {
551
+ _this.offset = i;
552
+ _this.bitoffset = 0;
553
+ }
554
+ }
555
+ }
556
+ else {
557
+ if (_this.isBufferOrUint8Array(shift_key)) {
558
+ let number = -1;
559
+ for (let i = (start || 0); i < Math.min(end || _this.size, _this.size); i++) {
560
+ if (number != shift_key.length - 1) {
561
+ number = number + 1;
562
+ }
563
+ else {
564
+ number = 0;
565
+ }
566
+ input[i] = input[i] >> shift_key[number];
567
+ if (consume) {
568
+ _this.offset = i;
569
+ _this.bitoffset = 0;
570
+ }
571
+ }
572
+ }
573
+ else {
574
+ throw new Error("XOR key must be a byte value, string, Uint8Array or Buffer");
515
575
  }
516
576
  }
517
577
  }
518
- export function ADD(_this, value, start, end, consume) {
578
+ export function ADD(_this, add_key, start, end, consume) {
579
+ const input = _this.data;
519
580
  if ((end || 0) > _this.size) {
520
581
  if (_this.strict == false) {
521
582
  _this.extendArray((end || 0) - _this.size);
@@ -525,10 +586,34 @@ export function ADD(_this, value, start, end, consume) {
525
586
  throw new Error("\x1b[33m[Strict mode]\x1b[0m: End offset outside of data: endOffset" + (end || 0) + " of " + _this.size);
526
587
  }
527
588
  }
528
- for (let i = (start || 0); i < Math.min(end || _this.size, _this.size); i++) {
529
- _this.data[i] += value;
530
- if (consume) {
531
- _this.offset = i;
589
+ if (typeof add_key == "number") {
590
+ for (let i = (start || 0); i < Math.min(end || _this.size, _this.size); i++) {
591
+ input[i] = input[i] + add_key;
592
+ if (consume) {
593
+ _this.offset = i;
594
+ _this.bitoffset = 0;
595
+ }
596
+ }
597
+ }
598
+ else {
599
+ if (_this.isBufferOrUint8Array(add_key)) {
600
+ let number = -1;
601
+ for (let i = (start || 0); i < Math.min(end || _this.size, _this.size); i++) {
602
+ if (number != add_key.length - 1) {
603
+ number = number + 1;
604
+ }
605
+ else {
606
+ number = 0;
607
+ }
608
+ input[i] = input[i] + add_key[number];
609
+ if (consume) {
610
+ _this.offset = i;
611
+ _this.bitoffset = 0;
612
+ }
613
+ }
614
+ }
615
+ else {
616
+ throw new Error("XOR key must be a byte value, string, Uint8Array or Buffer");
532
617
  }
533
618
  }
534
619
  }
@@ -654,11 +739,13 @@ export function wbyte(_this, value, unsigned) {
654
739
  }
655
740
  _this.data[_this.offset] = (unsigned == undefined || unsigned == false) ? value : value & 0xFF;
656
741
  _this.offset += 1;
742
+ _this.bitoffset = 0;
657
743
  }
658
744
  export function rbyte(_this, unsigned) {
659
745
  _this.check_size(1);
660
746
  var read = _this.data[_this.offset];
661
747
  _this.offset += 1;
748
+ _this.bitoffset = 0;
662
749
  if (unsigned == true) {
663
750
  return read & 0xFF;
664
751
  }
@@ -691,6 +778,7 @@ export function wint16(_this, value, unsigned, endian) {
691
778
  _this.data[_this.offset + 1] = (unsigned == undefined || unsigned == false) ? value : value & 0xff;
692
779
  }
693
780
  _this.offset += 2;
781
+ _this.bitoffset = 0;
694
782
  }
695
783
  export function rint16(_this, unsigned, endian) {
696
784
  _this.check_size(2);
@@ -702,6 +790,7 @@ export function rint16(_this, unsigned, endian) {
702
790
  read = (_this.data[_this.offset] << 8) | _this.data[_this.offset + 1];
703
791
  }
704
792
  _this.offset += 2;
793
+ _this.bitoffset = 0;
705
794
  if (unsigned == undefined || unsigned == false) {
706
795
  return read & 0x8000 ? -(0x10000 - read) : read;
707
796
  }
@@ -737,6 +826,8 @@ export function rhalffloat(_this, endian) {
737
826
  // Normalized number
738
827
  floatValue = (sign === 0 ? 1 : -1) * Math.pow(2, exponent - 15) * (1 + fraction / 0x0400);
739
828
  }
829
+ _this.offset += 2;
830
+ _this.bitoffset = 0;
740
831
  return floatValue;
741
832
  }
742
833
  export function whalffloat(_this, value, endian) {
@@ -780,6 +871,7 @@ export function whalffloat(_this, value, endian) {
780
871
  _this.data[_this.offset + 1] = halfFloatBits & 0xFF;
781
872
  }
782
873
  _this.offset += 2;
874
+ _this.bitoffset = 0;
783
875
  }
784
876
  export function wint32(_this, value, unsigned, endian) {
785
877
  _this.check_size(4, 0);
@@ -810,6 +902,7 @@ export function wint32(_this, value, unsigned, endian) {
810
902
  _this.data[_this.offset + 3] = (unsigned == undefined || unsigned == false) ? value : value & 0xFF;
811
903
  }
812
904
  _this.offset += 4;
905
+ _this.bitoffset = 0;
813
906
  }
814
907
  export function rint32(_this, unsigned, endian) {
815
908
  _this.check_size(4);
@@ -821,6 +914,7 @@ export function rint32(_this, unsigned, endian) {
821
914
  read = (_this.data[_this.offset] << 24) | (_this.data[_this.offset + 1] << 16) | (_this.data[_this.offset + 2] << 8) | _this.data[_this.offset + 3];
822
915
  }
823
916
  _this.offset += 4;
917
+ _this.bitoffset = 0;
824
918
  if (unsigned == undefined || unsigned == false) {
825
919
  return read;
826
920
  }
@@ -850,6 +944,8 @@ export function rfloat(_this, endian) {
850
944
  // Normalized number
851
945
  floatValue = Math.pow(-1, isNegative) * Math.pow(2, exponent - 127) * (1 + fraction / Math.pow(2, 23));
852
946
  }
947
+ _this.offset += 4;
948
+ _this.bitoffset = 0;
853
949
  return floatValue;
854
950
  }
855
951
  export function wfloat(_this, value, endian) {
@@ -872,6 +968,7 @@ export function wfloat(_this, value, endian) {
872
968
  shift += 8;
873
969
  }
874
970
  _this.offset += 4;
971
+ _this.bitoffset = 0;
875
972
  }
876
973
  export function rint64(_this, unsigned, endian) {
877
974
  _this.check_size(8);
@@ -886,10 +983,6 @@ export function rint64(_this, unsigned, endian) {
886
983
  if (value & (BigInt(1) << BigInt(63))) {
887
984
  value -= BigInt(1) << BigInt(64);
888
985
  }
889
- return value;
890
- }
891
- else {
892
- return value;
893
986
  }
894
987
  }
895
988
  else {
@@ -901,12 +994,11 @@ export function rint64(_this, unsigned, endian) {
901
994
  if (value & (BigInt(1) << BigInt(63))) {
902
995
  value -= BigInt(1) << BigInt(64);
903
996
  }
904
- return value;
905
- }
906
- else {
907
- return value;
908
997
  }
909
998
  }
999
+ _this.offset += 8;
1000
+ _this.bitoffset = 0;
1001
+ return value;
910
1002
  }
911
1003
  export function wint64(_this, value, unsigned, endian) {
912
1004
  _this.check_size(8, 0);
@@ -960,6 +1052,7 @@ export function wint64(_this, value, unsigned, endian) {
960
1052
  }
961
1053
  }
962
1054
  _this.offset += 8;
1055
+ _this.bitoffset = 0;
963
1056
  }
964
1057
  export function wdfloat(_this, value, endian) {
965
1058
  _this.check_size(8, 0);
@@ -982,6 +1075,7 @@ export function wdfloat(_this, value, endian) {
982
1075
  }
983
1076
  }
984
1077
  _this.offset += 8;
1078
+ _this.bitoffset = 0;
985
1079
  }
986
1080
  export function rdfloat(_this, endian) {
987
1081
  _this.check_size(8);
@@ -1011,6 +1105,8 @@ export function rdfloat(_this, endian) {
1011
1105
  // Normalized number
1012
1106
  floatValue = (sign == 0n ? 1 : -1) * Math.pow(2, exponent) * (1 + fraction);
1013
1107
  }
1108
+ _this.offset += 8;
1109
+ _this.bitoffset = 0;
1014
1110
  return floatValue;
1015
1111
  }
1016
1112
  export function rstring(_this, options) {
@@ -1189,6 +1285,7 @@ export function wstring(_this, string, options) {
1189
1285
  }
1190
1286
  }
1191
1287
  _this.offset += totalLength;
1288
+ _this.bitoffset = 0;
1192
1289
  }
1193
1290
  else if (stringType == 'pascal' || stringType == 'wide-pascal') {
1194
1291
  if (encoding == undefined) {
@@ -1254,6 +1351,7 @@ export function wstring(_this, string, options) {
1254
1351
  }
1255
1352
  }
1256
1353
  _this.offset += totalLength;
1354
+ _this.bitoffset = 0;
1257
1355
  }
1258
1356
  else {
1259
1357
  throw new Error('Unsupported string type: ' + stringType);