bireader 1.0.55 → 1.0.58

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.cjs CHANGED
@@ -1226,11 +1226,14 @@ function rfloat(_this, endian) {
1226
1226
  }
1227
1227
  function wfloat(_this, value, endian) {
1228
1228
  check_size(_this, 4, 0);
1229
- const maxValue = 3.402823466e+38;
1230
- const minValue = 1.175494351e-38;
1231
- if (value < minValue || value > maxValue) {
1229
+ const MIN_POSITIVE_FLOAT32 = 1.17549435e-38;
1230
+ const MAX_POSITIVE_FLOAT32 = 3.4028235e+38;
1231
+ const MIN_NEGATIVE_FLOAT32 = -3.4028235e+38;
1232
+ const MAX_NEGATIVE_FLOAT32 = -1.17549435e-38;
1233
+ if (!((value === 0) || (value >= MIN_POSITIVE_FLOAT32 && value <= MAX_POSITIVE_FLOAT32) ||
1234
+ (value >= MIN_NEGATIVE_FLOAT32 && value <= MAX_NEGATIVE_FLOAT32))) {
1232
1235
  _this.errorDump ? "[Error], hexdump:\n" + _this.hexdump() : "";
1233
- throw new Error('Value is out of range for the specified float length.' + " min: " + minValue + " max: " + maxValue + " value: " + value);
1236
+ throw new Error('Value is out of range for the specified float length.' + " min: " + MIN_NEGATIVE_FLOAT32 + " max: " + MAX_POSITIVE_FLOAT32 + " value: " + value);
1234
1237
  }
1235
1238
  const dataView = new DataView(new Uint8Array(4).buffer);
1236
1239
  dataView.setFloat32(0, value, true);
@@ -1255,6 +1258,7 @@ function rint64(_this, unsigned, endian) {
1255
1258
  if ((endian == undefined ? _this.endian : endian) == "little") {
1256
1259
  for (let i = 0; i < 8; i++) {
1257
1260
  value = value | BigInt(_this.data[_this.offset]) << BigInt(8 * i);
1261
+ _this.offset += 1;
1258
1262
  }
1259
1263
  if (unsigned == undefined || unsigned == false) {
1260
1264
  if (value & (BigInt(1) << BigInt(63))) {
@@ -1265,6 +1269,7 @@ function rint64(_this, unsigned, endian) {
1265
1269
  else {
1266
1270
  for (let i = 0; i < 8; i++) {
1267
1271
  value = (value << BigInt(8)) | BigInt(_this.data[_this.offset]);
1272
+ _this.offset += 1;
1268
1273
  }
1269
1274
  if (unsigned == undefined || unsigned == false) {
1270
1275
  if (value & (BigInt(1) << BigInt(63))) {
@@ -1272,7 +1277,6 @@ function rint64(_this, unsigned, endian) {
1272
1277
  }
1273
1278
  }
1274
1279
  }
1275
- _this.offset += 8;
1276
1280
  _this.bitoffset = 0;
1277
1281
  return value;
1278
1282
  }
@@ -1332,11 +1336,15 @@ function wint64(_this, value, unsigned, endian) {
1332
1336
  }
1333
1337
  function wdfloat(_this, value, endian) {
1334
1338
  check_size(_this, 8, 0);
1335
- const maxValue = 1.7976931348623158e308;
1336
- const minValue = 2.2250738585072014e-308;
1337
- if (value < minValue || value > maxValue) {
1339
+ const MIN_POSITIVE_FLOAT64 = 2.2250738585072014e-308;
1340
+ const MAX_POSITIVE_FLOAT64 = 1.7976931348623157e+308;
1341
+ const MIN_NEGATIVE_FLOAT64 = -1.7976931348623157e+308;
1342
+ const MAX_NEGATIVE_FLOAT64 = -2.2250738585072014e-308;
1343
+ if (!((value === 0) ||
1344
+ (value >= MIN_POSITIVE_FLOAT64 && value <= MAX_POSITIVE_FLOAT64) ||
1345
+ (value >= MIN_NEGATIVE_FLOAT64 && value <= MAX_NEGATIVE_FLOAT64))) {
1338
1346
  _this.errorDump ? "[Error], hexdump:\n" + _this.hexdump() : "";
1339
- throw new Error('Value is out of range for the specified 64bit length.' + " min: " + minValue + " max: " + maxValue + " value: " + value);
1347
+ throw new Error('Value is out of range for the specified 64bit length.' + " min: " + MIN_NEGATIVE_FLOAT64 + " max: " + MAX_POSITIVE_FLOAT64 + " value: " + value);
1340
1348
  }
1341
1349
  const intArray = new Int32Array(2);
1342
1350
  const floatArray = new Float64Array(intArray.buffer);
@@ -1592,11 +1600,10 @@ function wstring(_this, string, options) {
1592
1600
  }
1593
1601
  var maxBytes = Math.min(string.length, maxLength);
1594
1602
  const encodedString = encoder.encode(string.substring(0, maxBytes));
1595
- var totalLength = (length || encodedString.length) + lengthWriteSize;
1603
+ var totalLength = (length || encodedString.length);
1596
1604
  if (stringType == 'wide-pascal') {
1597
- totalLength = (length || (encodedString.length * 2)) + lengthWriteSize;
1605
+ totalLength = (length || (encodedString.length * 2));
1598
1606
  }
1599
- check_size(_this, totalLength, 0);
1600
1607
  if (lengthWriteSize == 1) {
1601
1608
  _this.writeUByte(maxBytes);
1602
1609
  }
@@ -1606,6 +1613,7 @@ function wstring(_this, string, options) {
1606
1613
  else if (lengthWriteSize == 4) {
1607
1614
  _this.writeUInt32(maxBytes, endian);
1608
1615
  }
1616
+ check_size(_this, totalLength, 0);
1609
1617
  // Write the string bytes to the Uint8Array
1610
1618
  for (let i = 0; i < encodedString.length; i++) {
1611
1619
  if (stringType == 'wide-pascal') {