bireader 1.0.2 → 1.0.3

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/reader.js +11 -7
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bireader",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "Read and write data in binary",
5
5
  "main": "index.js",
6
6
  "directories": {
package/src/reader.js CHANGED
@@ -21,6 +21,10 @@ class bireader {
21
21
  }
22
22
  }
23
23
 
24
+ #flip = function(unsignedValue){
25
+ return unsignedValue > 127 ? unsignedValue - 256 : unsignedValue;
26
+ }
27
+
24
28
  /**
25
29
  *
26
30
  * byte reader, includes bitfields and strings
@@ -2473,7 +2477,7 @@ class bireader {
2473
2477
  */
2474
2478
  readByte = this.byte = this.int8 = function(unsigned){
2475
2479
  this.#check_size(1)
2476
- const read = (this.data[this.offset])
2480
+ const read = this.#flip(this.data[this.offset])
2477
2481
  this.offset += 1
2478
2482
  if(unsigned == true){
2479
2483
  return read & 0xFF
@@ -2506,9 +2510,9 @@ class bireader {
2506
2510
  this.#check_size(2)
2507
2511
  var read
2508
2512
  if((endian != undefined ? endian : this.endian) == "little"){
2509
- read = (this.data[this.offset + 1] << 8) | this.data[this.offset];
2513
+ read = (this.#flip(this.data[this.offset + 1]) << 8) | this.#flip(this.data[this.offset]);
2510
2514
  } else {
2511
- read = (this.data[this.offset] << 8) | this.data[this.offset + 1];
2515
+ read = (this.#flip(this.data[this.offset]) << 8) | this.#flip(this.data[this.offset + 1]);
2512
2516
  }
2513
2517
  this.offset += 2
2514
2518
  if(unsigned == undefined || unsigned == false){
@@ -2643,9 +2647,9 @@ class bireader {
2643
2647
  this.#check_size(4)
2644
2648
  var read;
2645
2649
  if((endian != undefined ? endian : this.endian) == "little"){
2646
- read = ((this.data[this.offset + 3] << 24) | (this.data[this.offset + 2] << 16) | (this.data[this.offset + 1] << 8) | this.data[this.offset])
2650
+ read = ((this.#flip(this.data[this.offset + 3]) << 24) | (this.#flip(this.data[this.offset + 2]) << 16) | (this.#flip(this.data[this.offset + 1]) << 8) | this.#flip(this.data[this.offset]))
2647
2651
  } else {
2648
- read = (this.data[this.offset] << 24) | (this.data[this.offset + 1] << 16) | (this.data[this.offset + 2] << 8) | this.data[this.offset + 3]
2652
+ read = (this.#flip(this.data[this.offset]) << 24) | (this.#flip(this.data[this.offset + 1]) << 16) | (this.#flip(this.data[this.offset + 2]) << 8) | this.#flip(this.data[this.offset + 3])
2649
2653
  }
2650
2654
  this.offset += 4
2651
2655
  if(unsigned == undefined || unsigned == false){
@@ -2777,7 +2781,7 @@ class bireader {
2777
2781
  let value = BigInt(0);
2778
2782
  if((endian == undefined ? this.endian : endian) == "little"){
2779
2783
  for (let i = 0; i < 8; i++) {
2780
- value |= BigInt(this.data[this.offset]) << BigInt(8 * i);
2784
+ value |= BigInt(this.#flip(this.data[this.offset])) << BigInt(8 * i);
2781
2785
  this.offset += 1
2782
2786
  }
2783
2787
  if(unsigned == undefined || unsigned == false){
@@ -2790,7 +2794,7 @@ class bireader {
2790
2794
  }
2791
2795
  } else {
2792
2796
  for (let i = 0; i < 8; i++) {
2793
- value = (value << BigInt(8)) | BigInt(this.data[this.offset]);
2797
+ value = (value << BigInt(8)) | BigInt(this.#flip(this.data[this.offset]));
2794
2798
  this.offset += 1
2795
2799
  }
2796
2800
  if(unsigned == undefined || unsigned == false){