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