bireader 1.0.40 → 1.0.41

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
@@ -157,7 +157,7 @@ function remove(_this, startOffset, endOffset, consume, remove, fillValue) {
157
157
  }
158
158
  return data_removed;
159
159
  }
160
- function addData(_this, data, consume, offset, repalce) {
160
+ function addData(_this, data, consume, offset, replace) {
161
161
  if (_this.strict == true) {
162
162
  _this.errorDump ? "\x1b[31m[Error]\x1b[0m: hexdump:\n" + _this.hexdump() : "";
163
163
  throw new Error(`\x1b[33m[Strict mode]\x1b[0m: Can not insert data in strict mode. Use unrestrict() to enable.`);
@@ -169,7 +169,7 @@ function addData(_this, data, consume, offset, repalce) {
169
169
  throw new Error("Data insert must be a Uint8Array");
170
170
  }
171
171
  var needed_size = offset || _this.offset;
172
- if (repalce) {
172
+ if (replace) {
173
173
  needed_size = offset || _this.offset + data.length;
174
174
  }
175
175
  if (needed_size > _this.size) {
@@ -182,7 +182,7 @@ function addData(_this, data, consume, offset, repalce) {
182
182
  }
183
183
  _this.size = _this.data.length;
184
184
  }
185
- if (repalce) {
185
+ if (replace) {
186
186
  if (isBuffer(_this.data)) {
187
187
  const part1 = _this.data.subarray(0, needed_size - data.length);
188
188
  const part2 = _this.data.subarray(needed_size, _this.size);
@@ -674,6 +674,9 @@ function wbit(_this, value, bits, unsigned, endian) {
674
674
  if (bits == undefined) {
675
675
  throw new Error("Enter number of bits to write");
676
676
  }
677
+ if (bits == 0) {
678
+ return;
679
+ }
677
680
  if (bits <= 0 || bits > 32) {
678
681
  throw new Error('Bit length must be between 1 and 32.');
679
682
  }
@@ -731,6 +734,9 @@ function rbit(_this, bits, unsigned, endian) {
731
734
  if (bits == undefined || typeof bits != "number") {
732
735
  throw new Error("Enter number of bits to read");
733
736
  }
737
+ if (bits == 0) {
738
+ return 0;
739
+ }
734
740
  if (bits <= 0 || bits > 32) {
735
741
  throw new Error('Bit length must be between 1 and 32.');
736
742
  }
@@ -1465,7 +1471,7 @@ export class bireader {
1465
1471
  throw new Error("Write data must be Uint8Array or Buffer");
1466
1472
  }
1467
1473
  }
1468
- this.size = data.length + ((bitOffset || 0) % 8);
1474
+ this.size = data.length;
1469
1475
  this.data = data;
1470
1476
  }
1471
1477
  /**
@@ -1549,7 +1555,7 @@ export class bireader {
1549
1555
  * Note: Will extend array if strict mode is off and outside of max size
1550
1556
  *
1551
1557
  * @param {number} bytes - Bytes to skip
1552
- * @param {number} bits - Bits to skip (0-7)
1558
+ * @param {number} bits - Bits to skip
1553
1559
  */
1554
1560
  skip(bytes, bits) {
1555
1561
  return skip(this, bytes, bits);
@@ -1559,7 +1565,7 @@ export class bireader {
1559
1565
  * Note: Will extend array if strict mode is off and outside of max size
1560
1566
  *
1561
1567
  * @param {number} bytes - Bytes to skip
1562
- * @param {number} bits - Bits to skip (0-7)
1568
+ * @param {number} bits - Bits to skip
1563
1569
  */
1564
1570
  jump(bytes, bits) {
1565
1571
  this.skip(bytes, bits);
@@ -1572,7 +1578,7 @@ export class bireader {
1572
1578
  * Note: Will extend array if strict mode is off and outside of max size
1573
1579
  *
1574
1580
  * @param {number} byte - byte to set to
1575
- * @param {number} bit - bit to set to (0-7)
1581
+ * @param {number} bit - bit to set to
1576
1582
  */
1577
1583
  goto(byte, bit) {
1578
1584
  return goto(this, byte, bit);
@@ -1582,7 +1588,7 @@ export class bireader {
1582
1588
  * Note: Will extend array if strict mode is off and outside of max size
1583
1589
  *
1584
1590
  * @param {number} bytes - Bytes to skip
1585
- * @param {number} bits - Bits to skip (0-7)
1591
+ * @param {number} bits - Bits to skip
1586
1592
  */
1587
1593
  seek(bytes, bits) {
1588
1594
  return this.skip(bytes, bits);
@@ -1592,7 +1598,7 @@ export class bireader {
1592
1598
  * Note: Will extend array if strict mode is off and outside of max size
1593
1599
  *
1594
1600
  * @param {number} byte - byte to set to
1595
- * @param {number} bit - bit to set to (0-7)
1601
+ * @param {number} bit - bit to set to
1596
1602
  */
1597
1603
  pointer(byte, bit) {
1598
1604
  return this.goto(byte, bit);
@@ -1602,7 +1608,7 @@ export class bireader {
1602
1608
  * Note: Will extend array if strict mode is off and outside of max size
1603
1609
  *
1604
1610
  * @param {number} byte - byte to set to
1605
- * @param {number} bit - bit to set to (0-7)
1611
+ * @param {number} bit - bit to set to
1606
1612
  */
1607
1613
  warp(byte, bit) {
1608
1614
  return this.goto(byte, bit);
@@ -1621,8 +1627,7 @@ export class bireader {
1621
1627
  * Set byte and bit position to start of data
1622
1628
  */
1623
1629
  gotostart() {
1624
- this.offset = 0;
1625
- this.bitoffset = 0;
1630
+ return this.rewind();
1626
1631
  }
1627
1632
  //
1628
1633
  //get position
@@ -1641,7 +1646,7 @@ export class bireader {
1641
1646
  * @return {number} current byte position
1642
1647
  */
1643
1648
  getOffset() {
1644
- return this.offset;
1649
+ return this.tell();
1645
1650
  }
1646
1651
  /**
1647
1652
  * Get the current byte position
@@ -1649,7 +1654,7 @@ export class bireader {
1649
1654
  * @return {number} current byte position
1650
1655
  */
1651
1656
  saveOffset() {
1652
- return this.offset;
1657
+ return this.tell();
1653
1658
  }
1654
1659
  /**
1655
1660
  * Get the current bit position (0-7)
@@ -1665,7 +1670,7 @@ export class bireader {
1665
1670
  * @return {number} current bit position
1666
1671
  */
1667
1672
  getOffsetBit() {
1668
- return this.bitoffset;
1673
+ return this.tellB();
1669
1674
  }
1670
1675
  /**
1671
1676
  * Get the current bit position (0-7)
@@ -1681,7 +1686,7 @@ export class bireader {
1681
1686
  * @return {number} current absolute bit position
1682
1687
  */
1683
1688
  tellAbsB() {
1684
- return (this.offset * 8) + this.bitoffset;
1689
+ return this.saveOffsetAbsBit();
1685
1690
  }
1686
1691
  /**
1687
1692
  * Get the current absolute bit position (from start of data)
@@ -1689,7 +1694,7 @@ export class bireader {
1689
1694
  * @return {number} current absolute bit position
1690
1695
  */
1691
1696
  getOffsetAbsBit() {
1692
- return (this.offset * 8) + this.bitoffset;
1697
+ return this.saveOffsetAbsBit();
1693
1698
  }
1694
1699
  /**
1695
1700
  * Get the current absolute bit position (from start of data)
@@ -1697,7 +1702,7 @@ export class bireader {
1697
1702
  * @return {number} current absolute bit position
1698
1703
  */
1699
1704
  saveOffsetBit() {
1700
- return (this.offset * 8) + this.bitoffset;
1705
+ return this.saveOffsetAbsBit();
1701
1706
  }
1702
1707
  //
1703
1708
  //strict mode change
@@ -5923,7 +5928,7 @@ export class biwriter {
5923
5928
  }
5924
5929
  }
5925
5930
  this.data = data;
5926
- this.size = this.data.length + ((bitOffset || 0) % 8);
5931
+ this.size = this.data.length;
5927
5932
  }
5928
5933
  /**
5929
5934
  * Change Endian (default little)
@@ -6084,8 +6089,7 @@ export class biwriter {
6084
6089
  * Set byte and bit position to start of data
6085
6090
  */
6086
6091
  gotostart() {
6087
- this.offset = 0;
6088
- this.bitoffset = 0;
6092
+ return this.rewind();
6089
6093
  }
6090
6094
  //
6091
6095
  //get position
@@ -6104,7 +6108,7 @@ export class biwriter {
6104
6108
  * @return {number} current byte position
6105
6109
  */
6106
6110
  getOffset() {
6107
- return this.offset;
6111
+ return this.tell();
6108
6112
  }
6109
6113
  /**
6110
6114
  * Get the current byte position
@@ -6112,7 +6116,7 @@ export class biwriter {
6112
6116
  * @return {number} current byte position
6113
6117
  */
6114
6118
  saveOffset() {
6115
- return this.offset;
6119
+ return this.tell();
6116
6120
  }
6117
6121
  /**
6118
6122
  * Get the current bit position (0-7)
@@ -6128,7 +6132,7 @@ export class biwriter {
6128
6132
  * @return {number} current bit position
6129
6133
  */
6130
6134
  getOffsetBit() {
6131
- return this.bitoffset;
6135
+ return this.tellB();
6132
6136
  }
6133
6137
  /**
6134
6138
  * Get the current bit position (0-7)
@@ -6144,7 +6148,7 @@ export class biwriter {
6144
6148
  * @return {number} current absolute bit position
6145
6149
  */
6146
6150
  tellAbsB() {
6147
- return (this.offset * 8) + this.bitoffset;
6151
+ return this.saveOffsetAbsBit();
6148
6152
  }
6149
6153
  /**
6150
6154
  * Get the current absolute bit position (from start of data)
@@ -6152,7 +6156,7 @@ export class biwriter {
6152
6156
  * @return {number} current absolute bit position
6153
6157
  */
6154
6158
  getOffsetAbsBit() {
6155
- return (this.offset * 8) + this.bitoffset;
6159
+ return this.saveOffsetAbsBit();
6156
6160
  }
6157
6161
  /**
6158
6162
  * Get the current absolute bit position (from start of data)
@@ -6160,7 +6164,7 @@ export class biwriter {
6160
6164
  * @return {number} current absolute bit position
6161
6165
  */
6162
6166
  saveOffsetBit() {
6163
- return (this.offset * 8) + this.bitoffset;
6167
+ return this.saveOffsetAbsBit();
6164
6168
  }
6165
6169
  //
6166
6170
  //strict mode change
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bireader",
3
- "version": "1.0.40",
3
+ "version": "1.0.41",
4
4
  "description": "Read and write data in binary",
5
5
  "module": "lib/esm/index.mjs",
6
6
  "main": "lib/cjs/index.js",
@@ -19,7 +19,7 @@
19
19
  "./*": "./*"
20
20
  },
21
21
  "scripts": {
22
- "clean": "rmdir /s lib",
22
+ "clean": "rmdir /S /Q lib",
23
23
  "build": "npm run clean && npm run build:esm && npm run move && npm run build:cjs",
24
24
  "build:esm": "tsc --module esnext --outDir lib/esm",
25
25
  "move": "cd ./lib/esm/ && ren index.js index.mjs && cd ../../",