bireader 3.1.9 → 3.1.10

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/dist/index.cjs.js CHANGED
@@ -22,6 +22,11 @@ function _interopNamespaceDefault(e) {
22
22
 
23
23
  var buff__namespace = /*#__PURE__*/_interopNamespaceDefault(buff);
24
24
 
25
+ const MIN_SAFE = BigInt(Number.MIN_SAFE_INTEGER);
26
+ const MAX_SAFE = BigInt(Number.MAX_SAFE_INTEGER);
27
+ function isSafeInt64(big) {
28
+ return big >= MIN_SAFE && big <= MAX_SAFE;
29
+ }
25
30
  function isBuffer(obj) {
26
31
  return buffcheck(obj);
27
32
  }
@@ -1374,6 +1379,14 @@ function rint64$1(ctx, unsigned, endian) {
1374
1379
  }
1375
1380
  }
1376
1381
  ctx.bitoffset = 0;
1382
+ if (ctx.enforceBigInt) {
1383
+ return value;
1384
+ }
1385
+ else {
1386
+ if (isSafeInt64(value)) {
1387
+ return Number(value);
1388
+ }
1389
+ }
1377
1390
  return value;
1378
1391
  }
1379
1392
  function wint64$1(ctx, value, unsigned, endian) {
@@ -1460,9 +1473,9 @@ function wdfloat$1(ctx, value, endian) {
1460
1473
  function rdfloat$1(ctx, endian) {
1461
1474
  endian = (endian == undefined ? ctx.endian : endian);
1462
1475
  var uint64Value = ctx.readInt64(true, endian);
1463
- const sign = (uint64Value & 0x8000000000000000n) >> 63n;
1464
- const exponent = Number((uint64Value & 0x7ff0000000000000n) >> 52n) - 1023;
1465
- const fraction = Number(uint64Value & 0x000fffffffffffffn) / Math.pow(2, 52);
1476
+ const sign = (BigInt(uint64Value) & 0x8000000000000000n) >> 63n;
1477
+ const exponent = Number((BigInt(uint64Value) & 0x7ff0000000000000n) >> 52n) - 1023;
1478
+ const fraction = Number(BigInt(uint64Value) & 0x000fffffffffffffn) / Math.pow(2, 52);
1466
1479
  var floatValue;
1467
1480
  if (exponent == -1023) {
1468
1481
  if (fraction == 0) {
@@ -1772,6 +1785,7 @@ class BiBase {
1772
1785
  */
1773
1786
  this.strDefaults = { stringType: "utf-8", terminateValue: 0x0 };
1774
1787
  this.maxFileSize = null;
1788
+ this.enforceBigInt = false;
1775
1789
  }
1776
1790
  /**
1777
1791
  * Settings for when using .str
@@ -3449,9 +3463,11 @@ class BiBase {
3449
3463
  /**
3450
3464
  * Read signed 64 bit integer.
3451
3465
  *
3466
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
3467
+ *
3452
3468
  * @param {boolean} unsigned - if value is unsigned or not
3453
3469
  * @param {endian?} endian - ``big`` or ``little``
3454
- * @returns {bigint}
3470
+ * @returns {BigValue}
3455
3471
  */
3456
3472
  readInt64(unsigned, endian) {
3457
3473
  return rint64$1(this, unsigned, endian);
@@ -3510,7 +3526,9 @@ class BiBase {
3510
3526
  /**
3511
3527
  * Read unsigned 64 bit integer.
3512
3528
  *
3513
- * @returns {bigint}
3529
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
3530
+ *
3531
+ * @returns {BigValue}
3514
3532
  */
3515
3533
  readUInt64() {
3516
3534
  return this.readInt64(true);
@@ -3518,7 +3536,9 @@ class BiBase {
3518
3536
  /**
3519
3537
  * Read signed 64 bit integer.
3520
3538
  *
3521
- * @returns {bigint}
3539
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
3540
+ *
3541
+ * @returns {BigValue}
3522
3542
  */
3523
3543
  readInt64BE() {
3524
3544
  return this.readInt64(false, "big");
@@ -3526,7 +3546,9 @@ class BiBase {
3526
3546
  /**
3527
3547
  * Read unsigned 64 bit integer.
3528
3548
  *
3529
- * @returns {bigint}
3549
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
3550
+ *
3551
+ * @returns {BigValue}
3530
3552
  */
3531
3553
  readUInt64BE() {
3532
3554
  return this.readInt64(true, "big");
@@ -3534,7 +3556,9 @@ class BiBase {
3534
3556
  /**
3535
3557
  * Read signed 64 bit integer.
3536
3558
  *
3537
- * @returns {bigint}
3559
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
3560
+ *
3561
+ * @returns {BigValue}
3538
3562
  */
3539
3563
  readInt64LE() {
3540
3564
  return this.readInt64(false, "little");
@@ -3542,7 +3566,9 @@ class BiBase {
3542
3566
  /**
3543
3567
  * Read unsigned 64 bit integer.
3544
3568
  *
3545
- * @returns {bigint}
3569
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
3570
+ *
3571
+ * @returns {BigValue}
3546
3572
  */
3547
3573
  readUInt64LE() {
3548
3574
  return this.readInt64(true, "little");
@@ -3634,11 +3660,12 @@ class BiBase {
3634
3660
  *
3635
3661
  * @param {Buffer|Uint8Array} data - ``Buffer`` or ``Uint8Array``. Always found in ``BiReader.data``
3636
3662
  * @param {BiOptions?} options - Any options to set at start
3637
- * @param {number?} options.byteOffset - Byte offset to start reader (default ``0``)
3638
- * @param {number?} options.bitOffset - Bit offset 0-7 to start reader (default ``0``)
3639
- * @param {string?} options.endianness - Endianness ``big`` or ``little`` (default ``little``)
3640
- * @param {boolean?} options.strict - Strict mode: if ``true`` does not extend supplied array on outside write (default ``true``)
3641
- * @param {number?} options.extendBufferSize - Amount of data to add when extending the buffer array when strict mode is false. Note: Changes logic in ``.get`` and ``.return``.
3663
+ * @param {BiOptions["byteOffset"]?} options.byteOffset - Byte offset to start writer (default ``0``)
3664
+ * @param {BiOptions["bitOffset"]?} options.bitOffset - Bit offset 0-7 to start writer (default ``0``)
3665
+ * @param {BiOptions["endianness"]?} options.endianness - Endianness ``big`` or ``little`` (default ``little``)
3666
+ * @param {BiOptions["strict"]?} options.strict - Strict mode: if ``true`` does not extend supplied array on outside write (default ``false``)
3667
+ * @param {BiOptions["extendBufferSize"]?} options.extendBufferSize - Amount of data to add when extending the buffer array when strict mode is false. Note: Changes logic in ``.get`` and ``.return``.
3668
+ * @param {BiOptions["enforceBigInt"]?} options.enforceBigInt - 64 bit value reads will always stay ``BigInt``.
3642
3669
  *
3643
3670
  * @since 2.0
3644
3671
  */
@@ -3648,11 +3675,12 @@ class BiReader extends BiBase {
3648
3675
  *
3649
3676
  * @param {Buffer|Uint8Array} data - ``Buffer`` or ``Uint8Array``. Always found in ``BiReader.data``
3650
3677
  * @param {BiOptions?} options - Any options to set at start
3651
- * @param {number?} options.byteOffset - Byte offset to start reader (default ``0``)
3652
- * @param {number?} options.bitOffset - Bit offset 0-7 to start reader (default ``0``)
3653
- * @param {string?} options.endianness - Endianness ``big`` or ``little`` (default ``little``)
3654
- * @param {boolean?} options.strict - Strict mode: if ``true`` does not extend supplied array on outside write (default ``true``)
3655
- * @param {number?} options.extendBufferSize - Amount of data to add when extending the buffer array when strict mode is false. Note: Changes logic in ``.get`` and ``.return``.
3678
+ * @param {BiOptions["byteOffset"]?} options.byteOffset - Byte offset to start writer (default ``0``)
3679
+ * @param {BiOptions["bitOffset"]?} options.bitOffset - Bit offset 0-7 to start writer (default ``0``)
3680
+ * @param {BiOptions["endianness"]?} options.endianness - Endianness ``big`` or ``little`` (default ``little``)
3681
+ * @param {BiOptions["strict"]?} options.strict - Strict mode: if ``true`` does not extend supplied array on outside write (default ``false``)
3682
+ * @param {BiOptions["extendBufferSize"]?} options.extendBufferSize - Amount of data to add when extending the buffer array when strict mode is false. Note: Changes logic in ``.get`` and ``.return``.
3683
+ * @param {BiOptions["enforceBigInt"]?} options.enforceBigInt - 64 bit value reads will always stay ``BigInt``.
3656
3684
  */
3657
3685
  constructor(data, options = {}) {
3658
3686
  super();
@@ -3666,6 +3694,7 @@ class BiReader extends BiBase {
3666
3694
  }
3667
3695
  this.data = data;
3668
3696
  }
3697
+ this.enforceBigInt = options?.enforceBigInt ?? false;
3669
3698
  if (options.extendBufferSize != undefined && options.extendBufferSize != 0) {
3670
3699
  this.extendBufferSize = options.extendBufferSize;
3671
3700
  }
@@ -6166,7 +6195,9 @@ class BiReader extends BiBase {
6166
6195
  /**
6167
6196
  * Read signed 64 bit integer
6168
6197
  *
6169
- * @returns {bigint}
6198
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
6199
+ *
6200
+ * @returns {BigValue}
6170
6201
  */
6171
6202
  get int64() {
6172
6203
  return this.readInt64();
@@ -6174,7 +6205,9 @@ class BiReader extends BiBase {
6174
6205
  /**
6175
6206
  * Read signed 64 bit integer.
6176
6207
  *
6177
- * @returns {bigint}
6208
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
6209
+ *
6210
+ * @returns {BigValue}
6178
6211
  */
6179
6212
  get bigint() {
6180
6213
  return this.readInt64();
@@ -6182,7 +6215,9 @@ class BiReader extends BiBase {
6182
6215
  /**
6183
6216
  * Read signed 64 bit integer.
6184
6217
  *
6185
- * @returns {bigint}
6218
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
6219
+ *
6220
+ * @returns {BigValue}
6186
6221
  */
6187
6222
  get quad() {
6188
6223
  return this.readInt64();
@@ -6190,7 +6225,9 @@ class BiReader extends BiBase {
6190
6225
  /**
6191
6226
  * Read unsigned 64 bit integer.
6192
6227
  *
6193
- * @returns {bigint}
6228
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
6229
+ *
6230
+ * @returns {BigValue}
6194
6231
  */
6195
6232
  get uint64() {
6196
6233
  return this.readInt64(true);
@@ -6198,7 +6235,9 @@ class BiReader extends BiBase {
6198
6235
  /**
6199
6236
  * Read unsigned 64 bit integer.
6200
6237
  *
6201
- * @returns {bigint}
6238
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
6239
+ *
6240
+ * @returns {BigValue}
6202
6241
  */
6203
6242
  get ubigint() {
6204
6243
  return this.readInt64(true);
@@ -6206,7 +6245,9 @@ class BiReader extends BiBase {
6206
6245
  /**
6207
6246
  * Read unsigned 64 bit integer.
6208
6247
  *
6209
- * @returns {bigint}
6248
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
6249
+ *
6250
+ * @returns {BigValue}
6210
6251
  */
6211
6252
  get uquad() {
6212
6253
  return this.readInt64(true);
@@ -6214,7 +6255,9 @@ class BiReader extends BiBase {
6214
6255
  /**
6215
6256
  * Read signed 64 bit integer.
6216
6257
  *
6217
- * @returns {bigint}
6258
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
6259
+ *
6260
+ * @returns {BigValue}
6218
6261
  */
6219
6262
  get int64be() {
6220
6263
  return this.readInt64(false, "big");
@@ -6222,7 +6265,9 @@ class BiReader extends BiBase {
6222
6265
  /**
6223
6266
  * Read signed 64 bit integer.
6224
6267
  *
6225
- * @returns {bigint}
6268
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
6269
+ *
6270
+ * @returns {BigValue}
6226
6271
  */
6227
6272
  get bigintbe() {
6228
6273
  return this.readInt64(false, "big");
@@ -6230,7 +6275,9 @@ class BiReader extends BiBase {
6230
6275
  /**
6231
6276
  * Read signed 64 bit integer.
6232
6277
  *
6233
- * @returns {bigint}
6278
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
6279
+ *
6280
+ * @returns {BigValue}
6234
6281
  */
6235
6282
  get quadbe() {
6236
6283
  return this.readInt64(false, "big");
@@ -6238,7 +6285,9 @@ class BiReader extends BiBase {
6238
6285
  /**
6239
6286
  * Read unsigned 64 bit integer.
6240
6287
  *
6241
- * @returns {bigint}
6288
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
6289
+ *
6290
+ * @returns {BigValue}
6242
6291
  */
6243
6292
  get uint64be() {
6244
6293
  return this.readInt64(true, "big");
@@ -6246,7 +6295,9 @@ class BiReader extends BiBase {
6246
6295
  /**
6247
6296
  * Read unsigned 64 bit integer.
6248
6297
  *
6249
- * @returns {bigint}
6298
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
6299
+ *
6300
+ * @returns {BigValue}
6250
6301
  */
6251
6302
  get ubigintbe() {
6252
6303
  return this.readInt64(true, "big");
@@ -6254,7 +6305,9 @@ class BiReader extends BiBase {
6254
6305
  /**
6255
6306
  * Read unsigned 64 bit integer.
6256
6307
  *
6257
- * @returns {bigint}
6308
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
6309
+ *
6310
+ * @returns {BigValue}
6258
6311
  */
6259
6312
  get uquadbe() {
6260
6313
  return this.readInt64(true, "big");
@@ -6262,7 +6315,9 @@ class BiReader extends BiBase {
6262
6315
  /**
6263
6316
  * Read signed 64 bit integer.
6264
6317
  *
6265
- * @returns {bigint}
6318
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
6319
+ *
6320
+ * @returns {BigValue}
6266
6321
  */
6267
6322
  get int64le() {
6268
6323
  return this.readInt64(false, "little");
@@ -6270,7 +6325,9 @@ class BiReader extends BiBase {
6270
6325
  /**
6271
6326
  * Read signed 64 bit integer.
6272
6327
  *
6273
- * @returns {bigint}
6328
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
6329
+ *
6330
+ * @returns {BigValue}
6274
6331
  */
6275
6332
  get bigintle() {
6276
6333
  return this.readInt64(false, "little");
@@ -6278,7 +6335,9 @@ class BiReader extends BiBase {
6278
6335
  /**
6279
6336
  * Read signed 64 bit integer.
6280
6337
  *
6281
- * @returns {bigint}
6338
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
6339
+ *
6340
+ * @returns {BigValue}
6282
6341
  */
6283
6342
  get quadle() {
6284
6343
  return this.readInt64(false, "little");
@@ -6286,7 +6345,9 @@ class BiReader extends BiBase {
6286
6345
  /**
6287
6346
  * Read unsigned 64 bit integer.
6288
6347
  *
6289
- * @returns {bigint}
6348
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
6349
+ *
6350
+ * @returns {BigValue}
6290
6351
  */
6291
6352
  get uint64le() {
6292
6353
  return this.readInt64(true, "little");
@@ -6294,7 +6355,9 @@ class BiReader extends BiBase {
6294
6355
  /**
6295
6356
  * Read unsigned 64 bit integer.
6296
6357
  *
6297
- * @returns {bigint}
6358
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
6359
+ *
6360
+ * @returns {BigValue}
6298
6361
  */
6299
6362
  get ubigintle() {
6300
6363
  return this.readInt64(true, "little");
@@ -6302,7 +6365,9 @@ class BiReader extends BiBase {
6302
6365
  /**
6303
6366
  * Read unsigned 64 bit integer.
6304
6367
  *
6305
- * @returns {bigint}
6368
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
6369
+ *
6370
+ * @returns {BigValue}
6306
6371
  */
6307
6372
  get uquadle() {
6308
6373
  return this.readInt64(true, "little");
@@ -6699,6 +6764,7 @@ class BiReader extends BiBase {
6699
6764
  * @param {BiOptions["endianness"]?} options.endianness - Endianness ``big`` or ``little`` (default ``little``)
6700
6765
  * @param {BiOptions["strict"]?} options.strict - Strict mode: if ``true`` does not extend supplied array on outside write (default ``false``)
6701
6766
  * @param {BiOptions["extendBufferSize"]?} options.extendBufferSize - Amount of data to add when extending the buffer array when strict mode is false. Note: Changes logic in ``.get`` and ``.return``.
6767
+ * @param {BiOptions["enforceBigInt"]?} options.enforceBigInt - 64 bit value reads will always stay ``BigInt``.
6702
6768
  *
6703
6769
  * @since 2.0
6704
6770
  */
@@ -6713,6 +6779,7 @@ class BiWriter extends BiBase {
6713
6779
  * @param {BiOptions["endianness"]?} options.endianness - Endianness ``big`` or ``little`` (default ``little``)
6714
6780
  * @param {BiOptions["strict"]?} options.strict - Strict mode: if ``true`` does not extend supplied array on outside write (default ``false``)
6715
6781
  * @param {BiOptions["extendBufferSize"]?} options.extendBufferSize - Amount of data to add when extending the buffer array when strict mode is false. Note: Changes logic in ``.get`` and ``.return``.
6782
+ * @param {BiOptions["enforceBigInt"]?} options.enforceBigInt - 64 bit value reads will always stay ``BigInt``.
6716
6783
  */
6717
6784
  constructor(data, options = {}) {
6718
6785
  super();
@@ -6731,6 +6798,7 @@ class BiWriter extends BiBase {
6731
6798
  }
6732
6799
  this.data = data;
6733
6800
  }
6801
+ this.enforceBigInt = options?.enforceBigInt ?? false;
6734
6802
  if (options.extendBufferSize != undefined && options.extendBufferSize != 0) {
6735
6803
  this.extendBufferSize = options.extendBufferSize;
6736
6804
  }
@@ -11135,6 +11203,14 @@ function rint64(ctx, unsigned, endian) {
11135
11203
  }
11136
11204
  }
11137
11205
  ctx.bitoffset = 0;
11206
+ if (ctx.enforceBigInt) {
11207
+ return value;
11208
+ }
11209
+ else {
11210
+ if (isSafeInt64(value)) {
11211
+ return Number(value);
11212
+ }
11213
+ }
11138
11214
  return value;
11139
11215
  }
11140
11216
  function wint64(ctx, value, unsigned, endian) {
@@ -11226,10 +11302,10 @@ function wdfloat(ctx, value, endian) {
11226
11302
  }
11227
11303
  function rdfloat(ctx, endian) {
11228
11304
  endian = (endian == undefined ? ctx.endian : endian);
11229
- var uint64Value = ctx.readInt64(true, endian);
11230
- const sign = (uint64Value & 0x8000000000000000n) >> 63n;
11231
- const exponent = Number((uint64Value & 0x7ff0000000000000n) >> 52n) - 1023;
11232
- const fraction = Number(uint64Value & 0x000fffffffffffffn) / Math.pow(2, 52);
11305
+ var uint64Value = ctx.readInt64(true /*unsigned*/, endian);
11306
+ const sign = (BigInt(uint64Value) & 0x8000000000000000n) >> 63n;
11307
+ const exponent = Number((BigInt(uint64Value) & 0x7ff0000000000000n) >> 52n) - 1023;
11308
+ const fraction = Number(BigInt(uint64Value) & 0x000fffffffffffffn) / Math.pow(2, 52);
11233
11309
  var floatValue;
11234
11310
  if (exponent == -1023) {
11235
11311
  if (fraction == 0) {
@@ -11547,6 +11623,7 @@ class BiBaseStreamer {
11547
11623
  */
11548
11624
  this.strDefaults = { stringType: "utf-8", terminateValue: 0x0 };
11549
11625
  this.maxFileSize = null;
11626
+ this.enforceBigInt = false;
11550
11627
  this.filePath = filePath;
11551
11628
  if (readwrite) {
11552
11629
  this.fsMode = "w+";
@@ -13396,9 +13473,11 @@ class BiBaseStreamer {
13396
13473
  /**
13397
13474
  * Read signed 64 bit integer.
13398
13475
  *
13476
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
13477
+ *
13399
13478
  * @param {boolean} unsigned - if value is unsigned or not
13400
13479
  * @param {endian?} endian - ``big`` or ``little``
13401
- * @returns {bigint}
13480
+ * @returns {BigValue}
13402
13481
  */
13403
13482
  readInt64(unsigned, endian) {
13404
13483
  return rint64(this, unsigned, endian);
@@ -13457,7 +13536,9 @@ class BiBaseStreamer {
13457
13536
  /**
13458
13537
  * Read unsigned 64 bit integer.
13459
13538
  *
13460
- * @returns {bigint}
13539
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
13540
+ *
13541
+ * @returns {BigValue}
13461
13542
  */
13462
13543
  readUInt64() {
13463
13544
  return this.readInt64(true);
@@ -13465,7 +13546,9 @@ class BiBaseStreamer {
13465
13546
  /**
13466
13547
  * Read signed 64 bit integer.
13467
13548
  *
13468
- * @returns {bigint}
13549
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
13550
+ *
13551
+ * @returns {BigValue}
13469
13552
  */
13470
13553
  readInt64BE() {
13471
13554
  return this.readInt64(false, "big");
@@ -13473,7 +13556,9 @@ class BiBaseStreamer {
13473
13556
  /**
13474
13557
  * Read unsigned 64 bit integer.
13475
13558
  *
13476
- * @returns {bigint}
13559
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
13560
+ *
13561
+ * @returns {BigValue}
13477
13562
  */
13478
13563
  readUInt64BE() {
13479
13564
  return this.readInt64(true, "big");
@@ -13481,7 +13566,9 @@ class BiBaseStreamer {
13481
13566
  /**
13482
13567
  * Read signed 64 bit integer.
13483
13568
  *
13484
- * @returns {bigint}
13569
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
13570
+ *
13571
+ * @returns {BigValue}
13485
13572
  */
13486
13573
  readInt64LE() {
13487
13574
  return this.readInt64(false, "little");
@@ -13489,7 +13576,9 @@ class BiBaseStreamer {
13489
13576
  /**
13490
13577
  * Read unsigned 64 bit integer.
13491
13578
  *
13492
- * @returns {bigint}
13579
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
13580
+ *
13581
+ * @returns {BigValue}
13493
13582
  */
13494
13583
  readUInt64LE() {
13495
13584
  return this.readInt64(true, "little");
@@ -13581,11 +13670,12 @@ class BiBaseStreamer {
13581
13670
  *
13582
13671
  * @param {string} filePath - Path to file
13583
13672
  * @param {BiOptions?} options - Any options to set at start
13584
- * @param {number?} options.byteOffset - Byte offset to start reader (default ``0``)
13585
- * @param {number?} options.bitOffset - Bit offset 0-7 to start reader (default ``0``)
13586
- * @param {string?} options.endianness - Endianness ``big`` or ``little`` (default ``little``)
13587
- * @param {boolean?} options.strict - Strict mode: if ``true`` does not extend supplied array on outside write (default ``true``)
13588
- * @param {number?} options.extendBufferSize - Amount of data to add when extending the buffer array when strict mode is false. Note: Changes logic in ``.get`` and ``.return``.
13673
+ * @param {BiOptions["byteOffset"]?} options.byteOffset - Byte offset to start writer (default ``0``)
13674
+ * @param {BiOptions["bitOffset"]?} options.bitOffset - Bit offset 0-7 to start writer (default ``0``)
13675
+ * @param {BiOptions["endianness"]?} options.endianness - Endianness ``big`` or ``little`` (default ``little``)
13676
+ * @param {BiOptions["strict"]?} options.strict - Strict mode: if ``true`` does not extend supplied array on outside write (default ``false``)
13677
+ * @param {BiOptions["extendBufferSize"]?} options.extendBufferSize - Amount of data to add when extending the buffer array when strict mode is false. Note: Changes logic in ``.get`` and ``.return``.
13678
+ * @param {BiOptions["enforceBigInt"]?} options.enforceBigInt - 64 bit value reads will always stay ``BigInt``.
13589
13679
  *
13590
13680
  * @since 3.1
13591
13681
  */
@@ -13597,11 +13687,12 @@ class BiReaderStream extends BiBaseStreamer {
13597
13687
  *
13598
13688
  * @param {string} filePath - Path to file
13599
13689
  * @param {BiOptions?} options - Any options to set at start
13600
- * @param {number?} options.byteOffset - Byte offset to start reader (default ``0``)
13601
- * @param {number?} options.bitOffset - Bit offset 0-7 to start reader (default ``0``)
13602
- * @param {string?} options.endianness - Endianness ``big`` or ``little`` (default ``little``)
13603
- * @param {boolean?} options.strict - Strict mode: if ``true`` does not extend supplied array on outside write (default ``true``)
13604
- * @param {number?} options.extendBufferSize - Amount of data to add when extending the buffer array when strict mode is false. Note: Changes logic in ``.get`` and ``.return``.
13690
+ * @param {BiOptions["byteOffset"]?} options.byteOffset - Byte offset to start writer (default ``0``)
13691
+ * @param {BiOptions["bitOffset"]?} options.bitOffset - Bit offset 0-7 to start writer (default ``0``)
13692
+ * @param {BiOptions["endianness"]?} options.endianness - Endianness ``big`` or ``little`` (default ``little``)
13693
+ * @param {BiOptions["strict"]?} options.strict - Strict mode: if ``true`` does not extend supplied array on outside write (default ``false``)
13694
+ * @param {BiOptions["extendBufferSize"]?} options.extendBufferSize - Amount of data to add when extending the buffer array when strict mode is false. Note: Changes logic in ``.get`` and ``.return``.
13695
+ * @param {BiOptions["enforceBigInt"]?} options.enforceBigInt - 64 bit value reads will always stay ``BigInt``.
13605
13696
  */
13606
13697
  constructor(filePath, options = {}) {
13607
13698
  super(filePath, false);
@@ -13615,6 +13706,7 @@ class BiReaderStream extends BiBaseStreamer {
13615
13706
  if (options.endianness != undefined && !(options.endianness == "big" || options.endianness == "little")) {
13616
13707
  throw new Error("Byte order must be big or little");
13617
13708
  }
13709
+ this.enforceBigInt = options?.enforceBigInt ?? false;
13618
13710
  this.endian = options.endianness || "little";
13619
13711
  if (typeof options.strict == "boolean") {
13620
13712
  this.strict = options.strict;
@@ -16082,7 +16174,9 @@ class BiReaderStream extends BiBaseStreamer {
16082
16174
  /**
16083
16175
  * Read signed 64 bit integer
16084
16176
  *
16085
- * @returns {bigint}
16177
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
16178
+ *
16179
+ * @returns {BigValue}
16086
16180
  */
16087
16181
  get int64() {
16088
16182
  return this.readInt64();
@@ -16090,7 +16184,9 @@ class BiReaderStream extends BiBaseStreamer {
16090
16184
  /**
16091
16185
  * Read signed 64 bit integer.
16092
16186
  *
16093
- * @returns {bigint}
16187
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
16188
+ *
16189
+ * @returns {BigValue}
16094
16190
  */
16095
16191
  get bigint() {
16096
16192
  return this.readInt64();
@@ -16098,7 +16194,9 @@ class BiReaderStream extends BiBaseStreamer {
16098
16194
  /**
16099
16195
  * Read signed 64 bit integer.
16100
16196
  *
16101
- * @returns {bigint}
16197
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
16198
+ *
16199
+ * @returns {BigValue}
16102
16200
  */
16103
16201
  get quad() {
16104
16202
  return this.readInt64();
@@ -16106,7 +16204,9 @@ class BiReaderStream extends BiBaseStreamer {
16106
16204
  /**
16107
16205
  * Read unsigned 64 bit integer.
16108
16206
  *
16109
- * @returns {bigint}
16207
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
16208
+ *
16209
+ * @returns {BigValue}
16110
16210
  */
16111
16211
  get uint64() {
16112
16212
  return this.readInt64(true);
@@ -16114,7 +16214,9 @@ class BiReaderStream extends BiBaseStreamer {
16114
16214
  /**
16115
16215
  * Read unsigned 64 bit integer.
16116
16216
  *
16117
- * @returns {bigint}
16217
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
16218
+ *
16219
+ * @returns {BigValue}
16118
16220
  */
16119
16221
  get ubigint() {
16120
16222
  return this.readInt64(true);
@@ -16122,7 +16224,9 @@ class BiReaderStream extends BiBaseStreamer {
16122
16224
  /**
16123
16225
  * Read unsigned 64 bit integer.
16124
16226
  *
16125
- * @returns {bigint}
16227
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
16228
+ *
16229
+ * @returns {BigValue}
16126
16230
  */
16127
16231
  get uquad() {
16128
16232
  return this.readInt64(true);
@@ -16130,7 +16234,9 @@ class BiReaderStream extends BiBaseStreamer {
16130
16234
  /**
16131
16235
  * Read signed 64 bit integer.
16132
16236
  *
16133
- * @returns {bigint}
16237
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
16238
+ *
16239
+ * @returns {BigValue}
16134
16240
  */
16135
16241
  get int64be() {
16136
16242
  return this.readInt64(false, "big");
@@ -16138,7 +16244,9 @@ class BiReaderStream extends BiBaseStreamer {
16138
16244
  /**
16139
16245
  * Read signed 64 bit integer.
16140
16246
  *
16141
- * @returns {bigint}
16247
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
16248
+ *
16249
+ * @returns {BigValue}
16142
16250
  */
16143
16251
  get bigintbe() {
16144
16252
  return this.readInt64(false, "big");
@@ -16146,7 +16254,9 @@ class BiReaderStream extends BiBaseStreamer {
16146
16254
  /**
16147
16255
  * Read signed 64 bit integer.
16148
16256
  *
16149
- * @returns {bigint}
16257
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
16258
+ *
16259
+ * @returns {BigValue}
16150
16260
  */
16151
16261
  get quadbe() {
16152
16262
  return this.readInt64(false, "big");
@@ -16154,7 +16264,9 @@ class BiReaderStream extends BiBaseStreamer {
16154
16264
  /**
16155
16265
  * Read unsigned 64 bit integer.
16156
16266
  *
16157
- * @returns {bigint}
16267
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
16268
+ *
16269
+ * @returns {BigValue}
16158
16270
  */
16159
16271
  get uint64be() {
16160
16272
  return this.readInt64(true, "big");
@@ -16162,7 +16274,9 @@ class BiReaderStream extends BiBaseStreamer {
16162
16274
  /**
16163
16275
  * Read unsigned 64 bit integer.
16164
16276
  *
16165
- * @returns {bigint}
16277
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
16278
+ *
16279
+ * @returns {BigValue}
16166
16280
  */
16167
16281
  get ubigintbe() {
16168
16282
  return this.readInt64(true, "big");
@@ -16170,7 +16284,9 @@ class BiReaderStream extends BiBaseStreamer {
16170
16284
  /**
16171
16285
  * Read unsigned 64 bit integer.
16172
16286
  *
16173
- * @returns {bigint}
16287
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
16288
+ *
16289
+ * @returns {BigValue}
16174
16290
  */
16175
16291
  get uquadbe() {
16176
16292
  return this.readInt64(true, "big");
@@ -16178,7 +16294,9 @@ class BiReaderStream extends BiBaseStreamer {
16178
16294
  /**
16179
16295
  * Read signed 64 bit integer.
16180
16296
  *
16181
- * @returns {bigint}
16297
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
16298
+ *
16299
+ * @returns {BigValue}
16182
16300
  */
16183
16301
  get int64le() {
16184
16302
  return this.readInt64(false, "little");
@@ -16186,7 +16304,9 @@ class BiReaderStream extends BiBaseStreamer {
16186
16304
  /**
16187
16305
  * Read signed 64 bit integer.
16188
16306
  *
16189
- * @returns {bigint}
16307
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
16308
+ *
16309
+ * @returns {BigValue}
16190
16310
  */
16191
16311
  get bigintle() {
16192
16312
  return this.readInt64(false, "little");
@@ -16194,7 +16314,9 @@ class BiReaderStream extends BiBaseStreamer {
16194
16314
  /**
16195
16315
  * Read signed 64 bit integer.
16196
16316
  *
16197
- * @returns {bigint}
16317
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
16318
+ *
16319
+ * @returns {BigValue}
16198
16320
  */
16199
16321
  get quadle() {
16200
16322
  return this.readInt64(false, "little");
@@ -16202,7 +16324,9 @@ class BiReaderStream extends BiBaseStreamer {
16202
16324
  /**
16203
16325
  * Read unsigned 64 bit integer.
16204
16326
  *
16205
- * @returns {bigint}
16327
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
16328
+ *
16329
+ * @returns {BigValue}
16206
16330
  */
16207
16331
  get uint64le() {
16208
16332
  return this.readInt64(true, "little");
@@ -16210,7 +16334,9 @@ class BiReaderStream extends BiBaseStreamer {
16210
16334
  /**
16211
16335
  * Read unsigned 64 bit integer.
16212
16336
  *
16213
- * @returns {bigint}
16337
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
16338
+ *
16339
+ * @returns {BigValue}
16214
16340
  */
16215
16341
  get ubigintle() {
16216
16342
  return this.readInt64(true, "little");
@@ -16218,7 +16344,9 @@ class BiReaderStream extends BiBaseStreamer {
16218
16344
  /**
16219
16345
  * Read unsigned 64 bit integer.
16220
16346
  *
16221
- * @returns {bigint}
16347
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
16348
+ *
16349
+ * @returns {BigValue}
16222
16350
  */
16223
16351
  get uquadle() {
16224
16352
  return this.readInt64(true, "little");
@@ -16617,6 +16745,7 @@ class BiReaderStream extends BiBaseStreamer {
16617
16745
  * @param {BiOptions["endianness"]?} options.endianness - Endianness ``big`` or ``little`` (default ``little``)
16618
16746
  * @param {BiOptions["strict"]?} options.strict - Strict mode: if ``true`` does not extend supplied array on outside write (default ``false``)
16619
16747
  * @param {BiOptions["extendBufferSize"]?} options.extendBufferSize - Amount of data to add when extending the buffer array when strict mode is false. Note: Changes logic in ``.get`` and ``.return``.
16748
+ * @param {BiOptions["enforceBigInt"]?} options.enforceBigInt - 64 bit value reads will always stay ``BigInt``.
16620
16749
  *
16621
16750
  * @since 3.1
16622
16751
  */
@@ -16633,6 +16762,7 @@ class BiWriterStream extends BiBaseStreamer {
16633
16762
  * @param {BiOptions["endianness"]?} options.endianness - Endianness ``big`` or ``little`` (default ``little``)
16634
16763
  * @param {BiOptions["strict"]?} options.strict - Strict mode: if ``true`` does not extend supplied array on outside write (default ``false``)
16635
16764
  * @param {BiOptions["extendBufferSize"]?} options.extendBufferSize - Amount of data to add when extending the buffer array when strict mode is false. Note: Changes logic in ``.get`` and ``.return``.
16765
+ * @param {BiOptions["enforceBigInt"]?} options.enforceBigInt - 64 bit value reads will always stay ``BigInt``.
16636
16766
  */
16637
16767
  constructor(filePath, options = {}) {
16638
16768
  super(filePath, true);
@@ -16640,6 +16770,7 @@ class BiWriterStream extends BiBaseStreamer {
16640
16770
  if (options.extendBufferSize != undefined && options.extendBufferSize != 0) {
16641
16771
  this.extendBufferSize = options.extendBufferSize;
16642
16772
  }
16773
+ this.enforceBigInt = options?.enforceBigInt ?? false;
16643
16774
  if (typeof options.strict == "boolean") {
16644
16775
  this.strict = options.strict;
16645
16776
  }