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.esm.js CHANGED
@@ -1,6 +1,11 @@
1
1
  import fs from 'node:fs';
2
2
  import * as buff from 'node:buffer';
3
3
 
4
+ const MIN_SAFE = BigInt(Number.MIN_SAFE_INTEGER);
5
+ const MAX_SAFE = BigInt(Number.MAX_SAFE_INTEGER);
6
+ function isSafeInt64(big) {
7
+ return big >= MIN_SAFE && big <= MAX_SAFE;
8
+ }
4
9
  function isBuffer(obj) {
5
10
  return buffcheck(obj);
6
11
  }
@@ -1353,6 +1358,14 @@ function rint64$1(ctx, unsigned, endian) {
1353
1358
  }
1354
1359
  }
1355
1360
  ctx.bitoffset = 0;
1361
+ if (ctx.enforceBigInt) {
1362
+ return value;
1363
+ }
1364
+ else {
1365
+ if (isSafeInt64(value)) {
1366
+ return Number(value);
1367
+ }
1368
+ }
1356
1369
  return value;
1357
1370
  }
1358
1371
  function wint64$1(ctx, value, unsigned, endian) {
@@ -1439,9 +1452,9 @@ function wdfloat$1(ctx, value, endian) {
1439
1452
  function rdfloat$1(ctx, endian) {
1440
1453
  endian = (endian == undefined ? ctx.endian : endian);
1441
1454
  var uint64Value = ctx.readInt64(true, endian);
1442
- const sign = (uint64Value & 0x8000000000000000n) >> 63n;
1443
- const exponent = Number((uint64Value & 0x7ff0000000000000n) >> 52n) - 1023;
1444
- const fraction = Number(uint64Value & 0x000fffffffffffffn) / Math.pow(2, 52);
1455
+ const sign = (BigInt(uint64Value) & 0x8000000000000000n) >> 63n;
1456
+ const exponent = Number((BigInt(uint64Value) & 0x7ff0000000000000n) >> 52n) - 1023;
1457
+ const fraction = Number(BigInt(uint64Value) & 0x000fffffffffffffn) / Math.pow(2, 52);
1445
1458
  var floatValue;
1446
1459
  if (exponent == -1023) {
1447
1460
  if (fraction == 0) {
@@ -1751,6 +1764,7 @@ class BiBase {
1751
1764
  */
1752
1765
  this.strDefaults = { stringType: "utf-8", terminateValue: 0x0 };
1753
1766
  this.maxFileSize = null;
1767
+ this.enforceBigInt = false;
1754
1768
  }
1755
1769
  /**
1756
1770
  * Settings for when using .str
@@ -3428,9 +3442,11 @@ class BiBase {
3428
3442
  /**
3429
3443
  * Read signed 64 bit integer.
3430
3444
  *
3445
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
3446
+ *
3431
3447
  * @param {boolean} unsigned - if value is unsigned or not
3432
3448
  * @param {endian?} endian - ``big`` or ``little``
3433
- * @returns {bigint}
3449
+ * @returns {BigValue}
3434
3450
  */
3435
3451
  readInt64(unsigned, endian) {
3436
3452
  return rint64$1(this, unsigned, endian);
@@ -3489,7 +3505,9 @@ class BiBase {
3489
3505
  /**
3490
3506
  * Read unsigned 64 bit integer.
3491
3507
  *
3492
- * @returns {bigint}
3508
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
3509
+ *
3510
+ * @returns {BigValue}
3493
3511
  */
3494
3512
  readUInt64() {
3495
3513
  return this.readInt64(true);
@@ -3497,7 +3515,9 @@ class BiBase {
3497
3515
  /**
3498
3516
  * Read signed 64 bit integer.
3499
3517
  *
3500
- * @returns {bigint}
3518
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
3519
+ *
3520
+ * @returns {BigValue}
3501
3521
  */
3502
3522
  readInt64BE() {
3503
3523
  return this.readInt64(false, "big");
@@ -3505,7 +3525,9 @@ class BiBase {
3505
3525
  /**
3506
3526
  * Read unsigned 64 bit integer.
3507
3527
  *
3508
- * @returns {bigint}
3528
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
3529
+ *
3530
+ * @returns {BigValue}
3509
3531
  */
3510
3532
  readUInt64BE() {
3511
3533
  return this.readInt64(true, "big");
@@ -3513,7 +3535,9 @@ class BiBase {
3513
3535
  /**
3514
3536
  * Read signed 64 bit integer.
3515
3537
  *
3516
- * @returns {bigint}
3538
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
3539
+ *
3540
+ * @returns {BigValue}
3517
3541
  */
3518
3542
  readInt64LE() {
3519
3543
  return this.readInt64(false, "little");
@@ -3521,7 +3545,9 @@ class BiBase {
3521
3545
  /**
3522
3546
  * Read unsigned 64 bit integer.
3523
3547
  *
3524
- * @returns {bigint}
3548
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
3549
+ *
3550
+ * @returns {BigValue}
3525
3551
  */
3526
3552
  readUInt64LE() {
3527
3553
  return this.readInt64(true, "little");
@@ -3613,11 +3639,12 @@ class BiBase {
3613
3639
  *
3614
3640
  * @param {Buffer|Uint8Array} data - ``Buffer`` or ``Uint8Array``. Always found in ``BiReader.data``
3615
3641
  * @param {BiOptions?} options - Any options to set at start
3616
- * @param {number?} options.byteOffset - Byte offset to start reader (default ``0``)
3617
- * @param {number?} options.bitOffset - Bit offset 0-7 to start reader (default ``0``)
3618
- * @param {string?} options.endianness - Endianness ``big`` or ``little`` (default ``little``)
3619
- * @param {boolean?} options.strict - Strict mode: if ``true`` does not extend supplied array on outside write (default ``true``)
3620
- * @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``.
3642
+ * @param {BiOptions["byteOffset"]?} options.byteOffset - Byte offset to start writer (default ``0``)
3643
+ * @param {BiOptions["bitOffset"]?} options.bitOffset - Bit offset 0-7 to start writer (default ``0``)
3644
+ * @param {BiOptions["endianness"]?} options.endianness - Endianness ``big`` or ``little`` (default ``little``)
3645
+ * @param {BiOptions["strict"]?} options.strict - Strict mode: if ``true`` does not extend supplied array on outside write (default ``false``)
3646
+ * @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``.
3647
+ * @param {BiOptions["enforceBigInt"]?} options.enforceBigInt - 64 bit value reads will always stay ``BigInt``.
3621
3648
  *
3622
3649
  * @since 2.0
3623
3650
  */
@@ -3627,11 +3654,12 @@ class BiReader extends BiBase {
3627
3654
  *
3628
3655
  * @param {Buffer|Uint8Array} data - ``Buffer`` or ``Uint8Array``. Always found in ``BiReader.data``
3629
3656
  * @param {BiOptions?} options - Any options to set at start
3630
- * @param {number?} options.byteOffset - Byte offset to start reader (default ``0``)
3631
- * @param {number?} options.bitOffset - Bit offset 0-7 to start reader (default ``0``)
3632
- * @param {string?} options.endianness - Endianness ``big`` or ``little`` (default ``little``)
3633
- * @param {boolean?} options.strict - Strict mode: if ``true`` does not extend supplied array on outside write (default ``true``)
3634
- * @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``.
3657
+ * @param {BiOptions["byteOffset"]?} options.byteOffset - Byte offset to start writer (default ``0``)
3658
+ * @param {BiOptions["bitOffset"]?} options.bitOffset - Bit offset 0-7 to start writer (default ``0``)
3659
+ * @param {BiOptions["endianness"]?} options.endianness - Endianness ``big`` or ``little`` (default ``little``)
3660
+ * @param {BiOptions["strict"]?} options.strict - Strict mode: if ``true`` does not extend supplied array on outside write (default ``false``)
3661
+ * @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``.
3662
+ * @param {BiOptions["enforceBigInt"]?} options.enforceBigInt - 64 bit value reads will always stay ``BigInt``.
3635
3663
  */
3636
3664
  constructor(data, options = {}) {
3637
3665
  super();
@@ -3645,6 +3673,7 @@ class BiReader extends BiBase {
3645
3673
  }
3646
3674
  this.data = data;
3647
3675
  }
3676
+ this.enforceBigInt = options?.enforceBigInt ?? false;
3648
3677
  if (options.extendBufferSize != undefined && options.extendBufferSize != 0) {
3649
3678
  this.extendBufferSize = options.extendBufferSize;
3650
3679
  }
@@ -6145,7 +6174,9 @@ class BiReader extends BiBase {
6145
6174
  /**
6146
6175
  * Read signed 64 bit integer
6147
6176
  *
6148
- * @returns {bigint}
6177
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
6178
+ *
6179
+ * @returns {BigValue}
6149
6180
  */
6150
6181
  get int64() {
6151
6182
  return this.readInt64();
@@ -6153,7 +6184,9 @@ class BiReader extends BiBase {
6153
6184
  /**
6154
6185
  * Read signed 64 bit integer.
6155
6186
  *
6156
- * @returns {bigint}
6187
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
6188
+ *
6189
+ * @returns {BigValue}
6157
6190
  */
6158
6191
  get bigint() {
6159
6192
  return this.readInt64();
@@ -6161,7 +6194,9 @@ class BiReader extends BiBase {
6161
6194
  /**
6162
6195
  * Read signed 64 bit integer.
6163
6196
  *
6164
- * @returns {bigint}
6197
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
6198
+ *
6199
+ * @returns {BigValue}
6165
6200
  */
6166
6201
  get quad() {
6167
6202
  return this.readInt64();
@@ -6169,7 +6204,9 @@ class BiReader extends BiBase {
6169
6204
  /**
6170
6205
  * Read unsigned 64 bit integer.
6171
6206
  *
6172
- * @returns {bigint}
6207
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
6208
+ *
6209
+ * @returns {BigValue}
6173
6210
  */
6174
6211
  get uint64() {
6175
6212
  return this.readInt64(true);
@@ -6177,7 +6214,9 @@ class BiReader extends BiBase {
6177
6214
  /**
6178
6215
  * Read unsigned 64 bit integer.
6179
6216
  *
6180
- * @returns {bigint}
6217
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
6218
+ *
6219
+ * @returns {BigValue}
6181
6220
  */
6182
6221
  get ubigint() {
6183
6222
  return this.readInt64(true);
@@ -6185,7 +6224,9 @@ class BiReader extends BiBase {
6185
6224
  /**
6186
6225
  * Read unsigned 64 bit integer.
6187
6226
  *
6188
- * @returns {bigint}
6227
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
6228
+ *
6229
+ * @returns {BigValue}
6189
6230
  */
6190
6231
  get uquad() {
6191
6232
  return this.readInt64(true);
@@ -6193,7 +6234,9 @@ class BiReader extends BiBase {
6193
6234
  /**
6194
6235
  * Read signed 64 bit integer.
6195
6236
  *
6196
- * @returns {bigint}
6237
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
6238
+ *
6239
+ * @returns {BigValue}
6197
6240
  */
6198
6241
  get int64be() {
6199
6242
  return this.readInt64(false, "big");
@@ -6201,7 +6244,9 @@ class BiReader extends BiBase {
6201
6244
  /**
6202
6245
  * Read signed 64 bit integer.
6203
6246
  *
6204
- * @returns {bigint}
6247
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
6248
+ *
6249
+ * @returns {BigValue}
6205
6250
  */
6206
6251
  get bigintbe() {
6207
6252
  return this.readInt64(false, "big");
@@ -6209,7 +6254,9 @@ class BiReader extends BiBase {
6209
6254
  /**
6210
6255
  * Read signed 64 bit integer.
6211
6256
  *
6212
- * @returns {bigint}
6257
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
6258
+ *
6259
+ * @returns {BigValue}
6213
6260
  */
6214
6261
  get quadbe() {
6215
6262
  return this.readInt64(false, "big");
@@ -6217,7 +6264,9 @@ class BiReader extends BiBase {
6217
6264
  /**
6218
6265
  * Read unsigned 64 bit integer.
6219
6266
  *
6220
- * @returns {bigint}
6267
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
6268
+ *
6269
+ * @returns {BigValue}
6221
6270
  */
6222
6271
  get uint64be() {
6223
6272
  return this.readInt64(true, "big");
@@ -6225,7 +6274,9 @@ class BiReader extends BiBase {
6225
6274
  /**
6226
6275
  * Read unsigned 64 bit integer.
6227
6276
  *
6228
- * @returns {bigint}
6277
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
6278
+ *
6279
+ * @returns {BigValue}
6229
6280
  */
6230
6281
  get ubigintbe() {
6231
6282
  return this.readInt64(true, "big");
@@ -6233,7 +6284,9 @@ class BiReader extends BiBase {
6233
6284
  /**
6234
6285
  * Read unsigned 64 bit integer.
6235
6286
  *
6236
- * @returns {bigint}
6287
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
6288
+ *
6289
+ * @returns {BigValue}
6237
6290
  */
6238
6291
  get uquadbe() {
6239
6292
  return this.readInt64(true, "big");
@@ -6241,7 +6294,9 @@ class BiReader extends BiBase {
6241
6294
  /**
6242
6295
  * Read signed 64 bit integer.
6243
6296
  *
6244
- * @returns {bigint}
6297
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
6298
+ *
6299
+ * @returns {BigValue}
6245
6300
  */
6246
6301
  get int64le() {
6247
6302
  return this.readInt64(false, "little");
@@ -6249,7 +6304,9 @@ class BiReader extends BiBase {
6249
6304
  /**
6250
6305
  * Read signed 64 bit integer.
6251
6306
  *
6252
- * @returns {bigint}
6307
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
6308
+ *
6309
+ * @returns {BigValue}
6253
6310
  */
6254
6311
  get bigintle() {
6255
6312
  return this.readInt64(false, "little");
@@ -6257,7 +6314,9 @@ class BiReader extends BiBase {
6257
6314
  /**
6258
6315
  * Read signed 64 bit integer.
6259
6316
  *
6260
- * @returns {bigint}
6317
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
6318
+ *
6319
+ * @returns {BigValue}
6261
6320
  */
6262
6321
  get quadle() {
6263
6322
  return this.readInt64(false, "little");
@@ -6265,7 +6324,9 @@ class BiReader extends BiBase {
6265
6324
  /**
6266
6325
  * Read unsigned 64 bit integer.
6267
6326
  *
6268
- * @returns {bigint}
6327
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
6328
+ *
6329
+ * @returns {BigValue}
6269
6330
  */
6270
6331
  get uint64le() {
6271
6332
  return this.readInt64(true, "little");
@@ -6273,7 +6334,9 @@ class BiReader extends BiBase {
6273
6334
  /**
6274
6335
  * Read unsigned 64 bit integer.
6275
6336
  *
6276
- * @returns {bigint}
6337
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
6338
+ *
6339
+ * @returns {BigValue}
6277
6340
  */
6278
6341
  get ubigintle() {
6279
6342
  return this.readInt64(true, "little");
@@ -6281,7 +6344,9 @@ class BiReader extends BiBase {
6281
6344
  /**
6282
6345
  * Read unsigned 64 bit integer.
6283
6346
  *
6284
- * @returns {bigint}
6347
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
6348
+ *
6349
+ * @returns {BigValue}
6285
6350
  */
6286
6351
  get uquadle() {
6287
6352
  return this.readInt64(true, "little");
@@ -6678,6 +6743,7 @@ class BiReader extends BiBase {
6678
6743
  * @param {BiOptions["endianness"]?} options.endianness - Endianness ``big`` or ``little`` (default ``little``)
6679
6744
  * @param {BiOptions["strict"]?} options.strict - Strict mode: if ``true`` does not extend supplied array on outside write (default ``false``)
6680
6745
  * @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``.
6746
+ * @param {BiOptions["enforceBigInt"]?} options.enforceBigInt - 64 bit value reads will always stay ``BigInt``.
6681
6747
  *
6682
6748
  * @since 2.0
6683
6749
  */
@@ -6692,6 +6758,7 @@ class BiWriter extends BiBase {
6692
6758
  * @param {BiOptions["endianness"]?} options.endianness - Endianness ``big`` or ``little`` (default ``little``)
6693
6759
  * @param {BiOptions["strict"]?} options.strict - Strict mode: if ``true`` does not extend supplied array on outside write (default ``false``)
6694
6760
  * @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``.
6761
+ * @param {BiOptions["enforceBigInt"]?} options.enforceBigInt - 64 bit value reads will always stay ``BigInt``.
6695
6762
  */
6696
6763
  constructor(data, options = {}) {
6697
6764
  super();
@@ -6710,6 +6777,7 @@ class BiWriter extends BiBase {
6710
6777
  }
6711
6778
  this.data = data;
6712
6779
  }
6780
+ this.enforceBigInt = options?.enforceBigInt ?? false;
6713
6781
  if (options.extendBufferSize != undefined && options.extendBufferSize != 0) {
6714
6782
  this.extendBufferSize = options.extendBufferSize;
6715
6783
  }
@@ -11114,6 +11182,14 @@ function rint64(ctx, unsigned, endian) {
11114
11182
  }
11115
11183
  }
11116
11184
  ctx.bitoffset = 0;
11185
+ if (ctx.enforceBigInt) {
11186
+ return value;
11187
+ }
11188
+ else {
11189
+ if (isSafeInt64(value)) {
11190
+ return Number(value);
11191
+ }
11192
+ }
11117
11193
  return value;
11118
11194
  }
11119
11195
  function wint64(ctx, value, unsigned, endian) {
@@ -11205,10 +11281,10 @@ function wdfloat(ctx, value, endian) {
11205
11281
  }
11206
11282
  function rdfloat(ctx, endian) {
11207
11283
  endian = (endian == undefined ? ctx.endian : endian);
11208
- var uint64Value = ctx.readInt64(true, endian);
11209
- const sign = (uint64Value & 0x8000000000000000n) >> 63n;
11210
- const exponent = Number((uint64Value & 0x7ff0000000000000n) >> 52n) - 1023;
11211
- const fraction = Number(uint64Value & 0x000fffffffffffffn) / Math.pow(2, 52);
11284
+ var uint64Value = ctx.readInt64(true /*unsigned*/, endian);
11285
+ const sign = (BigInt(uint64Value) & 0x8000000000000000n) >> 63n;
11286
+ const exponent = Number((BigInt(uint64Value) & 0x7ff0000000000000n) >> 52n) - 1023;
11287
+ const fraction = Number(BigInt(uint64Value) & 0x000fffffffffffffn) / Math.pow(2, 52);
11212
11288
  var floatValue;
11213
11289
  if (exponent == -1023) {
11214
11290
  if (fraction == 0) {
@@ -11526,6 +11602,7 @@ class BiBaseStreamer {
11526
11602
  */
11527
11603
  this.strDefaults = { stringType: "utf-8", terminateValue: 0x0 };
11528
11604
  this.maxFileSize = null;
11605
+ this.enforceBigInt = false;
11529
11606
  this.filePath = filePath;
11530
11607
  if (readwrite) {
11531
11608
  this.fsMode = "w+";
@@ -13375,9 +13452,11 @@ class BiBaseStreamer {
13375
13452
  /**
13376
13453
  * Read signed 64 bit integer.
13377
13454
  *
13455
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
13456
+ *
13378
13457
  * @param {boolean} unsigned - if value is unsigned or not
13379
13458
  * @param {endian?} endian - ``big`` or ``little``
13380
- * @returns {bigint}
13459
+ * @returns {BigValue}
13381
13460
  */
13382
13461
  readInt64(unsigned, endian) {
13383
13462
  return rint64(this, unsigned, endian);
@@ -13436,7 +13515,9 @@ class BiBaseStreamer {
13436
13515
  /**
13437
13516
  * Read unsigned 64 bit integer.
13438
13517
  *
13439
- * @returns {bigint}
13518
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
13519
+ *
13520
+ * @returns {BigValue}
13440
13521
  */
13441
13522
  readUInt64() {
13442
13523
  return this.readInt64(true);
@@ -13444,7 +13525,9 @@ class BiBaseStreamer {
13444
13525
  /**
13445
13526
  * Read signed 64 bit integer.
13446
13527
  *
13447
- * @returns {bigint}
13528
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
13529
+ *
13530
+ * @returns {BigValue}
13448
13531
  */
13449
13532
  readInt64BE() {
13450
13533
  return this.readInt64(false, "big");
@@ -13452,7 +13535,9 @@ class BiBaseStreamer {
13452
13535
  /**
13453
13536
  * Read unsigned 64 bit integer.
13454
13537
  *
13455
- * @returns {bigint}
13538
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
13539
+ *
13540
+ * @returns {BigValue}
13456
13541
  */
13457
13542
  readUInt64BE() {
13458
13543
  return this.readInt64(true, "big");
@@ -13460,7 +13545,9 @@ class BiBaseStreamer {
13460
13545
  /**
13461
13546
  * Read signed 64 bit integer.
13462
13547
  *
13463
- * @returns {bigint}
13548
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
13549
+ *
13550
+ * @returns {BigValue}
13464
13551
  */
13465
13552
  readInt64LE() {
13466
13553
  return this.readInt64(false, "little");
@@ -13468,7 +13555,9 @@ class BiBaseStreamer {
13468
13555
  /**
13469
13556
  * Read unsigned 64 bit integer.
13470
13557
  *
13471
- * @returns {bigint}
13558
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
13559
+ *
13560
+ * @returns {BigValue}
13472
13561
  */
13473
13562
  readUInt64LE() {
13474
13563
  return this.readInt64(true, "little");
@@ -13560,11 +13649,12 @@ class BiBaseStreamer {
13560
13649
  *
13561
13650
  * @param {string} filePath - Path to file
13562
13651
  * @param {BiOptions?} options - Any options to set at start
13563
- * @param {number?} options.byteOffset - Byte offset to start reader (default ``0``)
13564
- * @param {number?} options.bitOffset - Bit offset 0-7 to start reader (default ``0``)
13565
- * @param {string?} options.endianness - Endianness ``big`` or ``little`` (default ``little``)
13566
- * @param {boolean?} options.strict - Strict mode: if ``true`` does not extend supplied array on outside write (default ``true``)
13567
- * @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``.
13652
+ * @param {BiOptions["byteOffset"]?} options.byteOffset - Byte offset to start writer (default ``0``)
13653
+ * @param {BiOptions["bitOffset"]?} options.bitOffset - Bit offset 0-7 to start writer (default ``0``)
13654
+ * @param {BiOptions["endianness"]?} options.endianness - Endianness ``big`` or ``little`` (default ``little``)
13655
+ * @param {BiOptions["strict"]?} options.strict - Strict mode: if ``true`` does not extend supplied array on outside write (default ``false``)
13656
+ * @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``.
13657
+ * @param {BiOptions["enforceBigInt"]?} options.enforceBigInt - 64 bit value reads will always stay ``BigInt``.
13568
13658
  *
13569
13659
  * @since 3.1
13570
13660
  */
@@ -13576,11 +13666,12 @@ class BiReaderStream extends BiBaseStreamer {
13576
13666
  *
13577
13667
  * @param {string} filePath - Path to file
13578
13668
  * @param {BiOptions?} options - Any options to set at start
13579
- * @param {number?} options.byteOffset - Byte offset to start reader (default ``0``)
13580
- * @param {number?} options.bitOffset - Bit offset 0-7 to start reader (default ``0``)
13581
- * @param {string?} options.endianness - Endianness ``big`` or ``little`` (default ``little``)
13582
- * @param {boolean?} options.strict - Strict mode: if ``true`` does not extend supplied array on outside write (default ``true``)
13583
- * @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``.
13669
+ * @param {BiOptions["byteOffset"]?} options.byteOffset - Byte offset to start writer (default ``0``)
13670
+ * @param {BiOptions["bitOffset"]?} options.bitOffset - Bit offset 0-7 to start writer (default ``0``)
13671
+ * @param {BiOptions["endianness"]?} options.endianness - Endianness ``big`` or ``little`` (default ``little``)
13672
+ * @param {BiOptions["strict"]?} options.strict - Strict mode: if ``true`` does not extend supplied array on outside write (default ``false``)
13673
+ * @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``.
13674
+ * @param {BiOptions["enforceBigInt"]?} options.enforceBigInt - 64 bit value reads will always stay ``BigInt``.
13584
13675
  */
13585
13676
  constructor(filePath, options = {}) {
13586
13677
  super(filePath, false);
@@ -13594,6 +13685,7 @@ class BiReaderStream extends BiBaseStreamer {
13594
13685
  if (options.endianness != undefined && !(options.endianness == "big" || options.endianness == "little")) {
13595
13686
  throw new Error("Byte order must be big or little");
13596
13687
  }
13688
+ this.enforceBigInt = options?.enforceBigInt ?? false;
13597
13689
  this.endian = options.endianness || "little";
13598
13690
  if (typeof options.strict == "boolean") {
13599
13691
  this.strict = options.strict;
@@ -16061,7 +16153,9 @@ class BiReaderStream extends BiBaseStreamer {
16061
16153
  /**
16062
16154
  * Read signed 64 bit integer
16063
16155
  *
16064
- * @returns {bigint}
16156
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
16157
+ *
16158
+ * @returns {BigValue}
16065
16159
  */
16066
16160
  get int64() {
16067
16161
  return this.readInt64();
@@ -16069,7 +16163,9 @@ class BiReaderStream extends BiBaseStreamer {
16069
16163
  /**
16070
16164
  * Read signed 64 bit integer.
16071
16165
  *
16072
- * @returns {bigint}
16166
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
16167
+ *
16168
+ * @returns {BigValue}
16073
16169
  */
16074
16170
  get bigint() {
16075
16171
  return this.readInt64();
@@ -16077,7 +16173,9 @@ class BiReaderStream extends BiBaseStreamer {
16077
16173
  /**
16078
16174
  * Read signed 64 bit integer.
16079
16175
  *
16080
- * @returns {bigint}
16176
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
16177
+ *
16178
+ * @returns {BigValue}
16081
16179
  */
16082
16180
  get quad() {
16083
16181
  return this.readInt64();
@@ -16085,7 +16183,9 @@ class BiReaderStream extends BiBaseStreamer {
16085
16183
  /**
16086
16184
  * Read unsigned 64 bit integer.
16087
16185
  *
16088
- * @returns {bigint}
16186
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
16187
+ *
16188
+ * @returns {BigValue}
16089
16189
  */
16090
16190
  get uint64() {
16091
16191
  return this.readInt64(true);
@@ -16093,7 +16193,9 @@ class BiReaderStream extends BiBaseStreamer {
16093
16193
  /**
16094
16194
  * Read unsigned 64 bit integer.
16095
16195
  *
16096
- * @returns {bigint}
16196
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
16197
+ *
16198
+ * @returns {BigValue}
16097
16199
  */
16098
16200
  get ubigint() {
16099
16201
  return this.readInt64(true);
@@ -16101,7 +16203,9 @@ class BiReaderStream extends BiBaseStreamer {
16101
16203
  /**
16102
16204
  * Read unsigned 64 bit integer.
16103
16205
  *
16104
- * @returns {bigint}
16206
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
16207
+ *
16208
+ * @returns {BigValue}
16105
16209
  */
16106
16210
  get uquad() {
16107
16211
  return this.readInt64(true);
@@ -16109,7 +16213,9 @@ class BiReaderStream extends BiBaseStreamer {
16109
16213
  /**
16110
16214
  * Read signed 64 bit integer.
16111
16215
  *
16112
- * @returns {bigint}
16216
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
16217
+ *
16218
+ * @returns {BigValue}
16113
16219
  */
16114
16220
  get int64be() {
16115
16221
  return this.readInt64(false, "big");
@@ -16117,7 +16223,9 @@ class BiReaderStream extends BiBaseStreamer {
16117
16223
  /**
16118
16224
  * Read signed 64 bit integer.
16119
16225
  *
16120
- * @returns {bigint}
16226
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
16227
+ *
16228
+ * @returns {BigValue}
16121
16229
  */
16122
16230
  get bigintbe() {
16123
16231
  return this.readInt64(false, "big");
@@ -16125,7 +16233,9 @@ class BiReaderStream extends BiBaseStreamer {
16125
16233
  /**
16126
16234
  * Read signed 64 bit integer.
16127
16235
  *
16128
- * @returns {bigint}
16236
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
16237
+ *
16238
+ * @returns {BigValue}
16129
16239
  */
16130
16240
  get quadbe() {
16131
16241
  return this.readInt64(false, "big");
@@ -16133,7 +16243,9 @@ class BiReaderStream extends BiBaseStreamer {
16133
16243
  /**
16134
16244
  * Read unsigned 64 bit integer.
16135
16245
  *
16136
- * @returns {bigint}
16246
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
16247
+ *
16248
+ * @returns {BigValue}
16137
16249
  */
16138
16250
  get uint64be() {
16139
16251
  return this.readInt64(true, "big");
@@ -16141,7 +16253,9 @@ class BiReaderStream extends BiBaseStreamer {
16141
16253
  /**
16142
16254
  * Read unsigned 64 bit integer.
16143
16255
  *
16144
- * @returns {bigint}
16256
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
16257
+ *
16258
+ * @returns {BigValue}
16145
16259
  */
16146
16260
  get ubigintbe() {
16147
16261
  return this.readInt64(true, "big");
@@ -16149,7 +16263,9 @@ class BiReaderStream extends BiBaseStreamer {
16149
16263
  /**
16150
16264
  * Read unsigned 64 bit integer.
16151
16265
  *
16152
- * @returns {bigint}
16266
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
16267
+ *
16268
+ * @returns {BigValue}
16153
16269
  */
16154
16270
  get uquadbe() {
16155
16271
  return this.readInt64(true, "big");
@@ -16157,7 +16273,9 @@ class BiReaderStream extends BiBaseStreamer {
16157
16273
  /**
16158
16274
  * Read signed 64 bit integer.
16159
16275
  *
16160
- * @returns {bigint}
16276
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
16277
+ *
16278
+ * @returns {BigValue}
16161
16279
  */
16162
16280
  get int64le() {
16163
16281
  return this.readInt64(false, "little");
@@ -16165,7 +16283,9 @@ class BiReaderStream extends BiBaseStreamer {
16165
16283
  /**
16166
16284
  * Read signed 64 bit integer.
16167
16285
  *
16168
- * @returns {bigint}
16286
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
16287
+ *
16288
+ * @returns {BigValue}
16169
16289
  */
16170
16290
  get bigintle() {
16171
16291
  return this.readInt64(false, "little");
@@ -16173,7 +16293,9 @@ class BiReaderStream extends BiBaseStreamer {
16173
16293
  /**
16174
16294
  * Read signed 64 bit integer.
16175
16295
  *
16176
- * @returns {bigint}
16296
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
16297
+ *
16298
+ * @returns {BigValue}
16177
16299
  */
16178
16300
  get quadle() {
16179
16301
  return this.readInt64(false, "little");
@@ -16181,7 +16303,9 @@ class BiReaderStream extends BiBaseStreamer {
16181
16303
  /**
16182
16304
  * Read unsigned 64 bit integer.
16183
16305
  *
16184
- * @returns {bigint}
16306
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
16307
+ *
16308
+ * @returns {BigValue}
16185
16309
  */
16186
16310
  get uint64le() {
16187
16311
  return this.readInt64(true, "little");
@@ -16189,7 +16313,9 @@ class BiReaderStream extends BiBaseStreamer {
16189
16313
  /**
16190
16314
  * Read unsigned 64 bit integer.
16191
16315
  *
16192
- * @returns {bigint}
16316
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
16317
+ *
16318
+ * @returns {BigValue}
16193
16319
  */
16194
16320
  get ubigintle() {
16195
16321
  return this.readInt64(true, "little");
@@ -16197,7 +16323,9 @@ class BiReaderStream extends BiBaseStreamer {
16197
16323
  /**
16198
16324
  * Read unsigned 64 bit integer.
16199
16325
  *
16200
- * @returns {bigint}
16326
+ * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
16327
+ *
16328
+ * @returns {BigValue}
16201
16329
  */
16202
16330
  get uquadle() {
16203
16331
  return this.readInt64(true, "little");
@@ -16596,6 +16724,7 @@ class BiReaderStream extends BiBaseStreamer {
16596
16724
  * @param {BiOptions["endianness"]?} options.endianness - Endianness ``big`` or ``little`` (default ``little``)
16597
16725
  * @param {BiOptions["strict"]?} options.strict - Strict mode: if ``true`` does not extend supplied array on outside write (default ``false``)
16598
16726
  * @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``.
16727
+ * @param {BiOptions["enforceBigInt"]?} options.enforceBigInt - 64 bit value reads will always stay ``BigInt``.
16599
16728
  *
16600
16729
  * @since 3.1
16601
16730
  */
@@ -16612,6 +16741,7 @@ class BiWriterStream extends BiBaseStreamer {
16612
16741
  * @param {BiOptions["endianness"]?} options.endianness - Endianness ``big`` or ``little`` (default ``little``)
16613
16742
  * @param {BiOptions["strict"]?} options.strict - Strict mode: if ``true`` does not extend supplied array on outside write (default ``false``)
16614
16743
  * @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``.
16744
+ * @param {BiOptions["enforceBigInt"]?} options.enforceBigInt - 64 bit value reads will always stay ``BigInt``.
16615
16745
  */
16616
16746
  constructor(filePath, options = {}) {
16617
16747
  super(filePath, true);
@@ -16619,6 +16749,7 @@ class BiWriterStream extends BiBaseStreamer {
16619
16749
  if (options.extendBufferSize != undefined && options.extendBufferSize != 0) {
16620
16750
  this.extendBufferSize = options.extendBufferSize;
16621
16751
  }
16752
+ this.enforceBigInt = options?.enforceBigInt ?? false;
16622
16753
  if (typeof options.strict == "boolean") {
16623
16754
  this.strict = options.strict;
16624
16755
  }