bireader 4.0.2 → 4.0.4

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.
@@ -1,38 +1,3 @@
1
- /******************************************************************************
2
- Copyright (c) Microsoft Corporation.
3
-
4
- Permission to use, copy, modify, and/or distribute this software for any
5
- purpose with or without fee is hereby granted.
6
-
7
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
8
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
9
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
10
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
11
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
12
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
13
- PERFORMANCE OF THIS SOFTWARE.
14
- ***************************************************************************** */
15
- /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
16
-
17
-
18
- function __classPrivateFieldGet(receiver, state, kind, f) {
19
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
20
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
21
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
22
- }
23
-
24
- function __classPrivateFieldSet(receiver, state, value, kind, f) {
25
- if (kind === "m") throw new TypeError("Private method is not writable");
26
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
27
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
28
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
29
- }
30
-
31
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
32
- var e = new Error(message);
33
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
34
- };
35
-
36
1
  // #region Types
37
2
  // #region Checks
38
3
  const testFallback = process && process.argv && process.argv.indexOf("FALLBACK=true") != -1;
@@ -1122,7 +1087,6 @@ async function _wstringAsync(encodedString, stringType, endian, terminateValue,
1122
1087
  /**
1123
1088
  * @file BiReader / Writer base for working in sync Buffers or full file reads. Node and Browser.
1124
1089
  */
1125
- var _BiBase_instances, _BiBase_offset, _BiBase_insetBit, _BiBase_data, _BiBase_view, _BiBase_updateSize, _BiBase_updateBuffer, _BiBase_updateView, _BiBase_checkSize, _BiBase_confrimSize, _BiBase_extendArray, _BiBase_findNumber;
1126
1090
  // #region Imports
1127
1091
  var fs$1;
1128
1092
  (async function () {
@@ -1160,13 +1124,88 @@ function _fileExists$1(filePath) {
1160
1124
  * Base class for BiReader and BiWriter
1161
1125
  */
1162
1126
  class BiBase {
1127
+ /**
1128
+ * Endianness of default read.
1129
+ * @type {endian}
1130
+ */
1131
+ endian = "little";
1132
+ /**
1133
+ * Current read byte location.
1134
+ */
1135
+ #offset = 0;
1136
+ /**
1137
+ * Current read byte's bit location. 0 - 7
1138
+ */
1139
+ #insetBit = 0;
1140
+ /**
1141
+ * Size in bytes of the current buffer.
1142
+ */
1143
+ size = 0;
1144
+ /**
1145
+ * Size in bits of the current buffer.
1146
+ */
1147
+ bitSize = 0;
1148
+ /**
1149
+ * Stops the buffer extending on reading or writing outside of current size
1150
+ */
1151
+ strict = false;
1152
+ /**
1153
+ * Console log a hexdump on error.
1154
+ */
1155
+ errorDump = false;
1156
+ /**
1157
+ * Master Buffer
1158
+ */
1159
+ #data = null;
1160
+ /**
1161
+ * DataView of master Buffer
1162
+ */
1163
+ #view;
1164
+ /**
1165
+ * When the data buffer needs to be extended while strict mode is ``false``, this will be the amount it extends.
1166
+ *
1167
+ * Otherwise it extends just the amount of the next written value.
1168
+ *
1169
+ * This can greatly speed up data writes when large files are being written.
1170
+ *
1171
+ * NOTE: Using ``BiWriter.get`` or ``BiWriter.return`` will now remove all data after the current write position. Use ``BiWriter.data`` to get the full buffer instead.
1172
+ */
1173
+ growthIncrement = 1048576;
1174
+ /**
1175
+ * Open file description
1176
+ */
1177
+ fd = null;
1178
+ /**
1179
+ * Current file path
1180
+ */
1181
+ filePath = null;
1182
+ /**
1183
+ * File write mode
1184
+ */
1185
+ fsMode = "r";
1186
+ /**
1187
+ * The settings that used when using the .str getter / setter
1188
+ */
1189
+ strDefaults = { stringType: "utf-8", terminateValue: 0x0 };
1190
+ /**
1191
+ * All int64 reads will return as bigint type
1192
+ */
1193
+ enforceBigInt;
1194
+ /**
1195
+ * Not using a file reader.
1196
+ */
1197
+ isMemoryMode;
1198
+ /**
1199
+ * If data can not be written to the buffer.
1200
+ */
1201
+ readOnly;
1163
1202
  /**
1164
1203
  * Get the current buffer data.
1165
1204
  *
1166
- * @type {DataType}
1205
+ * @type {ReturnMapping<DataType>}
1167
1206
  */
1168
1207
  get data() {
1169
- return __classPrivateFieldGet(this, _BiBase_data, "f");
1208
+ return this.#data;
1170
1209
  }
1171
1210
  ;
1172
1211
  /**
@@ -1176,90 +1215,22 @@ class BiBase {
1176
1215
  */
1177
1216
  set data(data) {
1178
1217
  if (this.isBufferOrUint8Array(data)) {
1179
- __classPrivateFieldSet(this, _BiBase_data, data, "f");
1180
- __classPrivateFieldGet(this, _BiBase_instances, "m", _BiBase_updateView).call(this);
1181
- this.size = __classPrivateFieldGet(this, _BiBase_data, "f").length;
1218
+ this.#data = data;
1219
+ this.#updateView();
1220
+ this.size = this.#data.length;
1182
1221
  this.bitSize = this.size * 8;
1183
1222
  }
1184
1223
  }
1185
1224
  ;
1225
+ wasExpanded = false;
1186
1226
  /**
1187
1227
  * Get the DataView of current buffer data.
1188
1228
  */
1189
1229
  get view() {
1190
- return __classPrivateFieldGet(this, _BiBase_view, "f");
1230
+ return this.#view;
1191
1231
  }
1192
1232
  ;
1193
1233
  constructor(input, options = {}) {
1194
- _BiBase_instances.add(this);
1195
- /**
1196
- * Endianness of default read.
1197
- * @type {endian}
1198
- */
1199
- this.endian = "little";
1200
- /**
1201
- * Current read byte location.
1202
- */
1203
- _BiBase_offset.set(this, 0);
1204
- /**
1205
- * Current read byte's bit location. 0 - 7
1206
- */
1207
- _BiBase_insetBit.set(this, 0);
1208
- /**
1209
- * Size in bytes of the current buffer.
1210
- */
1211
- this.size = 0;
1212
- /**
1213
- * Size in bits of the current buffer.
1214
- */
1215
- this.bitSize = 0;
1216
- /**
1217
- * Stops the buffer extending on reading or writing outside of current size
1218
- */
1219
- this.strict = false;
1220
- /**
1221
- * Console log a hexdump on error.
1222
- */
1223
- this.errorDump = false;
1224
- /**
1225
- * Master Buffer
1226
- */
1227
- _BiBase_data.set(this, null);
1228
- /**
1229
- * DataView of master Buffer
1230
- */
1231
- _BiBase_view.set(this, void 0);
1232
- /**
1233
- * When the data buffer needs to be extended while strict mode is ``false``, this will be the amount it extends.
1234
- *
1235
- * Otherwise it extends just the amount of the next written value.
1236
- *
1237
- * This can greatly speed up data writes when large files are being written.
1238
- *
1239
- * NOTE: Using ``BiWriter.get`` or ``BiWriter.return`` will now remove all data after the current write position. Use ``BiWriter.data`` to get the full buffer instead.
1240
- */
1241
- this.growthIncrement = 1048576;
1242
- /**
1243
- * Open file description
1244
- */
1245
- this.fd = null;
1246
- /**
1247
- * Current file path
1248
- */
1249
- this.filePath = null;
1250
- /**
1251
- * File write mode
1252
- */
1253
- this.fsMode = "r";
1254
- /**
1255
- * The settings that used when using the .str getter / setter
1256
- */
1257
- this.strDefaults = { stringType: "utf-8", terminateValue: 0x0 };
1258
- /**
1259
- * All int64 reads will return as bigint type
1260
- */
1261
- this.enforceBigInt = null;
1262
- this.wasExpanded = false;
1263
1234
  const { byteOffset, bitOffset, endianness, strict, growthIncrement, enforceBigInt, readOnly } = options;
1264
1235
  if (typeof strict != "boolean") {
1265
1236
  throw new Error("Strict mode must be true or false");
@@ -1268,7 +1239,7 @@ class BiBase {
1268
1239
  this.strict = readOnly ? true : strict;
1269
1240
  this.fsMode = this.readOnly ? 'r' : 'r+';
1270
1241
  this.enforceBigInt = !!enforceBigInt;
1271
- if (this.enforceBigInt && !hasBigInt) {
1242
+ if (!hasBigInt) {
1272
1243
  this.enforceBigInt = false;
1273
1244
  }
1274
1245
  this.growthIncrement = growthIncrement;
@@ -1286,27 +1257,27 @@ class BiBase {
1286
1257
  else if (this.isBufferOrUint8Array(input)) {
1287
1258
  this.data = input;
1288
1259
  this.isMemoryMode = true;
1289
- this.size = __classPrivateFieldGet(this, _BiBase_data, "f").length;
1290
- this.bitSize = __classPrivateFieldGet(this, _BiBase_data, "f").length * 8;
1260
+ this.size = this.#data.length;
1261
+ this.bitSize = this.#data.length * 8;
1291
1262
  }
1292
1263
  else {
1293
1264
  throw new Error("Write data must be Uint8Array or Buffer");
1294
1265
  }
1295
- __classPrivateFieldSet(this, _BiBase_offset, byteOffset ?? 0, "f");
1266
+ this.#offset = byteOffset ?? 0;
1296
1267
  if ((bitOffset ?? 0) != 0) {
1297
- __classPrivateFieldSet(this, _BiBase_offset, Math.floor(byteOffset / 8), "f");
1298
- __classPrivateFieldSet(this, _BiBase_insetBit, byteOffset % 8, "f");
1268
+ this.#offset = Math.floor(byteOffset / 8);
1269
+ this.#insetBit = byteOffset % 8;
1299
1270
  }
1300
- __classPrivateFieldSet(this, _BiBase_offset, ((Math.abs(__classPrivateFieldGet(this, _BiBase_offset, "f"))) + Math.ceil((Math.abs(__classPrivateFieldGet(this, _BiBase_insetBit, "f"))) / 8)), "f");
1271
+ this.#offset = ((Math.abs(this.#offset)) + Math.ceil((Math.abs(this.#insetBit)) / 8));
1301
1272
  // Adjust byte offset based on bit overflow
1302
- __classPrivateFieldSet(this, _BiBase_offset, __classPrivateFieldGet(this, _BiBase_offset, "f") + Math.floor((Math.abs(__classPrivateFieldGet(this, _BiBase_insetBit, "f"))) / 8), "f");
1273
+ this.#offset += Math.floor((Math.abs(this.#insetBit)) / 8);
1303
1274
  // Adjust bit offset
1304
- __classPrivateFieldSet(this, _BiBase_insetBit, Math.abs(normalizeBitOffset(__classPrivateFieldGet(this, _BiBase_insetBit, "f"))) % 8, "f");
1275
+ this.#insetBit = Math.abs(normalizeBitOffset(this.#insetBit)) % 8;
1305
1276
  // Ensure bit offset stays between 0-7
1306
- __classPrivateFieldSet(this, _BiBase_insetBit, Math.min(Math.max(__classPrivateFieldGet(this, _BiBase_insetBit, "f"), 0), 7), "f");
1277
+ this.#insetBit = Math.min(Math.max(this.#insetBit, 0), 7);
1307
1278
  // Ensure offset doesn't go negative
1308
- __classPrivateFieldSet(this, _BiBase_offset, Math.max(__classPrivateFieldGet(this, _BiBase_offset, "f"), 0), "f");
1309
- __classPrivateFieldGet(this, _BiBase_instances, "m", _BiBase_confrimSize).call(this, __classPrivateFieldGet(this, _BiBase_offset, "f"));
1279
+ this.#offset = Math.max(this.#offset, 0);
1280
+ this.#confrimSize(this.#offset);
1310
1281
  }
1311
1282
  ;
1312
1283
  /**
@@ -1348,11 +1319,142 @@ class BiBase {
1348
1319
  isUint8Array(obj) {
1349
1320
  return isUint8Array(obj);
1350
1321
  }
1322
+ /**
1323
+ * Internal update size
1324
+ *
1325
+ * run after setting data
1326
+ */
1327
+ #updateSize() {
1328
+ if (this.isMemoryMode) {
1329
+ this.size = this.#data.length;
1330
+ this.bitSize = this.size * 8;
1331
+ return;
1332
+ }
1333
+ if (typeof fs$1 === "undefined") {
1334
+ throw new Error("Can't load file outside of Node.");
1335
+ }
1336
+ if (this.fd != null) {
1337
+ try {
1338
+ const stat = fs$1.fstatSync(this.fd);
1339
+ this.size = stat.size;
1340
+ this.bitSize = this.size * 8;
1341
+ }
1342
+ catch (error) {
1343
+ throw new Error(error);
1344
+ }
1345
+ }
1346
+ }
1351
1347
  ;
1348
+ /**
1349
+ * Internal update buffer.
1350
+ *
1351
+ * Should come after updateSize
1352
+ */
1353
+ #updateBuffer() {
1354
+ if (!this.isMemoryMode) {
1355
+ if (this.fd == null) {
1356
+ try {
1357
+ this.fd = fs$1.openSync(this.filePath, this.fsMode);
1358
+ }
1359
+ catch (error) {
1360
+ throw new Error(error);
1361
+ }
1362
+ }
1363
+ const data = Buffer.alloc(this.size);
1364
+ try {
1365
+ const bytesRead = fs$1.readSync(this.fd, data, 0, data.length, 0);
1366
+ if (bytesRead != this.size) {
1367
+ throw new Error("Didn't update file buffer size. Expecting " + this.size + " but got " + bytesRead);
1368
+ }
1369
+ }
1370
+ catch (error) {
1371
+ throw new Error(error);
1372
+ }
1373
+ this.data = data;
1374
+ this.#updateSize();
1375
+ }
1376
+ this.#offset = this.#offset ?? 0;
1377
+ this.#insetBit = this.#insetBit ?? 0;
1378
+ this.#offset = ((Math.abs(this.#offset)) + Math.ceil((Math.abs(this.#insetBit)) / 8));
1379
+ // Adjust byte offset based on bit overflow
1380
+ this.#offset += Math.floor((Math.abs(this.#insetBit)) / 8);
1381
+ // Adjust bit offset
1382
+ this.#insetBit = Math.abs(normalizeBitOffset(this.#insetBit)) % 8;
1383
+ // Ensure bit offset stays between 0-7
1384
+ this.#insetBit = Math.min(Math.max(this.#insetBit, 0), 7);
1385
+ // Ensure offset doesn't go negative
1386
+ this.#offset = Math.max(this.#offset, 0);
1387
+ this.#confrimSize(this.#offset);
1388
+ }
1352
1389
  ;
1390
+ /**
1391
+ * Call this after everytime we set/replace `this.data`
1392
+ */
1393
+ #updateView() {
1394
+ if (this.#data) {
1395
+ this.#view = new DataView(this.#data.buffer, this.#data.byteOffset ?? 0, this.#data.byteLength);
1396
+ }
1397
+ }
1353
1398
  ;
1399
+ /**
1400
+ * Calls to check if expanding the buffer needs to happen
1401
+ */
1402
+ #checkSize(writeBytes = 0, writeBit = 0, offset = this.#offset) {
1403
+ this.open();
1404
+ const bits = writeBit + this.#insetBit;
1405
+ if (bits != 0) {
1406
+ //add bits
1407
+ writeBytes += Math.ceil(bits / 8);
1408
+ }
1409
+ //if bigger extend
1410
+ this.#confrimSize(offset + writeBytes);
1411
+ //start read location
1412
+ return offset;
1413
+ }
1354
1414
  ;
1415
+ /**
1416
+ * Checks if input requires expanding the buffer
1417
+ */
1418
+ #confrimSize(neededSize) {
1419
+ if (neededSize <= this.size) {
1420
+ return;
1421
+ }
1422
+ var targetSize = neededSize;
1423
+ if (targetSize > this.size) {
1424
+ if (this.strict || this.readOnly) {
1425
+ this.errorDump ? console.log("\x1b[31m[Error]\x1b[0m hexdump:\n" + this.hexdump({ returnString: true })) : "";
1426
+ throw new Error(`\x1b[33m[Strict mode]\x1b[0m: Reached end of data: ` + neededSize + " at " + this.#offset + " of " + this.size);
1427
+ }
1428
+ if (this.growthIncrement != 0) {
1429
+ this.wasExpanded = true;
1430
+ targetSize = Math.ceil(neededSize / this.growthIncrement) * this.growthIncrement;
1431
+ }
1432
+ this.#extendArray(targetSize);
1433
+ }
1434
+ }
1355
1435
  ;
1436
+ /**
1437
+ * Expends the buffer
1438
+ */
1439
+ #extendArray(targetSize) {
1440
+ this.open();
1441
+ if (targetSize <= this.size) {
1442
+ return;
1443
+ }
1444
+ const toPadd = targetSize - this.size;
1445
+ if (this.isBuffer(this.#data)) {
1446
+ var paddbuffer = Buffer.alloc(toPadd);
1447
+ this.data = Buffer.concat([this.#data, paddbuffer]);
1448
+ }
1449
+ else {
1450
+ const newBuf = new Uint8Array(this.size + toPadd);
1451
+ newBuf.set(this.#data);
1452
+ this.data = newBuf;
1453
+ }
1454
+ this.size = this.#data.length;
1455
+ this.bitSize = this.#data.length * 8;
1456
+ return;
1457
+ }
1356
1458
  ;
1357
1459
  ///////////////////////////////
1358
1460
  // #region FILE MODE
@@ -1391,8 +1493,8 @@ class BiBase {
1391
1493
  this.fd == null;
1392
1494
  this.isMemoryMode = true;
1393
1495
  this.data = data;
1394
- __classPrivateFieldGet(this, _BiBase_instances, "m", _BiBase_updateSize).call(this);
1395
- __classPrivateFieldGet(this, _BiBase_instances, "m", _BiBase_updateBuffer).call(this);
1496
+ this.#updateSize();
1497
+ this.#updateBuffer();
1396
1498
  return;
1397
1499
  }
1398
1500
  if (this.isMemoryMode) {
@@ -1413,8 +1515,8 @@ class BiBase {
1413
1515
  catch (error) {
1414
1516
  throw new Error(error);
1415
1517
  }
1416
- __classPrivateFieldGet(this, _BiBase_instances, "m", _BiBase_updateSize).call(this);
1417
- __classPrivateFieldGet(this, _BiBase_instances, "m", _BiBase_updateBuffer).call(this);
1518
+ this.#updateSize();
1519
+ this.#updateBuffer();
1418
1520
  }
1419
1521
  ;
1420
1522
  /**
@@ -1422,9 +1524,9 @@ class BiBase {
1422
1524
  */
1423
1525
  close() {
1424
1526
  if (this.isMemoryMode) {
1425
- const data = __classPrivateFieldGet(this, _BiBase_data, "f");
1426
- __classPrivateFieldSet(this, _BiBase_data, null, "f");
1427
- __classPrivateFieldSet(this, _BiBase_view, null, "f");
1527
+ const data = this.#data;
1528
+ this.#data = null;
1529
+ this.#view = null;
1428
1530
  return data;
1429
1531
  }
1430
1532
  if (this.fd === null) {
@@ -1441,9 +1543,9 @@ class BiBase {
1441
1543
  throw new Error(error);
1442
1544
  }
1443
1545
  this.fd = null;
1444
- const data = __classPrivateFieldGet(this, _BiBase_data, "f");
1445
- __classPrivateFieldSet(this, _BiBase_data, null, "f");
1446
- __classPrivateFieldSet(this, _BiBase_view, null, "f");
1546
+ const data = this.#data;
1547
+ this.#data = null;
1548
+ this.#view = null;
1447
1549
  return data;
1448
1550
  }
1449
1551
  ;
@@ -1452,17 +1554,17 @@ class BiBase {
1452
1554
  */
1453
1555
  commit() {
1454
1556
  if (this.isMemoryMode || this.readOnly) {
1455
- return __classPrivateFieldGet(this, _BiBase_data, "f");
1557
+ return this.#data;
1456
1558
  }
1457
1559
  // this.mode == "file"
1458
1560
  this.open();
1459
1561
  try {
1460
- fs$1.writeSync(this.fd, __classPrivateFieldGet(this, _BiBase_data, "f"), 0, __classPrivateFieldGet(this, _BiBase_data, "f").length);
1562
+ fs$1.writeSync(this.fd, this.#data, 0, this.#data.length);
1461
1563
  }
1462
1564
  catch (error) {
1463
1565
  throw new Error(error);
1464
1566
  }
1465
- __classPrivateFieldGet(this, _BiBase_instances, "m", _BiBase_updateSize).call(this);
1567
+ this.#updateSize();
1466
1568
  }
1467
1569
  ;
1468
1570
  /**
@@ -1680,7 +1782,7 @@ class BiBase {
1680
1782
  * @returns {number} current byte position
1681
1783
  */
1682
1784
  get offset() {
1683
- return __classPrivateFieldGet(this, _BiBase_offset, "f");
1785
+ return this.#offset;
1684
1786
  }
1685
1787
  ;
1686
1788
  /**
@@ -1770,7 +1872,7 @@ class BiBase {
1770
1872
  * @returns {number} current bit position
1771
1873
  */
1772
1874
  get bitOffset() {
1773
- return (__classPrivateFieldGet(this, _BiBase_offset, "f") * 8) + __classPrivateFieldGet(this, _BiBase_insetBit, "f");
1875
+ return (this.#offset * 8) + this.#insetBit;
1774
1876
  }
1775
1877
  ;
1776
1878
  /**
@@ -1855,7 +1957,7 @@ class BiBase {
1855
1957
  * @returns {number} current bit position
1856
1958
  */
1857
1959
  get insetBit() {
1858
- return __classPrivateFieldGet(this, _BiBase_insetBit, "f");
1960
+ return this.#insetBit;
1859
1961
  }
1860
1962
  ;
1861
1963
  /**
@@ -1914,7 +2016,7 @@ class BiBase {
1914
2016
  * @returns {number} size
1915
2017
  */
1916
2018
  get remain() {
1917
- return this.size - __classPrivateFieldGet(this, _BiBase_offset, "f");
2019
+ return this.size - this.#offset;
1918
2020
  }
1919
2021
  ;
1920
2022
  /**
@@ -1959,7 +2061,7 @@ class BiBase {
1959
2061
  * @returns {number} size
1960
2062
  */
1961
2063
  get getLine() {
1962
- return Math.abs(Math.floor((__classPrivateFieldGet(this, _BiBase_offset, "f") - 1) / 16));
2064
+ return Math.abs(Math.floor((this.#offset - 1) / 16));
1963
2065
  }
1964
2066
  ;
1965
2067
  /**
@@ -1981,13 +2083,13 @@ class BiBase {
1981
2083
  *
1982
2084
  * Use ``.data`` instead if you want the full buffer data.
1983
2085
  *
1984
- * @returns {DataType} ``Buffer`` or ``Uint8Array``
2086
+ * @returns {ReturnMapping<DataType>} ``Buffer`` or ``Uint8Array``
1985
2087
  */
1986
2088
  get() {
1987
2089
  if (this.growthIncrement != 0 && this.wasExpanded) {
1988
2090
  this.trim();
1989
2091
  }
1990
- return __classPrivateFieldGet(this, _BiBase_data, "f");
2092
+ return this.#data;
1991
2093
  }
1992
2094
  ;
1993
2095
  /**
@@ -1997,7 +2099,7 @@ class BiBase {
1997
2099
  *
1998
2100
  * Use ``.data`` instead if you want the full buffer data.
1999
2101
  *
2000
- * @returns {DataType} ``Buffer`` or ``Uint8Array``
2102
+ * @returns {ReturnMapping<DataType>} ``Buffer`` or ``Uint8Array``
2001
2103
  */
2002
2104
  getFullBuffer() {
2003
2105
  return this.get();
@@ -2010,7 +2112,7 @@ class BiBase {
2010
2112
  *
2011
2113
  * Use ``.data`` instead if you want the full buffer data.
2012
2114
  *
2013
- * @returns {DataType} ``Buffer`` or ``Uint8Array``
2115
+ * @returns {ReturnMapping<DataType>} ``Buffer`` or ``Uint8Array``
2014
2116
  */
2015
2117
  return() {
2016
2118
  return this.get();
@@ -2058,7 +2160,7 @@ class BiBase {
2058
2160
  */
2059
2161
  hexdump(options = {}) {
2060
2162
  const length = options?.length ?? 192;
2061
- const startByte = options?.startByte ?? __classPrivateFieldGet(this, _BiBase_offset, "f");
2163
+ const startByte = options?.startByte ?? this.#offset;
2062
2164
  const endByte = Math.min(startByte + length, this.size);
2063
2165
  const newSize = endByte - startByte;
2064
2166
  if (startByte > this.size || endByte > this.size) {
@@ -2116,14 +2218,14 @@ class BiBase {
2116
2218
  }
2117
2219
  this.open();
2118
2220
  if (this.isBuffer(this.data)) {
2119
- var offset = this.data.subarray(__classPrivateFieldGet(this, _BiBase_offset, "f"), this.size).indexOf(bytesToFind);
2221
+ var offset = this.data.subarray(this.#offset, this.size).indexOf(bytesToFind);
2120
2222
  if (offset == -1) {
2121
2223
  return -1;
2122
2224
  }
2123
- return offset + __classPrivateFieldGet(this, _BiBase_offset, "f");
2225
+ return offset + this.#offset;
2124
2226
  }
2125
2227
  // this.data == Uint8Array
2126
- for (let i = __classPrivateFieldGet(this, _BiBase_offset, "f"); i <= this.size - bytesToFind.length; i++) {
2228
+ for (let i = this.#offset; i <= this.size - bytesToFind.length; i++) {
2127
2229
  var match = true;
2128
2230
  for (let j = 0; j < bytesToFind.length; j++) {
2129
2231
  if (this.data[i + j] !== bytesToFind[j]) {
@@ -2153,6 +2255,44 @@ class BiBase {
2153
2255
  return this.findBytes(encoded);
2154
2256
  }
2155
2257
  ;
2258
+ #findNumber(value, bits, unsigned, endian = this.endian) {
2259
+ this.#checkSize(Math.floor(bits / 8), 0, this.#offset);
2260
+ for (let z = this.#offset; z <= (this.size - (bits / 8)); z++) {
2261
+ var offsetInBits = 0;
2262
+ var value = 0;
2263
+ for (var i = 0; i < bits;) {
2264
+ const remaining = bits - i;
2265
+ const bitOffset = offsetInBits & 7;
2266
+ const currentByte = this.data[z + (offsetInBits >> 3)];
2267
+ const read = Math.min(remaining, 8 - bitOffset);
2268
+ if (endian == "big") {
2269
+ let mask = ~(0xFF << read);
2270
+ let readBits = (currentByte >> (8 - read - bitOffset)) & mask;
2271
+ value <<= read;
2272
+ value |= readBits;
2273
+ }
2274
+ else {
2275
+ let mask = ~(0xFF << read);
2276
+ let readBits = (currentByte >> bitOffset) & mask;
2277
+ value |= readBits << i;
2278
+ }
2279
+ offsetInBits += read;
2280
+ i += read;
2281
+ }
2282
+ if (unsigned || bits <= 7) {
2283
+ value = value >>> 0;
2284
+ }
2285
+ else {
2286
+ if (bits !== 32 && value & (1 << (bits - 1))) {
2287
+ value |= -1 ^ ((1 << bits) - 1);
2288
+ }
2289
+ }
2290
+ if (value === value) {
2291
+ return z - this.#offset; // Found the byte, return the index from current
2292
+ }
2293
+ }
2294
+ return -1; // number not found
2295
+ }
2156
2296
  ;
2157
2297
  /**
2158
2298
  * Searches for byte value (can be signed or unsigned) position from current read position.
@@ -2166,7 +2306,7 @@ class BiBase {
2166
2306
  * @param {endian} endian - endianness of value (default set endian).
2167
2307
  */
2168
2308
  findByte(value, unsigned = true, endian = this.endian) {
2169
- return __classPrivateFieldGet(this, _BiBase_instances, "m", _BiBase_findNumber).call(this, value, 8, unsigned, endian);
2309
+ return this.#findNumber(value, 8, unsigned, endian);
2170
2310
  }
2171
2311
  ;
2172
2312
  /**
@@ -2181,7 +2321,7 @@ class BiBase {
2181
2321
  * @param {endian} endian - endianness of value (default set endian).
2182
2322
  */
2183
2323
  findShort(value, unsigned = true, endian = this.endian) {
2184
- return __classPrivateFieldGet(this, _BiBase_instances, "m", _BiBase_findNumber).call(this, value, 16, unsigned, endian);
2324
+ return this.#findNumber(value, 16, unsigned, endian);
2185
2325
  }
2186
2326
  ;
2187
2327
  /**
@@ -2196,7 +2336,7 @@ class BiBase {
2196
2336
  * @param {endian} endian - endianness of value (default set endian).
2197
2337
  */
2198
2338
  findInt(value, unsigned = true, endian = this.endian) {
2199
- return __classPrivateFieldGet(this, _BiBase_instances, "m", _BiBase_findNumber).call(this, value, 32, unsigned, endian);
2339
+ return this.#findNumber(value, 32, unsigned, endian);
2200
2340
  }
2201
2341
  ;
2202
2342
  /**
@@ -2214,8 +2354,8 @@ class BiBase {
2214
2354
  if (!hasBigInt) {
2215
2355
  throw new Error("System doesn't support BigInt values.");
2216
2356
  }
2217
- __classPrivateFieldGet(this, _BiBase_instances, "m", _BiBase_checkSize).call(this, 8, 0, __classPrivateFieldGet(this, _BiBase_offset, "f"));
2218
- for (let z = __classPrivateFieldGet(this, _BiBase_offset, "f"); z <= (this.size - 8); z++) {
2357
+ this.#checkSize(8, 0, this.#offset);
2358
+ for (let z = this.#offset; z <= (this.size - 8); z++) {
2219
2359
  var startingValue = BigInt(0);
2220
2360
  if (endian == "little") {
2221
2361
  for (let i = 0; i < 8; i++) {
@@ -2255,8 +2395,8 @@ class BiBase {
2255
2395
  * @param {endian} endian - endianness of value (default set endian).
2256
2396
  */
2257
2397
  findHalfFloat(value, endian = this.endian) {
2258
- __classPrivateFieldGet(this, _BiBase_instances, "m", _BiBase_checkSize).call(this, 2, 0, __classPrivateFieldGet(this, _BiBase_offset, "f"));
2259
- for (let z = __classPrivateFieldGet(this, _BiBase_offset, "f"); z <= (this.size - 2); z++) {
2398
+ this.#checkSize(2, 0, this.#offset);
2399
+ for (let z = this.#offset; z <= (this.size - 2); z++) {
2260
2400
  var startingValue = 0;
2261
2401
  if (endian == "little") {
2262
2402
  startingValue = ((this.data[z + 1] & 0xFFFF) << 8) | (this.data[z] & 0xFFFF);
@@ -2307,8 +2447,8 @@ class BiBase {
2307
2447
  * @param {endian} endian - endianness of value (default set endian).
2308
2448
  */
2309
2449
  findFloat(value, endian = this.endian) {
2310
- __classPrivateFieldGet(this, _BiBase_instances, "m", _BiBase_checkSize).call(this, 4, 0, __classPrivateFieldGet(this, _BiBase_offset, "f"));
2311
- for (let z = __classPrivateFieldGet(this, _BiBase_offset, "f"); z <= (this.size - 4); z++) {
2450
+ this.#checkSize(4, 0, this.#offset);
2451
+ for (let z = this.#offset; z <= (this.size - 4); z++) {
2312
2452
  var startingValue = 0;
2313
2453
  if (endian == "little") {
2314
2454
  startingValue = ((this.data[z + 3] & 0xFF) << 24) |
@@ -2361,8 +2501,8 @@ class BiBase {
2361
2501
  if (!hasBigInt) {
2362
2502
  throw new Error("System doesn't support BigInt values.");
2363
2503
  }
2364
- __classPrivateFieldGet(this, _BiBase_instances, "m", _BiBase_checkSize).call(this, 8, 0, __classPrivateFieldGet(this, _BiBase_offset, "f"));
2365
- for (let z = __classPrivateFieldGet(this, _BiBase_offset, "f"); z <= (this.size - 8); z++) {
2504
+ this.#checkSize(8, 0, this.#offset);
2505
+ for (let z = this.#offset; z <= (this.size - 8); z++) {
2366
2506
  var startingValue = BigInt(0);
2367
2507
  if (endian == "little") {
2368
2508
  for (let i = 0; i < 8; i++) {
@@ -2417,7 +2557,7 @@ class BiBase {
2417
2557
  * @param {number} number - Byte to align
2418
2558
  */
2419
2559
  align(number) {
2420
- const a = __classPrivateFieldGet(this, _BiBase_offset, "f") % number;
2560
+ const a = this.#offset % number;
2421
2561
  if (a) {
2422
2562
  this.skip(number - a);
2423
2563
  }
@@ -2431,7 +2571,7 @@ class BiBase {
2431
2571
  * @param {number} number - Byte to align
2432
2572
  */
2433
2573
  alignRev(number) {
2434
- const a = __classPrivateFieldGet(this, _BiBase_offset, "f") % number;
2574
+ const a = this.#offset % number;
2435
2575
  if (a) {
2436
2576
  this.skip(a * -1);
2437
2577
  }
@@ -2446,21 +2586,21 @@ class BiBase {
2446
2586
  * @param {number} bits - Bits to skip
2447
2587
  */
2448
2588
  skip(bytes, bits) {
2449
- var newOffset = ((bytes + __classPrivateFieldGet(this, _BiBase_offset, "f")) + Math.ceil((__classPrivateFieldGet(this, _BiBase_insetBit, "f") + bits) / 8));
2589
+ var newOffset = ((bytes + this.#offset) + Math.ceil((this.#insetBit + bits) / 8));
2450
2590
  if (bits && bits < 0) {
2451
- newOffset = Math.floor((((bytes + __classPrivateFieldGet(this, _BiBase_offset, "f")) * 8) + __classPrivateFieldGet(this, _BiBase_insetBit, "f") + bits) / 8);
2591
+ newOffset = Math.floor((((bytes + this.#offset) * 8) + this.#insetBit + bits) / 8);
2452
2592
  }
2453
- __classPrivateFieldGet(this, _BiBase_instances, "m", _BiBase_confrimSize).call(this, newOffset);
2593
+ this.#confrimSize(newOffset);
2454
2594
  // Adjust byte offset based on bit overflow
2455
- __classPrivateFieldSet(this, _BiBase_offset, __classPrivateFieldGet(this, _BiBase_offset, "f") + Math.floor((__classPrivateFieldGet(this, _BiBase_insetBit, "f") + bits) / 8), "f");
2595
+ this.#offset += Math.floor((this.#insetBit + bits) / 8);
2456
2596
  // Adjust bit offset
2457
- __classPrivateFieldSet(this, _BiBase_insetBit, (__classPrivateFieldGet(this, _BiBase_insetBit, "f") + normalizeBitOffset(bits)) % 8, "f");
2597
+ this.#insetBit = (this.#insetBit + normalizeBitOffset(bits)) % 8;
2458
2598
  // Adjust byte offset based on byte overflow
2459
- __classPrivateFieldSet(this, _BiBase_offset, __classPrivateFieldGet(this, _BiBase_offset, "f") + bytes, "f");
2599
+ this.#offset += bytes;
2460
2600
  // Ensure bit offset stays between 0-7
2461
- __classPrivateFieldSet(this, _BiBase_insetBit, Math.min(Math.max(__classPrivateFieldGet(this, _BiBase_insetBit, "f"), 0), 7), "f");
2601
+ this.#insetBit = Math.min(Math.max(this.#insetBit, 0), 7);
2462
2602
  // Ensure offset doesn't go negative
2463
- __classPrivateFieldSet(this, _BiBase_offset, Math.max(__classPrivateFieldGet(this, _BiBase_offset, "f"), 0), "f");
2603
+ this.#offset = Math.max(this.#offset, 0);
2464
2604
  return;
2465
2605
  }
2466
2606
  ;
@@ -2501,16 +2641,16 @@ class BiBase {
2501
2641
  if (bit && bit < 0) {
2502
2642
  newOffset = Math.floor(((byte * 8) + bit) / 8);
2503
2643
  }
2504
- __classPrivateFieldGet(this, _BiBase_instances, "m", _BiBase_confrimSize).call(this, newOffset);
2505
- __classPrivateFieldSet(this, _BiBase_offset, byte, "f");
2644
+ this.#confrimSize(newOffset);
2645
+ this.#offset = byte;
2506
2646
  // Adjust byte offset based on bit overflow
2507
- __classPrivateFieldSet(this, _BiBase_offset, __classPrivateFieldGet(this, _BiBase_offset, "f") + Math.floor(bit / 8), "f");
2647
+ this.#offset += Math.floor(bit / 8);
2508
2648
  // Adjust bit offset
2509
- __classPrivateFieldSet(this, _BiBase_insetBit, normalizeBitOffset(bit) % 8, "f");
2649
+ this.#insetBit = normalizeBitOffset(bit) % 8;
2510
2650
  // Ensure bit offset stays between 0-7
2511
- __classPrivateFieldSet(this, _BiBase_insetBit, Math.min(Math.max(__classPrivateFieldGet(this, _BiBase_insetBit, "f"), 0), 7), "f");
2651
+ this.#insetBit = Math.min(Math.max(this.#insetBit, 0), 7);
2512
2652
  // Ensure offset doesn't go negative
2513
- __classPrivateFieldSet(this, _BiBase_offset, Math.max(__classPrivateFieldGet(this, _BiBase_offset, "f"), 0), "f");
2653
+ this.#offset = Math.max(this.#offset, 0);
2514
2654
  return;
2515
2655
  }
2516
2656
  ;
@@ -2554,8 +2694,8 @@ class BiBase {
2554
2694
  * Set byte and bit position to start of data.
2555
2695
  */
2556
2696
  rewind() {
2557
- __classPrivateFieldSet(this, _BiBase_offset, 0, "f");
2558
- __classPrivateFieldSet(this, _BiBase_insetBit, 0, "f");
2697
+ this.#offset = 0;
2698
+ this.#insetBit = 0;
2559
2699
  }
2560
2700
  ;
2561
2701
  /**
@@ -2569,8 +2709,8 @@ class BiBase {
2569
2709
  * Set current byte and bit position to end of data.
2570
2710
  */
2571
2711
  last() {
2572
- __classPrivateFieldSet(this, _BiBase_offset, this.size, "f");
2573
- __classPrivateFieldSet(this, _BiBase_insetBit, 0, "f");
2712
+ this.#offset = this.size;
2713
+ this.#insetBit = 0;
2574
2714
  }
2575
2715
  ;
2576
2716
  /**
@@ -2600,14 +2740,14 @@ class BiBase {
2600
2740
  * @param {boolean} consume - Move position to end of removed data (default false)
2601
2741
  * @returns {DataType} Removed data as ``Buffer`` or ``Uint8Array``
2602
2742
  */
2603
- delete(startOffset = 0, endOffset = __classPrivateFieldGet(this, _BiBase_offset, "f"), consume = false) {
2743
+ delete(startOffset = 0, endOffset = this.#offset, consume = false) {
2604
2744
  if (this.readOnly || this.strict) {
2605
2745
  this.errorDump ? console.log("\x1b[31m[Error]\x1b[0m hexdump:\n" + this.hexdump({ returnString: true })) : "";
2606
2746
  throw new Error("\x1b[33m[Strict mode]\x1b[0m: Can not remove data in strict mode: endOffset " + endOffset + " of " + this.size);
2607
2747
  }
2608
2748
  this.open();
2609
2749
  startOffset = Math.abs(startOffset);
2610
- __classPrivateFieldGet(this, _BiBase_instances, "m", _BiBase_confrimSize).call(this, endOffset);
2750
+ this.#confrimSize(endOffset);
2611
2751
  const dataRemoved = this.data.subarray(startOffset, endOffset);
2612
2752
  const part1 = this.data.subarray(0, startOffset);
2613
2753
  const part2 = this.data.subarray(endOffset, this.size);
@@ -2623,8 +2763,8 @@ class BiBase {
2623
2763
  this.size = this.data.length;
2624
2764
  this.bitSize = this.data.length * 8;
2625
2765
  if (consume) {
2626
- __classPrivateFieldSet(this, _BiBase_offset, startOffset, "f");
2627
- __classPrivateFieldSet(this, _BiBase_insetBit, 0, "f");
2766
+ this.#offset = startOffset;
2767
+ this.#insetBit = 0;
2628
2768
  }
2629
2769
  return dataRemoved;
2630
2770
  }
@@ -2637,7 +2777,7 @@ class BiBase {
2637
2777
  * @returns {DataType} Removed data as ``Buffer`` or ``Uint8Array``
2638
2778
  */
2639
2779
  clip() {
2640
- return this.delete(__classPrivateFieldGet(this, _BiBase_offset, "f"), this.size, false);
2780
+ return this.delete(this.#offset, this.size, false);
2641
2781
  }
2642
2782
  ;
2643
2783
  /**
@@ -2648,7 +2788,7 @@ class BiBase {
2648
2788
  * @returns {DataType} Removed data as ``Buffer`` or ``Uint8Array``
2649
2789
  */
2650
2790
  trim() {
2651
- return this.delete(__classPrivateFieldGet(this, _BiBase_offset, "f"), this.size, false);
2791
+ return this.delete(this.#offset, this.size, false);
2652
2792
  }
2653
2793
  ;
2654
2794
  /**
@@ -2661,7 +2801,7 @@ class BiBase {
2661
2801
  * @returns {DataType} Removed data as ``Buffer`` or ``Uint8Array``
2662
2802
  */
2663
2803
  crop(length = 0, consume = false) {
2664
- return this.delete(__classPrivateFieldGet(this, _BiBase_offset, "f"), __classPrivateFieldGet(this, _BiBase_offset, "f") + length, consume);
2804
+ return this.delete(this.#offset, this.#offset + length, consume);
2665
2805
  }
2666
2806
  ;
2667
2807
  /**
@@ -2674,7 +2814,7 @@ class BiBase {
2674
2814
  * @returns {DataType} Removed data as ``Buffer`` or ``Uint8Array``
2675
2815
  */
2676
2816
  drop(length = 0, consume = false) {
2677
- return this.delete(__classPrivateFieldGet(this, _BiBase_offset, "f"), __classPrivateFieldGet(this, _BiBase_offset, "f") + length, consume);
2817
+ return this.delete(this.#offset, this.#offset + length, consume);
2678
2818
  }
2679
2819
  ;
2680
2820
  ///////////////////////////////
@@ -2685,11 +2825,11 @@ class BiBase {
2685
2825
  *
2686
2826
  * Note: Errors on strict mode if past end of data.
2687
2827
  *
2688
- * @param {DataType} data - ``Uint8Array`` or ``Buffer`` to replace in data
2828
+ * @param {ReturnMapping<DataType>} data - ``Uint8Array`` or ``Buffer`` to replace in data
2689
2829
  * @param {number} offset - Offset to add it at (defaults to current position)
2690
2830
  * @param {boolean} consume - Move current byte position to end of data (default false)
2691
2831
  */
2692
- replace(data, offset = __classPrivateFieldGet(this, _BiBase_offset, "f"), consume = false) {
2832
+ replace(data, offset = this.#offset, consume = false) {
2693
2833
  if (this.readOnly) {
2694
2834
  this.errorDump ? console.log("\x1b[31m[Error]\x1b[0m hexdump:\n" + this.hexdump({ returnString: true })) : "";
2695
2835
  throw new Error("Can't replace data in readOnly mode!");
@@ -2710,7 +2850,7 @@ class BiBase {
2710
2850
  }
2711
2851
  }
2712
2852
  const neededSize = offset + data.length;
2713
- __classPrivateFieldGet(this, _BiBase_instances, "m", _BiBase_confrimSize).call(this, neededSize);
2853
+ this.#confrimSize(neededSize);
2714
2854
  const part1 = this.data.subarray(0, neededSize - data.length);
2715
2855
  const part2 = this.data.subarray(neededSize, this.size);
2716
2856
  if (this.isBuffer(this.data)) {
@@ -2726,8 +2866,8 @@ class BiBase {
2726
2866
  this.size = this.data.length;
2727
2867
  this.bitSize = this.data.length * 8;
2728
2868
  if (consume) {
2729
- __classPrivateFieldSet(this, _BiBase_offset, offset + data.length, "f");
2730
- __classPrivateFieldSet(this, _BiBase_insetBit, 0, "f");
2869
+ this.#offset = offset + data.length;
2870
+ this.#insetBit = 0;
2731
2871
  }
2732
2872
  }
2733
2873
  ;
@@ -2736,11 +2876,11 @@ class BiBase {
2736
2876
  *
2737
2877
  * Note: Errors on strict mode.
2738
2878
  *
2739
- * @param {DataType} data - ``Uint8Array`` or ``Buffer`` to replace in data
2879
+ * @param {ReturnMapping<DataType>} data - ``Uint8Array`` or ``Buffer`` to replace in data
2740
2880
  * @param {number} offset - Offset to add it at (defaults to current position)
2741
2881
  * @param {boolean} consume - Move current byte position to end of data (default false)
2742
2882
  */
2743
- overwrite(data, offset = __classPrivateFieldGet(this, _BiBase_offset, "f"), consume = false) {
2883
+ overwrite(data, offset = this.#offset, consume = false) {
2744
2884
  return this.replace(data, offset, consume);
2745
2885
  }
2746
2886
  ;
@@ -2756,7 +2896,7 @@ class BiBase {
2756
2896
  * @param {number} fillValue - Byte value to to fill returned data (does NOT fill unless supplied)
2757
2897
  * @returns {DataType} Selected data as ``Uint8Array`` or ``Buffer``
2758
2898
  */
2759
- fill(startOffset = __classPrivateFieldGet(this, _BiBase_offset, "f"), endOffset = this.size, consume = false, fillValue) {
2899
+ fill(startOffset = this.#offset, endOffset = this.size, consume = false, fillValue) {
2760
2900
  if (this.readOnly) {
2761
2901
  this.errorDump ? console.log("\x1b[31m[Error]\x1b[0m hexdump:\n" + this.hexdump({ returnString: true })) : "";
2762
2902
  throw new Error("Can't remove data in readonly mode!");
@@ -2782,7 +2922,7 @@ class BiBase {
2782
2922
  if (endOffset > this.size && this.strict) {
2783
2923
  throw new Error('Cannot extend data while in strict mode. Use unrestrict() to enable.');
2784
2924
  }
2785
- __classPrivateFieldGet(this, _BiBase_instances, "m", _BiBase_confrimSize).call(this, endOffset);
2925
+ this.#confrimSize(endOffset);
2786
2926
  const dataRemoved = this.data.subarray(startOffset, endOffset);
2787
2927
  // without a fill value it's a basic lift
2788
2928
  if (fillValue != undefined) {
@@ -2804,8 +2944,8 @@ class BiBase {
2804
2944
  this.bitSize = this.data.length * 8;
2805
2945
  }
2806
2946
  if (consume) {
2807
- __classPrivateFieldSet(this, _BiBase_offset, endOffset, "f");
2808
- __classPrivateFieldSet(this, _BiBase_insetBit, 0, "f");
2947
+ this.#offset = endOffset;
2948
+ this.#insetBit = 0;
2809
2949
  }
2810
2950
  return dataRemoved;
2811
2951
  }
@@ -2819,7 +2959,7 @@ class BiBase {
2819
2959
  * @param {number} fillValue - Byte value to to fill returned data (does NOT fill unless supplied)
2820
2960
  * @returns {DataType} Selected data as ``Uint8Array`` or ``Buffer``
2821
2961
  */
2822
- lift(startOffset = __classPrivateFieldGet(this, _BiBase_offset, "f"), endOffset = this.size, consume = false, fillValue) {
2962
+ lift(startOffset = this.#offset, endOffset = this.size, consume = false, fillValue) {
2823
2963
  return this.fill(startOffset, endOffset, consume, fillValue);
2824
2964
  }
2825
2965
  ;
@@ -2833,7 +2973,7 @@ class BiBase {
2833
2973
  * @returns {DataType} Selected data as ``Uint8Array`` or ``Buffer``
2834
2974
  */
2835
2975
  extract(length = 0, consume = false) {
2836
- return this.fill(__classPrivateFieldGet(this, _BiBase_offset, "f"), __classPrivateFieldGet(this, _BiBase_offset, "f") + length, consume);
2976
+ return this.fill(this.#offset, this.#offset + length, consume);
2837
2977
  }
2838
2978
  ;
2839
2979
  /**
@@ -2846,7 +2986,7 @@ class BiBase {
2846
2986
  * @returns {DataType} Selected data as ``Uint8Array`` or ``Buffer``
2847
2987
  */
2848
2988
  slice(length = 0, consume = false) {
2849
- return this.fill(__classPrivateFieldGet(this, _BiBase_offset, "f"), __classPrivateFieldGet(this, _BiBase_offset, "f") + length, consume);
2989
+ return this.fill(this.#offset, this.#offset + length, consume);
2850
2990
  }
2851
2991
  ;
2852
2992
  /**
@@ -2859,7 +2999,7 @@ class BiBase {
2859
2999
  * @returns {DataType} Selected data as ``Uint8Array`` or ``Buffer``
2860
3000
  */
2861
3001
  wrap(length = 0, consume = false) {
2862
- return this.fill(__classPrivateFieldGet(this, _BiBase_offset, "f"), __classPrivateFieldGet(this, _BiBase_offset, "f") + length, consume);
3002
+ return this.fill(this.#offset, this.#offset + length, consume);
2863
3003
  }
2864
3004
  ;
2865
3005
  ///////////////////////////////
@@ -2870,11 +3010,11 @@ class BiBase {
2870
3010
  *
2871
3011
  * Note: Errors on strict mode.
2872
3012
  *
2873
- * @param {DataType} data - ``Uint8Array`` or ``Buffer`` to add to data
3013
+ * @param {ReturnMapping<DataType>} data - ``Uint8Array`` or ``Buffer`` to add to data
2874
3014
  * @param {number} offset - Byte position to add at (defaults to current position)
2875
3015
  * @param {boolean} consume - Move current byte position to end of data (default true)
2876
3016
  */
2877
- insert(data, offset = __classPrivateFieldGet(this, _BiBase_offset, "f"), consume = true) {
3017
+ insert(data, offset = this.#offset, consume = true) {
2878
3018
  if (this.strict == true || this.readOnly) {
2879
3019
  this.errorDump ? console.log("\x1b[31m[Error]\x1b[0m hexdump:\n" + this.hexdump({ returnString: true })) : "";
2880
3020
  throw new Error(`\x1b[33m[Strict mode]\x1b[0m: Can not insert data in strict mode. Use unrestrict() to enable.`);
@@ -2918,8 +3058,8 @@ class BiBase {
2918
3058
  this.size = this.data.length;
2919
3059
  this.bitSize = this.data.length * 8;
2920
3060
  if (consume) {
2921
- __classPrivateFieldSet(this, _BiBase_offset, offset + data.length, "f");
2922
- __classPrivateFieldSet(this, _BiBase_insetBit, 0, "f");
3061
+ this.#offset = offset + data.length;
3062
+ this.#insetBit = 0;
2923
3063
  }
2924
3064
  }
2925
3065
  ;
@@ -2928,11 +3068,11 @@ class BiBase {
2928
3068
  *
2929
3069
  * Note: Errors on strict mode.
2930
3070
  *
2931
- * @param {DataType} data - ``Uint8Array`` or ``Buffer`` to add to data
3071
+ * @param {ReturnMapping<DataType>} data - ``Uint8Array`` or ``Buffer`` to add to data
2932
3072
  * @param {number} offset - Byte position to add at (defaults to current position)
2933
3073
  * @param {boolean} consume - Move current byte position to end of data (default true)
2934
3074
  */
2935
- place(data, offset = __classPrivateFieldGet(this, _BiBase_offset, "f"), consume = true) {
3075
+ place(data, offset = this.#offset, consume = true) {
2936
3076
  return this.insert(data, offset, consume);
2937
3077
  }
2938
3078
  ;
@@ -2941,7 +3081,7 @@ class BiBase {
2941
3081
  *
2942
3082
  * Note: Errors on strict mode.
2943
3083
  *
2944
- * @param {DataType} data - ``Uint8Array`` or ``Buffer`` to add to data
3084
+ * @param {ReturnMapping<DataType>} data - ``Uint8Array`` or ``Buffer`` to add to data
2945
3085
  * @param {boolean} consume - Move current write position to end of data (default false)
2946
3086
  */
2947
3087
  unshift(data, consume = false) {
@@ -2953,7 +3093,7 @@ class BiBase {
2953
3093
  *
2954
3094
  * Note: Errors on strict mode.
2955
3095
  *
2956
- * @param {DataType} data - ``Uint8Array`` or ``Buffer`` to add to data
3096
+ * @param {ReturnMapping<DataType>} data - ``Uint8Array`` or ``Buffer`` to add to data
2957
3097
  * @param {boolean} consume - Move current write position to end of data (default false)
2958
3098
  */
2959
3099
  prepend(data, consume = false) {
@@ -2965,7 +3105,7 @@ class BiBase {
2965
3105
  *
2966
3106
  * Note: Errors on strict mode.
2967
3107
  *
2968
- * @param {DataType} data - ``Uint8Array`` or ``Buffer`` to add to data
3108
+ * @param {ReturnMapping<DataType>} data - ``Uint8Array`` or ``Buffer`` to add to data
2969
3109
  * @param {boolean} consume - Move current write position to end of data (default false)
2970
3110
  */
2971
3111
  push(data, consume = false) {
@@ -2977,7 +3117,7 @@ class BiBase {
2977
3117
  *
2978
3118
  * Note: Errors on strict mode.
2979
3119
  *
2980
- * @param {DataType} data - ``Uint8Array`` or ``Buffer`` to add to data
3120
+ * @param {ReturnMapping<DataType>} data - ``Uint8Array`` or ``Buffer`` to add to data
2981
3121
  * @param {boolean} consume - Move current write position to end of data (default false)
2982
3122
  */
2983
3123
  append(data, consume = false) {
@@ -2995,7 +3135,7 @@ class BiBase {
2995
3135
  * @param {number} endOffset - End location (default end of data)
2996
3136
  * @param {boolean} consume - Move current position to end of data (default false)
2997
3137
  */
2998
- xor(xorKey, startOffset = __classPrivateFieldGet(this, _BiBase_offset, "f"), endOffset = this.size, consume = false) {
3138
+ xor(xorKey, startOffset = this.#offset, endOffset = this.size, consume = false) {
2999
3139
  if (this.readOnly) {
3000
3140
  this.errorDump ? console.log("\x1b[31m[Error]\x1b[0m hexdump:\n" + this.hexdump({ returnString: true })) : "";
3001
3141
  throw new Error("Can't write data in readonly mode!");
@@ -3007,11 +3147,11 @@ class BiBase {
3007
3147
  throw new Error("XOR must be a number, string, Uint8Array or Buffer");
3008
3148
  }
3009
3149
  this.open();
3010
- __classPrivateFieldGet(this, _BiBase_instances, "m", _BiBase_confrimSize).call(this, endOffset);
3150
+ this.#confrimSize(endOffset);
3011
3151
  const returnData = _XOR(this.data, startOffset, Math.min(endOffset, this.size), xorKey);
3012
3152
  if (consume) {
3013
- __classPrivateFieldSet(this, _BiBase_offset, returnData.offset, "f");
3014
- __classPrivateFieldSet(this, _BiBase_insetBit, returnData.bitoffset, "f");
3153
+ this.#offset = returnData.offset;
3154
+ this.#insetBit = returnData.bitoffset;
3015
3155
  }
3016
3156
  }
3017
3157
  ;
@@ -3040,7 +3180,7 @@ class BiBase {
3040
3180
  else {
3041
3181
  throw new Error("XOR must be a number, string, Uint8Array or Buffer");
3042
3182
  }
3043
- return this.xor(xorKey, __classPrivateFieldGet(this, _BiBase_offset, "f"), __classPrivateFieldGet(this, _BiBase_offset, "f") + length, consume);
3183
+ return this.xor(xorKey, this.#offset, this.#offset + length, consume);
3044
3184
  }
3045
3185
  ;
3046
3186
  /**
@@ -3051,7 +3191,7 @@ class BiBase {
3051
3191
  * @param {number} endOffset - End location (default end of data)
3052
3192
  * @param {boolean} consume - Move current position to end of data (default false)
3053
3193
  */
3054
- or(orKey, startOffset = __classPrivateFieldGet(this, _BiBase_offset, "f"), endOffset = this.size, consume = false) {
3194
+ or(orKey, startOffset = this.#offset, endOffset = this.size, consume = false) {
3055
3195
  if (this.readOnly) {
3056
3196
  this.errorDump ? console.log("\x1b[31m[Error]\x1b[0m hexdump:\n" + this.hexdump({ returnString: true })) : "";
3057
3197
  throw new Error("Can't write data in readonly mode!");
@@ -3063,11 +3203,11 @@ class BiBase {
3063
3203
  throw new Error("OR must be a number, string, Uint8Array or Buffer");
3064
3204
  }
3065
3205
  this.open();
3066
- __classPrivateFieldGet(this, _BiBase_instances, "m", _BiBase_confrimSize).call(this, endOffset);
3206
+ this.#confrimSize(endOffset);
3067
3207
  const returnData = _OR(this.data, startOffset, Math.min(endOffset, this.size), orKey);
3068
3208
  if (consume) {
3069
- __classPrivateFieldSet(this, _BiBase_offset, returnData.offset, "f");
3070
- __classPrivateFieldSet(this, _BiBase_insetBit, returnData.bitoffset, "f");
3209
+ this.#offset = returnData.offset;
3210
+ this.#insetBit = returnData.bitoffset;
3071
3211
  }
3072
3212
  }
3073
3213
  ;
@@ -3096,7 +3236,7 @@ class BiBase {
3096
3236
  else {
3097
3237
  throw new Error("OR must be a number, string, Uint8Array or Buffer");
3098
3238
  }
3099
- return this.or(orKey, __classPrivateFieldGet(this, _BiBase_offset, "f"), __classPrivateFieldGet(this, _BiBase_offset, "f") + length, consume || false);
3239
+ return this.or(orKey, this.#offset, this.#offset + length, consume || false);
3100
3240
  }
3101
3241
  ;
3102
3242
  /**
@@ -3107,7 +3247,7 @@ class BiBase {
3107
3247
  * @param {number} endOffset - End location (default end of data)
3108
3248
  * @param {boolean} consume - Move current position to end of data (default false)
3109
3249
  */
3110
- and(andKey, startOffset = __classPrivateFieldGet(this, _BiBase_offset, "f"), endOffset = this.size, consume = false) {
3250
+ and(andKey, startOffset = this.#offset, endOffset = this.size, consume = false) {
3111
3251
  if (this.readOnly) {
3112
3252
  this.errorDump ? console.log("\x1b[31m[Error]\x1b[0m hexdump:\n" + this.hexdump({ returnString: true })) : "";
3113
3253
  throw new Error("Can't write data in readonly mode!");
@@ -3119,11 +3259,11 @@ class BiBase {
3119
3259
  throw new Error("AND must be a number, string, number array or Buffer");
3120
3260
  }
3121
3261
  this.open();
3122
- __classPrivateFieldGet(this, _BiBase_instances, "m", _BiBase_confrimSize).call(this, endOffset);
3262
+ this.#confrimSize(endOffset);
3123
3263
  const returnData = _AND(this.data, startOffset, Math.min(endOffset, this.size), andKey);
3124
3264
  if (consume) {
3125
- __classPrivateFieldSet(this, _BiBase_offset, returnData.offset, "f");
3126
- __classPrivateFieldSet(this, _BiBase_insetBit, returnData.bitoffset, "f");
3265
+ this.#offset = returnData.offset;
3266
+ this.#insetBit = returnData.bitoffset;
3127
3267
  }
3128
3268
  }
3129
3269
  ;
@@ -3152,7 +3292,7 @@ class BiBase {
3152
3292
  else {
3153
3293
  throw new Error("AND must be a number, string, Uint8Array or Buffer");
3154
3294
  }
3155
- return this.and(andKey, __classPrivateFieldGet(this, _BiBase_offset, "f"), __classPrivateFieldGet(this, _BiBase_offset, "f") + length, consume);
3295
+ return this.and(andKey, this.#offset, this.#offset + length, consume);
3156
3296
  }
3157
3297
  ;
3158
3298
  /**
@@ -3163,7 +3303,7 @@ class BiBase {
3163
3303
  * @param {number} endOffset - End location (default end of data)
3164
3304
  * @param {boolean} consume - Move current position to end of data (default false)
3165
3305
  */
3166
- add(addKey, startOffset = __classPrivateFieldGet(this, _BiBase_offset, "f"), endOffset = this.size, consume = false) {
3306
+ add(addKey, startOffset = this.#offset, endOffset = this.size, consume = false) {
3167
3307
  if (this.readOnly) {
3168
3308
  this.errorDump ? console.log("\x1b[31m[Error]\x1b[0m hexdump:\n" + this.hexdump({ returnString: true })) : "";
3169
3309
  throw new Error("Can't write data in readonly mode!");
@@ -3175,11 +3315,11 @@ class BiBase {
3175
3315
  throw new Error("Add key must be a number, string, number array or Buffer");
3176
3316
  }
3177
3317
  this.open();
3178
- __classPrivateFieldGet(this, _BiBase_instances, "m", _BiBase_confrimSize).call(this, endOffset);
3318
+ this.#confrimSize(endOffset);
3179
3319
  const returnData = _ADD(this.data, startOffset, Math.min(endOffset, this.size), addKey);
3180
3320
  if (consume) {
3181
- __classPrivateFieldSet(this, _BiBase_offset, returnData.offset, "f");
3182
- __classPrivateFieldSet(this, _BiBase_insetBit, returnData.bitoffset, "f");
3321
+ this.#offset = returnData.offset;
3322
+ this.#insetBit = returnData.bitoffset;
3183
3323
  }
3184
3324
  }
3185
3325
  ;
@@ -3208,7 +3348,7 @@ class BiBase {
3208
3348
  else {
3209
3349
  throw new Error("ADD must be a number, string, Uint8Array or Buffer");
3210
3350
  }
3211
- return this.add(addKey, __classPrivateFieldGet(this, _BiBase_offset, "f"), __classPrivateFieldGet(this, _BiBase_offset, "f") + length, consume);
3351
+ return this.add(addKey, this.#offset, this.#offset + length, consume);
3212
3352
  }
3213
3353
  ;
3214
3354
  /**
@@ -3218,17 +3358,17 @@ class BiBase {
3218
3358
  * @param {number} endOffset - End location (default end of data)
3219
3359
  * @param {boolean} consume - Move current position to end of data (default false)
3220
3360
  */
3221
- not(startOffset = __classPrivateFieldGet(this, _BiBase_offset, "f"), endOffset = this.size, consume = false) {
3361
+ not(startOffset = this.#offset, endOffset = this.size, consume = false) {
3222
3362
  if (this.readOnly) {
3223
3363
  this.errorDump ? console.log("\x1b[31m[Error]\x1b[0m hexdump:\n" + this.hexdump({ returnString: true })) : "";
3224
3364
  throw new Error("Can't write data in readonly mode!");
3225
3365
  }
3226
3366
  this.open();
3227
- __classPrivateFieldGet(this, _BiBase_instances, "m", _BiBase_confrimSize).call(this, endOffset);
3367
+ this.#confrimSize(endOffset);
3228
3368
  const returnData = _NOT(this.data, startOffset, Math.min(endOffset, this.size));
3229
3369
  if (consume) {
3230
- __classPrivateFieldSet(this, _BiBase_offset, returnData.offset, "f");
3231
- __classPrivateFieldSet(this, _BiBase_insetBit, returnData.bitoffset, "f");
3370
+ this.#offset = returnData.offset;
3371
+ this.#insetBit = returnData.bitoffset;
3232
3372
  }
3233
3373
  }
3234
3374
  ;
@@ -3239,7 +3379,7 @@ class BiBase {
3239
3379
  * @param {boolean} consume - Move current position to end of data (default false)
3240
3380
  */
3241
3381
  notThis(length = 1, consume = false) {
3242
- return this.not(__classPrivateFieldGet(this, _BiBase_offset, "f"), __classPrivateFieldGet(this, _BiBase_offset, "f") + length, consume);
3382
+ return this.not(this.#offset, this.#offset + length, consume);
3243
3383
  }
3244
3384
  ;
3245
3385
  /**
@@ -3250,7 +3390,7 @@ class BiBase {
3250
3390
  * @param {number} endOffset - End location (default end of data)
3251
3391
  * @param {boolean} consume - Move current position to end of data (default false)
3252
3392
  */
3253
- lShift(shiftKey, startOffset = __classPrivateFieldGet(this, _BiBase_offset, "f"), endOffset = this.size, consume = false) {
3393
+ lShift(shiftKey, startOffset = this.#offset, endOffset = this.size, consume = false) {
3254
3394
  if (this.readOnly) {
3255
3395
  this.errorDump ? console.log("\x1b[31m[Error]\x1b[0m hexdump:\n" + this.hexdump({ returnString: true })) : "";
3256
3396
  throw new Error("Can't write data in readonly mode!");
@@ -3262,11 +3402,11 @@ class BiBase {
3262
3402
  throw new Error("Left shift must be a number, string, number array or Buffer");
3263
3403
  }
3264
3404
  this.open();
3265
- __classPrivateFieldGet(this, _BiBase_instances, "m", _BiBase_confrimSize).call(this, endOffset);
3405
+ this.#confrimSize(endOffset);
3266
3406
  const returnData = _LSHIFT(this.data, startOffset, Math.min(endOffset, this.size), shiftKey);
3267
3407
  if (consume) {
3268
- __classPrivateFieldSet(this, _BiBase_offset, returnData.offset, "f");
3269
- __classPrivateFieldSet(this, _BiBase_insetBit, returnData.bitoffset, "f");
3408
+ this.#offset = returnData.offset;
3409
+ this.#insetBit = returnData.bitoffset;
3270
3410
  }
3271
3411
  }
3272
3412
  ;
@@ -3295,7 +3435,7 @@ class BiBase {
3295
3435
  else {
3296
3436
  throw new Error("Left shift must be a number, string, Uint8Array or Buffer");
3297
3437
  }
3298
- return this.lShift(shiftKey, __classPrivateFieldGet(this, _BiBase_offset, "f"), __classPrivateFieldGet(this, _BiBase_offset, "f") + length, consume);
3438
+ return this.lShift(shiftKey, this.#offset, this.#offset + length, consume);
3299
3439
  }
3300
3440
  ;
3301
3441
  /**
@@ -3306,7 +3446,7 @@ class BiBase {
3306
3446
  * @param {number} endOffset - End location (default end of data)
3307
3447
  * @param {boolean} consume - Move current position to end of data (default false)
3308
3448
  */
3309
- rShift(shiftKey, startOffset = __classPrivateFieldGet(this, _BiBase_offset, "f"), endOffset = this.size, consume = false) {
3449
+ rShift(shiftKey, startOffset = this.#offset, endOffset = this.size, consume = false) {
3310
3450
  if (this.readOnly) {
3311
3451
  this.errorDump ? console.log("\x1b[31m[Error]\x1b[0m hexdump:\n" + this.hexdump({ returnString: true })) : "";
3312
3452
  throw new Error("Can't write data in readonly mode!");
@@ -3318,11 +3458,11 @@ class BiBase {
3318
3458
  throw new Error("Right shift must be a number, string, number array or Buffer");
3319
3459
  }
3320
3460
  this.open();
3321
- __classPrivateFieldGet(this, _BiBase_instances, "m", _BiBase_confrimSize).call(this, endOffset);
3461
+ this.#confrimSize(endOffset);
3322
3462
  const returnData = _RSHIFT(this.data, startOffset, Math.min(endOffset, this.size), shiftKey);
3323
3463
  if (consume) {
3324
- __classPrivateFieldSet(this, _BiBase_offset, returnData.offset, "f");
3325
- __classPrivateFieldSet(this, _BiBase_insetBit, returnData.bitoffset, "f");
3464
+ this.#offset = returnData.offset;
3465
+ this.#insetBit = returnData.bitoffset;
3326
3466
  }
3327
3467
  }
3328
3468
  ;
@@ -3351,7 +3491,7 @@ class BiBase {
3351
3491
  else {
3352
3492
  throw new Error("right shift must be a number, string, Uint8Array or Buffer");
3353
3493
  }
3354
- return this.rShift(shiftKey, __classPrivateFieldGet(this, _BiBase_offset, "f"), __classPrivateFieldGet(this, _BiBase_offset, "f") + length, consume);
3494
+ return this.rShift(shiftKey, this.#offset, this.#offset + length, consume);
3355
3495
  }
3356
3496
  ;
3357
3497
  ///////////////////////////////
@@ -3379,13 +3519,13 @@ class BiBase {
3379
3519
  if (bits <= 0 || bits > 32) {
3380
3520
  throw new Error('Bit length must be between 1 and 32. Got ' + bits);
3381
3521
  }
3382
- const sizeNeeded = Math.floor(((bits - 1) + __classPrivateFieldGet(this, _BiBase_insetBit, "f")) / 8) + __classPrivateFieldGet(this, _BiBase_offset, "f");
3383
- __classPrivateFieldGet(this, _BiBase_instances, "m", _BiBase_confrimSize).call(this, sizeNeeded);
3384
- const bitStart = (__classPrivateFieldGet(this, _BiBase_offset, "f") * 8) + __classPrivateFieldGet(this, _BiBase_insetBit, "f");
3522
+ const sizeNeeded = Math.floor(((bits - 1) + this.#insetBit) / 8) + this.#offset;
3523
+ this.#confrimSize(sizeNeeded);
3524
+ const bitStart = (this.#offset * 8) + this.#insetBit;
3385
3525
  const value = _rbit(this.data, bits, bitStart, endian, unsigned);
3386
3526
  if (consume) {
3387
- __classPrivateFieldSet(this, _BiBase_offset, __classPrivateFieldGet(this, _BiBase_offset, "f") + Math.floor((bits + __classPrivateFieldGet(this, _BiBase_insetBit, "f")) / 8), "f");
3388
- __classPrivateFieldSet(this, _BiBase_insetBit, (bits + __classPrivateFieldGet(this, _BiBase_insetBit, "f")) % 8, "f");
3527
+ this.#offset += Math.floor((bits + this.#insetBit) / 8);
3528
+ this.#insetBit = (bits + this.#insetBit) % 8;
3389
3529
  }
3390
3530
  return value;
3391
3531
  }
@@ -3465,13 +3605,13 @@ class BiBase {
3465
3605
  throw new Error('Bit length must be between 1 and 32. Got ' + bits);
3466
3606
  }
3467
3607
  value = numberSafe(value, bits, unsigned);
3468
- const endOffset = Math.ceil(((bits - 1) + __classPrivateFieldGet(this, _BiBase_insetBit, "f")) / 8) + __classPrivateFieldGet(this, _BiBase_offset, "f");
3469
- __classPrivateFieldGet(this, _BiBase_instances, "m", _BiBase_confrimSize).call(this, endOffset);
3470
- const offset = (__classPrivateFieldGet(this, _BiBase_offset, "f") * 8) + __classPrivateFieldGet(this, _BiBase_insetBit, "f");
3608
+ const endOffset = Math.ceil(((bits - 1) + this.#insetBit) / 8) + this.#offset;
3609
+ this.#confrimSize(endOffset);
3610
+ const offset = (this.#offset * 8) + this.#insetBit;
3471
3611
  _wbit(this.data, value, bits, offset, endian, unsigned);
3472
3612
  if (consume) {
3473
- __classPrivateFieldSet(this, _BiBase_offset, __classPrivateFieldGet(this, _BiBase_offset, "f") + Math.floor((bits + __classPrivateFieldGet(this, _BiBase_insetBit, "f")) / 8), "f");
3474
- __classPrivateFieldSet(this, _BiBase_insetBit, (bits + __classPrivateFieldGet(this, _BiBase_insetBit, "f")) % 8, "f");
3613
+ this.#offset += Math.floor((bits + this.#insetBit) / 8);
3614
+ this.#insetBit = (bits + this.#insetBit) % 8;
3475
3615
  }
3476
3616
  return;
3477
3617
  }
@@ -3542,12 +3682,12 @@ class BiBase {
3542
3682
  */
3543
3683
  readByte(unsigned = false, consume = true) {
3544
3684
  this.open();
3545
- var trueByte = __classPrivateFieldGet(this, _BiBase_offset, "f");
3546
- var trueBit = __classPrivateFieldGet(this, _BiBase_insetBit, "f");
3685
+ var trueByte = this.#offset;
3686
+ var trueBit = this.#insetBit;
3547
3687
  if (trueBit != 0) {
3548
3688
  trueByte += 1;
3549
3689
  }
3550
- __classPrivateFieldGet(this, _BiBase_instances, "m", _BiBase_checkSize).call(this, 1, 0, trueByte);
3690
+ this.#checkSize(1, 0, trueByte);
3551
3691
  var value;
3552
3692
  if (canInt8) {
3553
3693
  value = unsigned ? this.view.getUint8(trueByte) : this.view.getInt8(trueByte);
@@ -3556,8 +3696,8 @@ class BiBase {
3556
3696
  value = _rbyte(this.data, trueByte, unsigned);
3557
3697
  }
3558
3698
  if (consume) {
3559
- __classPrivateFieldSet(this, _BiBase_offset, __classPrivateFieldGet(this, _BiBase_offset, "f") + 1, "f");
3560
- __classPrivateFieldSet(this, _BiBase_insetBit, 0, "f");
3699
+ this.#offset += 1;
3700
+ this.#insetBit = 0;
3561
3701
  }
3562
3702
  return value;
3563
3703
  }
@@ -3606,12 +3746,12 @@ class BiBase {
3606
3746
  throw new Error("Can't write data in readonly mode!");
3607
3747
  }
3608
3748
  this.open();
3609
- var trueByte = __classPrivateFieldGet(this, _BiBase_offset, "f");
3610
- var trueBit = __classPrivateFieldGet(this, _BiBase_insetBit, "f");
3749
+ var trueByte = this.#offset;
3750
+ var trueBit = this.#insetBit;
3611
3751
  if (trueBit != 0) {
3612
3752
  trueByte += 1;
3613
3753
  }
3614
- __classPrivateFieldGet(this, _BiBase_instances, "m", _BiBase_checkSize).call(this, 1, 0, trueByte);
3754
+ this.#checkSize(1, 0, trueByte);
3615
3755
  if (canInt8) {
3616
3756
  if (unsigned) {
3617
3757
  this.view.setUint8(trueByte, value);
@@ -3624,8 +3764,8 @@ class BiBase {
3624
3764
  _wbyte(this.data, numberSafe(value, 8, unsigned), trueByte, unsigned);
3625
3765
  }
3626
3766
  if (consume) {
3627
- __classPrivateFieldSet(this, _BiBase_offset, __classPrivateFieldGet(this, _BiBase_offset, "f") + 1, "f");
3628
- __classPrivateFieldSet(this, _BiBase_insetBit, 0, "f");
3767
+ this.#offset += 1;
3768
+ this.#insetBit = 0;
3629
3769
  }
3630
3770
  return;
3631
3771
  }
@@ -3675,12 +3815,12 @@ class BiBase {
3675
3815
  */
3676
3816
  readInt16(unsigned = false, endian = this.endian, consume = true) {
3677
3817
  this.open();
3678
- var trueByte = __classPrivateFieldGet(this, _BiBase_offset, "f");
3679
- var trueBit = __classPrivateFieldGet(this, _BiBase_insetBit, "f");
3818
+ var trueByte = this.#offset;
3819
+ var trueBit = this.#insetBit;
3680
3820
  if (trueBit != 0) {
3681
3821
  trueByte += 1;
3682
3822
  }
3683
- __classPrivateFieldGet(this, _BiBase_instances, "m", _BiBase_checkSize).call(this, 2, 0, trueByte);
3823
+ this.#checkSize(2, 0, trueByte);
3684
3824
  var value;
3685
3825
  if (canInt16) {
3686
3826
  if (unsigned) {
@@ -3694,8 +3834,8 @@ class BiBase {
3694
3834
  value = _rint16(this.data, trueByte, endian, unsigned);
3695
3835
  }
3696
3836
  if (consume) {
3697
- __classPrivateFieldSet(this, _BiBase_offset, __classPrivateFieldGet(this, _BiBase_offset, "f") + 2, "f");
3698
- __classPrivateFieldSet(this, _BiBase_insetBit, 0, "f");
3837
+ this.#offset += 2;
3838
+ this.#insetBit = 0;
3699
3839
  }
3700
3840
  return value;
3701
3841
  }
@@ -3761,12 +3901,12 @@ class BiBase {
3761
3901
  throw new Error("Can't write data in readonly mode!");
3762
3902
  }
3763
3903
  this.open();
3764
- var trueByte = __classPrivateFieldGet(this, _BiBase_offset, "f");
3765
- var trueBit = __classPrivateFieldGet(this, _BiBase_insetBit, "f");
3904
+ var trueByte = this.#offset;
3905
+ var trueBit = this.#insetBit;
3766
3906
  if (trueBit != 0) {
3767
3907
  trueByte += 1;
3768
3908
  }
3769
- __classPrivateFieldGet(this, _BiBase_instances, "m", _BiBase_checkSize).call(this, 2, 0, trueByte);
3909
+ this.#checkSize(2, 0, trueByte);
3770
3910
  if (canInt16) {
3771
3911
  if (unsigned) {
3772
3912
  this.view.setUint16(trueByte, value, endian == "little");
@@ -3779,8 +3919,8 @@ class BiBase {
3779
3919
  _wint16(this.data, numberSafe(value, 16, unsigned), trueByte, endian, unsigned);
3780
3920
  }
3781
3921
  if (consume) {
3782
- __classPrivateFieldSet(this, _BiBase_offset, __classPrivateFieldGet(this, _BiBase_offset, "f") + 2, "f");
3783
- __classPrivateFieldSet(this, _BiBase_insetBit, 0, "f");
3922
+ this.#offset += 2;
3923
+ this.#insetBit = 0;
3784
3924
  }
3785
3925
  return;
3786
3926
  }
@@ -3843,12 +3983,12 @@ class BiBase {
3843
3983
  */
3844
3984
  readHalfFloat(endian = this.endian, consume = true) {
3845
3985
  this.open();
3846
- var trueByte = __classPrivateFieldGet(this, _BiBase_offset, "f");
3847
- var trueBit = __classPrivateFieldGet(this, _BiBase_insetBit, "f");
3986
+ var trueByte = this.#offset;
3987
+ var trueBit = this.#insetBit;
3848
3988
  if (trueBit != 0) {
3849
3989
  trueByte += 1;
3850
3990
  }
3851
- __classPrivateFieldGet(this, _BiBase_instances, "m", _BiBase_checkSize).call(this, 2, 0, trueByte);
3991
+ this.#checkSize(2, 0, trueByte);
3852
3992
  var value;
3853
3993
  if (canFloat16) {
3854
3994
  value = this.view.getFloat16(trueByte, endian == "little");
@@ -3857,8 +3997,8 @@ class BiBase {
3857
3997
  value = _rhalffloat(this.data, trueByte, endian);
3858
3998
  }
3859
3999
  if (consume) {
3860
- __classPrivateFieldSet(this, _BiBase_offset, __classPrivateFieldGet(this, _BiBase_offset, "f") + 2, "f");
3861
- __classPrivateFieldSet(this, _BiBase_insetBit, 0, "f");
4000
+ this.#offset += 2;
4001
+ this.#insetBit = 0;
3862
4002
  }
3863
4003
  return value;
3864
4004
  }
@@ -3923,12 +4063,12 @@ class BiBase {
3923
4063
  throw new Error("Can't write data in readonly mode!");
3924
4064
  }
3925
4065
  this.open();
3926
- var trueByte = __classPrivateFieldGet(this, _BiBase_offset, "f");
3927
- var trueBit = __classPrivateFieldGet(this, _BiBase_insetBit, "f");
4066
+ var trueByte = this.#offset;
4067
+ var trueBit = this.#insetBit;
3928
4068
  if (trueBit != 0) {
3929
4069
  trueByte += 1;
3930
4070
  }
3931
- __classPrivateFieldGet(this, _BiBase_instances, "m", _BiBase_checkSize).call(this, 2, 0, trueByte);
4071
+ this.#checkSize(2, 0, trueByte);
3932
4072
  if (canFloat16) {
3933
4073
  this.view.setFloat16(trueByte, value, endian == "little");
3934
4074
  }
@@ -3936,8 +4076,8 @@ class BiBase {
3936
4076
  _whalffloat(this.data, value, trueByte, endian);
3937
4077
  }
3938
4078
  if (consume) {
3939
- __classPrivateFieldSet(this, _BiBase_offset, __classPrivateFieldGet(this, _BiBase_offset, "f") + 2, "f");
3940
- __classPrivateFieldSet(this, _BiBase_insetBit, 0, "f");
4079
+ this.#offset += 2;
4080
+ this.#insetBit = 0;
3941
4081
  }
3942
4082
  return;
3943
4083
  }
@@ -4002,12 +4142,12 @@ class BiBase {
4002
4142
  */
4003
4143
  readInt32(unsigned = false, endian = this.endian, consume = true) {
4004
4144
  this.open();
4005
- var trueByte = __classPrivateFieldGet(this, _BiBase_offset, "f");
4006
- var trueBit = __classPrivateFieldGet(this, _BiBase_insetBit, "f");
4145
+ var trueByte = this.#offset;
4146
+ var trueBit = this.#insetBit;
4007
4147
  if (trueBit != 0) {
4008
4148
  trueByte += 1;
4009
4149
  }
4010
- __classPrivateFieldGet(this, _BiBase_instances, "m", _BiBase_checkSize).call(this, 4, 0, trueByte);
4150
+ this.#checkSize(4, 0, trueByte);
4011
4151
  var value;
4012
4152
  if (canInt32) {
4013
4153
  if (unsigned) {
@@ -4021,8 +4161,8 @@ class BiBase {
4021
4161
  value = _rint32(this.data, trueByte, endian, unsigned);
4022
4162
  }
4023
4163
  if (consume) {
4024
- __classPrivateFieldSet(this, _BiBase_offset, __classPrivateFieldGet(this, _BiBase_offset, "f") + 4, "f");
4025
- __classPrivateFieldSet(this, _BiBase_insetBit, 0, "f");
4164
+ this.#offset += 4;
4165
+ this.#insetBit = 0;
4026
4166
  }
4027
4167
  return value;
4028
4168
  }
@@ -4107,12 +4247,12 @@ class BiBase {
4107
4247
  throw new Error("Can't write data in readonly mode!");
4108
4248
  }
4109
4249
  this.open();
4110
- var trueByte = __classPrivateFieldGet(this, _BiBase_offset, "f");
4111
- var trueBit = __classPrivateFieldGet(this, _BiBase_insetBit, "f");
4250
+ var trueByte = this.#offset;
4251
+ var trueBit = this.#insetBit;
4112
4252
  if (trueBit != 0) {
4113
4253
  trueByte += 1;
4114
4254
  }
4115
- __classPrivateFieldGet(this, _BiBase_instances, "m", _BiBase_checkSize).call(this, 4, 0, trueByte);
4255
+ this.#checkSize(4, 0, trueByte);
4116
4256
  if (canInt32) {
4117
4257
  if (unsigned) {
4118
4258
  this.view.setUint32(trueByte, value, endian == "little");
@@ -4125,8 +4265,8 @@ class BiBase {
4125
4265
  _wint32(this.data, numberSafe(value, 32, unsigned), trueByte, endian, unsigned);
4126
4266
  }
4127
4267
  if (consume) {
4128
- __classPrivateFieldSet(this, _BiBase_offset, __classPrivateFieldGet(this, _BiBase_offset, "f") + 4, "f");
4129
- __classPrivateFieldSet(this, _BiBase_insetBit, 0, "f");
4268
+ this.#offset += 4;
4269
+ this.#insetBit = 0;
4130
4270
  }
4131
4271
  return;
4132
4272
  }
@@ -4209,12 +4349,12 @@ class BiBase {
4209
4349
  */
4210
4350
  readFloat(endian = this.endian, consume = true) {
4211
4351
  this.open();
4212
- var trueByte = __classPrivateFieldGet(this, _BiBase_offset, "f");
4213
- var trueBit = __classPrivateFieldGet(this, _BiBase_insetBit, "f");
4352
+ var trueByte = this.#offset;
4353
+ var trueBit = this.#insetBit;
4214
4354
  if (trueBit != 0) {
4215
4355
  trueByte += 1;
4216
4356
  }
4217
- __classPrivateFieldGet(this, _BiBase_instances, "m", _BiBase_checkSize).call(this, 4, 0, trueByte);
4357
+ this.#checkSize(4, 0, trueByte);
4218
4358
  var value;
4219
4359
  if (canFloat32) {
4220
4360
  value = this.view.getFloat32(trueByte, endian == "little");
@@ -4223,8 +4363,8 @@ class BiBase {
4223
4363
  value = _rfloat(this.data, trueByte, endian);
4224
4364
  }
4225
4365
  if (consume) {
4226
- __classPrivateFieldSet(this, _BiBase_offset, __classPrivateFieldGet(this, _BiBase_offset, "f") + 4, "f");
4227
- __classPrivateFieldSet(this, _BiBase_insetBit, 0, "f");
4366
+ this.#offset += 4;
4367
+ this.#insetBit = 0;
4228
4368
  }
4229
4369
  return value;
4230
4370
  }
@@ -4289,12 +4429,12 @@ class BiBase {
4289
4429
  throw new Error("Can't write data in readonly mode!");
4290
4430
  }
4291
4431
  this.open();
4292
- var trueByte = __classPrivateFieldGet(this, _BiBase_offset, "f");
4293
- var trueBit = __classPrivateFieldGet(this, _BiBase_insetBit, "f");
4432
+ var trueByte = this.#offset;
4433
+ var trueBit = this.#insetBit;
4294
4434
  if (trueBit != 0) {
4295
4435
  trueByte += 1;
4296
4436
  }
4297
- __classPrivateFieldGet(this, _BiBase_instances, "m", _BiBase_checkSize).call(this, 4, 0, trueByte);
4437
+ this.#checkSize(4, 0, trueByte);
4298
4438
  if (canFloat32) {
4299
4439
  this.view.setFloat32(trueByte, value, endian == "little");
4300
4440
  }
@@ -4302,8 +4442,8 @@ class BiBase {
4302
4442
  _wfloat(this.data, value, trueByte, endian);
4303
4443
  }
4304
4444
  if (consume) {
4305
- __classPrivateFieldSet(this, _BiBase_offset, __classPrivateFieldGet(this, _BiBase_offset, "f") + 4, "f");
4306
- __classPrivateFieldSet(this, _BiBase_insetBit, 0, "f");
4445
+ this.#offset += 4;
4446
+ this.#insetBit = 0;
4307
4447
  }
4308
4448
  return;
4309
4449
  }
@@ -4361,12 +4501,12 @@ class BiBase {
4361
4501
  throw new Error("System doesn't support BigInt values.");
4362
4502
  }
4363
4503
  this.open();
4364
- var trueByte = __classPrivateFieldGet(this, _BiBase_offset, "f");
4365
- var trueBit = __classPrivateFieldGet(this, _BiBase_insetBit, "f");
4504
+ var trueByte = this.#offset;
4505
+ var trueBit = this.#insetBit;
4366
4506
  if (trueBit != 0) {
4367
4507
  trueByte += 1;
4368
4508
  }
4369
- __classPrivateFieldGet(this, _BiBase_instances, "m", _BiBase_checkSize).call(this, 8, 0, trueByte);
4509
+ this.#checkSize(8, 0, trueByte);
4370
4510
  var value;
4371
4511
  if (canBigInt64) {
4372
4512
  if (unsigned) {
@@ -4380,8 +4520,8 @@ class BiBase {
4380
4520
  value = _rint64(this.data, trueByte, endian, unsigned);
4381
4521
  }
4382
4522
  if (consume) {
4383
- __classPrivateFieldSet(this, _BiBase_offset, __classPrivateFieldGet(this, _BiBase_offset, "f") + 8, "f");
4384
- __classPrivateFieldSet(this, _BiBase_insetBit, 0, "f");
4523
+ this.#offset += 8;
4524
+ this.#insetBit = 0;
4385
4525
  }
4386
4526
  if (this.enforceBigInt == true || (typeof value == "bigint" && !isSafeInt64(value))) {
4387
4527
  return value;
@@ -4401,7 +4541,7 @@ class BiBase {
4401
4541
  *
4402
4542
  * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
4403
4543
  *
4404
- * @returns {BigValue}
4544
+ * @returns {ReturnBigValueMapping<alwaysBigInt>}
4405
4545
  */
4406
4546
  readUInt64() {
4407
4547
  return this.readInt64(true);
@@ -4412,7 +4552,7 @@ class BiBase {
4412
4552
  *
4413
4553
  * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
4414
4554
  *
4415
- * @returns {BigValue}
4555
+ * @returns {ReturnBigValueMapping<alwaysBigInt>}
4416
4556
  */
4417
4557
  readInt64BE() {
4418
4558
  return this.readInt64(false, "big");
@@ -4423,7 +4563,7 @@ class BiBase {
4423
4563
  *
4424
4564
  * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
4425
4565
  *
4426
- * @returns {BigValue}
4566
+ * @returns {ReturnBigValueMapping<alwaysBigInt>}
4427
4567
  */
4428
4568
  readInt64LE() {
4429
4569
  return this.readInt64(false, "little");
@@ -4434,7 +4574,7 @@ class BiBase {
4434
4574
  *
4435
4575
  * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
4436
4576
  *
4437
- * @returns {BigValue}
4577
+ * @returns {ReturnBigValueMapping<alwaysBigInt>}
4438
4578
  */
4439
4579
  readUInt64BE() {
4440
4580
  return this.readInt64(true, "big");
@@ -4445,7 +4585,7 @@ class BiBase {
4445
4585
  *
4446
4586
  * Note: If ``enforceBigInt`` was set to ``true``, this always returns a ``BigInt`` otherwise it will return a ``number`` if integer safe.
4447
4587
  *
4448
- * @returns {BigValue}
4588
+ * @returns {ReturnBigValueMapping<alwaysBigInt>}
4449
4589
  */
4450
4590
  readUInt64LE() {
4451
4591
  return this.readInt64(true, "little");
@@ -4468,12 +4608,12 @@ class BiBase {
4468
4608
  throw new Error("System doesn't support BigInt values.");
4469
4609
  }
4470
4610
  this.open();
4471
- var trueByte = __classPrivateFieldGet(this, _BiBase_offset, "f");
4472
- var trueBit = __classPrivateFieldGet(this, _BiBase_insetBit, "f");
4611
+ var trueByte = this.#offset;
4612
+ var trueBit = this.#insetBit;
4473
4613
  if (trueBit != 0) {
4474
4614
  trueByte += 1;
4475
4615
  }
4476
- __classPrivateFieldGet(this, _BiBase_instances, "m", _BiBase_checkSize).call(this, 8, 0, trueByte);
4616
+ this.#checkSize(8, 0, trueByte);
4477
4617
  if (canBigInt64) {
4478
4618
  if (unsigned) {
4479
4619
  this.view.setBigInt64(trueByte, BigInt(value), endian == "little");
@@ -4486,8 +4626,8 @@ class BiBase {
4486
4626
  _wint64(this.data, numberSafe(value, 64, unsigned), trueByte, endian, unsigned);
4487
4627
  }
4488
4628
  if (consume) {
4489
- __classPrivateFieldSet(this, _BiBase_offset, __classPrivateFieldGet(this, _BiBase_offset, "f") + 8, "f");
4490
- __classPrivateFieldSet(this, _BiBase_insetBit, 0, "f");
4629
+ this.#offset += 8;
4630
+ this.#insetBit = 0;
4491
4631
  }
4492
4632
  return;
4493
4633
  }
@@ -4549,12 +4689,12 @@ class BiBase {
4549
4689
  */
4550
4690
  readDoubleFloat(endian = this.endian, consume = true) {
4551
4691
  this.open();
4552
- var trueByte = __classPrivateFieldGet(this, _BiBase_offset, "f");
4553
- var trueBit = __classPrivateFieldGet(this, _BiBase_insetBit, "f");
4692
+ var trueByte = this.#offset;
4693
+ var trueBit = this.#insetBit;
4554
4694
  if (trueBit != 0) {
4555
4695
  trueByte += 1;
4556
4696
  }
4557
- __classPrivateFieldGet(this, _BiBase_instances, "m", _BiBase_checkSize).call(this, 8, 0, trueByte);
4697
+ this.#checkSize(8, 0, trueByte);
4558
4698
  var value;
4559
4699
  if (canFloat64) {
4560
4700
  value = this.view.getFloat64(trueByte, endian == "little");
@@ -4566,8 +4706,8 @@ class BiBase {
4566
4706
  value = _rdfloat(this.data, trueByte, endian);
4567
4707
  }
4568
4708
  if (consume) {
4569
- __classPrivateFieldSet(this, _BiBase_offset, __classPrivateFieldGet(this, _BiBase_offset, "f") + 8, "f");
4570
- __classPrivateFieldSet(this, _BiBase_insetBit, 0, "f");
4709
+ this.#offset += 8;
4710
+ this.#insetBit = 0;
4571
4711
  }
4572
4712
  return value;
4573
4713
  }
@@ -4630,12 +4770,12 @@ class BiBase {
4630
4770
  throw new Error("Can't write data in readonly mode!");
4631
4771
  }
4632
4772
  this.open();
4633
- var trueByte = __classPrivateFieldGet(this, _BiBase_offset, "f");
4634
- var trueBit = __classPrivateFieldGet(this, _BiBase_insetBit, "f");
4773
+ var trueByte = this.#offset;
4774
+ var trueBit = this.#insetBit;
4635
4775
  if (trueBit != 0) {
4636
4776
  trueByte += 1;
4637
4777
  }
4638
- __classPrivateFieldGet(this, _BiBase_instances, "m", _BiBase_checkSize).call(this, 8, 0, trueByte);
4778
+ this.#checkSize(8, 0, trueByte);
4639
4779
  if (canFloat64) {
4640
4780
  this.view.setFloat64(trueByte, value, endian == "little");
4641
4781
  }
@@ -4643,8 +4783,8 @@ class BiBase {
4643
4783
  _wdfloat(this.data, value, trueByte, endian);
4644
4784
  }
4645
4785
  if (consume) {
4646
- __classPrivateFieldSet(this, _BiBase_offset, __classPrivateFieldGet(this, _BiBase_offset, "f") + 8, "f");
4647
- __classPrivateFieldSet(this, _BiBase_insetBit, 0, "f");
4786
+ this.#offset += 8;
4787
+ this.#insetBit = 0;
4648
4788
  }
4649
4789
  return;
4650
4790
  }
@@ -4737,10 +4877,10 @@ class BiBase {
4737
4877
  readLengthinBytes = length;
4738
4878
  break;
4739
4879
  }
4740
- __classPrivateFieldGet(this, _BiBase_instances, "m", _BiBase_checkSize).call(this, readLengthinBytes);
4880
+ this.#checkSize(readLengthinBytes);
4741
4881
  }
4742
4882
  else {
4743
- readLengthinBytes = this.data.length - __classPrivateFieldGet(this, _BiBase_offset, "f");
4883
+ readLengthinBytes = this.data.length - this.#offset;
4744
4884
  }
4745
4885
  if (terminateValue != undefined && typeof terminateValue == "number") {
4746
4886
  terminate = terminateValue & 0xFF;
@@ -4748,12 +4888,12 @@ class BiBase {
4748
4888
  else {
4749
4889
  terminate = 0;
4750
4890
  }
4751
- const saved_offset = __classPrivateFieldGet(this, _BiBase_offset, "f");
4752
- const saved_bitoffset = __classPrivateFieldGet(this, _BiBase_insetBit, "f");
4891
+ const saved_offset = this.#offset;
4892
+ const saved_bitoffset = this.#insetBit;
4753
4893
  const str = _rstring(stringType, lengthReadSize, readLengthinBytes, terminate, stripNull, encoding, endian, this.readUByte.bind(this), this.readUInt16.bind(this), this.readUInt32.bind(this));
4754
4894
  if (!consume) {
4755
- __classPrivateFieldSet(this, _BiBase_offset, saved_offset, "f");
4756
- __classPrivateFieldSet(this, _BiBase_insetBit, saved_bitoffset, "f");
4895
+ this.#offset = saved_offset;
4896
+ this.#insetBit = saved_bitoffset;
4757
4897
  }
4758
4898
  return str;
4759
4899
  }
@@ -4850,189 +4990,35 @@ class BiBase {
4850
4990
  }
4851
4991
  break;
4852
4992
  }
4853
- __classPrivateFieldGet(this, _BiBase_instances, "m", _BiBase_checkSize).call(this, totalLength, 0, __classPrivateFieldGet(this, _BiBase_offset, "f"));
4854
- const savedOffset = __classPrivateFieldGet(this, _BiBase_offset, "f");
4855
- const savedBitOffset = __classPrivateFieldGet(this, _BiBase_insetBit, "f");
4993
+ this.#checkSize(totalLength, 0, this.#offset);
4994
+ const savedOffset = this.#offset;
4995
+ const savedBitOffset = this.#insetBit;
4856
4996
  _wstring(encodedString, stringType, endian, terminateValue, lengthWriteSize, this.writeUByte.bind(this), this.writeUInt16.bind(this), this.writeUInt32.bind(this));
4857
4997
  if (!consume) {
4858
- __classPrivateFieldSet(this, _BiBase_offset, savedOffset, "f");
4859
- __classPrivateFieldSet(this, _BiBase_insetBit, savedBitOffset, "f");
4998
+ this.#offset = savedOffset;
4999
+ this.#insetBit = savedBitOffset;
4860
5000
  }
4861
5001
  return;
4862
5002
  }
4863
5003
  ;
4864
5004
  }
4865
- _BiBase_offset = new WeakMap(), _BiBase_insetBit = new WeakMap(), _BiBase_data = new WeakMap(), _BiBase_view = new WeakMap(), _BiBase_instances = new WeakSet(), _BiBase_updateSize = function _BiBase_updateSize() {
4866
- if (this.isMemoryMode) {
4867
- this.size = __classPrivateFieldGet(this, _BiBase_data, "f").length;
4868
- this.bitSize = this.size * 8;
4869
- return;
4870
- }
4871
- if (typeof fs$1 === "undefined") {
4872
- throw new Error("Can't load file outside of Node.");
4873
- }
4874
- if (this.fd != null) {
4875
- try {
4876
- const stat = fs$1.fstatSync(this.fd);
4877
- this.size = stat.size;
4878
- this.bitSize = this.size * 8;
4879
- }
4880
- catch (error) {
4881
- throw new Error(error);
4882
- }
4883
- }
4884
- }, _BiBase_updateBuffer = function _BiBase_updateBuffer() {
4885
- if (!this.isMemoryMode) {
4886
- if (this.fd == null) {
4887
- try {
4888
- this.fd = fs$1.openSync(this.filePath, this.fsMode);
4889
- }
4890
- catch (error) {
4891
- throw new Error(error);
4892
- }
4893
- }
4894
- const data = Buffer.alloc(this.size);
4895
- try {
4896
- const bytesRead = fs$1.readSync(this.fd, data, 0, data.length, 0);
4897
- if (bytesRead != this.size) {
4898
- throw new Error("Didn't update file buffer size. Expecting " + this.size + " but got " + bytesRead);
4899
- }
4900
- }
4901
- catch (error) {
4902
- throw new Error(error);
4903
- }
4904
- this.data = data;
4905
- __classPrivateFieldGet(this, _BiBase_instances, "m", _BiBase_updateSize).call(this);
4906
- }
4907
- __classPrivateFieldSet(this, _BiBase_offset, __classPrivateFieldGet(this, _BiBase_offset, "f") ?? 0, "f");
4908
- __classPrivateFieldSet(this, _BiBase_insetBit, __classPrivateFieldGet(this, _BiBase_insetBit, "f") ?? 0, "f");
4909
- __classPrivateFieldSet(this, _BiBase_offset, ((Math.abs(__classPrivateFieldGet(this, _BiBase_offset, "f"))) + Math.ceil((Math.abs(__classPrivateFieldGet(this, _BiBase_insetBit, "f"))) / 8)), "f");
4910
- // Adjust byte offset based on bit overflow
4911
- __classPrivateFieldSet(this, _BiBase_offset, __classPrivateFieldGet(this, _BiBase_offset, "f") + Math.floor((Math.abs(__classPrivateFieldGet(this, _BiBase_insetBit, "f"))) / 8), "f");
4912
- // Adjust bit offset
4913
- __classPrivateFieldSet(this, _BiBase_insetBit, Math.abs(normalizeBitOffset(__classPrivateFieldGet(this, _BiBase_insetBit, "f"))) % 8, "f");
4914
- // Ensure bit offset stays between 0-7
4915
- __classPrivateFieldSet(this, _BiBase_insetBit, Math.min(Math.max(__classPrivateFieldGet(this, _BiBase_insetBit, "f"), 0), 7), "f");
4916
- // Ensure offset doesn't go negative
4917
- __classPrivateFieldSet(this, _BiBase_offset, Math.max(__classPrivateFieldGet(this, _BiBase_offset, "f"), 0), "f");
4918
- __classPrivateFieldGet(this, _BiBase_instances, "m", _BiBase_confrimSize).call(this, __classPrivateFieldGet(this, _BiBase_offset, "f"));
4919
- }, _BiBase_updateView = function _BiBase_updateView() {
4920
- if (__classPrivateFieldGet(this, _BiBase_data, "f")) {
4921
- __classPrivateFieldSet(this, _BiBase_view, new DataView(__classPrivateFieldGet(this, _BiBase_data, "f").buffer, __classPrivateFieldGet(this, _BiBase_data, "f").byteOffset ?? 0, __classPrivateFieldGet(this, _BiBase_data, "f").byteLength), "f");
4922
- }
4923
- }, _BiBase_checkSize = function _BiBase_checkSize(writeBytes = 0, writeBit = 0, offset = __classPrivateFieldGet(this, _BiBase_offset, "f")) {
4924
- this.open();
4925
- const bits = writeBit + __classPrivateFieldGet(this, _BiBase_insetBit, "f");
4926
- if (bits != 0) {
4927
- //add bits
4928
- writeBytes += Math.ceil(bits / 8);
4929
- }
4930
- //if bigger extend
4931
- __classPrivateFieldGet(this, _BiBase_instances, "m", _BiBase_confrimSize).call(this, offset + writeBytes);
4932
- //start read location
4933
- return offset;
4934
- }, _BiBase_confrimSize = function _BiBase_confrimSize(neededSize) {
4935
- if (neededSize <= this.size) {
4936
- return;
4937
- }
4938
- var targetSize = neededSize;
4939
- if (targetSize > this.size) {
4940
- if (this.strict || this.readOnly) {
4941
- this.errorDump ? console.log("\x1b[31m[Error]\x1b[0m hexdump:\n" + this.hexdump({ returnString: true })) : "";
4942
- throw new Error(`\x1b[33m[Strict mode]\x1b[0m: Reached end of data: ` + neededSize + " at " + __classPrivateFieldGet(this, _BiBase_offset, "f") + " of " + this.size);
4943
- }
4944
- if (this.growthIncrement != 0) {
4945
- this.wasExpanded = true;
4946
- targetSize = Math.ceil(neededSize / this.growthIncrement) * this.growthIncrement;
4947
- }
4948
- __classPrivateFieldGet(this, _BiBase_instances, "m", _BiBase_extendArray).call(this, targetSize);
4949
- }
4950
- }, _BiBase_extendArray = function _BiBase_extendArray(targetSize) {
4951
- this.open();
4952
- if (targetSize <= this.size) {
4953
- return;
4954
- }
4955
- const toPadd = targetSize - this.size;
4956
- if (this.isBuffer(__classPrivateFieldGet(this, _BiBase_data, "f"))) {
4957
- var paddbuffer = Buffer.alloc(toPadd);
4958
- this.data = Buffer.concat([__classPrivateFieldGet(this, _BiBase_data, "f"), paddbuffer]);
4959
- }
4960
- else {
4961
- const newBuf = new Uint8Array(this.size + toPadd);
4962
- newBuf.set(__classPrivateFieldGet(this, _BiBase_data, "f"));
4963
- this.data = newBuf;
4964
- }
4965
- this.size = __classPrivateFieldGet(this, _BiBase_data, "f").length;
4966
- this.bitSize = __classPrivateFieldGet(this, _BiBase_data, "f").length * 8;
4967
- return;
4968
- }, _BiBase_findNumber = function _BiBase_findNumber(value, bits, unsigned, endian = this.endian) {
4969
- __classPrivateFieldGet(this, _BiBase_instances, "m", _BiBase_checkSize).call(this, Math.floor(bits / 8), 0, __classPrivateFieldGet(this, _BiBase_offset, "f"));
4970
- for (let z = __classPrivateFieldGet(this, _BiBase_offset, "f"); z <= (this.size - (bits / 8)); z++) {
4971
- var offsetInBits = 0;
4972
- var value = 0;
4973
- for (var i = 0; i < bits;) {
4974
- const remaining = bits - i;
4975
- const bitOffset = offsetInBits & 7;
4976
- const currentByte = this.data[z + (offsetInBits >> 3)];
4977
- const read = Math.min(remaining, 8 - bitOffset);
4978
- if (endian == "big") {
4979
- let mask = ~(0xFF << read);
4980
- let readBits = (currentByte >> (8 - read - bitOffset)) & mask;
4981
- value <<= read;
4982
- value |= readBits;
4983
- }
4984
- else {
4985
- let mask = ~(0xFF << read);
4986
- let readBits = (currentByte >> bitOffset) & mask;
4987
- value |= readBits << i;
4988
- }
4989
- offsetInBits += read;
4990
- i += read;
4991
- }
4992
- if (unsigned || bits <= 7) {
4993
- value = value >>> 0;
4994
- }
4995
- else {
4996
- if (bits !== 32 && value & (1 << (bits - 1))) {
4997
- value |= -1 ^ ((1 << bits) - 1);
4998
- }
4999
- }
5000
- if (value === value) {
5001
- return z - __classPrivateFieldGet(this, _BiBase_offset, "f"); // Found the byte, return the index from current
5002
- }
5003
- }
5004
- return -1; // number not found
5005
- };
5006
5005
 
5007
5006
  /**
5008
5007
  * Binary reader, includes bitfields and strings.
5009
5008
  *
5010
- * @param {string|Buffer|Uint8Array} input - File path or a ``Buffer`` or ``Uint8Array``. Always found in ``BiReader.data``
5009
+ * @param {DataType} input - File path or a `Buffer` or `Uint8Array`. Always found in .{@link data}
5011
5010
  * @param {BiOptions?} options - Any options to set at start
5012
- * @param {BiOptions["byteOffset"]?} options.byteOffset - Byte offset to start reader (default ``0``)
5013
- * @param {BiOptions["bitOffset"]?} options.bitOffset - Bit offset 0-7 to start reader (default ``0``)
5014
- * @param {BiOptions["endianness"]?} options.endianness - Endianness ``big`` or ``little`` (default ``little``)
5015
- * @param {BiOptions["strict"]?} options.strict - Strict mode: if ``true`` does not extend supplied array on outside write (default ``true``)
5016
- * @param {BiOptions["growthIncrement"]?} options.growthIncrement - Amount of data to add when extending the buffer array when strict mode is false. Note: Changes logic in ``.get`` and ``.return``.
5017
- * @param {BiOptions["enforceBigInt"]?} options.enforceBigInt - 64 bit value reads will always be ``BigInt``.
5018
- * @param {BiOptions["writeable"]} options.writeable - Allow data writes when reading a file (default ``true`` in reader)
5011
+ * @param {BiOptions["byteOffset"]?} [options.byteOffset = 0] - Byte offset to start reader (default `0`)
5012
+ * @param {BiOptions["bitOffset"]?} [options.bitOffset = 0] - Bit offset (overrides {@link byteOffset}) (default `0`)
5013
+ * @param {BiOptions["endianness"]?} [options.endianness = "little"] - Endianness `big` or `little` (default `little`)
5014
+ * @param {BiOptions["strict"]?} [options.strict = true] - Strict mode: if `true` does not extend supplied array on outside read or write (default `true`)
5015
+ * @param {BiOptions["growthIncrement"]?} [options.growthIncrement = 1048576] - Amount of data to add when extending the buffer array when strict mode is false (default `1 MiB`)
5016
+ * @param {BiOptions["enforceBigInt"]?} [options.enforceBigInt = false] - 64 bit value reads will always return `bigint`. (default `false`)
5017
+ * @param {BiOptions["readOnly"]?} [options.readOnly = true] - Allow data writes when reading a file (default `true` in reader)
5019
5018
  *
5020
5019
  * @since 2.0
5021
5020
  */
5022
5021
  class BiReader extends BiBase {
5023
- /**
5024
- * Binary reader, includes bitfields and strings.
5025
- *
5026
- * @param {string|Buffer|Uint8Array} input - File path or a ``Buffer`` or ``Uint8Array``. Always found in ``BiReader.data``
5027
- * @param {BiOptions?} options - Any options to set at start
5028
- * @param {BiOptions["byteOffset"]?} options.byteOffset - Byte offset to start reader (default ``0``)
5029
- * @param {BiOptions["bitOffset"]?} options.bitOffset - Bit offset 0-7 to start reader (default ``0``)
5030
- * @param {BiOptions["endianness"]?} options.endianness - Endianness ``big`` or ``little`` (default ``little``)
5031
- * @param {BiOptions["strict"]?} options.strict - Strict mode: if ``true`` does not extend supplied array on outside write (default ``true`` in reader)
5032
- * @param {BiOptions["growthIncrement"]?} options.growthIncrement - Amount of data to add when extending the buffer array when strict mode is false. Note: Changes logic in ``.get`` and ``.return``.
5033
- * @param {BiOptions["enforceBigInt"]?} options.enforceBigInt - 64 bit value reads will always be ``BigInt``.
5034
- * @param {BiOptions["readOnly"]} options.readOnly - If you want to prevent write operations (default ``true`` in reader)
5035
- */
5036
5022
  constructor(input, options = {}) {
5037
5023
  options.byteOffset = options.byteOffset ?? 0;
5038
5024
  options.bitOffset = options.bitOffset ?? 0;
@@ -8524,39 +8510,19 @@ class BiReader extends BiBase {
8524
8510
  /**
8525
8511
  * Binary writer, includes bitfields and strings.
8526
8512
  *
8527
- * @param {string|Buffer|Uint8Array} input - File path or a ``Buffer`` or ``Uint8Array``. Always found in ``BiWriter.data``
8513
+ * @param {DataType} input - File path or a `Buffer` or `Uint8Array`. Always found in .{@link data}
8528
8514
  * @param {BiOptions?} options - Any options to set at start
8529
- * @param {BiOptions["byteOffset"]?} options.byteOffset - Byte offset to start writer (default ``0``)
8530
- * @param {BiOptions["bitOffset"]?} options.bitOffset - Bit offset 0-7 to start writer (default ``0``)
8531
- * @param {BiOptions["endianness"]?} options.endianness - Endianness ``big`` or ``little`` (default ``little``)
8532
- * @param {BiOptions["strict"]?} options.strict - Strict mode: if ``true`` does not extend supplied array on outside write (default ``false`` in writer)
8533
- * @param {BiOptions["growthIncrement"]?} options.growthIncrement - Amount of data to add when extending the buffer array when strict mode is false. Note: Changes logic in ``.get`` and ``.return``.
8534
- * @param {BiOptions["enforceBigInt"]?} options.enforceBigInt - 64 bit value reads will always be ``BigInt``.
8515
+ * @param {BiOptions["byteOffset"]?} [options.byteOffset = 0] - Byte offset to start reader (default `0`)
8516
+ * @param {BiOptions["bitOffset"]?} [options.bitOffset = 0] - Bit offset (overrides {@link byteOffset}) (default `0`)
8517
+ * @param {BiOptions["endianness"]?} [options.endianness = "little"] - Endianness `big` or `little` (default `little`)
8518
+ * @param {BiOptions["strict"]?} [options.strict = true] - Strict mode: if `true` does not extend supplied array on outside read or write (default `true`)
8519
+ * @param {BiOptions["growthIncrement"]?} [options.growthIncrement = 1048576] - Amount of data to add when extending the buffer array when strict mode is false (default `1 MiB`)
8520
+ * @param {BiOptions["enforceBigInt"]?} [options.enforceBigInt = false] - 64 bit value reads will always return `bigint`. (default `false`)
8535
8521
  *
8536
8522
  * @since 2.0
8537
8523
  */
8538
8524
  class BiWriter extends BiBase {
8539
- /**
8540
- * Binary writer, includes bitfields and strings.
8541
- *
8542
- * @param {string|Buffer|Uint8Array} input - ``Buffer`` or ``Uint8Array``. Always found in ``BiWriter.data``
8543
- * @param {BiOptions?} options - Any options to set at start
8544
- * @param {BiOptions["byteOffset"]?} options.byteOffset - Byte offset to start writer (default ``0``)
8545
- * @param {BiOptions["bitOffset"]?} options.bitOffset - Bit offset 0-7 to start writer (default ``0``)
8546
- * @param {BiOptions["endianness"]?} options.endianness - Endianness ``big`` or ``little`` (default ``little``)
8547
- * @param {BiOptions["strict"]?} options.strict - Strict mode: if ``true`` does not extend supplied array on outside write (default ``false`` in writer)
8548
- * @param {BiOptions["windowSize"]?} options.growthIncrement - Amount of data to add when extending the buffer array when strict mode is false. Note: Changes logic in ``.get`` and ``.return``.
8549
- * @param {BiOptions["enforceBigInt"]?} options.enforceBigInt - 64 bit value reads will always be ``BigInt``.
8550
- */
8551
- constructor(input, options = {
8552
- byteOffset: 0,
8553
- bitOffset: 0,
8554
- endianness: "little",
8555
- strict: false,
8556
- growthIncrement: 0,
8557
- enforceBigInt: false,
8558
- readOnly: false
8559
- }) {
8525
+ constructor(input, options = {}) {
8560
8526
  options.byteOffset = options.byteOffset ?? 0;
8561
8527
  options.bitOffset = options.bitOffset ?? 0;
8562
8528
  options.endianness = options.endianness ?? "little";
@@ -12008,7 +11974,6 @@ class BiWriter extends BiBase {
12008
11974
  /**
12009
11975
  * @file BiReaderAsync / Writer base for working in sync Buffers or full file reads. Node and Browser.
12010
11976
  */
12011
- var _BiBaseAsync_instances, _BiBaseAsync_offset, _BiBaseAsync_insetBit, _BiBaseAsync_data, _BiBaseAsync_view, _BiBaseAsync_updateSize, _BiBaseAsync_updateView, _BiBaseAsync_initFile, _BiBaseAsync_initMemory, _BiBaseAsync_getChunkIndex, _BiBaseAsync_getNumChunks, _BiBaseAsync_preloadAllChunks, _BiBaseAsync_ensureChunkLoaded, _BiBaseAsync_performChunkLoad, _BiBaseAsync_ensureRangeLoaded, _BiBaseAsync_peekBytes, _BiBaseAsync_writeBytesAt, _BiBaseAsync_confrimSize, _BiBaseAsync_extendArray, _BiBaseAsync_setFileSize, _BiBaseAsync_invalidateFromChunk, _BiBaseAsync_shiftTailForward, _BiBaseAsync_shiftTailBackward, _BiBaseAsync_updateOffsets, _BiBaseAsync_readBytes, _BiBaseAsync_writeBytes, _BiBaseAsync_findNumber;
12012
11977
  // #region Imports
12013
11978
  var fs;
12014
11979
  (async function () {
@@ -12017,12 +11982,14 @@ var fs;
12017
11982
  try {
12018
11983
  if (typeof require !== 'undefined') {
12019
11984
  if (typeof fs === "undefined") {
12020
- fs = require('fs/promises');
11985
+ const _fs = require('fs');
11986
+ fs = _fs.promises;
12021
11987
  }
12022
11988
  }
12023
11989
  else {
12024
11990
  if (typeof fs === "undefined") {
12025
- fs = await import('fs/promises');
11991
+ const _fs = await import('fs');
11992
+ fs = _fs.promises;
12026
11993
  }
12027
11994
  }
12028
11995
  }
@@ -12037,7 +12004,6 @@ async function _fileExists(filePath) {
12037
12004
  return true; // File exists
12038
12005
  }
12039
12006
  catch (error) {
12040
- // @ts-ignore
12041
12007
  return false;
12042
12008
  }
12043
12009
  }
@@ -12052,150 +12018,165 @@ const view8ByteDummy = new DataView(buff8ByteDummy.buffer, buff8ByteDummy.byteOf
12052
12018
  * Base class for BiReader and BiWriter
12053
12019
  */
12054
12020
  class BiBaseAsync {
12021
+ /**
12022
+ * Endianness of default read.
12023
+ * @type {endian}
12024
+ */
12025
+ endian = "little";
12026
+ /**
12027
+ * Current read byte location.
12028
+ */
12029
+ #offset = 0;
12030
+ /**
12031
+ * Current read byte's bit location. 0 - 7
12032
+ */
12033
+ #insetBit = 0;
12034
+ /**
12035
+ * Size in bytes of the current buffer.
12036
+ */
12037
+ size = 0;
12038
+ /**
12039
+ * Size in bits of the current buffer.
12040
+ */
12041
+ bitSize = 0;
12042
+ /**
12043
+ * Allows the buffer to extend reading or writing outside of current size
12044
+ */
12045
+ strict = false;
12046
+ /**
12047
+ * Console log a hexdump on error.
12048
+ */
12049
+ errorDump = false;
12050
+ /**
12051
+ * Master Buffer
12052
+ */
12053
+ #data = null;
12054
+ /**
12055
+ * DataView of master Buffer
12056
+ */
12057
+ #view = null;
12058
+ /**
12059
+ * When the data buffer needs to be extended while strict mode is ``false``, this will be the amount it extends.
12060
+ *
12061
+ * Otherwise it extends just the amount of the next written value.
12062
+ *
12063
+ * This can greatly speed up data writes when large files are being written.
12064
+ *
12065
+ * NOTE: Using ``BiWriterAsync.get`` or ``BiWriterAsync.return`` will now remove all data after the current write position. Use ``BiWriterAsync.data`` to get the full buffer instead.
12066
+ */
12067
+ growthIncrement = 1048576;
12068
+ /**
12069
+ * Open file handle
12070
+ */
12071
+ fd = null;
12072
+ /**
12073
+ * Current file path
12074
+ */
12075
+ filePath;
12076
+ /**
12077
+ * File write mode
12078
+ */
12079
+ fsMode = "r";
12080
+ /**
12081
+ * The settings that used when using the .str getter / setter
12082
+ */
12083
+ strDefaults = { stringType: "utf-8", terminateValue: 0x0 };
12084
+ /**
12085
+ * All int64 reads will return as bigint type
12086
+ */
12087
+ enforceBigInt = null;
12088
+ /**
12089
+ * Not using a file reader.
12090
+ */
12091
+ isMemoryMode = false;
12092
+ /**
12093
+ * If data can not be written to the buffer.
12094
+ */
12095
+ readOnly;
12055
12096
  /**
12056
12097
  * Get the current buffer data.
12057
12098
  *
12058
12099
  * Use async {@link getData} while in file mode!
12059
12100
  */
12060
12101
  get data() {
12061
- return __classPrivateFieldGet(this, _BiBaseAsync_data, "f");
12102
+ return this.#data;
12062
12103
  }
12063
12104
  ;
12064
12105
  /**
12065
12106
  * Get the current buffer data.
12107
+ *
12108
+ * For use in file mode!
12066
12109
  */
12067
12110
  async getData() {
12068
12111
  return await this.get();
12069
12112
  }
12070
12113
  ;
12071
- set setData(data) {
12114
+ /**
12115
+ * Set the current buffer data.
12116
+ */
12117
+ set data(data) {
12072
12118
  if (this.isBufferOrUint8Array(data)) {
12073
- __classPrivateFieldSet(this, _BiBaseAsync_data, data, "f");
12074
- __classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_updateView).call(this);
12075
- this.size = __classPrivateFieldGet(this, _BiBaseAsync_data, "f").length;
12119
+ this.#data = data;
12120
+ this.#updateView();
12121
+ this.size = this.#data.length;
12076
12122
  this.bitSize = this.size * 8;
12077
12123
  }
12078
12124
  }
12079
12125
  ;
12126
+ /**
12127
+ * If the buffer was extended and needs to be trimmed
12128
+ */
12129
+ wasExpanded = false;
12080
12130
  /**
12081
12131
  * Get the DataView of current buffer data.
12082
12132
  */
12083
12133
  get view() {
12084
- return __classPrivateFieldGet(this, _BiBaseAsync_view, "f");
12134
+ return this.#view;
12085
12135
  }
12086
12136
  ;
12137
+ // ASYNC ONLY
12138
+ /**
12139
+ * array of loaded data chunks
12140
+ */
12141
+ chunks = [];
12142
+ /**
12143
+ * Promises for data chunks
12144
+ */
12145
+ chunkPromises = [];
12146
+ /**
12147
+ * Edited data chunks
12148
+ */
12149
+ dirtyChunks = new Set();
12150
+ /**
12151
+ * The amount of data to "chunk" and read a time from the file
12152
+ *
12153
+ * When set to 0, reads whole file at once.
12154
+ */
12155
+ windowSize = 4096;
12156
+ /**
12157
+ * Data is finished loading
12158
+ */
12159
+ isFullyLoaded = false;
12160
+ /**
12161
+ * Array of all chunks to quickly load all parts
12162
+ */
12163
+ loadAllPromise = null;
12087
12164
  constructor(input, options = {}) {
12088
- _BiBaseAsync_instances.add(this);
12089
- /**
12090
- * Endianness of default read.
12091
- * @type {endian}
12092
- */
12093
- this.endian = "little";
12094
- /**
12095
- * Current read byte location.
12096
- */
12097
- _BiBaseAsync_offset.set(this, 0);
12098
- /**
12099
- * Current read byte's bit location. 0 - 7
12100
- */
12101
- _BiBaseAsync_insetBit.set(this, 0);
12102
- /**
12103
- * Size in bytes of the current buffer.
12104
- */
12105
- this.size = 0;
12106
- /**
12107
- * Size in bits of the current buffer.
12108
- */
12109
- this.bitSize = 0;
12110
- /**
12111
- * Allows the buffer to extend reading or writing outside of current size
12112
- */
12113
- this.strict = false;
12114
- /**
12115
- * Console log a hexdump on error.
12116
- */
12117
- this.errorDump = false;
12118
- /**
12119
- * Master Buffer
12120
- */
12121
- _BiBaseAsync_data.set(this, null);
12122
- /**
12123
- * DataView of master Buffer
12124
- */
12125
- _BiBaseAsync_view.set(this, null);
12126
- /**
12127
- * When the data buffer needs to be extended while strict mode is ``false``, this will be the amount it extends.
12128
- *
12129
- * Otherwise it extends just the amount of the next written value.
12130
- *
12131
- * This can greatly speed up data writes when large files are being written.
12132
- *
12133
- * NOTE: Using ``BiWriterAsync.get`` or ``BiWriterAsync.return`` will now remove all data after the current write position. Use ``BiWriterAsync.data`` to get the full buffer instead.
12134
- */
12135
- this.growthIncrement = 1048576;
12136
- /**
12137
- * Open file handle
12138
- */
12139
- this.fd = null;
12140
- /**
12141
- * File write mode
12142
- */
12143
- this.fsMode = "r";
12144
- /**
12145
- * The settings that used when using the .str getter / setter
12146
- */
12147
- this.strDefaults = { stringType: "utf-8", terminateValue: 0x0 };
12148
- /**
12149
- * All int64 reads will return as bigint type
12150
- */
12151
- this.enforceBigInt = null;
12152
- /**
12153
- * Not using a file reader.
12154
- */
12155
- this.isMemoryMode = false;
12156
- this.wasExpanded = false;
12157
- // ASYNC ONLY
12158
- /**
12159
- * array of loaded data chunks
12160
- */
12161
- this.chunks = [];
12162
- /**
12163
- * Promises for data chunks
12164
- */
12165
- this.chunkPromises = [];
12166
- /**
12167
- * Edited data chunks
12168
- */
12169
- this.dirtyChunks = new Set();
12170
- /**
12171
- * The amount of data to "chunk" and read a time from the file
12172
- *
12173
- * When set to 0, reads whole file at once.
12174
- */
12175
- this.windowSize = 4096;
12176
- /**
12177
- * Data is finished loading
12178
- */
12179
- this.isFullyLoaded = false;
12180
- /**
12181
- * Array of all chunks to quickly load all parts
12182
- */
12183
- this.loadAllPromise = null;
12184
12165
  const { byteOffset, bitOffset, endianness, strict, growthIncrement, enforceBigInt, readOnly, windowSize, } = options;
12185
12166
  if (typeof strict != "boolean") {
12186
12167
  throw new TypeError("Strict mode must be true or false");
12187
12168
  }
12188
- __classPrivateFieldSet(this, _BiBaseAsync_offset, byteOffset, "f");
12169
+ this.#offset = byteOffset;
12189
12170
  if ((bitOffset ?? 0) != 0) {
12190
- __classPrivateFieldSet(this, _BiBaseAsync_offset, Math.floor(byteOffset / 8), "f");
12191
- __classPrivateFieldSet(this, _BiBaseAsync_insetBit, byteOffset % 8, "f");
12171
+ this.#offset = Math.floor(byteOffset / 8);
12172
+ this.#insetBit = byteOffset % 8;
12192
12173
  }
12193
12174
  this.windowSize = windowSize;
12194
12175
  this.readOnly = !!readOnly;
12195
12176
  this.strict = this.readOnly ? true : strict;
12196
12177
  this.fsMode = this.readOnly ? 'r' : 'r+';
12197
12178
  this.enforceBigInt = !!enforceBigInt;
12198
- if (this.enforceBigInt && !hasBigInt) {
12179
+ if (!hasBigInt) {
12199
12180
  this.enforceBigInt = false;
12200
12181
  }
12201
12182
  this.growthIncrement = growthIncrement;
@@ -12211,11 +12192,11 @@ class BiBaseAsync {
12211
12192
  this.isMemoryMode = false;
12212
12193
  }
12213
12194
  else if (this.isBufferOrUint8Array(input)) {
12214
- this.setData = input;
12195
+ this.data = input;
12215
12196
  this.isMemoryMode = true;
12216
12197
  this.filePath = null;
12217
12198
  this.windowSize = 0;
12218
- __classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_initMemory).call(this);
12199
+ this.#initMemory();
12219
12200
  }
12220
12201
  else {
12221
12202
  throw new TypeError('Source must be a file path (string) or Uint8Array/Buffer');
@@ -12262,26 +12243,523 @@ class BiBaseAsync {
12262
12243
  return isUint8Array(obj);
12263
12244
  }
12264
12245
  ;
12246
+ /**
12247
+ * Internal update size
12248
+ *
12249
+ * run after setting data
12250
+ */
12251
+ async #updateSize() {
12252
+ if (this.isMemoryMode) {
12253
+ this.size = this.data.length;
12254
+ this.bitSize = this.size * 8;
12255
+ return;
12256
+ }
12257
+ if (typeof fs === "undefined") {
12258
+ throw new Error("Can't load file outside Node.");
12259
+ }
12260
+ if (this.fd != null) {
12261
+ try {
12262
+ const stat = await this.fd.stat();
12263
+ this.size = stat.size;
12264
+ this.bitSize = this.size * 8;
12265
+ }
12266
+ catch (error) {
12267
+ throw new Error(error);
12268
+ }
12269
+ }
12270
+ }
12265
12271
  ;
12272
+ /**
12273
+ * Call this after everytime we set/replace `this.data`
12274
+ */
12275
+ #updateView() {
12276
+ if (this.#data) {
12277
+ this.#view = new DataView(this.#data.buffer, this.#data.byteOffset ?? 0, this.#data.byteLength);
12278
+ }
12279
+ }
12266
12280
  ;
12281
+ /**
12282
+ * `this.fd` must be null and not in memory mode
12283
+ */
12284
+ async #initFile() {
12285
+ if (this.isMemoryMode || this.fd != null) {
12286
+ return;
12287
+ }
12288
+ if (!(await _fileExists(this.filePath))) {
12289
+ await fs.writeFile(this.filePath, "");
12290
+ }
12291
+ try {
12292
+ this.fd = await fs.open(this.filePath, this.fsMode);
12293
+ }
12294
+ catch (error) {
12295
+ throw new Error(error);
12296
+ }
12297
+ await this.#updateSize();
12298
+ const numChunks = this.#getNumChunks();
12299
+ this.chunks = new Array(numChunks).fill(null);
12300
+ this.chunkPromises = new Array(numChunks).fill(null);
12301
+ if (this.windowSize == 0) {
12302
+ this.loadAllPromise = this.#preloadAllChunks();
12303
+ }
12304
+ else {
12305
+ this.loadAllPromise = Promise.resolve();
12306
+ }
12307
+ }
12267
12308
  ;
12309
+ /**
12310
+ * Not for file mode
12311
+ */
12312
+ #initMemory() {
12313
+ if (!this.isMemoryMode) {
12314
+ return;
12315
+ }
12316
+ if (this.isFullyLoaded) {
12317
+ return;
12318
+ }
12319
+ this.size = this.data.length;
12320
+ this.bitSize = this.size * 8;
12321
+ const numChunks = this.#getNumChunks();
12322
+ this.chunks = new Array(numChunks).fill(null);
12323
+ this.chunkPromises = new Array(numChunks).fill(null);
12324
+ this.isFullyLoaded = true;
12325
+ this.loadAllPromise = null;
12326
+ }
12268
12327
  ;
12328
+ /**
12329
+ * For when there is a full file read
12330
+ */
12331
+ #getChunkIndex(offset) {
12332
+ return this.windowSize === 0 ? 0 : Math.floor(offset / this.windowSize);
12333
+ }
12269
12334
  ;
12335
+ /**
12336
+ * For when there is a full file read
12337
+ */
12338
+ #getNumChunks() {
12339
+ return this.windowSize === 0 ? 1 : Math.ceil(this.size / this.windowSize);
12340
+ }
12270
12341
  ;
12342
+ /**
12343
+ * When the whole file is loaded at once
12344
+ */
12345
+ async #preloadAllChunks() {
12346
+ const promises = [];
12347
+ for (let i = 0; i < this.chunks.length; i++) {
12348
+ promises.push(this.#ensureChunkLoaded(i));
12349
+ }
12350
+ await Promise.all(promises);
12351
+ this.isFullyLoaded = true;
12352
+ }
12271
12353
  ;
12354
+ /**
12355
+ * Checks the chunk is loaded
12356
+ *
12357
+ * @param {number} chunkIndex
12358
+ */
12359
+ async #ensureChunkLoaded(chunkIndex) {
12360
+ if (this.windowSize === 0) {
12361
+ chunkIndex = 0;
12362
+ }
12363
+ if (chunkIndex >= this.chunks.length) {
12364
+ return null;
12365
+ }
12366
+ if (this.chunks[chunkIndex] !== null) {
12367
+ return this.chunks[chunkIndex];
12368
+ }
12369
+ if (this.isMemoryMode) {
12370
+ const start = chunkIndex * this.windowSize;
12371
+ const end = Math.min(start + this.windowSize, this.size);
12372
+ this.chunks[chunkIndex] = this.data.subarray(start, end);
12373
+ return this.chunks[chunkIndex];
12374
+ }
12375
+ if (this.chunkPromises[chunkIndex]) {
12376
+ return await this.chunkPromises[chunkIndex];
12377
+ }
12378
+ const promise = this.#performChunkLoad(chunkIndex);
12379
+ this.chunkPromises[chunkIndex] = promise;
12380
+ return await promise;
12381
+ }
12272
12382
  ;
12383
+ /**
12384
+ * Gets needed chunk
12385
+ *
12386
+ * @param {number} chunkIndex
12387
+ */
12388
+ async #performChunkLoad(chunkIndex) {
12389
+ const start = chunkIndex * this.windowSize;
12390
+ const length = Math.min(this.windowSize, this.size - start);
12391
+ const buffer = Buffer.alloc(length);
12392
+ await this.fd.read(buffer, 0, length, start);
12393
+ this.chunks[chunkIndex] = buffer;
12394
+ return buffer;
12395
+ }
12273
12396
  ;
12397
+ /**
12398
+ * Makes sure the needed size is loaded
12399
+ *
12400
+ * @param {number} offset
12401
+ * @param {number} length
12402
+ */
12403
+ async #ensureRangeLoaded(offset, length) {
12404
+ const needed = offset + length;
12405
+ if (needed > this.size) {
12406
+ if (this.strict || this.readOnly) {
12407
+ throw new Error(`Operation exceeds file size (${needed} > ${this.size})`);
12408
+ }
12409
+ await this.#confrimSize(needed);
12410
+ }
12411
+ const startChunk = this.#getChunkIndex(offset);
12412
+ const endChunk = this.#getChunkIndex(offset + length - 1);
12413
+ const promises = [];
12414
+ for (let i = startChunk; i <= endChunk && i < this.chunks.length; i++) {
12415
+ if (this.chunks[i] === null) {
12416
+ promises.push(this.#ensureChunkLoaded(i));
12417
+ }
12418
+ }
12419
+ await Promise.all(promises);
12420
+ }
12274
12421
  ;
12422
+ /**
12423
+ * Get bytes without changing offset
12424
+ *
12425
+ * @param {number} offset
12426
+ * @param {number} length
12427
+ */
12428
+ async #peekBytes(offset, length) {
12429
+ await this.open();
12430
+ if (length <= 0) {
12431
+ if (this.isMemoryMode) {
12432
+ if (this.isBuffer(this.data)) {
12433
+ return Buffer.alloc(0);
12434
+ }
12435
+ else {
12436
+ return new Uint8Array(0);
12437
+ }
12438
+ }
12439
+ else {
12440
+ return Buffer.alloc(0);
12441
+ }
12442
+ }
12443
+ await this.#ensureRangeLoaded(offset, length);
12444
+ var result;
12445
+ if (this.isMemoryMode) {
12446
+ return this.data.subarray(offset, offset + length);
12447
+ }
12448
+ else {
12449
+ result = Buffer.alloc(length);
12450
+ }
12451
+ let pos = offset;
12452
+ let writePos = 0;
12453
+ while (writePos < length) {
12454
+ const chunkIndex = this.#getChunkIndex(pos);
12455
+ const chunk = this.chunks[chunkIndex];
12456
+ const chunkOffset = pos % this.windowSize;
12457
+ const toCopy = Math.min(length - writePos, chunk.length - chunkOffset);
12458
+ result.set(chunk.subarray(chunkOffset, chunkOffset + toCopy), writePos);
12459
+ writePos += toCopy;
12460
+ pos += toCopy;
12461
+ }
12462
+ return result;
12463
+ }
12275
12464
  ;
12465
+ /**
12466
+ * write bytes internal
12467
+ *
12468
+ * @param {number} offset
12469
+ * @param {Uint8Array | Buffer | number[]} data
12470
+ */
12471
+ async #writeBytesAt(offset, data) {
12472
+ await this.open();
12473
+ if (data.length === 0) {
12474
+ return;
12475
+ }
12476
+ await this.#ensureRangeLoaded(offset, data.length);
12477
+ let pos = offset;
12478
+ let readPos = 0;
12479
+ if (this.isMemoryMode) {
12480
+ for (let i = 0, n = offset; i < data.length; i++, n++) {
12481
+ this.#data[n] = data[i];
12482
+ }
12483
+ return;
12484
+ }
12485
+ while (readPos < data.length) {
12486
+ const chunkIndex = this.#getChunkIndex(pos);
12487
+ const chunk = this.chunks[chunkIndex];
12488
+ const chunkOffset = pos % this.windowSize;
12489
+ const toCopy = Math.min(data.length - readPos, chunk.length - chunkOffset);
12490
+ var sub;
12491
+ if (this.isBufferOrUint8Array(data)) {
12492
+ sub = data.subarray(readPos, readPos + toCopy);
12493
+ }
12494
+ else {
12495
+ sub = data.slice(readPos, readPos + toCopy);
12496
+ }
12497
+ chunk.set(sub, chunkOffset);
12498
+ this.dirtyChunks.add(chunkIndex);
12499
+ readPos += toCopy;
12500
+ pos += toCopy;
12501
+ }
12502
+ }
12276
12503
  ;
12504
+ /**
12505
+ * Checks loaded size
12506
+ *
12507
+ * Will set `wasExpanded` if expanded
12508
+ *
12509
+ * @param {number} neededSize
12510
+ */
12511
+ async #confrimSize(neededSize) {
12512
+ // check if the current request fits in range
12513
+ if (neededSize <= this.size) {
12514
+ return;
12515
+ }
12516
+ var targetSize = neededSize;
12517
+ // now adjust the size if less to `growthIncrement` factor
12518
+ if (targetSize > this.size) {
12519
+ if (this.strict || this.readOnly) {
12520
+ this.errorDump ? console.log("\x1b[31m[Error]\x1b[0m hexdump:\n" + this.hexdump({ returnString: true })) : "";
12521
+ throw new Error(`\x1b[33m[Strict mode]\x1b[0m: Reached end of data: ` + neededSize + " at " + this.#offset + " of " + this.size);
12522
+ }
12523
+ if (this.growthIncrement != 0) {
12524
+ this.wasExpanded = true;
12525
+ targetSize = Math.ceil(neededSize / this.growthIncrement) * this.growthIncrement;
12526
+ }
12527
+ await this.#extendArray(targetSize);
12528
+ }
12529
+ }
12277
12530
  ;
12531
+ /**
12532
+ * extends the data
12533
+ *
12534
+ * @param {number} targetSize
12535
+ */
12536
+ async #extendArray(targetSize) {
12537
+ await this.flush();
12538
+ if (this.isMemoryMode) {
12539
+ const toPadd = targetSize - this.size;
12540
+ if (isBuffer(this.#data)) {
12541
+ const paddbuffer = Buffer.alloc(toPadd);
12542
+ this.data = Buffer.concat([this.#data, paddbuffer]);
12543
+ }
12544
+ else {
12545
+ const newBuf = new Uint8Array(this.size + toPadd);
12546
+ newBuf.set(this.#data);
12547
+ this.data = newBuf;
12548
+ }
12549
+ this.size = targetSize;
12550
+ this.bitSize = this.size * 8;
12551
+ this.chunks = new Array(this.#getNumChunks()).fill(null);
12552
+ this.chunkPromises = new Array(this.#getNumChunks()).fill(null);
12553
+ this.dirtyChunks.clear();
12554
+ }
12555
+ else {
12556
+ await this.fd.truncate(targetSize);
12557
+ this.size = targetSize;
12558
+ this.bitSize = this.size * 8;
12559
+ const oldNum = this.chunks.length;
12560
+ const newNum = this.#getNumChunks();
12561
+ this.chunks.length = newNum;
12562
+ this.chunkPromises.length = newNum;
12563
+ for (let i = oldNum; i < newNum; i++) {
12564
+ this.chunks[i] = null;
12565
+ this.chunkPromises[i] = null;
12566
+ }
12567
+ }
12568
+ }
12278
12569
  ;
12570
+ /**
12571
+ * For updating file size
12572
+ *
12573
+ * @param {number} exactSize
12574
+ * @returns
12575
+ */
12576
+ async #setFileSize(exactSize) {
12577
+ if (exactSize === this.size) {
12578
+ return;
12579
+ }
12580
+ await this.flush();
12581
+ if (this.isMemoryMode) {
12582
+ const newData = this.data.subarray(0, exactSize);
12583
+ this.data = newData;
12584
+ this.size = exactSize;
12585
+ this.bitSize = this.size * 8;
12586
+ const newNum = Math.ceil(exactSize / this.windowSize);
12587
+ this.chunks = new Array(newNum).fill(null);
12588
+ this.chunkPromises = new Array(newNum).fill(null);
12589
+ this.dirtyChunks.clear();
12590
+ }
12591
+ else {
12592
+ await this.fd.truncate(exactSize);
12593
+ this.size = exactSize;
12594
+ this.bitSize = this.size * 8;
12595
+ const oldNum = this.chunks.length;
12596
+ const newNum = Math.ceil(exactSize / this.windowSize);
12597
+ this.chunks.length = newNum;
12598
+ this.chunkPromises.length = newNum;
12599
+ if (newNum < oldNum) {
12600
+ this.dirtyChunks = new Set([...this.dirtyChunks].filter(i => i < newNum));
12601
+ }
12602
+ else {
12603
+ for (let i = oldNum; i < newNum; i++) {
12604
+ this.chunks[i] = null;
12605
+ this.chunkPromises[i] = null;
12606
+ }
12607
+ }
12608
+ }
12609
+ }
12279
12610
  ;
12611
+ /**
12612
+ * removes a chunk
12613
+ *
12614
+ * @param {number} startChunk
12615
+ */
12616
+ #invalidateFromChunk(startChunk) {
12617
+ for (let i = Math.max(0, startChunk); i < this.chunks.length; i++) {
12618
+ this.chunks[i] = null;
12619
+ this.chunkPromises[i] = null;
12620
+ this.dirtyChunks.delete(i);
12621
+ }
12622
+ }
12280
12623
  ;
12624
+ /**
12625
+ * Pulls data back
12626
+ *
12627
+ * @param {number} insertOffset
12628
+ * @param {number} insertLen
12629
+ * @param {number} oldEnd
12630
+ * @param {boolean} consume
12631
+ */
12632
+ async #shiftTailForward(insertOffset, insertLen, oldEnd, consume = false) {
12633
+ if (insertLen <= 0) {
12634
+ return;
12635
+ }
12636
+ if (this.isMemoryMode) {
12637
+ const tailCopy = this.data.subarray(insertOffset, oldEnd);
12638
+ this.data.set(tailCopy, insertOffset + insertLen);
12639
+ }
12640
+ else {
12641
+ let readEnd = oldEnd;
12642
+ let writeEnd = oldEnd + insertLen;
12643
+ const buf = Buffer.alloc(Math.min(this.windowSize, this.size));
12644
+ while (readEnd > insertOffset) {
12645
+ const len = Math.min(this.windowSize, readEnd - insertOffset);
12646
+ const readStart = readEnd - len;
12647
+ const { bytesRead } = await this.fd.read(buf, 0, len, readStart);
12648
+ const writeStart = writeEnd - len;
12649
+ await this.fd.write(buf, 0, bytesRead, writeStart);
12650
+ readEnd = readStart;
12651
+ writeEnd = writeStart;
12652
+ }
12653
+ }
12654
+ if (consume) {
12655
+ this.#offset = insertOffset + insertLen;
12656
+ this.#insetBit = 0;
12657
+ }
12658
+ }
12281
12659
  ;
12660
+ /**
12661
+ *
12662
+ * @param {number} removeOffset
12663
+ * @param {number} removeLen
12664
+ * @param {boolean} consume
12665
+ */
12666
+ async #shiftTailBackward(removeOffset, removeLen, consume = false) {
12667
+ if (removeLen <= 0) {
12668
+ return;
12669
+ }
12670
+ if (this.isMemoryMode) {
12671
+ const tailStart = removeOffset + removeLen;
12672
+ const tailCopy = this.data.subarray(tailStart, this.size);
12673
+ this.data.set(tailCopy, removeOffset);
12674
+ }
12675
+ else {
12676
+ const oldEnd = this.size;
12677
+ let readPos = removeOffset + removeLen;
12678
+ let writePos = removeOffset;
12679
+ const buf = Buffer.alloc(Math.min(this.windowSize, this.size));
12680
+ while (readPos < oldEnd) {
12681
+ const len = Math.min(this.windowSize, oldEnd - readPos);
12682
+ const { bytesRead } = await this.fd.read(buf, 0, len, readPos);
12683
+ await this.fd.write(buf, 0, bytesRead, writePos);
12684
+ readPos += bytesRead;
12685
+ writePos += bytesRead;
12686
+ }
12687
+ }
12688
+ if (consume) {
12689
+ this.#offset = removeOffset;
12690
+ this.#insetBit = 0;
12691
+ }
12692
+ }
12282
12693
  ;
12694
+ async #updateOffsets(newOffset, trueBytes, trueBits) {
12695
+ if (newOffset < 0) {
12696
+ throw new RangeError('Offset cannot be negative');
12697
+ }
12698
+ if (newOffset > this.size) {
12699
+ if (this.strict || this.readOnly) {
12700
+ this.errorDump ? console.log("\x1b[31m[Error]\x1b[0m hexdump:\n" + this.hexdump({ returnString: true })) : "";
12701
+ throw new Error(`\x1b[33m[Strict mode]\x1b[0m: Reached end of data: ` + newOffset + " at " + this.#offset + " of " + this.size);
12702
+ }
12703
+ await this.#confrimSize(newOffset);
12704
+ }
12705
+ this.#offset = trueBytes;
12706
+ // Adjust byte offset based on bit overflow
12707
+ this.#offset += Math.floor(trueBits / 8);
12708
+ // Adjust bit offset
12709
+ this.#insetBit = normalizeBitOffset(trueBits) % 8;
12710
+ // Ensure bit offset stays between 0-7
12711
+ this.#insetBit = Math.min(Math.max(this.#insetBit, 0), 7);
12712
+ // Ensure offset doesn't go negative
12713
+ this.#offset = Math.max(this.#offset, 0);
12714
+ }
12283
12715
  ;
12716
+ async #readBytes(length, consume = true) {
12717
+ await this.open();
12718
+ if (length <= 0) {
12719
+ return new Uint8Array(0);
12720
+ }
12721
+ const offSave = this.#offset;
12722
+ var trueByte = this.#offset;
12723
+ const trueBit = this.#insetBit;
12724
+ if (trueBit != 0) {
12725
+ trueByte += 1;
12726
+ }
12727
+ this.#offset = trueByte;
12728
+ const data = await this.#peekBytes(trueByte, length);
12729
+ if (consume) {
12730
+ this.#offset += length;
12731
+ this.#insetBit = 0;
12732
+ }
12733
+ else {
12734
+ this.#offset = offSave;
12735
+ }
12736
+ return data;
12737
+ }
12284
12738
  ;
12739
+ async #writeBytes(data, consume = true) {
12740
+ if (this.readOnly) {
12741
+ throw new Error('Cannot write to read-only file');
12742
+ }
12743
+ await this.open();
12744
+ if (data.length === 0) {
12745
+ return;
12746
+ }
12747
+ const offSave = this.#offset;
12748
+ var trueByte = this.#offset;
12749
+ const trueBit = this.#insetBit;
12750
+ if (trueBit != 0) {
12751
+ trueByte += 1;
12752
+ }
12753
+ this.#offset = trueByte;
12754
+ await this.#writeBytesAt(trueByte, data);
12755
+ if (consume) {
12756
+ this.#offset += data.length;
12757
+ this.#insetBit = 0;
12758
+ }
12759
+ else {
12760
+ this.#offset = offSave;
12761
+ }
12762
+ }
12285
12763
  ;
12286
12764
  ///////////////////////////////
12287
12765
  // #region FILE MODE
@@ -12315,13 +12793,13 @@ class BiBaseAsync {
12315
12793
  */
12316
12794
  async open(data) {
12317
12795
  if (!this.isMemoryMode) {
12318
- await __classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_initFile).call(this);
12796
+ await this.#initFile();
12319
12797
  }
12320
12798
  else {
12321
12799
  if (this.isBufferOrUint8Array(data)) {
12322
- this.setData = data;
12800
+ this.data = data;
12323
12801
  }
12324
- __classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_initMemory).call(this);
12802
+ this.#initMemory();
12325
12803
  }
12326
12804
  }
12327
12805
  ;
@@ -12392,8 +12870,8 @@ class BiBaseAsync {
12392
12870
  try {
12393
12871
  await this.close();
12394
12872
  this.fd = null;
12395
- __classPrivateFieldSet(this, _BiBaseAsync_data, null, "f");
12396
- __classPrivateFieldSet(this, _BiBaseAsync_view, null, "f");
12873
+ this.#data = null;
12874
+ this.#view = null;
12397
12875
  await fs.rename(this.filePath, newFilePath);
12398
12876
  }
12399
12877
  catch (error) {
@@ -12584,7 +13062,7 @@ class BiBaseAsync {
12584
13062
  * @returns {number} current byte position
12585
13063
  */
12586
13064
  get offset() {
12587
- return __classPrivateFieldGet(this, _BiBaseAsync_offset, "f");
13065
+ return this.#offset;
12588
13066
  }
12589
13067
  ;
12590
13068
  /**
@@ -12602,7 +13080,7 @@ class BiBaseAsync {
12602
13080
  * @returns {number} current byte position
12603
13081
  */
12604
13082
  get tell() {
12605
- return __classPrivateFieldGet(this, _BiBaseAsync_offset, "f");
13083
+ return this.#offset;
12606
13084
  }
12607
13085
  ;
12608
13086
  /**
@@ -12611,7 +13089,7 @@ class BiBaseAsync {
12611
13089
  * @returns {number} current byte position
12612
13090
  */
12613
13091
  get FTell() {
12614
- return __classPrivateFieldGet(this, _BiBaseAsync_offset, "f");
13092
+ return this.#offset;
12615
13093
  }
12616
13094
  ;
12617
13095
  /**
@@ -12620,7 +13098,7 @@ class BiBaseAsync {
12620
13098
  * @returns {number} current byte position
12621
13099
  */
12622
13100
  get saveOffset() {
12623
- return __classPrivateFieldGet(this, _BiBaseAsync_offset, "f");
13101
+ return this.#offset;
12624
13102
  }
12625
13103
  ;
12626
13104
  /**
@@ -12629,7 +13107,7 @@ class BiBaseAsync {
12629
13107
  * @returns {number} current byte position
12630
13108
  */
12631
13109
  get off() {
12632
- return __classPrivateFieldGet(this, _BiBaseAsync_offset, "f");
13110
+ return this.#offset;
12633
13111
  }
12634
13112
  ;
12635
13113
  /**
@@ -12665,7 +13143,7 @@ class BiBaseAsync {
12665
13143
  * @returns {number} current bit position
12666
13144
  */
12667
13145
  get bitOffset() {
12668
- return (__classPrivateFieldGet(this, _BiBaseAsync_offset, "f") * 8) + __classPrivateFieldGet(this, _BiBaseAsync_insetBit, "f");
13146
+ return (this.#offset * 8) + this.#insetBit;
12669
13147
  }
12670
13148
  ;
12671
13149
  /**
@@ -12709,7 +13187,7 @@ class BiBaseAsync {
12709
13187
  * @returns {number} current bit position
12710
13188
  */
12711
13189
  get tellBits() {
12712
- return __classPrivateFieldGet(this, _BiBaseAsync_insetBit, "f");
13190
+ return this.#insetBit;
12713
13191
  }
12714
13192
  ;
12715
13193
  /**
@@ -12741,7 +13219,7 @@ class BiBaseAsync {
12741
13219
  * @returns {number} current bit position
12742
13220
  */
12743
13221
  get insetBit() {
12744
- return __classPrivateFieldGet(this, _BiBaseAsync_insetBit, "f");
13222
+ return this.#insetBit;
12745
13223
  }
12746
13224
  ;
12747
13225
  /**
@@ -12793,7 +13271,7 @@ class BiBaseAsync {
12793
13271
  * @returns {number} size
12794
13272
  */
12795
13273
  get remain() {
12796
- return this.size - __classPrivateFieldGet(this, _BiBaseAsync_offset, "f");
13274
+ return this.size - this.#offset;
12797
13275
  }
12798
13276
  ;
12799
13277
  /**
@@ -12838,7 +13316,7 @@ class BiBaseAsync {
12838
13316
  * @returns {number} size
12839
13317
  */
12840
13318
  get getLine() {
12841
- return Math.abs(Math.floor((__classPrivateFieldGet(this, _BiBaseAsync_offset, "f") - 1) / 16));
13319
+ return Math.abs(Math.floor((this.#offset - 1) / 16));
12842
13320
  }
12843
13321
  ;
12844
13322
  /**
@@ -12872,15 +13350,15 @@ class BiBaseAsync {
12872
13350
  await this.trim();
12873
13351
  }
12874
13352
  if (this.isMemoryMode) {
12875
- return __classPrivateFieldGet(this, _BiBaseAsync_data, "f");
13353
+ return this.#data;
12876
13354
  }
12877
13355
  const chunks = [];
12878
- for (let i = 0; i < __classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_getNumChunks).call(this); i++) {
12879
- const chunk = await __classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_ensureChunkLoaded).call(this, i);
13356
+ for (let i = 0; i < this.#getNumChunks(); i++) {
13357
+ const chunk = await this.#ensureChunkLoaded(i);
12880
13358
  chunks.push(chunk);
12881
13359
  }
12882
13360
  if (this.growthIncrement != 0) {
12883
- return Buffer.concat(chunks).subarray(0, __classPrivateFieldGet(this, _BiBaseAsync_offset, "f"));
13361
+ return Buffer.concat(chunks).subarray(0, this.#offset);
12884
13362
  }
12885
13363
  return Buffer.concat(chunks);
12886
13364
  }
@@ -12912,8 +13390,8 @@ class BiBaseAsync {
12912
13390
  */
12913
13391
  async end() {
12914
13392
  if (this.isMemoryMode) {
12915
- __classPrivateFieldSet(this, _BiBaseAsync_data, null, "f");
12916
- __classPrivateFieldSet(this, _BiBaseAsync_view, null, "f");
13393
+ this.#data = null;
13394
+ this.#view = null;
12917
13395
  return;
12918
13396
  }
12919
13397
  await this.commit();
@@ -12954,13 +13432,13 @@ class BiBaseAsync {
12954
13432
  async hexdump(options = {}) {
12955
13433
  await this.open();
12956
13434
  const length = options?.length ?? 192;
12957
- const startByte = options?.startByte ?? __classPrivateFieldGet(this, _BiBaseAsync_offset, "f");
13435
+ const startByte = options?.startByte ?? this.#offset;
12958
13436
  const endByte = Math.min(startByte + length, this.size);
12959
13437
  const newSize = endByte - startByte;
12960
13438
  if (startByte > this.size || endByte > this.size) {
12961
13439
  throw new RangeError("Hexdump amount is outside of data size: " + newSize + " of " + endByte);
12962
13440
  }
12963
- const data = await __classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_peekBytes).call(this, startByte, Math.min(endByte, this.size) - startByte);
13441
+ const data = await this.#peekBytes(startByte, Math.min(endByte, this.size) - startByte);
12964
13442
  return _hexDump(data, options, startByte, endByte);
12965
13443
  }
12966
13444
  ;
@@ -13011,16 +13489,16 @@ class BiBaseAsync {
13011
13489
  if (Array.isArray(bytesToFind)) {
13012
13490
  bytesToFind = new Uint8Array(bytesToFind);
13013
13491
  }
13014
- const data = await __classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_peekBytes).call(this, 0, this.size);
13492
+ const data = await this.#peekBytes(0, this.size);
13015
13493
  if (this.isBuffer(data)) {
13016
- var offset = data.subarray(__classPrivateFieldGet(this, _BiBaseAsync_offset, "f"), this.size).indexOf(bytesToFind);
13494
+ var offset = data.subarray(this.#offset, this.size).indexOf(bytesToFind);
13017
13495
  if (offset == -1) {
13018
13496
  return -1;
13019
13497
  }
13020
- return offset + __classPrivateFieldGet(this, _BiBaseAsync_offset, "f");
13498
+ return offset + this.#offset;
13021
13499
  }
13022
13500
  // data = Uint8Array
13023
- for (let i = __classPrivateFieldGet(this, _BiBaseAsync_offset, "f"); i <= this.size - bytesToFind.length; i++) {
13501
+ for (let i = this.#offset; i <= this.size - bytesToFind.length; i++) {
13024
13502
  var match = true;
13025
13503
  for (let j = 0; j < bytesToFind.length; j++) {
13026
13504
  if (data[i + j] !== bytesToFind[j]) {
@@ -13050,6 +13528,43 @@ class BiBaseAsync {
13050
13528
  return await this.findBytes(encoded);
13051
13529
  }
13052
13530
  ;
13531
+ #findNumber(data, value, bits, unsigned, endian = this.endian) {
13532
+ for (let z = this.#offset; z <= (this.size - (bits / 8)); z++) {
13533
+ var offsetInBits = 0;
13534
+ var currentValue = 0;
13535
+ for (var i = 0; i < bits;) {
13536
+ const remaining = bits - i;
13537
+ const bitOffset = offsetInBits & 7;
13538
+ const currentByte = data[z + (offsetInBits >> 3)];
13539
+ const read = Math.min(remaining, 8 - bitOffset);
13540
+ if (endian == "big") {
13541
+ let mask = ~(0xFF << read);
13542
+ let readBits = (currentByte >> (8 - read - bitOffset)) & mask;
13543
+ currentValue <<= read;
13544
+ currentValue |= readBits;
13545
+ }
13546
+ else {
13547
+ let mask = ~(0xFF << read);
13548
+ let readBits = (currentByte >> bitOffset) & mask;
13549
+ currentValue |= readBits << i;
13550
+ }
13551
+ offsetInBits += read;
13552
+ i += read;
13553
+ }
13554
+ if (unsigned == true || bits <= 7) {
13555
+ currentValue = currentValue >>> 0;
13556
+ }
13557
+ else {
13558
+ if (currentValue & (1 << (bits - 1))) {
13559
+ currentValue |= -1 ^ ((1 << bits) - 1);
13560
+ }
13561
+ }
13562
+ if (currentValue === value) {
13563
+ return z - this.#offset; // Found the byte, return the index from current
13564
+ }
13565
+ }
13566
+ return -1; // number not found
13567
+ }
13053
13568
  /**
13054
13569
  * Searches for byte value (can be signed or unsigned) position from current read position.
13055
13570
  *
@@ -13062,8 +13577,8 @@ class BiBaseAsync {
13062
13577
  * @param {endian} endian - endianness of value (default set endian).
13063
13578
  */
13064
13579
  async findByte(value, unsigned = true, endian = this.endian) {
13065
- const data = await __classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_peekBytes).call(this, 0, this.size);
13066
- return __classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_findNumber).call(this, data, value, 8, unsigned, endian);
13580
+ const data = await this.#peekBytes(0, this.size);
13581
+ return this.#findNumber(data, value, 8, unsigned, endian);
13067
13582
  }
13068
13583
  ;
13069
13584
  /**
@@ -13078,8 +13593,8 @@ class BiBaseAsync {
13078
13593
  * @param {endian} endian - endianness of value (default set endian).
13079
13594
  */
13080
13595
  async findShort(value, unsigned = true, endian = this.endian) {
13081
- const data = await __classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_peekBytes).call(this, 0, this.size);
13082
- return __classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_findNumber).call(this, data, value, 16, unsigned, endian);
13596
+ const data = await this.#peekBytes(0, this.size);
13597
+ return this.#findNumber(data, value, 16, unsigned, endian);
13083
13598
  }
13084
13599
  ;
13085
13600
  /**
@@ -13094,8 +13609,8 @@ class BiBaseAsync {
13094
13609
  * @param {endian} endian - endianness of value (default set endian).
13095
13610
  */
13096
13611
  async findInt(value, unsigned = true, endian = this.endian) {
13097
- const data = await __classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_peekBytes).call(this, 0, this.size);
13098
- return __classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_findNumber).call(this, data, value, 32, unsigned, endian);
13612
+ const data = await this.#peekBytes(0, this.size);
13613
+ return this.#findNumber(data, value, 32, unsigned, endian);
13099
13614
  }
13100
13615
  ;
13101
13616
  /**
@@ -13113,8 +13628,8 @@ class BiBaseAsync {
13113
13628
  if (!hasBigInt) {
13114
13629
  throw new Error("System doesn't support BigInt values.");
13115
13630
  }
13116
- const data = await __classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_peekBytes).call(this, 0, this.size);
13117
- for (let z = __classPrivateFieldGet(this, _BiBaseAsync_offset, "f"); z <= (this.size - 8); z++) {
13631
+ const data = await this.#peekBytes(0, this.size);
13632
+ for (let z = this.#offset; z <= (this.size - 8); z++) {
13118
13633
  var currentValue = BigInt(0);
13119
13634
  if (endian == "little") {
13120
13635
  for (let i = 0; i < 8; i++) {
@@ -13154,8 +13669,8 @@ class BiBaseAsync {
13154
13669
  * @param {endian} endian - endianness of value (default set endian).
13155
13670
  */
13156
13671
  async findHalfFloat(value, endian = this.endian) {
13157
- const data = await __classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_peekBytes).call(this, 0, this.size);
13158
- for (let z = __classPrivateFieldGet(this, _BiBaseAsync_offset, "f"); z <= (this.size - 2); z++) {
13672
+ const data = await this.#peekBytes(0, this.size);
13673
+ for (let z = this.#offset; z <= (this.size - 2); z++) {
13159
13674
  var currentValue = 0;
13160
13675
  if (endian == "little") {
13161
13676
  currentValue = ((data[z + 1] & 0xFFFF) << 8) | (data[z] & 0xFFFF);
@@ -13206,8 +13721,8 @@ class BiBaseAsync {
13206
13721
  * @param {endian} endian - endianness of value (default set endian).
13207
13722
  */
13208
13723
  async findFloat(value, endian = this.endian) {
13209
- const data = await __classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_peekBytes).call(this, 0, this.size);
13210
- for (let z = __classPrivateFieldGet(this, _BiBaseAsync_offset, "f"); z <= (this.size - 4); z++) {
13724
+ const data = await this.#peekBytes(0, this.size);
13725
+ for (let z = this.#offset; z <= (this.size - 4); z++) {
13211
13726
  var currentValue = 0;
13212
13727
  if (endian == "little") {
13213
13728
  currentValue = ((data[z + 3] & 0xFF) << 24) |
@@ -13260,8 +13775,8 @@ class BiBaseAsync {
13260
13775
  if (!hasBigInt) {
13261
13776
  throw new Error("System doesn't support BigInt values.");
13262
13777
  }
13263
- const data = await __classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_peekBytes).call(this, 0, this.size);
13264
- for (let z = __classPrivateFieldGet(this, _BiBaseAsync_offset, "f"); z <= (this.size - 8); z++) {
13778
+ const data = await this.#peekBytes(0, this.size);
13779
+ for (let z = this.#offset; z <= (this.size - 8); z++) {
13265
13780
  var currentValue = BigInt(0);
13266
13781
  if (endian == "little") {
13267
13782
  for (let i = 0; i < 8; i++) {
@@ -13316,7 +13831,7 @@ class BiBaseAsync {
13316
13831
  * @param {number} number - Byte to align
13317
13832
  */
13318
13833
  async align(number) {
13319
- const a = __classPrivateFieldGet(this, _BiBaseAsync_offset, "f") % number;
13834
+ const a = this.#offset % number;
13320
13835
  if (a) {
13321
13836
  await this.skip(number - a);
13322
13837
  }
@@ -13330,7 +13845,7 @@ class BiBaseAsync {
13330
13845
  * @param {number} number - Byte to align
13331
13846
  */
13332
13847
  async alignRev(number) {
13333
- const a = __classPrivateFieldGet(this, _BiBaseAsync_offset, "f") % number;
13848
+ const a = this.#offset % number;
13334
13849
  if (a) {
13335
13850
  await this.skip(a * -1);
13336
13851
  }
@@ -13346,11 +13861,11 @@ class BiBaseAsync {
13346
13861
  */
13347
13862
  async skip(bytes = 0, bits = 0) {
13348
13863
  await this.open();
13349
- var newOffset = ((bytes + __classPrivateFieldGet(this, _BiBaseAsync_offset, "f")) + Math.ceil((__classPrivateFieldGet(this, _BiBaseAsync_insetBit, "f") + bits) / 8));
13864
+ var newOffset = ((bytes + this.#offset) + Math.ceil((this.#insetBit + bits) / 8));
13350
13865
  if (bits && bits < 0) {
13351
- newOffset = Math.floor((((bytes + __classPrivateFieldGet(this, _BiBaseAsync_offset, "f")) * 8) + __classPrivateFieldGet(this, _BiBaseAsync_insetBit, "f") + bits) / 8);
13866
+ newOffset = Math.floor((((bytes + this.#offset) * 8) + this.#insetBit + bits) / 8);
13352
13867
  }
13353
- await __classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_updateOffsets).call(this, newOffset, bytes, bits);
13868
+ await this.#updateOffsets(newOffset, bytes, bits);
13354
13869
  }
13355
13870
  ;
13356
13871
  /**
@@ -13400,7 +13915,7 @@ class BiBaseAsync {
13400
13915
  async goto(byte = 0, bit = 0) {
13401
13916
  await this.open();
13402
13917
  var newOffset = byte + Math.ceil(bit / 8);
13403
- await __classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_updateOffsets).call(this, newOffset, byte, bit);
13918
+ await this.#updateOffsets(newOffset, byte, bit);
13404
13919
  }
13405
13920
  ;
13406
13921
  /**
@@ -13431,8 +13946,8 @@ class BiBaseAsync {
13431
13946
  * Set byte and bit position to start of data.
13432
13947
  */
13433
13948
  rewind() {
13434
- __classPrivateFieldSet(this, _BiBaseAsync_offset, 0, "f");
13435
- __classPrivateFieldSet(this, _BiBaseAsync_insetBit, 0, "f");
13949
+ this.#offset = 0;
13950
+ this.#insetBit = 0;
13436
13951
  }
13437
13952
  ;
13438
13953
  /**
@@ -13446,8 +13961,8 @@ class BiBaseAsync {
13446
13961
  * Set current byte and bit position to end of data.
13447
13962
  */
13448
13963
  last() {
13449
- __classPrivateFieldSet(this, _BiBaseAsync_offset, this.size, "f");
13450
- __classPrivateFieldSet(this, _BiBaseAsync_insetBit, 0, "f");
13964
+ this.#offset = this.size;
13965
+ this.#insetBit = 0;
13451
13966
  }
13452
13967
  ;
13453
13968
  /**
@@ -13476,7 +13991,7 @@ class BiBaseAsync {
13476
13991
  * @param {number} endOffset - End location (default current position)
13477
13992
  * @param {boolean} consume - Move position to end of removed data (default false)
13478
13993
  */
13479
- async delete(startOffset = 0, endOffset = __classPrivateFieldGet(this, _BiBaseAsync_offset, "f"), consume = false) {
13994
+ async delete(startOffset = 0, endOffset = this.#offset, consume = false) {
13480
13995
  if (this.readOnly || this.strict) {
13481
13996
  this.errorDump ? console.log("\x1b[31m[Error]\x1b[0m hexdump:\n" + this.hexdump({ returnString: true })) : "";
13482
13997
  throw new Error("\x1b[33m[Strict mode]\x1b[0m: Can not remove data in strict mode: endOffset " + endOffset + " of " + this.size);
@@ -13502,12 +14017,12 @@ class BiBaseAsync {
13502
14017
  if (this.readOnly || this.strict) {
13503
14018
  throw new Error('Cannot modify readOnly data');
13504
14019
  }
13505
- const removed = await __classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_peekBytes).call(this, startOffset, removeLen);
13506
- await __classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_shiftTailBackward).call(this, startOffset, removeLen, consume);
14020
+ const removed = await this.#peekBytes(startOffset, removeLen);
14021
+ await this.#shiftTailBackward(startOffset, removeLen, consume);
13507
14022
  const newSize = this.size - removeLen;
13508
- await __classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_setFileSize).call(this, newSize);
13509
- const startChunk = __classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_getChunkIndex).call(this, startOffset);
13510
- __classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_invalidateFromChunk).call(this, startChunk);
14023
+ await this.#setFileSize(newSize);
14024
+ const startChunk = this.#getChunkIndex(startOffset);
14025
+ this.#invalidateFromChunk(startChunk);
13511
14026
  return removed;
13512
14027
  }
13513
14028
  ;
@@ -13517,7 +14032,7 @@ class BiBaseAsync {
13517
14032
  * Note: Errors in strict mode.
13518
14033
  */
13519
14034
  async clip() {
13520
- return await this.delete(__classPrivateFieldGet(this, _BiBaseAsync_offset, "f"), this.size, false);
14035
+ return await this.delete(this.#offset, this.size, false);
13521
14036
  }
13522
14037
  ;
13523
14038
  /**
@@ -13526,7 +14041,7 @@ class BiBaseAsync {
13526
14041
  * Note: Errors in strict mode.
13527
14042
  */
13528
14043
  async trim() {
13529
- return await this.delete(__classPrivateFieldGet(this, _BiBaseAsync_offset, "f"), this.size, false);
14044
+ return await this.delete(this.#offset, this.size, false);
13530
14045
  }
13531
14046
  ;
13532
14047
  /**
@@ -13538,7 +14053,7 @@ class BiBaseAsync {
13538
14053
  * @param {boolean} consume - Move position to end of removed data (default false)
13539
14054
  */
13540
14055
  async crop(length = 0, consume = false) {
13541
- return await this.delete(__classPrivateFieldGet(this, _BiBaseAsync_offset, "f"), __classPrivateFieldGet(this, _BiBaseAsync_offset, "f") + length, consume);
14056
+ return await this.delete(this.#offset, this.#offset + length, consume);
13542
14057
  }
13543
14058
  ;
13544
14059
  /**
@@ -13550,7 +14065,7 @@ class BiBaseAsync {
13550
14065
  * @param {boolean} consume - Move position to end of removed data (default false)
13551
14066
  */
13552
14067
  async drop(length = 0, consume = false) {
13553
- return await this.delete(__classPrivateFieldGet(this, _BiBaseAsync_offset, "f"), __classPrivateFieldGet(this, _BiBaseAsync_offset, "f") + length, consume);
14068
+ return await this.delete(this.#offset, this.#offset + length, consume);
13554
14069
  }
13555
14070
  ;
13556
14071
  /**
@@ -13562,7 +14077,7 @@ class BiBaseAsync {
13562
14077
  * @param {number} offset - Offset to add it at (defaults to current position)
13563
14078
  * @param {boolean} consume - Move current byte position to end of data (default false)
13564
14079
  */
13565
- async replace(data, offset = __classPrivateFieldGet(this, _BiBaseAsync_offset, "f"), consume = false) {
14080
+ async replace(data, offset = this.#offset, consume = false) {
13566
14081
  if (this.readOnly) {
13567
14082
  this.errorDump ? console.log("\x1b[31m[Error]\x1b[0m hexdump:\n" + this.hexdump({ returnString: true })) : "";
13568
14083
  throw new Error("Can't replace data in readOnly mode!");
@@ -13588,7 +14103,7 @@ class BiBaseAsync {
13588
14103
  data = Buffer.from(data);
13589
14104
  }
13590
14105
  }
13591
- const insertLen = data?.length ?? 0;
14106
+ const insertLen = data.length ?? 0;
13592
14107
  if (insertLen === 0) {
13593
14108
  return;
13594
14109
  }
@@ -13596,18 +14111,18 @@ class BiBaseAsync {
13596
14111
  if (this.strict || this.readOnly) {
13597
14112
  throw new Error('Growing requires strict: false');
13598
14113
  }
13599
- await __classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_confrimSize).call(this, offset + insertLen);
14114
+ await this.#confrimSize(offset + insertLen);
13600
14115
  }
13601
- const savedOffset = __classPrivateFieldGet(this, _BiBaseAsync_offset, "f");
13602
- const savedBitOffset = __classPrivateFieldGet(this, _BiBaseAsync_insetBit, "f");
13603
- __classPrivateFieldSet(this, _BiBaseAsync_offset, offset, "f");
13604
- __classPrivateFieldSet(this, _BiBaseAsync_insetBit, 0, "f");
13605
- await __classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_writeBytes).call(this, data, consume);
14116
+ const savedOffset = this.#offset;
14117
+ const savedBitOffset = this.#insetBit;
14118
+ this.#offset = offset;
14119
+ this.#insetBit = 0;
14120
+ await this.#writeBytes(data, consume);
13606
14121
  const tailStartChunk = Math.floor((offset + insertLen) / this.windowSize);
13607
- __classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_invalidateFromChunk).call(this, tailStartChunk);
14122
+ this.#invalidateFromChunk(tailStartChunk);
13608
14123
  if (!consume) {
13609
- __classPrivateFieldSet(this, _BiBaseAsync_offset, savedOffset, "f");
13610
- __classPrivateFieldSet(this, _BiBaseAsync_insetBit, savedBitOffset, "f");
14124
+ this.#offset = savedOffset;
14125
+ this.#insetBit = savedBitOffset;
13611
14126
  }
13612
14127
  }
13613
14128
  ;
@@ -13617,10 +14132,10 @@ class BiBaseAsync {
13617
14132
  * Note: Errors on strict mode.
13618
14133
  *
13619
14134
  * @param {DataType} data - ``Uint8Array`` or ``Buffer`` to replace in data
13620
- * @param {boolean} consume - Move current byte position to end of data (default false)
13621
14135
  * @param {number} offset - Offset to add it at (defaults to current position)
14136
+ * @param {boolean} consume - Move current byte position to end of data (default false)
13622
14137
  */
13623
- async overwrite(data, consume = false, offset = __classPrivateFieldGet(this, _BiBaseAsync_offset, "f")) {
14138
+ async overwrite(data, offset = this.#offset, consume = false) {
13624
14139
  return await this.replace(data, offset, consume);
13625
14140
  }
13626
14141
  ;
@@ -13635,7 +14150,7 @@ class BiBaseAsync {
13635
14150
  * @param {boolean} consume - Move position to end of lifted data (default false)
13636
14151
  * @param {number} fillValue - Byte value to to fill returned data (does NOT fill unless supplied)
13637
14152
  */
13638
- async fill(startOffset = __classPrivateFieldGet(this, _BiBaseAsync_offset, "f"), endOffset = this.size, consume = false, fillValue) {
14153
+ async fill(startOffset = this.#offset, endOffset = this.size, consume = false, fillValue) {
13639
14154
  if (this.readOnly) {
13640
14155
  this.errorDump ? console.log("\x1b[31m[Error]\x1b[0m hexdump:\n" + this.hexdump({ returnString: true })) : "";
13641
14156
  throw new Error("Can't remove data in readOnly mode!");
@@ -13661,7 +14176,7 @@ class BiBaseAsync {
13661
14176
  if (endOffset > this.size && this.strict) {
13662
14177
  throw new Error('Cannot extend data while in strict mode. Use unrestrict() to enable.');
13663
14178
  }
13664
- const dataRemoved = await __classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_peekBytes).call(this, startOffset, removeLen);
14179
+ const dataRemoved = await this.#peekBytes(startOffset, removeLen);
13665
14180
  if (fillValue != undefined) {
13666
14181
  var replacement;
13667
14182
  if (this.isMemoryMode) {
@@ -13675,21 +14190,21 @@ class BiBaseAsync {
13675
14190
  else {
13676
14191
  replacement = Buffer.alloc(removeLen, fillValue);
13677
14192
  }
13678
- const offsetSaver = __classPrivateFieldGet(this, _BiBaseAsync_offset, "f");
13679
- const offsetBitSaver = __classPrivateFieldGet(this, _BiBaseAsync_insetBit, "f");
13680
- await __classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_writeBytes).call(this, replacement, consume);
14193
+ const offsetSaver = this.#offset;
14194
+ const offsetBitSaver = this.#insetBit;
14195
+ await this.#writeBytes(replacement, consume);
13681
14196
  if (!consume) {
13682
- __classPrivateFieldSet(this, _BiBaseAsync_offset, offsetSaver, "f");
13683
- __classPrivateFieldSet(this, _BiBaseAsync_insetBit, offsetBitSaver, "f");
14197
+ this.#offset = offsetSaver;
14198
+ this.#insetBit = offsetBitSaver;
13684
14199
  }
13685
14200
  return replacement;
13686
14201
  }
13687
14202
  else {
13688
- await __classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_shiftTailBackward).call(this, startOffset, removeLen, consume);
14203
+ await this.#shiftTailBackward(startOffset, removeLen, consume);
13689
14204
  const newSize = this.size - removeLen;
13690
- await __classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_setFileSize).call(this, newSize);
13691
- const startChunk = __classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_getChunkIndex).call(this, startOffset);
13692
- __classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_invalidateFromChunk).call(this, startChunk);
14205
+ await this.#setFileSize(newSize);
14206
+ const startChunk = this.#getChunkIndex(startOffset);
14207
+ this.#invalidateFromChunk(startChunk);
13693
14208
  }
13694
14209
  return dataRemoved;
13695
14210
  }
@@ -13702,7 +14217,7 @@ class BiBaseAsync {
13702
14217
  * @param {boolean} consume - Move position to end of lifted data (default false)
13703
14218
  * @param {number} fillValue - Byte value to to fill returned data (does NOT fill unless supplied)
13704
14219
  */
13705
- async lift(startOffset = __classPrivateFieldGet(this, _BiBaseAsync_offset, "f"), endOffset = this.size, consume = false, fillValue) {
14220
+ async lift(startOffset = this.#offset, endOffset = this.size, consume = false, fillValue) {
13706
14221
  return await this.fill(startOffset, endOffset, consume, fillValue);
13707
14222
  }
13708
14223
  ;
@@ -13715,7 +14230,7 @@ class BiBaseAsync {
13715
14230
  * @param {number} consume - Moves offset to end of length
13716
14231
  */
13717
14232
  async extract(length = 0, consume = false) {
13718
- return await this.fill(__classPrivateFieldGet(this, _BiBaseAsync_offset, "f"), __classPrivateFieldGet(this, _BiBaseAsync_offset, "f") + length, consume);
14233
+ return await this.fill(this.#offset, this.#offset + length, consume);
13719
14234
  }
13720
14235
  ;
13721
14236
  /**
@@ -13727,7 +14242,7 @@ class BiBaseAsync {
13727
14242
  * @param {number} consume - Moves offset to end of length
13728
14243
  */
13729
14244
  async slice(length = 0, consume = false) {
13730
- return await this.fill(__classPrivateFieldGet(this, _BiBaseAsync_offset, "f"), __classPrivateFieldGet(this, _BiBaseAsync_offset, "f") + length, consume);
14245
+ return await this.fill(this.#offset, this.#offset + length, consume);
13731
14246
  }
13732
14247
  ;
13733
14248
  /**
@@ -13739,7 +14254,7 @@ class BiBaseAsync {
13739
14254
  * @param {number} consume - Moves offset to end of length
13740
14255
  */
13741
14256
  async wrap(length = 0, consume = false) {
13742
- return await this.fill(__classPrivateFieldGet(this, _BiBaseAsync_offset, "f"), __classPrivateFieldGet(this, _BiBaseAsync_offset, "f") + length, consume);
14257
+ return await this.fill(this.#offset, this.#offset + length, consume);
13743
14258
  }
13744
14259
  ;
13745
14260
  ///////////////////////////////
@@ -13754,7 +14269,7 @@ class BiBaseAsync {
13754
14269
  * @param {number} offset - Byte position to add at (defaults to current position)
13755
14270
  * @param {boolean} consume - Move current byte position to end of data (default true)
13756
14271
  */
13757
- async insert(data, offset = __classPrivateFieldGet(this, _BiBaseAsync_offset, "f"), consume = true) {
14272
+ async insert(data, offset = this.#offset, consume = true) {
13758
14273
  if (this.readOnly || this.strict) {
13759
14274
  this.errorDump ? console.log("\x1b[31m[Error]\x1b[0m hexdump:\n" + this.hexdump({ returnString: true })) : "";
13760
14275
  throw new Error(`\x1b[33m[Strict mode]\x1b[0m: Can not insert data in strict mode. Use unrestrict() to enable.`);
@@ -13785,7 +14300,7 @@ class BiBaseAsync {
13785
14300
  data = Buffer.from(data);
13786
14301
  }
13787
14302
  }
13788
- const insertLen = data?.length ?? 0;
14303
+ const insertLen = data.length ?? 0;
13789
14304
  if (insertLen === 0) {
13790
14305
  return;
13791
14306
  }
@@ -13794,19 +14309,19 @@ class BiBaseAsync {
13794
14309
  if (this.strict || this.readOnly) {
13795
14310
  throw new Error('Growing requires strict: false');
13796
14311
  }
13797
- await __classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_confrimSize).call(this, offset + insertLen);
13798
- }
13799
- await __classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_shiftTailForward).call(this, offset, insertLen, oldSize, false);
13800
- const savedOffset = __classPrivateFieldGet(this, _BiBaseAsync_offset, "f");
13801
- const savedBitOffset = __classPrivateFieldGet(this, _BiBaseAsync_insetBit, "f");
13802
- __classPrivateFieldSet(this, _BiBaseAsync_offset, offset, "f");
13803
- __classPrivateFieldSet(this, _BiBaseAsync_insetBit, 0, "f");
13804
- await __classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_writeBytes).call(this, data, consume);
14312
+ await this.#confrimSize(offset + insertLen);
14313
+ }
14314
+ await this.#shiftTailForward(offset, insertLen, oldSize, false);
14315
+ const savedOffset = this.#offset;
14316
+ const savedBitOffset = this.#insetBit;
14317
+ this.#offset = offset;
14318
+ this.#insetBit = 0;
14319
+ await this.#writeBytes(data, consume);
13805
14320
  const tailStartChunk = Math.floor((offset + insertLen) / this.windowSize);
13806
- __classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_invalidateFromChunk).call(this, tailStartChunk);
14321
+ this.#invalidateFromChunk(tailStartChunk);
13807
14322
  if (!consume) {
13808
- __classPrivateFieldSet(this, _BiBaseAsync_offset, savedOffset, "f");
13809
- __classPrivateFieldSet(this, _BiBaseAsync_insetBit, savedBitOffset, "f");
14323
+ this.#offset = savedOffset;
14324
+ this.#insetBit = savedBitOffset;
13810
14325
  }
13811
14326
  }
13812
14327
  ;
@@ -13819,7 +14334,7 @@ class BiBaseAsync {
13819
14334
  * @param {number} offset - Byte position to add at (defaults to current position)
13820
14335
  * @param {boolean} consume - Move current byte position to end of data (default true)
13821
14336
  */
13822
- async place(data, offset = __classPrivateFieldGet(this, _BiBaseAsync_offset, "f"), consume = true) {
14337
+ async place(data, offset = this.#offset, consume = true) {
13823
14338
  return await this.insert(data, offset, consume);
13824
14339
  }
13825
14340
  ;
@@ -13882,7 +14397,7 @@ class BiBaseAsync {
13882
14397
  * @param {number} endOffset - End location (default end of data)
13883
14398
  * @param {boolean} consume - Move current position to end of data (default false)
13884
14399
  */
13885
- async xor(xorKey, startOffset = __classPrivateFieldGet(this, _BiBaseAsync_offset, "f"), endOffset = this.size, consume = false) {
14400
+ async xor(xorKey, startOffset = this.#offset, endOffset = this.size, consume = false) {
13886
14401
  if (this.readOnly) {
13887
14402
  throw new Error("Can't write data in readOnly mode!");
13888
14403
  }
@@ -13892,9 +14407,9 @@ class BiBaseAsync {
13892
14407
  else if (!(this.isBufferOrUint8Array(xorKey) || typeof xorKey == "number")) {
13893
14408
  throw new Error("XOR must be a number, string, Uint8Array or Buffer");
13894
14409
  }
13895
- const bytes = await __classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_readBytes).call(this, Math.min(endOffset - startOffset, this.size - startOffset), consume);
14410
+ const bytes = await this.#readBytes(Math.min(endOffset - startOffset, this.size - startOffset), consume);
13896
14411
  _XOR(bytes, 0, bytes.length, xorKey);
13897
- return await __classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_writeBytesAt).call(this, startOffset, bytes);
14412
+ return await this.#writeBytesAt(startOffset, bytes);
13898
14413
  }
13899
14414
  ;
13900
14415
  /**
@@ -13921,7 +14436,7 @@ class BiBaseAsync {
13921
14436
  else {
13922
14437
  throw new Error("XOR must be a number, string, Uint8Array or Buffer");
13923
14438
  }
13924
- return await this.xor(xorKey, __classPrivateFieldGet(this, _BiBaseAsync_offset, "f"), __classPrivateFieldGet(this, _BiBaseAsync_offset, "f") + length, consume);
14439
+ return await this.xor(xorKey, this.#offset, this.#offset + length, consume);
13925
14440
  }
13926
14441
  ;
13927
14442
  /**
@@ -13932,7 +14447,7 @@ class BiBaseAsync {
13932
14447
  * @param {number} endOffset - End location (default end of data)
13933
14448
  * @param {boolean} consume - Move current position to end of data (default false)
13934
14449
  */
13935
- async or(orKey, startOffset = __classPrivateFieldGet(this, _BiBaseAsync_offset, "f"), endOffset = this.size, consume = false) {
14450
+ async or(orKey, startOffset = this.#offset, endOffset = this.size, consume = false) {
13936
14451
  if (this.readOnly) {
13937
14452
  throw new Error("Can't write data in readOnly mode!");
13938
14453
  }
@@ -13942,9 +14457,9 @@ class BiBaseAsync {
13942
14457
  else if (!(this.isBufferOrUint8Array(orKey) || typeof orKey == "number")) {
13943
14458
  throw new Error("OR must be a number, string, Uint8Array or Buffer");
13944
14459
  }
13945
- const bytes = await __classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_readBytes).call(this, Math.min(endOffset - startOffset, this.size - startOffset), consume);
14460
+ const bytes = await this.#readBytes(Math.min(endOffset - startOffset, this.size - startOffset), consume);
13946
14461
  _OR(bytes, 0, bytes.length, orKey);
13947
- return await __classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_writeBytesAt).call(this, startOffset, bytes);
14462
+ return await this.#writeBytesAt(startOffset, bytes);
13948
14463
  }
13949
14464
  ;
13950
14465
  /**
@@ -13971,7 +14486,7 @@ class BiBaseAsync {
13971
14486
  else {
13972
14487
  throw new Error("OR must be a number, string, Uint8Array or Buffer");
13973
14488
  }
13974
- return await this.or(orKey, __classPrivateFieldGet(this, _BiBaseAsync_offset, "f"), __classPrivateFieldGet(this, _BiBaseAsync_offset, "f") + length, consume || false);
14489
+ return await this.or(orKey, this.#offset, this.#offset + length, consume || false);
13975
14490
  }
13976
14491
  ;
13977
14492
  /**
@@ -13982,7 +14497,7 @@ class BiBaseAsync {
13982
14497
  * @param {number} endOffset - End location (default end of data)
13983
14498
  * @param {boolean} consume - Move current position to end of data (default false)
13984
14499
  */
13985
- async and(andKey, startOffset = __classPrivateFieldGet(this, _BiBaseAsync_offset, "f"), endOffset = this.size, consume = false) {
14500
+ async and(andKey, startOffset = this.#offset, endOffset = this.size, consume = false) {
13986
14501
  if (this.readOnly) {
13987
14502
  throw new Error("Can't write data in readOnly mode!");
13988
14503
  }
@@ -13992,9 +14507,9 @@ class BiBaseAsync {
13992
14507
  else if (!(typeof andKey == "object" || typeof andKey == "number")) {
13993
14508
  throw new Error("AND must be a number, string, number array or Buffer");
13994
14509
  }
13995
- const bytes = await __classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_readBytes).call(this, Math.min(endOffset - startOffset, this.size - startOffset), consume);
14510
+ const bytes = await this.#readBytes(Math.min(endOffset - startOffset, this.size - startOffset), consume);
13996
14511
  _AND(bytes, 0, bytes.length, andKey);
13997
- return await __classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_writeBytesAt).call(this, startOffset, bytes);
14512
+ return await this.#writeBytesAt(startOffset, bytes);
13998
14513
  }
13999
14514
  ;
14000
14515
  /**
@@ -14021,7 +14536,7 @@ class BiBaseAsync {
14021
14536
  else {
14022
14537
  throw new Error("AND must be a number, string, Uint8Array or Buffer");
14023
14538
  }
14024
- return await this.and(andKey, __classPrivateFieldGet(this, _BiBaseAsync_offset, "f"), __classPrivateFieldGet(this, _BiBaseAsync_offset, "f") + length, consume);
14539
+ return await this.and(andKey, this.#offset, this.#offset + length, consume);
14025
14540
  }
14026
14541
  ;
14027
14542
  /**
@@ -14032,7 +14547,7 @@ class BiBaseAsync {
14032
14547
  * @param {number} endOffset - End location (default end of data)
14033
14548
  * @param {boolean} consume - Move current position to end of data (default false)
14034
14549
  */
14035
- async add(addKey, startOffset = __classPrivateFieldGet(this, _BiBaseAsync_offset, "f"), endOffset = this.size, consume = false) {
14550
+ async add(addKey, startOffset = this.#offset, endOffset = this.size, consume = false) {
14036
14551
  if (this.readOnly) {
14037
14552
  throw new Error("Can't write data in readOnly mode!");
14038
14553
  }
@@ -14042,9 +14557,9 @@ class BiBaseAsync {
14042
14557
  else if (!(typeof addKey == "object" || typeof addKey == "number")) {
14043
14558
  throw new Error("Add key must be a number, string, number array or Buffer");
14044
14559
  }
14045
- const bytes = await __classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_readBytes).call(this, Math.min(endOffset - startOffset, this.size - startOffset), consume);
14560
+ const bytes = await this.#readBytes(Math.min(endOffset - startOffset, this.size - startOffset), consume);
14046
14561
  _ADD(bytes, 0, bytes.length, addKey);
14047
- return await __classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_writeBytesAt).call(this, startOffset, bytes);
14562
+ return await this.#writeBytesAt(startOffset, bytes);
14048
14563
  }
14049
14564
  ;
14050
14565
  /**
@@ -14071,7 +14586,7 @@ class BiBaseAsync {
14071
14586
  else {
14072
14587
  throw new Error("ADD must be a number, string, Uint8Array or Buffer");
14073
14588
  }
14074
- return await this.add(addKey, __classPrivateFieldGet(this, _BiBaseAsync_offset, "f"), __classPrivateFieldGet(this, _BiBaseAsync_offset, "f") + length, consume);
14589
+ return await this.add(addKey, this.#offset, this.#offset + length, consume);
14075
14590
  }
14076
14591
  ;
14077
14592
  /**
@@ -14081,13 +14596,13 @@ class BiBaseAsync {
14081
14596
  * @param {number} endOffset - End location (default end of data)
14082
14597
  * @param {boolean} consume - Move current position to end of data (default false)
14083
14598
  */
14084
- async not(startOffset = __classPrivateFieldGet(this, _BiBaseAsync_offset, "f"), endOffset = this.size, consume = false) {
14599
+ async not(startOffset = this.#offset, endOffset = this.size, consume = false) {
14085
14600
  if (this.readOnly) {
14086
14601
  throw new Error("Can't write data in readOnly mode!");
14087
14602
  }
14088
- const bytes = await __classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_readBytes).call(this, Math.min(endOffset - startOffset, this.size - startOffset), consume);
14603
+ const bytes = await this.#readBytes(Math.min(endOffset - startOffset, this.size - startOffset), consume);
14089
14604
  _NOT(bytes, 0, bytes.length);
14090
- return await __classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_writeBytesAt).call(this, startOffset, bytes);
14605
+ return await this.#writeBytesAt(startOffset, bytes);
14091
14606
  }
14092
14607
  ;
14093
14608
  /**
@@ -14097,7 +14612,7 @@ class BiBaseAsync {
14097
14612
  * @param {boolean} consume - Move current position to end of data (default false)
14098
14613
  */
14099
14614
  async notThis(length = 1, consume = false) {
14100
- return await this.not(__classPrivateFieldGet(this, _BiBaseAsync_offset, "f"), __classPrivateFieldGet(this, _BiBaseAsync_offset, "f") + length, consume);
14615
+ return await this.not(this.#offset, this.#offset + length, consume);
14101
14616
  }
14102
14617
  ;
14103
14618
  /**
@@ -14108,7 +14623,7 @@ class BiBaseAsync {
14108
14623
  * @param {number} endOffset - End location (default end of data)
14109
14624
  * @param {boolean} consume - Move current position to end of data (default false)
14110
14625
  */
14111
- async lShift(shiftKey, startOffset = __classPrivateFieldGet(this, _BiBaseAsync_offset, "f"), endOffset = this.size, consume = false) {
14626
+ async lShift(shiftKey, startOffset = this.#offset, endOffset = this.size, consume = false) {
14112
14627
  if (this.readOnly) {
14113
14628
  throw new Error("Can't write data in readOnly mode!");
14114
14629
  }
@@ -14118,9 +14633,9 @@ class BiBaseAsync {
14118
14633
  else if (!(typeof shiftKey == "object" || typeof shiftKey == "number")) {
14119
14634
  throw new Error("Left shift must be a number, string, number array or Buffer");
14120
14635
  }
14121
- const bytes = await __classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_readBytes).call(this, Math.min(endOffset - startOffset, this.size - startOffset), consume);
14636
+ const bytes = await this.#readBytes(Math.min(endOffset - startOffset, this.size - startOffset), consume);
14122
14637
  _LSHIFT(bytes, 0, bytes.length, shiftKey);
14123
- return await __classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_writeBytesAt).call(this, startOffset, bytes);
14638
+ return await this.#writeBytesAt(startOffset, bytes);
14124
14639
  }
14125
14640
  ;
14126
14641
  /**
@@ -14147,7 +14662,7 @@ class BiBaseAsync {
14147
14662
  else {
14148
14663
  throw new Error("Left shift must be a number, string, Uint8Array or Buffer");
14149
14664
  }
14150
- return await this.lShift(shiftKey, __classPrivateFieldGet(this, _BiBaseAsync_offset, "f"), __classPrivateFieldGet(this, _BiBaseAsync_offset, "f") + length, consume);
14665
+ return await this.lShift(shiftKey, this.#offset, this.#offset + length, consume);
14151
14666
  }
14152
14667
  ;
14153
14668
  /**
@@ -14158,7 +14673,7 @@ class BiBaseAsync {
14158
14673
  * @param {number} endOffset - End location (default end of data)
14159
14674
  * @param {boolean} consume - Move current position to end of data (default false)
14160
14675
  */
14161
- async rShift(shiftKey, startOffset = __classPrivateFieldGet(this, _BiBaseAsync_offset, "f"), endOffset = this.size, consume = false) {
14676
+ async rShift(shiftKey, startOffset = this.#offset, endOffset = this.size, consume = false) {
14162
14677
  if (this.readOnly) {
14163
14678
  throw new Error("Can't write data in readOnly mode!");
14164
14679
  }
@@ -14168,9 +14683,9 @@ class BiBaseAsync {
14168
14683
  else if (!(typeof shiftKey == "object" || typeof shiftKey == "number")) {
14169
14684
  throw new Error("Right shift must be a number, string, number array or Buffer");
14170
14685
  }
14171
- const bytes = await __classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_readBytes).call(this, Math.min(endOffset - startOffset, this.size - startOffset), consume);
14686
+ const bytes = await this.#readBytes(Math.min(endOffset - startOffset, this.size - startOffset), consume);
14172
14687
  _RSHIFT(bytes, 0, bytes.length, shiftKey);
14173
- return await __classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_writeBytesAt).call(this, startOffset, bytes);
14688
+ return await this.#writeBytesAt(startOffset, bytes);
14174
14689
  }
14175
14690
  ;
14176
14691
  /**
@@ -14197,7 +14712,7 @@ class BiBaseAsync {
14197
14712
  else {
14198
14713
  throw new Error("right shift must be a number, string, Uint8Array or Buffer");
14199
14714
  }
14200
- return await this.rShift(shiftKey, __classPrivateFieldGet(this, _BiBaseAsync_offset, "f"), __classPrivateFieldGet(this, _BiBaseAsync_offset, "f") + length, consume);
14715
+ return await this.rShift(shiftKey, this.#offset, this.#offset + length, consume);
14201
14716
  }
14202
14717
  ;
14203
14718
  ///////////////////////////////
@@ -14224,17 +14739,17 @@ class BiBaseAsync {
14224
14739
  if (bits <= 0 || bits > 32) {
14225
14740
  throw new Error('Bit length must be between 1 and 32. Got ' + bits);
14226
14741
  }
14227
- const byteEnd = Math.ceil((((bits - 1) + __classPrivateFieldGet(this, _BiBaseAsync_insetBit, "f")) / 8) + __classPrivateFieldGet(this, _BiBaseAsync_offset, "f"));
14742
+ const byteEnd = Math.ceil((((bits - 1) + this.#insetBit) / 8) + this.#offset);
14228
14743
  if (byteEnd > this.size) {
14229
14744
  throw new Error(`Not enough bytes in file (need ${byteEnd}, have ${this.size})`);
14230
14745
  }
14231
- const bitStart = (__classPrivateFieldGet(this, _BiBaseAsync_offset, "f") * 8) + __classPrivateFieldGet(this, _BiBaseAsync_insetBit, "f");
14232
- const byteStart = Math.floor(((__classPrivateFieldGet(this, _BiBaseAsync_offset, "f") * 8) + __classPrivateFieldGet(this, _BiBaseAsync_insetBit, "f")) / 8);
14233
- const temp = await __classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_peekBytes).call(this, byteStart, byteEnd - byteStart);
14746
+ const bitStart = (this.#offset * 8) + this.#insetBit;
14747
+ const byteStart = Math.floor(((this.#offset * 8) + this.#insetBit) / 8);
14748
+ const temp = await this.#peekBytes(byteStart, byteEnd - byteStart);
14234
14749
  const value = _rbit(temp, bits, bitStart % 8, endian, unsigned);
14235
14750
  if (consume) {
14236
- __classPrivateFieldSet(this, _BiBaseAsync_offset, __classPrivateFieldGet(this, _BiBaseAsync_offset, "f") + Math.floor((bits + __classPrivateFieldGet(this, _BiBaseAsync_insetBit, "f")) / 8), "f"); //end byte
14237
- __classPrivateFieldSet(this, _BiBaseAsync_insetBit, (bits + __classPrivateFieldGet(this, _BiBaseAsync_insetBit, "f")) % 8, "f");
14751
+ this.#offset += Math.floor((bits + this.#insetBit) / 8); //end byte
14752
+ this.#insetBit = (bits + this.#insetBit) % 8;
14238
14753
  }
14239
14754
  return value;
14240
14755
  }
@@ -14310,13 +14825,13 @@ class BiBaseAsync {
14310
14825
  throw new Error('Bit length must be between 1 and 32. Got ' + bits);
14311
14826
  }
14312
14827
  value = numberSafe(value, bits, unsigned);
14313
- const endOffset = Math.ceil((((bits - 1) + __classPrivateFieldGet(this, _BiBaseAsync_insetBit, "f")) / 8) + __classPrivateFieldGet(this, _BiBaseAsync_offset, "f"));
14314
- const temp = await __classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_peekBytes).call(this, __classPrivateFieldGet(this, _BiBaseAsync_offset, "f"), Math.ceil(endOffset - __classPrivateFieldGet(this, _BiBaseAsync_offset, "f")));
14315
- _wbit(temp, value, bits, __classPrivateFieldGet(this, _BiBaseAsync_insetBit, "f"), endian, unsigned);
14316
- await __classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_writeBytesAt).call(this, __classPrivateFieldGet(this, _BiBaseAsync_offset, "f"), temp);
14828
+ const endOffset = Math.ceil((((bits - 1) + this.#insetBit) / 8) + this.#offset);
14829
+ const temp = await this.#peekBytes(this.#offset, Math.ceil(endOffset - this.#offset));
14830
+ _wbit(temp, value, bits, this.#insetBit, endian, unsigned);
14831
+ await this.#writeBytesAt(this.#offset, temp);
14317
14832
  if (consume) {
14318
- __classPrivateFieldSet(this, _BiBaseAsync_offset, __classPrivateFieldGet(this, _BiBaseAsync_offset, "f") + Math.floor((bits + __classPrivateFieldGet(this, _BiBaseAsync_insetBit, "f")) / 8), "f");
14319
- __classPrivateFieldSet(this, _BiBaseAsync_insetBit, (bits + __classPrivateFieldGet(this, _BiBaseAsync_insetBit, "f")) % 8, "f");
14833
+ this.#offset += Math.floor((bits + this.#insetBit) / 8);
14834
+ this.#insetBit = (bits + this.#insetBit) % 8;
14320
14835
  }
14321
14836
  }
14322
14837
  ;
@@ -14385,7 +14900,7 @@ class BiBaseAsync {
14385
14900
  */
14386
14901
  async readByte(unsigned = false, consume = true) {
14387
14902
  await this.open();
14388
- const data = await __classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_readBytes).call(this, 1, consume);
14903
+ const data = await this.#readBytes(1, consume);
14389
14904
  var value = data[0];
14390
14905
  if (unsigned) {
14391
14906
  value = value & 0xFF;
@@ -14440,7 +14955,7 @@ class BiBaseAsync {
14440
14955
  throw new Error("Can't write data in readOnly mode!");
14441
14956
  }
14442
14957
  this.open();
14443
- await __classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_writeBytes).call(this, [numberSafe(value, 8, unsigned)], consume);
14958
+ await this.#writeBytes([numberSafe(value, 8, unsigned)], consume);
14444
14959
  }
14445
14960
  ;
14446
14961
  /**
@@ -14475,7 +14990,7 @@ class BiBaseAsync {
14475
14990
  */
14476
14991
  async readInt16(unsigned = false, endian = this.endian, consume = true) {
14477
14992
  await this.open();
14478
- const buf = await __classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_readBytes).call(this, 2, consume);
14993
+ const buf = await this.#readBytes(2, consume);
14479
14994
  const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
14480
14995
  if (canInt16) {
14481
14996
  if (unsigned) {
@@ -14550,7 +15065,7 @@ class BiBaseAsync {
14550
15065
  else {
14551
15066
  _wint16(buff2ByteDummy, numberSafe(value, 16, unsigned), 0, endian, unsigned);
14552
15067
  }
14553
- return await __classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_writeBytes).call(this, buff2ByteDummy, consume);
15068
+ return await this.#writeBytes(buff2ByteDummy, consume);
14554
15069
  }
14555
15070
  ;
14556
15071
  /**
@@ -14609,7 +15124,7 @@ class BiBaseAsync {
14609
15124
  * @param {boolean} consume - move offset after read
14610
15125
  */
14611
15126
  async readHalfFloat(endian = this.endian, consume = true) {
14612
- const buf = await __classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_readBytes).call(this, 2, consume);
15127
+ const buf = await this.#readBytes(2, consume);
14613
15128
  const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
14614
15129
  if (canFloat16) {
14615
15130
  return view.getFloat16(0, endian == "little");
@@ -14674,7 +15189,7 @@ class BiBaseAsync {
14674
15189
  else {
14675
15190
  _whalffloat(buff2ByteDummy, value, 0, endian);
14676
15191
  }
14677
- return await __classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_writeBytes).call(this, buff2ByteDummy, consume);
15192
+ return await this.#writeBytes(buff2ByteDummy, consume);
14678
15193
  }
14679
15194
  ;
14680
15195
  /**
@@ -14731,7 +15246,7 @@ class BiBaseAsync {
14731
15246
  * Read signed 32 bit integer.
14732
15247
  */
14733
15248
  async readInt32(unsigned = false, endian = this.endian, consume = true) {
14734
- const buf = await __classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_readBytes).call(this, 4, consume);
15249
+ const buf = await this.#readBytes(4, consume);
14735
15250
  const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
14736
15251
  if (canInt32) {
14737
15252
  if (unsigned) {
@@ -14821,7 +15336,7 @@ class BiBaseAsync {
14821
15336
  else {
14822
15337
  _wint32(buff4ByteDummy, numberSafe(value, 32, unsigned), 0, endian, unsigned);
14823
15338
  }
14824
- return await __classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_writeBytes).call(this, buff4ByteDummy, consume);
15339
+ return await this.#writeBytes(buff4ByteDummy, consume);
14825
15340
  }
14826
15341
  /**
14827
15342
  * Write signed 32 bit integer.
@@ -14899,7 +15414,7 @@ class BiBaseAsync {
14899
15414
  * @param {boolean} consume - move offset after read
14900
15415
  */
14901
15416
  async readFloat(endian = this.endian, consume = true) {
14902
- const buf = await __classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_readBytes).call(this, 4, consume);
15417
+ const buf = await this.#readBytes(4, consume);
14903
15418
  const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
14904
15419
  if (canFloat32) {
14905
15420
  return view.getFloat32(0, endian == "little");
@@ -14964,7 +15479,7 @@ class BiBaseAsync {
14964
15479
  else {
14965
15480
  _wfloat(buff4ByteDummy, value, 0, endian);
14966
15481
  }
14967
- return await __classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_writeBytes).call(this, buff4ByteDummy, consume);
15482
+ return await this.#writeBytes(buff4ByteDummy, consume);
14968
15483
  }
14969
15484
  ;
14970
15485
  /**
@@ -15019,7 +15534,7 @@ class BiBaseAsync {
15019
15534
  if (!hasBigInt) {
15020
15535
  throw new Error("System doesn't support BigInt values.");
15021
15536
  }
15022
- const buf = await __classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_readBytes).call(this, 8, consume);
15537
+ const buf = await this.#readBytes(8, consume);
15023
15538
  const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
15024
15539
  var value;
15025
15540
  if (canBigInt64) {
@@ -15117,7 +15632,7 @@ class BiBaseAsync {
15117
15632
  else {
15118
15633
  _wint64(buff8ByteDummy, numberSafe(value, 64, unsigned), 0, endian, unsigned);
15119
15634
  }
15120
- return await __classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_writeBytes).call(this, buff8ByteDummy, consume);
15635
+ return await this.#writeBytes(buff8ByteDummy, consume);
15121
15636
  }
15122
15637
  ;
15123
15638
  /**
@@ -15175,7 +15690,7 @@ class BiBaseAsync {
15175
15690
  * @param {endian} endian - ``big`` or ``little``
15176
15691
  */
15177
15692
  async readDoubleFloat(endian = this.endian, consume = true) {
15178
- const buf = await __classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_readBytes).call(this, 8, consume);
15693
+ const buf = await this.#readBytes(8, consume);
15179
15694
  const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
15180
15695
  if (canFloat64) {
15181
15696
  return view.getFloat64(0, endian == "little");
@@ -15241,7 +15756,7 @@ class BiBaseAsync {
15241
15756
  else {
15242
15757
  _wdfloat(buff8ByteDummy, value, 0, endian);
15243
15758
  }
15244
- return await __classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_writeBytes).call(this, buff8ByteDummy, consume);
15759
+ return await this.#writeBytes(buff8ByteDummy, consume);
15245
15760
  }
15246
15761
  ;
15247
15762
  /**
@@ -15333,13 +15848,13 @@ class BiBaseAsync {
15333
15848
  }
15334
15849
  }
15335
15850
  else {
15336
- readLengthinBytes = this.data.length - __classPrivateFieldGet(this, _BiBaseAsync_offset, "f");
15851
+ readLengthinBytes = this.data.length - this.#offset;
15337
15852
  }
15338
- if (__classPrivateFieldGet(this, _BiBaseAsync_offset, "f") + readLengthinBytes > this.size) {
15853
+ if (this.#offset + readLengthinBytes > this.size) {
15339
15854
  if (this.strict || this.readOnly) {
15340
15855
  throw new Error('Growing requires strict: false');
15341
15856
  }
15342
- await __classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_confrimSize).call(this, __classPrivateFieldGet(this, _BiBaseAsync_offset, "f") + readLengthinBytes);
15857
+ await this.#confrimSize(this.#offset + readLengthinBytes);
15343
15858
  }
15344
15859
  if (terminateValue != undefined && typeof terminateValue == "number") {
15345
15860
  terminate = terminateValue & 0xFF;
@@ -15347,12 +15862,12 @@ class BiBaseAsync {
15347
15862
  else {
15348
15863
  terminate = 0;
15349
15864
  }
15350
- const saved_offset = __classPrivateFieldGet(this, _BiBaseAsync_offset, "f");
15351
- const saved_bitoffset = __classPrivateFieldGet(this, _BiBaseAsync_insetBit, "f");
15865
+ const saved_offset = this.#offset;
15866
+ const saved_bitoffset = this.#insetBit;
15352
15867
  const str = await _rstringAsync(stringType, lengthReadSize, readLengthinBytes, terminate, stripNull, encoding, endian, this.readUByte.bind(this), this.readUInt16.bind(this), this.readUInt32.bind(this));
15353
15868
  if (!consume) {
15354
- __classPrivateFieldSet(this, _BiBaseAsync_offset, saved_offset, "f");
15355
- __classPrivateFieldSet(this, _BiBaseAsync_insetBit, saved_bitoffset, "f");
15869
+ this.#offset = saved_offset;
15870
+ this.#insetBit = saved_bitoffset;
15356
15871
  }
15357
15872
  return str;
15358
15873
  }
@@ -15448,557 +15963,35 @@ class BiBaseAsync {
15448
15963
  }
15449
15964
  break;
15450
15965
  }
15451
- await __classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_confrimSize).call(this, __classPrivateFieldGet(this, _BiBaseAsync_offset, "f") + totalLength);
15452
- const savedOffset = __classPrivateFieldGet(this, _BiBaseAsync_offset, "f");
15453
- const savedBitOffset = __classPrivateFieldGet(this, _BiBaseAsync_insetBit, "f");
15966
+ await this.#confrimSize(this.#offset + totalLength);
15967
+ const savedOffset = this.#offset;
15968
+ const savedBitOffset = this.#insetBit;
15454
15969
  await _wstringAsync(encodedString, stringType, endian, terminateValue, lengthWriteSize, this.writeUByte.bind(this), this.writeUInt16.bind(this), this.writeUInt32.bind(this));
15455
15970
  if (!consume) {
15456
- __classPrivateFieldSet(this, _BiBaseAsync_offset, savedOffset, "f");
15457
- __classPrivateFieldSet(this, _BiBaseAsync_insetBit, savedBitOffset, "f");
15971
+ this.#offset = savedOffset;
15972
+ this.#insetBit = savedBitOffset;
15458
15973
  }
15459
15974
  }
15460
15975
  ;
15461
15976
  }
15462
- _BiBaseAsync_offset = new WeakMap(), _BiBaseAsync_insetBit = new WeakMap(), _BiBaseAsync_data = new WeakMap(), _BiBaseAsync_view = new WeakMap(), _BiBaseAsync_instances = new WeakSet(), _BiBaseAsync_updateSize =
15463
- /**
15464
- * Internal update size
15465
- *
15466
- * run after setting data
15467
- */
15468
- async function _BiBaseAsync_updateSize() {
15469
- if (this.isMemoryMode) {
15470
- this.size = this.data.length;
15471
- this.bitSize = this.size * 8;
15472
- return;
15473
- }
15474
- if (typeof fs === "undefined") {
15475
- throw new Error("Can't load file outside Node.");
15476
- }
15477
- if (this.fd != null) {
15478
- try {
15479
- const stat = await this.fd.stat();
15480
- this.size = stat.size;
15481
- this.bitSize = this.size * 8;
15482
- }
15483
- catch (error) {
15484
- throw new Error(error);
15485
- }
15486
- }
15487
- }, _BiBaseAsync_updateView = function _BiBaseAsync_updateView() {
15488
- if (__classPrivateFieldGet(this, _BiBaseAsync_data, "f")) {
15489
- __classPrivateFieldSet(this, _BiBaseAsync_view, new DataView(__classPrivateFieldGet(this, _BiBaseAsync_data, "f").buffer, __classPrivateFieldGet(this, _BiBaseAsync_data, "f").byteOffset ?? 0, __classPrivateFieldGet(this, _BiBaseAsync_data, "f").byteLength), "f");
15490
- }
15491
- }, _BiBaseAsync_initFile =
15492
- /**
15493
- * `this.fd` must be null and not in memory mode
15494
- */
15495
- async function _BiBaseAsync_initFile() {
15496
- if (this.isMemoryMode || this.fd != null) {
15497
- return;
15498
- }
15499
- if (!(await _fileExists(this.filePath))) {
15500
- await fs.writeFile(this.filePath, "");
15501
- }
15502
- try {
15503
- this.fd = await fs.open(this.filePath, this.fsMode);
15504
- }
15505
- catch (error) {
15506
- throw new Error(error);
15507
- }
15508
- await __classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_updateSize).call(this);
15509
- const numChunks = __classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_getNumChunks).call(this);
15510
- this.chunks = new Array(numChunks).fill(null);
15511
- this.chunkPromises = new Array(numChunks).fill(null);
15512
- if (this.windowSize == 0) {
15513
- this.loadAllPromise = __classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_preloadAllChunks).call(this);
15514
- }
15515
- else {
15516
- this.loadAllPromise = Promise.resolve();
15517
- }
15518
- }, _BiBaseAsync_initMemory = function _BiBaseAsync_initMemory() {
15519
- if (!this.isMemoryMode) {
15520
- return;
15521
- }
15522
- if (this.isFullyLoaded) {
15523
- return;
15524
- }
15525
- this.size = this.data.length;
15526
- this.bitSize = this.size * 8;
15527
- const numChunks = __classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_getNumChunks).call(this);
15528
- this.chunks = new Array(numChunks).fill(null);
15529
- this.chunkPromises = new Array(numChunks).fill(null);
15530
- this.isFullyLoaded = true;
15531
- this.loadAllPromise = null;
15532
- }, _BiBaseAsync_getChunkIndex = function _BiBaseAsync_getChunkIndex(offset) {
15533
- return this.windowSize === 0 ? 0 : Math.floor(offset / this.windowSize);
15534
- }, _BiBaseAsync_getNumChunks = function _BiBaseAsync_getNumChunks() {
15535
- return this.windowSize === 0 ? 1 : Math.ceil(this.size / this.windowSize);
15536
- }, _BiBaseAsync_preloadAllChunks =
15537
- /**
15538
- * When the whole file is loaded at once
15539
- */
15540
- async function _BiBaseAsync_preloadAllChunks() {
15541
- const promises = [];
15542
- for (let i = 0; i < this.chunks.length; i++) {
15543
- promises.push(__classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_ensureChunkLoaded).call(this, i));
15544
- }
15545
- await Promise.all(promises);
15546
- this.isFullyLoaded = true;
15547
- }, _BiBaseAsync_ensureChunkLoaded =
15548
- /**
15549
- * Checks the chunk is loaded
15550
- *
15551
- * @param {number} chunkIndex
15552
- */
15553
- async function _BiBaseAsync_ensureChunkLoaded(chunkIndex) {
15554
- if (this.windowSize === 0) {
15555
- chunkIndex = 0;
15556
- }
15557
- if (chunkIndex >= this.chunks.length) {
15558
- return null;
15559
- }
15560
- if (this.chunks[chunkIndex] !== null) {
15561
- return this.chunks[chunkIndex];
15562
- }
15563
- if (this.isMemoryMode) {
15564
- const start = chunkIndex * this.windowSize;
15565
- const end = Math.min(start + this.windowSize, this.size);
15566
- this.chunks[chunkIndex] = this.data.subarray(start, end);
15567
- return this.chunks[chunkIndex];
15568
- }
15569
- if (this.chunkPromises[chunkIndex]) {
15570
- return await this.chunkPromises[chunkIndex];
15571
- }
15572
- const promise = __classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_performChunkLoad).call(this, chunkIndex);
15573
- this.chunkPromises[chunkIndex] = promise;
15574
- return await promise;
15575
- }, _BiBaseAsync_performChunkLoad =
15576
- /**
15577
- * Gets needed chunk
15578
- *
15579
- * @param {number} chunkIndex
15580
- */
15581
- async function _BiBaseAsync_performChunkLoad(chunkIndex) {
15582
- const start = chunkIndex * this.windowSize;
15583
- const length = Math.min(this.windowSize, this.size - start);
15584
- const buffer = Buffer.alloc(length);
15585
- await this.fd.read(buffer, 0, length, start);
15586
- this.chunks[chunkIndex] = buffer;
15587
- return buffer;
15588
- }, _BiBaseAsync_ensureRangeLoaded =
15589
- /**
15590
- * Makes sure the needed size is loaded
15591
- *
15592
- * @param {number} offset
15593
- * @param {number} length
15594
- */
15595
- async function _BiBaseAsync_ensureRangeLoaded(offset, length) {
15596
- const needed = offset + length;
15597
- if (needed > this.size) {
15598
- if (this.strict || this.readOnly) {
15599
- throw new Error(`Operation exceeds file size (${needed} > ${this.size})`);
15600
- }
15601
- await __classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_confrimSize).call(this, needed);
15602
- }
15603
- const startChunk = __classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_getChunkIndex).call(this, offset);
15604
- const endChunk = __classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_getChunkIndex).call(this, offset + length - 1);
15605
- const promises = [];
15606
- for (let i = startChunk; i <= endChunk && i < this.chunks.length; i++) {
15607
- if (this.chunks[i] === null) {
15608
- promises.push(__classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_ensureChunkLoaded).call(this, i));
15609
- }
15610
- }
15611
- await Promise.all(promises);
15612
- }, _BiBaseAsync_peekBytes =
15613
- /**
15614
- * Get bytes without changing offset
15615
- *
15616
- * @param {number} offset
15617
- * @param {number} length
15618
- */
15619
- async function _BiBaseAsync_peekBytes(offset, length) {
15620
- await this.open();
15621
- if (length <= 0) {
15622
- if (this.isMemoryMode) {
15623
- if (this.isBuffer(this.data)) {
15624
- return Buffer.alloc(0);
15625
- }
15626
- else {
15627
- return new Uint8Array(0);
15628
- }
15629
- }
15630
- else {
15631
- return Buffer.alloc(0);
15632
- }
15633
- }
15634
- await __classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_ensureRangeLoaded).call(this, offset, length);
15635
- var result;
15636
- if (this.isMemoryMode) {
15637
- return this.data.subarray(offset, offset + length);
15638
- }
15639
- else {
15640
- result = Buffer.alloc(length);
15641
- }
15642
- let pos = offset;
15643
- let writePos = 0;
15644
- while (writePos < length) {
15645
- const chunkIndex = __classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_getChunkIndex).call(this, pos);
15646
- const chunk = this.chunks[chunkIndex];
15647
- const chunkOffset = pos % this.windowSize;
15648
- const toCopy = Math.min(length - writePos, chunk.length - chunkOffset);
15649
- result.set(chunk.subarray(chunkOffset, chunkOffset + toCopy), writePos);
15650
- writePos += toCopy;
15651
- pos += toCopy;
15652
- }
15653
- return result;
15654
- }, _BiBaseAsync_writeBytesAt =
15655
- /**
15656
- * write bytes internal
15657
- *
15658
- * @param {number} offset
15659
- * @param {Uint8Array | Buffer | number[]} data
15660
- */
15661
- async function _BiBaseAsync_writeBytesAt(offset, data) {
15662
- await this.open();
15663
- if (data.length === 0) {
15664
- return;
15665
- }
15666
- await __classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_ensureRangeLoaded).call(this, offset, data.length);
15667
- let pos = offset;
15668
- let readPos = 0;
15669
- if (this.isMemoryMode) {
15670
- for (let i = 0, n = offset; i < data.length; i++, n++) {
15671
- __classPrivateFieldGet(this, _BiBaseAsync_data, "f")[n] = data[i];
15672
- }
15673
- return;
15674
- }
15675
- while (readPos < data.length) {
15676
- const chunkIndex = __classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_getChunkIndex).call(this, pos);
15677
- const chunk = this.chunks[chunkIndex];
15678
- const chunkOffset = pos % this.windowSize;
15679
- const toCopy = Math.min(data.length - readPos, chunk.length - chunkOffset);
15680
- var sub;
15681
- if (this.isBufferOrUint8Array(data)) {
15682
- sub = data.subarray(readPos, readPos + toCopy);
15683
- }
15684
- else {
15685
- sub = data.slice(readPos, readPos + toCopy);
15686
- }
15687
- chunk.set(sub, chunkOffset);
15688
- this.dirtyChunks.add(chunkIndex);
15689
- readPos += toCopy;
15690
- pos += toCopy;
15691
- }
15692
- }, _BiBaseAsync_confrimSize =
15693
- /**
15694
- * Checks loaded size
15695
- *
15696
- * Will set `wasExpanded` if expanded
15697
- *
15698
- * @param {number} neededSize
15699
- */
15700
- async function _BiBaseAsync_confrimSize(neededSize) {
15701
- // check if the current request fits in range
15702
- if (neededSize <= this.size) {
15703
- return;
15704
- }
15705
- var targetSize = neededSize;
15706
- // now adjust the size if less to `growthIncrement` factor
15707
- if (targetSize > this.size) {
15708
- if (this.strict || this.readOnly) {
15709
- this.errorDump ? console.log("\x1b[31m[Error]\x1b[0m hexdump:\n" + this.hexdump({ returnString: true })) : "";
15710
- throw new Error(`\x1b[33m[Strict mode]\x1b[0m: Reached end of data: ` + neededSize + " at " + __classPrivateFieldGet(this, _BiBaseAsync_offset, "f") + " of " + this.size);
15711
- }
15712
- if (this.growthIncrement != 0) {
15713
- this.wasExpanded = true;
15714
- targetSize = Math.ceil(neededSize / this.growthIncrement) * this.growthIncrement;
15715
- }
15716
- await __classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_extendArray).call(this, targetSize);
15717
- }
15718
- }, _BiBaseAsync_extendArray =
15719
- /**
15720
- * extends the data
15721
- *
15722
- * @param {number} targetSize
15723
- */
15724
- async function _BiBaseAsync_extendArray(targetSize) {
15725
- await this.flush();
15726
- if (this.isMemoryMode) {
15727
- const toPadd = targetSize - this.size;
15728
- var newData;
15729
- if (isBuffer(__classPrivateFieldGet(this, _BiBaseAsync_data, "f"))) {
15730
- var paddbuffer = Buffer.alloc(toPadd);
15731
- newData = Buffer.concat([__classPrivateFieldGet(this, _BiBaseAsync_data, "f"), paddbuffer]);
15732
- }
15733
- else {
15734
- newData = new Uint8Array(this.size + toPadd);
15735
- newData.set(__classPrivateFieldGet(this, _BiBaseAsync_data, "f"));
15736
- }
15737
- this.setData = newData;
15738
- this.size = targetSize;
15739
- this.bitSize = this.size * 8;
15740
- this.chunks = new Array(__classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_getNumChunks).call(this)).fill(null);
15741
- this.chunkPromises = new Array(__classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_getNumChunks).call(this)).fill(null);
15742
- this.dirtyChunks.clear();
15743
- }
15744
- else {
15745
- await this.fd.truncate(targetSize);
15746
- this.size = targetSize;
15747
- this.bitSize = this.size * 8;
15748
- const oldNum = this.chunks.length;
15749
- const newNum = __classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_getNumChunks).call(this);
15750
- this.chunks.length = newNum;
15751
- this.chunkPromises.length = newNum;
15752
- for (let i = oldNum; i < newNum; i++) {
15753
- this.chunks[i] = null;
15754
- this.chunkPromises[i] = null;
15755
- }
15756
- }
15757
- }, _BiBaseAsync_setFileSize =
15758
- /**
15759
- * For updating file size
15760
- *
15761
- * @param {number} exactSize
15762
- * @returns
15763
- */
15764
- async function _BiBaseAsync_setFileSize(exactSize) {
15765
- if (exactSize === this.size) {
15766
- return;
15767
- }
15768
- await this.flush();
15769
- if (this.isMemoryMode) {
15770
- const newData = this.data.subarray(0, exactSize);
15771
- this.setData = newData;
15772
- this.size = exactSize;
15773
- this.bitSize = this.size * 8;
15774
- const newNum = Math.ceil(exactSize / this.windowSize);
15775
- this.chunks = new Array(newNum).fill(null);
15776
- this.chunkPromises = new Array(newNum).fill(null);
15777
- this.dirtyChunks.clear();
15778
- }
15779
- else {
15780
- await this.fd.truncate(exactSize);
15781
- this.size = exactSize;
15782
- this.bitSize = this.size * 8;
15783
- const oldNum = this.chunks.length;
15784
- const newNum = Math.ceil(exactSize / this.windowSize);
15785
- this.chunks.length = newNum;
15786
- this.chunkPromises.length = newNum;
15787
- if (newNum < oldNum) {
15788
- this.dirtyChunks = new Set([...this.dirtyChunks].filter(i => i < newNum));
15789
- }
15790
- else {
15791
- for (let i = oldNum; i < newNum; i++) {
15792
- this.chunks[i] = null;
15793
- this.chunkPromises[i] = null;
15794
- }
15795
- }
15796
- }
15797
- }, _BiBaseAsync_invalidateFromChunk = function _BiBaseAsync_invalidateFromChunk(startChunk) {
15798
- for (let i = Math.max(0, startChunk); i < this.chunks.length; i++) {
15799
- this.chunks[i] = null;
15800
- this.chunkPromises[i] = null;
15801
- this.dirtyChunks.delete(i);
15802
- }
15803
- }, _BiBaseAsync_shiftTailForward =
15804
- /**
15805
- * Pulls data back
15806
- *
15807
- * @param {number} insertOffset
15808
- * @param {number} insertLen
15809
- * @param {number} oldEnd
15810
- * @param {boolean} consume
15811
- */
15812
- async function _BiBaseAsync_shiftTailForward(insertOffset, insertLen, oldEnd, consume = false) {
15813
- if (insertLen <= 0) {
15814
- return;
15815
- }
15816
- if (this.isMemoryMode) {
15817
- const tailCopy = this.data.subarray(insertOffset, oldEnd);
15818
- this.data.set(tailCopy, insertOffset + insertLen);
15819
- }
15820
- else {
15821
- let readEnd = oldEnd;
15822
- let writeEnd = oldEnd + insertLen;
15823
- const buf = Buffer.alloc(Math.min(this.windowSize, this.size));
15824
- while (readEnd > insertOffset) {
15825
- const len = Math.min(this.windowSize, readEnd - insertOffset);
15826
- const readStart = readEnd - len;
15827
- const { bytesRead } = await this.fd.read(buf, 0, len, readStart);
15828
- const writeStart = writeEnd - len;
15829
- await this.fd.write(buf, 0, bytesRead, writeStart);
15830
- readEnd = readStart;
15831
- writeEnd = writeStart;
15832
- }
15833
- }
15834
- if (consume) {
15835
- __classPrivateFieldSet(this, _BiBaseAsync_offset, insertOffset + insertLen, "f");
15836
- __classPrivateFieldSet(this, _BiBaseAsync_insetBit, 0, "f");
15837
- }
15838
- }, _BiBaseAsync_shiftTailBackward =
15839
- /**
15840
- *
15841
- * @param {number} removeOffset
15842
- * @param {number} removeLen
15843
- * @param {boolean} consume
15844
- */
15845
- async function _BiBaseAsync_shiftTailBackward(removeOffset, removeLen, consume = false) {
15846
- if (removeLen <= 0) {
15847
- return;
15848
- }
15849
- if (this.isMemoryMode) {
15850
- const tailStart = removeOffset + removeLen;
15851
- const tailCopy = this.data.subarray(tailStart, this.size);
15852
- this.data.set(tailCopy, removeOffset);
15853
- }
15854
- else {
15855
- const oldEnd = this.size;
15856
- let readPos = removeOffset + removeLen;
15857
- let writePos = removeOffset;
15858
- const buf = Buffer.alloc(Math.min(this.windowSize, this.size));
15859
- while (readPos < oldEnd) {
15860
- const len = Math.min(this.windowSize, oldEnd - readPos);
15861
- const { bytesRead } = await this.fd.read(buf, 0, len, readPos);
15862
- await this.fd.write(buf, 0, bytesRead, writePos);
15863
- readPos += bytesRead;
15864
- writePos += bytesRead;
15865
- }
15866
- }
15867
- if (consume) {
15868
- __classPrivateFieldSet(this, _BiBaseAsync_offset, removeOffset, "f");
15869
- __classPrivateFieldSet(this, _BiBaseAsync_insetBit, 0, "f");
15870
- }
15871
- }, _BiBaseAsync_updateOffsets = async function _BiBaseAsync_updateOffsets(newOffset, trueBytes, trueBits) {
15872
- if (newOffset < 0) {
15873
- throw new RangeError('Offset cannot be negative');
15874
- }
15875
- if (newOffset > this.size) {
15876
- if (this.strict || this.readOnly) {
15877
- this.errorDump ? console.log("\x1b[31m[Error]\x1b[0m hexdump:\n" + this.hexdump({ returnString: true })) : "";
15878
- throw new Error(`\x1b[33m[Strict mode]\x1b[0m: Reached end of data: ` + newOffset + " at " + __classPrivateFieldGet(this, _BiBaseAsync_offset, "f") + " of " + this.size);
15879
- }
15880
- await __classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_confrimSize).call(this, newOffset);
15881
- }
15882
- __classPrivateFieldSet(this, _BiBaseAsync_offset, trueBytes, "f");
15883
- // Adjust byte offset based on bit overflow
15884
- __classPrivateFieldSet(this, _BiBaseAsync_offset, __classPrivateFieldGet(this, _BiBaseAsync_offset, "f") + Math.floor(trueBits / 8), "f");
15885
- // Adjust bit offset
15886
- __classPrivateFieldSet(this, _BiBaseAsync_insetBit, normalizeBitOffset(trueBits) % 8, "f");
15887
- // Ensure bit offset stays between 0-7
15888
- __classPrivateFieldSet(this, _BiBaseAsync_insetBit, Math.min(Math.max(__classPrivateFieldGet(this, _BiBaseAsync_insetBit, "f"), 0), 7), "f");
15889
- // Ensure offset doesn't go negative
15890
- __classPrivateFieldSet(this, _BiBaseAsync_offset, Math.max(__classPrivateFieldGet(this, _BiBaseAsync_offset, "f"), 0), "f");
15891
- }, _BiBaseAsync_readBytes = async function _BiBaseAsync_readBytes(length, consume = true) {
15892
- await this.open();
15893
- if (length <= 0) {
15894
- return new Uint8Array(0);
15895
- }
15896
- const offSave = __classPrivateFieldGet(this, _BiBaseAsync_offset, "f");
15897
- var trueByte = __classPrivateFieldGet(this, _BiBaseAsync_offset, "f");
15898
- const trueBit = __classPrivateFieldGet(this, _BiBaseAsync_insetBit, "f");
15899
- if (trueBit != 0) {
15900
- trueByte += 1;
15901
- }
15902
- __classPrivateFieldSet(this, _BiBaseAsync_offset, trueByte, "f");
15903
- const data = await __classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_peekBytes).call(this, trueByte, length);
15904
- if (consume) {
15905
- __classPrivateFieldSet(this, _BiBaseAsync_offset, __classPrivateFieldGet(this, _BiBaseAsync_offset, "f") + length, "f");
15906
- __classPrivateFieldSet(this, _BiBaseAsync_insetBit, 0, "f");
15907
- }
15908
- else {
15909
- __classPrivateFieldSet(this, _BiBaseAsync_offset, offSave, "f");
15910
- }
15911
- return data;
15912
- }, _BiBaseAsync_writeBytes = async function _BiBaseAsync_writeBytes(data, consume = true) {
15913
- if (this.readOnly) {
15914
- throw new Error('Cannot write to read-only file');
15915
- }
15916
- await this.open();
15917
- if (data.length === 0) {
15918
- return;
15919
- }
15920
- const offSave = __classPrivateFieldGet(this, _BiBaseAsync_offset, "f");
15921
- var trueByte = __classPrivateFieldGet(this, _BiBaseAsync_offset, "f");
15922
- const trueBit = __classPrivateFieldGet(this, _BiBaseAsync_insetBit, "f");
15923
- if (trueBit != 0) {
15924
- trueByte += 1;
15925
- }
15926
- __classPrivateFieldSet(this, _BiBaseAsync_offset, trueByte, "f");
15927
- await __classPrivateFieldGet(this, _BiBaseAsync_instances, "m", _BiBaseAsync_writeBytesAt).call(this, trueByte, data);
15928
- if (consume) {
15929
- __classPrivateFieldSet(this, _BiBaseAsync_offset, __classPrivateFieldGet(this, _BiBaseAsync_offset, "f") + data.length, "f");
15930
- __classPrivateFieldSet(this, _BiBaseAsync_insetBit, 0, "f");
15931
- }
15932
- else {
15933
- __classPrivateFieldSet(this, _BiBaseAsync_offset, offSave, "f");
15934
- }
15935
- }, _BiBaseAsync_findNumber = function _BiBaseAsync_findNumber(data, value, bits, unsigned, endian = this.endian) {
15936
- for (let z = __classPrivateFieldGet(this, _BiBaseAsync_offset, "f"); z <= (this.size - (bits / 8)); z++) {
15937
- var offsetInBits = 0;
15938
- var currentValue = 0;
15939
- for (var i = 0; i < bits;) {
15940
- const remaining = bits - i;
15941
- const bitOffset = offsetInBits & 7;
15942
- const currentByte = data[z + (offsetInBits >> 3)];
15943
- const read = Math.min(remaining, 8 - bitOffset);
15944
- if (endian == "big") {
15945
- let mask = ~(0xFF << read);
15946
- let readBits = (currentByte >> (8 - read - bitOffset)) & mask;
15947
- currentValue <<= read;
15948
- currentValue |= readBits;
15949
- }
15950
- else {
15951
- let mask = ~(0xFF << read);
15952
- let readBits = (currentByte >> bitOffset) & mask;
15953
- currentValue |= readBits << i;
15954
- }
15955
- offsetInBits += read;
15956
- i += read;
15957
- }
15958
- if (unsigned == true || bits <= 7) {
15959
- currentValue = currentValue >>> 0;
15960
- }
15961
- else {
15962
- if (currentValue & (1 << (bits - 1))) {
15963
- currentValue |= -1 ^ ((1 << bits) - 1);
15964
- }
15965
- }
15966
- if (currentValue === value) {
15967
- return z - __classPrivateFieldGet(this, _BiBaseAsync_offset, "f"); // Found the byte, return the index from current
15968
- }
15969
- }
15970
- return -1; // number not found
15971
- };
15972
15977
 
15973
15978
  /**
15974
15979
  * Async Binary reader, includes bitfields and strings.
15975
15980
  *
15976
- * @param {string|Buffer|Uint8Array} input - File path or a ``Buffer`` or ``Uint8Array``. Always found in ``BiReader.data``
15981
+ * @param {DataType} input - File path or a `Buffer` or `Uint8Array`.
15977
15982
  * @param {BiOptions?} options - Any options to set at start
15978
- * @param {BiOptions["byteOffset"]?} options.byteOffset - Byte offset to start writer (default ``0``)
15979
- * @param {BiOptions["bitOffset"]?} options.bitOffset - Bit offset 0-7 to start writer (default ``0``)
15980
- * @param {BiOptions["endianness"]?} options.endianness - Endianness ``big`` or ``little`` (default ``little``)
15981
- * @param {BiOptions["strict"]?} options.strict - Strict mode: if ``true`` does not extend supplied array on outside write (default ``false``)
15982
- * @param {BiOptions["growthIncrement"]?} options.growthIncrement - Amount of data to add when extending the buffer array when strict mode is false. Note: Changes logic in ``.get`` and ``.return``.
15983
- * @param {BiOptions["enforceBigInt"]?} options.enforceBigInt - 64 bit value reads will always stay ``BigInt``.
15984
- * @param {BiOptions["readOnly"]} options.readOnly - If you want to prevent write operations (default true in reader)
15983
+ * @param {BiOptions["byteOffset"]?} [options.byteOffset = 0] - Byte offset to start reader (default `0`)
15984
+ * @param {BiOptions["bitOffset"]?} [options.bitOffset = 0] - Bit offset (overrides {@link byteOffset}) (default `0`)
15985
+ * @param {BiOptions["endianness"]?} [options.endianness = "little"] - Endianness `big` or `little` (default `little`)
15986
+ * @param {BiOptions["strict"]?} [options.strict = true] - Strict mode: if `true` does not extend supplied array on outside read or write (default `true`)
15987
+ * @param {BiOptions["growthIncrement"]?} [options.growthIncrement = 1048576] - Amount of data to add when extending the buffer array when strict mode is false (default `1 MiB`)
15988
+ * @param {BiOptions["enforceBigInt"]?} [options.enforceBigInt = false] - 64 bit value reads will always return `bigint`. (default `false`)
15989
+ * @param {BiOptions["readOnly"]?} [options.readOnly = true] - Allow data writes when reading a file (default `true` in reader)
15990
+ * @param {BiOptions["windowSize"]?} [options.windowSize = 4096] - Size of the chunk of a file to load per read. Set to `0` to load the whole file in one async read (default `4 KiB`)
15985
15991
  *
15986
15992
  * @since 4.0
15987
15993
  */
15988
15994
  class BiReaderAsync extends BiBaseAsync {
15989
- /**
15990
- * Async Binary reader, includes bitfields and strings.
15991
- *
15992
- * @param {string|Buffer|Uint8Array} input - File path or a ``Buffer`` or ``Uint8Array``. Always found in ``BiReader.data``
15993
- * @param {BiOptions?} options - Any options to set at start
15994
- * @param {BiOptions["byteOffset"]?} options.byteOffset - Byte offset to start writer (default ``0``)
15995
- * @param {BiOptions["bitOffset"]?} options.bitOffset - Bit offset 0-7 to start writer (default ``0``)
15996
- * @param {BiOptions["endianness"]?} options.endianness - Endianness ``big`` or ``little`` (default ``little``)
15997
- * @param {BiOptions["strict"]?} options.strict - Strict mode: if ``true`` does not extend supplied array on outside write (default ``false``)
15998
- * @param {BiOptions["growthIncrement"]?} options.growthIncrement - Amount of data to add when extending the buffer array when strict mode is false.
15999
- * @param {BiOptions["enforceBigInt"]?} options.enforceBigInt - 64 bit value reads will always stay ``BigInt``.
16000
- * @param {BiOptions["readOnly"]} options.readOnly - If you want to prevent write operations (default true in reader)
16001
- */
16002
15995
  constructor(input, options = {}) {
16003
15996
  options.byteOffset = options.byteOffset ?? 0;
16004
15997
  options.bitOffset = options.bitOffset ?? 0;
@@ -16015,21 +16008,20 @@ class BiReaderAsync extends BiBaseAsync {
16015
16008
  }
16016
16009
  ;
16017
16010
  /**
16018
- * Creates and opens a new `BiReaderAsync`
16011
+ * Creates and opens a new `BiReaderAsync`.
16019
16012
  *
16020
- * Includes bitfields and strings.
16021
- *
16022
- * @param {string|Buffer|Uint8Array} input - File path or a ``Buffer`` or ``Uint8Array``. Always found in ``BiReader.data``
16013
+ * @param {DataType} input - File path or a `Buffer` or `Uint8Array`.
16023
16014
  * @param {BiOptions?} options - Any options to set at start
16024
- * @param {BiOptions["byteOffset"]?} options.byteOffset - Byte offset to start writer (default ``0``)
16025
- * @param {BiOptions["bitOffset"]?} options.bitOffset - Bit offset 0-7 to start writer (default ``0``)
16026
- * @param {BiOptions["endianness"]?} options.endianness - Endianness ``big`` or ``little`` (default ``little``)
16027
- * @param {BiOptions["strict"]?} options.strict - Strict mode: if ``true`` does not extend supplied array on outside write (default ``false``)
16028
- * @param {BiOptions["growthIncrement"]?} options.growthIncrement - Amount of data to add when extending the buffer array when strict mode is false. Note: Changes logic in ``.get`` and ``.return``.
16029
- * @param {BiOptions["enforceBigInt"]?} options.enforceBigInt - 64 bit value reads will always stay ``BigInt``.
16030
- * @param {BiOptions["readonly"]} options.readonly - If you want to prevent write operations (default true in reader)
16015
+ * @param {BiOptions["byteOffset"]?} [options.byteOffset = 0] - Byte offset to start reader (default `0`)
16016
+ * @param {BiOptions["bitOffset"]?} [options.bitOffset = 0] - Bit offset (overrides {@link byteOffset}) (default `0`)
16017
+ * @param {BiOptions["endianness"]?} [options.endianness = "little"] - Endianness `big` or `little` (default `little`)
16018
+ * @param {BiOptions["strict"]?} [options.strict = true] - Strict mode: if `true` does not extend supplied array on outside read or write (default `true`)
16019
+ * @param {BiOptions["growthIncrement"]?} [options.growthIncrement = 1048576] - Amount of data to add when extending the buffer array when strict mode is false (default `1 MiB`)
16020
+ * @param {BiOptions["enforceBigInt"]?} [options.enforceBigInt = false] - 64 bit value reads will always return `bigint`. (default `false`)
16021
+ * @param {BiOptions["readOnly"]?} [options.readOnly = true] - Allow data writes when reading a file (default `true` in reader)
16022
+ * @param {BiOptions["windowSize"]?} [options.windowSize = 4096] - Size of the chunk of a file to load per read. Set to `0` to load the whole file in one async read (default `4 KiB`)
16031
16023
  *
16032
- * @returns {Promise<BiReaderAsync<DataType, hasBigInt>>}
16024
+ * @since 4.0
16033
16025
  */
16034
16026
  static async create(input, options = {}) {
16035
16027
  const instance = new BiReaderAsync(input, options);
@@ -19514,30 +19506,19 @@ class BiReaderAsync extends BiBaseAsync {
19514
19506
  /**
19515
19507
  * Async Binary writer, includes bitfields and strings.
19516
19508
  *
19517
- * @param {string|Buffer|Uint8Array} input - File path or a ``Buffer`` or ``Uint8Array``. Always found in ``BiWriter.data``
19509
+ * @param {DataType} input - File path or a `Buffer` or ``Uint8Array`.
19518
19510
  * @param {BiOptions?} options - Any options to set at start
19519
- * @param {BiOptions["byteOffset"]?} options.byteOffset - Byte offset to start writer (default ``0``)
19520
- * @param {BiOptions["bitOffset"]?} options.bitOffset - Bit offset 0-7 to start writer (default ``0``)
19521
- * @param {BiOptions["endianness"]?} options.endianness - Endianness ``big`` or ``little`` (default ``little``)
19522
- * @param {BiOptions["strict"]?} options.strict - Strict mode: if ``true`` does not extend supplied array on outside write (default ``false``)
19523
- * @param {BiOptions["growthIncrement"]?} options.growthIncrement - Amount of data to add when extending the buffer array when strict mode is false. Note: Changes logic in ``.get`` and ``.return``.
19524
- * @param {BiOptions["enforceBigInt"]?} options.enforceBigInt - 64 bit value reads will always stay ``BigInt``.
19511
+ * @param {BiOptions["byteOffset"]?} [options.byteOffset = 0] - Byte offset to start reader (default `0`)
19512
+ * @param {BiOptions["bitOffset"]?} [options.bitOffset = 0] - Bit offset (overrides {@link byteOffset}) (default `0`)
19513
+ * @param {BiOptions["endianness"]?} [options.endianness = "little"] - Endianness `big` or `little` (default `little`)
19514
+ * @param {BiOptions["strict"]?} [options.strict = true] - Strict mode: if `true` does not extend supplied array on outside read or write (default `true`)
19515
+ * @param {BiOptions["growthIncrement"]?} [options.growthIncrement = 1048576] - Amount of data to add when extending the buffer array when strict mode is false (default `1 MiB`)
19516
+ * @param {BiOptions["enforceBigInt"]?} [options.enforceBigInt = false] - 64 bit value reads will always return `bigint`. (default `false`)
19517
+ * @param {BiOptions["windowSize"]?} [options.windowSize = 4096] - Size of the chunk of a file to load per read. Set to `0` to load the whole file in one async read (default `4 KiB`)
19525
19518
  *
19526
19519
  * @since 4.0
19527
19520
  */
19528
19521
  class BiWriterAsync extends BiBaseAsync {
19529
- /**
19530
- * Async Binary writer, includes bitfields and strings.
19531
- *
19532
- * @param {string|Buffer|Uint8Array} input - ``Buffer`` or ``Uint8Array``. Always found in ``BiWriter.data``
19533
- * @param {BiOptions?} options - Any options to set at start
19534
- * @param {BiOptions["byteOffset"]?} options.byteOffset - Byte offset to start writer (default ``0``)
19535
- * @param {BiOptions["bitOffset"]?} options.bitOffset - Bit offset 0-7 to start writer (default ``0``)
19536
- * @param {BiOptions["endianness"]?} options.endianness - Endianness ``big`` or ``little`` (default ``little``)
19537
- * @param {BiOptions["strict"]?} options.strict - Strict mode: if ``true`` does not extend supplied array on outside write (default ``false``)
19538
- * @param {BiOptions["growthIncrement"]?} options.growthIncrement - Amount of data to add when extending the buffer array when strict mode is false.
19539
- * @param {BiOptions["enforceBigInt"]?} options.enforceBigInt - 64 bit value reads will always stay ``BigInt``.
19540
- */
19541
19522
  constructor(input, options = {}) {
19542
19523
  options.byteOffset = options.byteOffset ?? 0;
19543
19524
  options.bitOffset = options.bitOffset ?? 0;
@@ -19557,21 +19538,19 @@ class BiWriterAsync extends BiBaseAsync {
19557
19538
  ;
19558
19539
  /**
19559
19540
  *
19560
- * Creates and opens a new `BiWriterAsync`
19561
- *
19562
- * includes bitfields and strings.
19541
+ * Creates and opens a new `BiWriterAsync`.
19563
19542
  *
19564
- * @param {string|Buffer|Uint8Array} input - ``Buffer`` or ``Uint8Array``. Always found in ``BiWriter.data``
19543
+ * @param {DataType} input - File path or a `Buffer` or ``Uint8Array`.
19565
19544
  * @param {BiOptions?} options - Any options to set at start
19566
- * @param {BiOptions["byteOffset"]?} options.byteOffset - Byte offset to start writer (default ``0``)
19567
- * @param {BiOptions["bitOffset"]?} options.bitOffset - Bit offset 0-7 to start writer (default ``0``)
19568
- * @param {BiOptions["endianness"]?} options.endianness - Endianness ``big`` or ``little`` (default ``little``)
19569
- * @param {BiOptions["strict"]?} options.strict - Strict mode: if ``true`` does not extend supplied array on outside write (default ``false``)
19570
- * @param {BiOptions["growthIncrement"]?} options.growthIncrement - Amount of data to add when extending the buffer array when strict mode is false. Note: Changes logic in ``.get`` and ``.return``.
19571
- * @param {BiOptions["enforceBigInt"]?} options.enforceBigInt - 64 bit value reads will always stay ``BigInt``.
19572
- * @param {BiOptions["writeable"]} options.writeable - Allow data writes when reading a file (default true in writer)
19545
+ * @param {BiOptions["byteOffset"]?} [options.byteOffset = 0] - Byte offset to start reader (default `0`)
19546
+ * @param {BiOptions["bitOffset"]?} [options.bitOffset = 0] - Bit offset (overrides {@link byteOffset}) (default `0`)
19547
+ * @param {BiOptions["endianness"]?} [options.endianness = "little"] - Endianness `big` or `little` (default `little`)
19548
+ * @param {BiOptions["strict"]?} [options.strict = true] - Strict mode: if `true` does not extend supplied array on outside read or write (default `true`)
19549
+ * @param {BiOptions["growthIncrement"]?} [options.growthIncrement = 1048576] - Amount of data to add when extending the buffer array when strict mode is false (default `1 MiB`)
19550
+ * @param {BiOptions["enforceBigInt"]?} [options.enforceBigInt = false] - 64 bit value reads will always return `bigint`. (default `false`)
19551
+ * @param {BiOptions["windowSize"]?} [options.windowSize = 4096] - Size of the chunk of a file to load per read. Set to `0` to load the whole file in one async read (default `4 KiB`)
19573
19552
  *
19574
- * @returns {Promise<BiWriterAsync<DataType, hasBigInt>>}
19553
+ * @returns {Promise<BiWriterAsync<DataType, alwaysBigInt>>}
19575
19554
  */
19576
19555
  static async create(input, options = {}) {
19577
19556
  const instance = new BiWriterAsync(input, options);
@@ -23015,6 +22994,7 @@ class BiWriterAsync extends BiBaseAsync {
23015
22994
  ;
23016
22995
  }
23017
22996
 
22997
+ // node import
23018
22998
  /**
23019
22999
  * Not in use anymore.
23020
23000
  * @since 3.0
@@ -23057,4 +23037,4 @@ class BiWriterStream {
23057
23037
  }
23058
23038
 
23059
23039
  export { BiBase, BiReader, BiReaderAsync, BiReaderStream, BiWriter, BiWriterAsync, BiWriterStream, bireader, biwriter, hexdump };
23060
- //# sourceMappingURL=index.esm.js.map
23040
+ //# sourceMappingURL=indexImport.js.map