bireader 1.0.44 → 1.0.45
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.map +1 -1
- package/lib/cjs/index.js +57 -41
- package/lib/cjs/index.js.map +1 -1
- package/lib/esm/index.d.ts.map +1 -1
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/index.mjs +57 -41
- package/package.json +1 -1
package/lib/esm/index.mjs
CHANGED
|
@@ -1643,6 +1643,16 @@ export class bireader {
|
|
|
1643
1643
|
this.strict = false;
|
|
1644
1644
|
this.errorDump = true;
|
|
1645
1645
|
this.data = [];
|
|
1646
|
+
if (data == undefined) {
|
|
1647
|
+
throw new Error("Data required");
|
|
1648
|
+
}
|
|
1649
|
+
else {
|
|
1650
|
+
if (!this.isBufferOrUint8Array(data)) {
|
|
1651
|
+
throw new Error("Write data must be Uint8Array or Buffer");
|
|
1652
|
+
}
|
|
1653
|
+
}
|
|
1654
|
+
this.size = data.length;
|
|
1655
|
+
this.data = data;
|
|
1646
1656
|
if (endianness != undefined && typeof endianness != "string") {
|
|
1647
1657
|
throw new Error("Endian must be big or little");
|
|
1648
1658
|
}
|
|
@@ -1650,6 +1660,14 @@ export class bireader {
|
|
|
1650
1660
|
throw new Error("Byte order must be big or little");
|
|
1651
1661
|
}
|
|
1652
1662
|
this.endian = endianness || "little";
|
|
1663
|
+
if (typeof strict == "boolean") {
|
|
1664
|
+
this.strict = strict;
|
|
1665
|
+
}
|
|
1666
|
+
else {
|
|
1667
|
+
if (strict != undefined) {
|
|
1668
|
+
throw new Error("Strict mode must be true of false");
|
|
1669
|
+
}
|
|
1670
|
+
}
|
|
1653
1671
|
if (byteOffset != undefined || bitOffset != undefined) {
|
|
1654
1672
|
this.offset = ((Math.abs(byteOffset || 0)) + Math.ceil((Math.abs(bitOffset || 0)) / 8));
|
|
1655
1673
|
// Adjust byte offset based on bit overflow
|
|
@@ -1660,25 +1678,15 @@ export class bireader {
|
|
|
1660
1678
|
this.bitoffset = Math.min(Math.max(this.bitoffset, 0), 7);
|
|
1661
1679
|
// Ensure offset doesn't go negative
|
|
1662
1680
|
this.offset = Math.max(this.offset, 0);
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
}
|
|
1671
|
-
}
|
|
1672
|
-
if (data == undefined) {
|
|
1673
|
-
throw new Error("Data required");
|
|
1674
|
-
}
|
|
1675
|
-
else {
|
|
1676
|
-
if (!this.isBufferOrUint8Array(data)) {
|
|
1677
|
-
throw new Error("Write data must be Uint8Array or Buffer");
|
|
1681
|
+
if (this.offset > this.size) {
|
|
1682
|
+
if (this.strict == false) {
|
|
1683
|
+
this.extendArray(this.offset - this.size);
|
|
1684
|
+
}
|
|
1685
|
+
else {
|
|
1686
|
+
throw new Error(`Starting offset outside of size: ${this.offset} of ${this.size}`);
|
|
1687
|
+
}
|
|
1678
1688
|
}
|
|
1679
1689
|
}
|
|
1680
|
-
this.size = data.length;
|
|
1681
|
-
this.data = data;
|
|
1682
1690
|
}
|
|
1683
1691
|
/**
|
|
1684
1692
|
*
|
|
@@ -6209,11 +6217,34 @@ export class biwriter {
|
|
|
6209
6217
|
this.strict = false;
|
|
6210
6218
|
this.errorDump = true;
|
|
6211
6219
|
this.data = [];
|
|
6220
|
+
if (data == undefined) {
|
|
6221
|
+
if (typeof Buffer !== 'undefined') {
|
|
6222
|
+
this.data = Buffer.alloc(this.offset || 1 + (this.bitoffset != 0 ? 1 : 0));
|
|
6223
|
+
}
|
|
6224
|
+
else {
|
|
6225
|
+
this.data = new Uint8Array(this.offset || 1 + (this.bitoffset != 0 ? 1 : 0));
|
|
6226
|
+
}
|
|
6227
|
+
}
|
|
6228
|
+
else {
|
|
6229
|
+
if (!this.isBufferOrUint8Array(data)) {
|
|
6230
|
+
throw new Error("Write data must be Uint8Array or Buffer.");
|
|
6231
|
+
}
|
|
6232
|
+
this.data = data;
|
|
6233
|
+
}
|
|
6234
|
+
this.size = this.data.length;
|
|
6235
|
+
if (typeof strict == "boolean") {
|
|
6236
|
+
this.strict = strict;
|
|
6237
|
+
}
|
|
6238
|
+
else {
|
|
6239
|
+
if (strict != undefined) {
|
|
6240
|
+
throw new Error("Strict mode must be true of false.");
|
|
6241
|
+
}
|
|
6242
|
+
}
|
|
6212
6243
|
if (endianness != undefined && typeof endianness != "string") {
|
|
6213
|
-
throw new Error("endianness must be big or little");
|
|
6244
|
+
throw new Error("endianness must be big or little.");
|
|
6214
6245
|
}
|
|
6215
6246
|
if (endianness != undefined && !(endianness == "big" || endianness == "little")) {
|
|
6216
|
-
throw new Error("Endianness must be big or little");
|
|
6247
|
+
throw new Error("Endianness must be big or little.");
|
|
6217
6248
|
}
|
|
6218
6249
|
this.endian = endianness || "little";
|
|
6219
6250
|
if (byteOffset != undefined || bitOffset != undefined) {
|
|
@@ -6226,30 +6257,15 @@ export class biwriter {
|
|
|
6226
6257
|
this.bitoffset = Math.min(Math.max(this.bitoffset, 0), 7);
|
|
6227
6258
|
// Ensure offset doesn't go negative
|
|
6228
6259
|
this.offset = Math.max(this.offset, 0);
|
|
6229
|
-
|
|
6230
|
-
|
|
6231
|
-
|
|
6232
|
-
|
|
6233
|
-
|
|
6234
|
-
|
|
6235
|
-
|
|
6236
|
-
}
|
|
6237
|
-
}
|
|
6238
|
-
if (data == undefined) {
|
|
6239
|
-
if (typeof Buffer !== 'undefined') {
|
|
6240
|
-
this.data = Buffer.alloc(this.offset || 1 + (this.bitoffset != 0 ? 1 : 0));
|
|
6241
|
-
}
|
|
6242
|
-
else {
|
|
6243
|
-
this.data = new Uint8Array(this.offset || 1 + (this.bitoffset != 0 ? 1 : 0));
|
|
6244
|
-
}
|
|
6245
|
-
}
|
|
6246
|
-
else {
|
|
6247
|
-
if (!this.isBufferOrUint8Array(data)) {
|
|
6248
|
-
throw new Error("Write data must be Uint8Array or Buffer");
|
|
6260
|
+
if (this.offset > this.size) {
|
|
6261
|
+
if (this.strict == false) {
|
|
6262
|
+
this.extendArray(this.offset - this.size);
|
|
6263
|
+
}
|
|
6264
|
+
else {
|
|
6265
|
+
throw new Error(`Starting offset outside of size: ${this.offset} of ${this.size}`);
|
|
6266
|
+
}
|
|
6249
6267
|
}
|
|
6250
6268
|
}
|
|
6251
|
-
this.data = data;
|
|
6252
|
-
this.size = this.data.length;
|
|
6253
6269
|
}
|
|
6254
6270
|
/**
|
|
6255
6271
|
* Change Endian (default little)
|