bireader 1.0.40 → 1.0.42
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/cjs/index.d.ts +6 -6
- package/lib/cjs/index.d.ts.map +1 -1
- package/lib/cjs/index.js +33 -29
- package/lib/cjs/index.js.map +1 -1
- package/lib/esm/index.d.ts +6 -6
- package/lib/esm/index.d.ts.map +1 -1
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/index.mjs +33 -29
- package/package.json +2 -2
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,
|
|
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 (
|
|
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 (
|
|
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,8 +674,11 @@ 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
|
-
throw new Error('Bit length must be between 1 and 32.');
|
|
681
|
+
throw new Error('Bit length must be between 1 and 32. Got ' + bits);
|
|
679
682
|
}
|
|
680
683
|
if (unsigned == true) {
|
|
681
684
|
if (value < 0 || value > Math.pow(2, bits)) {
|
|
@@ -731,8 +734,11 @@ 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
|
-
throw new Error('Bit length must be between 1 and 32.');
|
|
741
|
+
throw new Error('Bit length must be between 1 and 32. Got ' + bits);
|
|
736
742
|
}
|
|
737
743
|
const size_needed = ((((bits - 1) + _this.bitoffset) / 8) + _this.offset);
|
|
738
744
|
if (bits <= 0 || size_needed > _this.size) {
|
|
@@ -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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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
|
|
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
|
|
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
|
|
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.
|
|
3
|
+
"version": "1.0.42",
|
|
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 /
|
|
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 ../../",
|