bireader 1.0.39 → 1.0.40

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.
package/lib/esm/index.mjs CHANGED
@@ -80,8 +80,11 @@ function alignRev(_this, n) {
80
80
  _this.skip(a * -1);
81
81
  }
82
82
  }
83
- function goto(_this, byte, bit) {
84
- const new_size = (byte + Math.ceil((bit || 0) / 8));
83
+ function goto(_this, bytes, bits) {
84
+ var new_size = (((bytes || 0)) + Math.ceil(((bits || 0)) / 8));
85
+ if (bits && bits < 0) {
86
+ new_size = Math.floor(((((bytes || 0)) * 8) + (bits || 0)) / 8);
87
+ }
85
88
  if (new_size > _this.size) {
86
89
  if (_this.strict == false) {
87
90
  _this.extendArray(new_size - _this.size);
@@ -91,8 +94,15 @@ function goto(_this, byte, bit) {
91
94
  throw new Error("\x1b[33m[Strict mode]\x1b[0m: Goto utside of range of data: goto " + new_size + " of " + _this.size);
92
95
  }
93
96
  }
94
- _this.offset = byte;
95
- _this.bitoffset = (bit || 0) % 8;
97
+ _this.offset = bytes;
98
+ // Adjust byte offset based on bit overflow
99
+ _this.offset += Math.floor(((bits || 0)) / 8);
100
+ // Adjust bit offset
101
+ _this.bitoffset = ((bits || 0) + 64) % 8;
102
+ // Ensure bit offset stays between 0-7
103
+ _this.bitoffset = Math.min(Math.max(_this.bitoffset, 0), 7);
104
+ // Ensure offset doesn't go negative
105
+ _this.offset = Math.max(_this.offset, 0);
96
106
  }
97
107
  function remove(_this, startOffset, endOffset, consume, remove, fillValue) {
98
108
  const new_start = Math.abs(startOffset || 0);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bireader",
3
- "version": "1.0.39",
3
+ "version": "1.0.40",
4
4
  "description": "Read and write data in binary",
5
5
  "module": "lib/esm/index.mjs",
6
6
  "main": "lib/cjs/index.js",