bson 5.3.0 → 6.0.0-alpha

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.
Files changed (73) hide show
  1. package/README.md +51 -43
  2. package/bson.d.ts +10 -23
  3. package/lib/bson.bundle.js +73 -130
  4. package/lib/bson.bundle.js.map +1 -1
  5. package/lib/bson.cjs +73 -130
  6. package/lib/bson.cjs.map +1 -1
  7. package/lib/bson.mjs +73 -130
  8. package/lib/bson.mjs.map +1 -1
  9. package/lib/bson.rn.cjs +4051 -0
  10. package/lib/bson.rn.cjs.map +1 -0
  11. package/package.json +26 -24
  12. package/src/binary.ts +19 -53
  13. package/src/bson.ts +2 -2
  14. package/src/code.ts +1 -1
  15. package/src/constants.ts +1 -1
  16. package/src/decimal128.ts +35 -67
  17. package/src/objectid.ts +20 -37
  18. package/src/parser/deserializer.ts +8 -8
  19. package/src/symbol.ts +1 -1
  20. package/src/timestamp.ts +7 -5
  21. package/src/utils/byte_utils.ts +2 -2
  22. package/src/utils/node_byte_utils.ts +3 -3
  23. package/src/utils/web_byte_utils.ts +2 -2
  24. package/vendor/base64/LICENSE-MIT.txt +20 -0
  25. package/vendor/base64/README.md +112 -0
  26. package/vendor/base64/base64.js +157 -0
  27. package/vendor/base64/package.json +43 -0
  28. package/vendor/text-encoding/LICENSE.md +237 -0
  29. package/vendor/text-encoding/README.md +111 -0
  30. package/vendor/text-encoding/index.js +9 -0
  31. package/vendor/text-encoding/lib/encoding-indexes.js +47 -0
  32. package/vendor/text-encoding/lib/encoding.js +3301 -0
  33. package/vendor/text-encoding/package.json +37 -0
  34. package/lib/binary.d.ts +0 -182
  35. package/lib/binary.d.ts.map +0 -1
  36. package/lib/bson.d.ts +0 -97
  37. package/lib/bson.d.ts.map +0 -1
  38. package/lib/bson_value.d.ts +0 -10
  39. package/lib/bson_value.d.ts.map +0 -1
  40. package/lib/code.d.ts +0 -32
  41. package/lib/code.d.ts.map +0 -1
  42. package/lib/constants.d.ts +0 -107
  43. package/lib/constants.d.ts.map +0 -1
  44. package/lib/db_ref.d.ts +0 -40
  45. package/lib/db_ref.d.ts.map +0 -1
  46. package/lib/decimal128.d.ts +0 -34
  47. package/lib/decimal128.d.ts.map +0 -1
  48. package/lib/double.d.ts +0 -35
  49. package/lib/double.d.ts.map +0 -1
  50. package/lib/error.d.ts +0 -50
  51. package/lib/error.d.ts.map +0 -1
  52. package/lib/extended_json.d.ts +0 -82
  53. package/lib/extended_json.d.ts.map +0 -1
  54. package/lib/index.d.ts +0 -4
  55. package/lib/index.d.ts.map +0 -1
  56. package/lib/int_32.d.ts +0 -35
  57. package/lib/int_32.d.ts.map +0 -1
  58. package/lib/long.d.ts +0 -323
  59. package/lib/long.d.ts.map +0 -1
  60. package/lib/max_key.d.ts +0 -19
  61. package/lib/max_key.d.ts.map +0 -1
  62. package/lib/min_key.d.ts +0 -19
  63. package/lib/min_key.d.ts.map +0 -1
  64. package/lib/objectid.d.ts +0 -96
  65. package/lib/objectid.d.ts.map +0 -1
  66. package/lib/regexp.d.ts +0 -36
  67. package/lib/regexp.d.ts.map +0 -1
  68. package/lib/symbol.d.ts +0 -28
  69. package/lib/symbol.d.ts.map +0 -1
  70. package/lib/timestamp.d.ts +0 -66
  71. package/lib/timestamp.d.ts.map +0 -1
  72. package/lib/validate_utf8.d.ts +0 -10
  73. package/lib/validate_utf8.d.ts.map +0 -1
@@ -17,7 +17,7 @@ function isDate(d) {
17
17
  return Object.prototype.toString.call(d) === '[object Date]';
18
18
  }
19
19
 
20
- const BSON_MAJOR_VERSION = 5;
20
+ const BSON_MAJOR_VERSION = 6;
21
21
  const BSON_INT32_MAX = 0x7fffffff;
22
22
  const BSON_INT32_MIN = -0x80000000;
23
23
  const BSON_INT64_MAX = Math.pow(2, 63) - 1;
@@ -166,8 +166,8 @@ const nodeJsByteUtils = {
166
166
  fromUTF8(text) {
167
167
  return Buffer.from(text, 'utf8');
168
168
  },
169
- toUTF8(buffer) {
170
- return nodeJsByteUtils.toLocalBufferType(buffer).toString('utf8');
169
+ toUTF8(buffer, start, end) {
170
+ return nodeJsByteUtils.toLocalBufferType(buffer).toString('utf8', start, end);
171
171
  },
172
172
  utf8ByteLength(input) {
173
173
  return Buffer.byteLength(input, 'utf8');
@@ -277,8 +277,8 @@ const webByteUtils = {
277
277
  fromUTF8(text) {
278
278
  return new TextEncoder().encode(text);
279
279
  },
280
- toUTF8(uint8array) {
281
- return new TextDecoder('utf8', { fatal: false }).decode(uint8array);
280
+ toUTF8(uint8array, start, end) {
281
+ return new TextDecoder('utf8', { fatal: false }).decode(uint8array.slice(start, end));
282
282
  },
283
283
  utf8ByteLength(input) {
284
284
  return webByteUtils.fromUTF8(input).byteLength;
@@ -312,11 +312,11 @@ class Binary extends BSONValue {
312
312
  constructor(buffer, subType) {
313
313
  super();
314
314
  if (!(buffer == null) &&
315
- !(typeof buffer === 'string') &&
315
+ typeof buffer === 'string' &&
316
316
  !ArrayBuffer.isView(buffer) &&
317
- !(buffer instanceof ArrayBuffer) &&
317
+ !isAnyArrayBuffer(buffer) &&
318
318
  !Array.isArray(buffer)) {
319
- throw new BSONError('Binary can only be constructed from string, Buffer, TypedArray, or Array<number>');
319
+ throw new BSONError('Binary can only be constructed from Uint8Array or number[]');
320
320
  }
321
321
  this.sub_type = subType ?? Binary.BSON_BINARY_SUBTYPE_DEFAULT;
322
322
  if (buffer == null) {
@@ -324,15 +324,9 @@ class Binary extends BSONValue {
324
324
  this.position = 0;
325
325
  }
326
326
  else {
327
- if (typeof buffer === 'string') {
328
- this.buffer = ByteUtils.fromISO88591(buffer);
329
- }
330
- else if (Array.isArray(buffer)) {
331
- this.buffer = ByteUtils.fromNumberArray(buffer);
332
- }
333
- else {
334
- this.buffer = ByteUtils.toLocalBufferType(buffer);
335
- }
327
+ this.buffer = Array.isArray(buffer)
328
+ ? ByteUtils.fromNumberArray(buffer)
329
+ : ByteUtils.toLocalBufferType(buffer);
336
330
  this.position = this.buffer.byteLength;
337
331
  }
338
332
  }
@@ -378,25 +372,17 @@ class Binary extends BSONValue {
378
372
  offset + sequence.byteLength > this.position ? offset + sequence.length : this.position;
379
373
  }
380
374
  else if (typeof sequence === 'string') {
381
- const bytes = ByteUtils.fromISO88591(sequence);
382
- this.buffer.set(bytes, offset);
383
- this.position =
384
- offset + sequence.length > this.position ? offset + sequence.length : this.position;
375
+ throw new BSONError('input cannot be string');
385
376
  }
386
377
  }
387
378
  read(position, length) {
388
379
  length = length && length > 0 ? length : this.position;
389
380
  return this.buffer.slice(position, position + length);
390
381
  }
391
- value(asRaw) {
392
- asRaw = !!asRaw;
393
- if (asRaw && this.buffer.length === this.position) {
394
- return this.buffer;
395
- }
396
- if (asRaw) {
397
- return this.buffer.slice(0, this.position);
398
- }
399
- return ByteUtils.toISO88591(this.buffer.subarray(0, this.position));
382
+ value() {
383
+ return this.buffer.length === this.position
384
+ ? this.buffer
385
+ : this.buffer.subarray(0, this.position);
400
386
  }
401
387
  length() {
402
388
  return this.position;
@@ -410,8 +396,8 @@ class Binary extends BSONValue {
410
396
  if (encoding === 'base64')
411
397
  return ByteUtils.toBase64(this.buffer);
412
398
  if (encoding === 'utf8' || encoding === 'utf-8')
413
- return ByteUtils.toUTF8(this.buffer);
414
- return ByteUtils.toUTF8(this.buffer);
399
+ return ByteUtils.toUTF8(this.buffer, 0, this.buffer.byteLength);
400
+ return ByteUtils.toUTF8(this.buffer, 0, this.buffer.byteLength);
415
401
  }
416
402
  toExtendedJSON(options) {
417
403
  options = options || {};
@@ -597,7 +583,6 @@ class UUID extends Binary {
597
583
  return `new UUID("${this.toHexString()}")`;
598
584
  }
599
585
  }
600
- UUID.cacheHexString = false;
601
586
 
602
587
  class Code extends BSONValue {
603
588
  get _bsontype() {
@@ -628,7 +613,7 @@ class Code extends BSONValue {
628
613
  }
629
614
  inspect() {
630
615
  const codeJson = this.toJSON();
631
- return `new Code("${String(codeJson.code)}"${codeJson.scope != null ? `, ${JSON.stringify(codeJson.scope)}` : ''})`;
616
+ return `new Code(${JSON.stringify(String(codeJson.code))}${codeJson.scope != null ? `, ${JSON.stringify(codeJson.scope)}` : ''})`;
632
617
  }
633
618
  }
634
619
 
@@ -1438,6 +1423,7 @@ class Decimal128 extends BSONValue {
1438
1423
  }
1439
1424
  static fromString(representation) {
1440
1425
  let isNegative = false;
1426
+ let sawSign = false;
1441
1427
  let sawRadix = false;
1442
1428
  let foundNonZero = false;
1443
1429
  let significantDigits = 0;
@@ -1448,10 +1434,8 @@ class Decimal128 extends BSONValue {
1448
1434
  const digits = [0];
1449
1435
  let nDigitsStored = 0;
1450
1436
  let digitsInsert = 0;
1451
- let firstDigit = 0;
1452
1437
  let lastDigit = 0;
1453
1438
  let exponent = 0;
1454
- let i = 0;
1455
1439
  let significandHigh = new Long(0, 0);
1456
1440
  let significandLow = new Long(0, 0);
1457
1441
  let biasedExponent = 0;
@@ -1479,6 +1463,7 @@ class Decimal128 extends BSONValue {
1479
1463
  }
1480
1464
  }
1481
1465
  if (representation[index] === '+' || representation[index] === '-') {
1466
+ sawSign = true;
1482
1467
  isNegative = representation[index++] === '-';
1483
1468
  }
1484
1469
  if (!isDigit(representation[index]) && representation[index] !== '.') {
@@ -1497,7 +1482,7 @@ class Decimal128 extends BSONValue {
1497
1482
  index = index + 1;
1498
1483
  continue;
1499
1484
  }
1500
- if (nDigitsStored < 34) {
1485
+ if (nDigitsStored < MAX_DIGITS) {
1501
1486
  if (representation[index] !== '0' || foundNonZero) {
1502
1487
  if (!foundNonZero) {
1503
1488
  firstNonZero = nDigitsRead;
@@ -1525,10 +1510,7 @@ class Decimal128 extends BSONValue {
1525
1510
  }
1526
1511
  if (representation[index])
1527
1512
  return new Decimal128(NAN_BUFFER);
1528
- firstDigit = 0;
1529
1513
  if (!nDigitsStored) {
1530
- firstDigit = 0;
1531
- lastDigit = 0;
1532
1514
  digits[0] = 0;
1533
1515
  nDigits = 1;
1534
1516
  nDigitsStored = 1;
@@ -1538,12 +1520,12 @@ class Decimal128 extends BSONValue {
1538
1520
  lastDigit = nDigitsStored - 1;
1539
1521
  significantDigits = nDigits;
1540
1522
  if (significantDigits !== 1) {
1541
- while (digits[firstNonZero + significantDigits - 1] === 0) {
1523
+ while (representation[firstNonZero + significantDigits - 1 + Number(sawSign) + Number(sawRadix)] === '0') {
1542
1524
  significantDigits = significantDigits - 1;
1543
1525
  }
1544
1526
  }
1545
1527
  }
1546
- if (exponent <= radixPosition && radixPosition - exponent > 1 << 14) {
1528
+ if (exponent <= radixPosition && radixPosition > exponent + (1 << 14)) {
1547
1529
  exponent = EXPONENT_MIN;
1548
1530
  }
1549
1531
  else {
@@ -1551,9 +1533,8 @@ class Decimal128 extends BSONValue {
1551
1533
  }
1552
1534
  while (exponent > EXPONENT_MAX) {
1553
1535
  lastDigit = lastDigit + 1;
1554
- if (lastDigit - firstDigit > MAX_DIGITS) {
1555
- const digitsString = digits.join('');
1556
- if (digitsString.match(/^0+$/)) {
1536
+ if (lastDigit >= MAX_DIGITS) {
1537
+ if (significantDigits === 0) {
1557
1538
  exponent = EXPONENT_MAX;
1558
1539
  break;
1559
1540
  }
@@ -1562,69 +1543,43 @@ class Decimal128 extends BSONValue {
1562
1543
  exponent = exponent - 1;
1563
1544
  }
1564
1545
  while (exponent < EXPONENT_MIN || nDigitsStored < nDigits) {
1565
- if (lastDigit === 0 && significantDigits < nDigitsStored) {
1566
- exponent = EXPONENT_MIN;
1567
- significantDigits = 0;
1568
- break;
1546
+ if (lastDigit === 0) {
1547
+ if (significantDigits === 0) {
1548
+ exponent = EXPONENT_MIN;
1549
+ break;
1550
+ }
1551
+ invalidErr(representation, 'exponent underflow');
1569
1552
  }
1570
1553
  if (nDigitsStored < nDigits) {
1554
+ if (representation[nDigits - 1 + Number(sawSign) + Number(sawRadix)] !== '0' &&
1555
+ significantDigits !== 0) {
1556
+ invalidErr(representation, 'inexact rounding');
1557
+ }
1571
1558
  nDigits = nDigits - 1;
1572
1559
  }
1573
1560
  else {
1561
+ if (digits[lastDigit] !== 0) {
1562
+ invalidErr(representation, 'inexact rounding');
1563
+ }
1574
1564
  lastDigit = lastDigit - 1;
1575
1565
  }
1576
1566
  if (exponent < EXPONENT_MAX) {
1577
1567
  exponent = exponent + 1;
1578
1568
  }
1579
1569
  else {
1580
- const digitsString = digits.join('');
1581
- if (digitsString.match(/^0+$/)) {
1582
- exponent = EXPONENT_MAX;
1583
- break;
1584
- }
1585
1570
  invalidErr(representation, 'overflow');
1586
1571
  }
1587
1572
  }
1588
- if (lastDigit - firstDigit + 1 < significantDigits) {
1589
- let endOfString = nDigitsRead;
1573
+ if (lastDigit + 1 < significantDigits) {
1590
1574
  if (sawRadix) {
1591
1575
  firstNonZero = firstNonZero + 1;
1592
- endOfString = endOfString + 1;
1593
1576
  }
1594
- if (isNegative) {
1577
+ if (sawSign) {
1595
1578
  firstNonZero = firstNonZero + 1;
1596
- endOfString = endOfString + 1;
1597
1579
  }
1598
1580
  const roundDigit = parseInt(representation[firstNonZero + lastDigit + 1], 10);
1599
- let roundBit = 0;
1600
- if (roundDigit >= 5) {
1601
- roundBit = 1;
1602
- if (roundDigit === 5) {
1603
- roundBit = digits[lastDigit] % 2 === 1 ? 1 : 0;
1604
- for (i = firstNonZero + lastDigit + 2; i < endOfString; i++) {
1605
- if (parseInt(representation[i], 10)) {
1606
- roundBit = 1;
1607
- break;
1608
- }
1609
- }
1610
- }
1611
- }
1612
- if (roundBit) {
1613
- let dIdx = lastDigit;
1614
- for (; dIdx >= 0; dIdx--) {
1615
- if (++digits[dIdx] > 9) {
1616
- digits[dIdx] = 0;
1617
- if (dIdx === 0) {
1618
- if (exponent < EXPONENT_MAX) {
1619
- exponent = exponent + 1;
1620
- digits[dIdx] = 1;
1621
- }
1622
- else {
1623
- return new Decimal128(isNegative ? INF_NEGATIVE_BUFFER : INF_POSITIVE_BUFFER);
1624
- }
1625
- }
1626
- }
1627
- }
1581
+ if (roundDigit !== 0) {
1582
+ invalidErr(representation, 'inexact rounding');
1628
1583
  }
1629
1584
  }
1630
1585
  significandHigh = Long.fromNumber(0);
@@ -1633,8 +1588,8 @@ class Decimal128 extends BSONValue {
1633
1588
  significandHigh = Long.fromNumber(0);
1634
1589
  significandLow = Long.fromNumber(0);
1635
1590
  }
1636
- else if (lastDigit - firstDigit < 17) {
1637
- let dIdx = firstDigit;
1591
+ else if (lastDigit < 17) {
1592
+ let dIdx = 0;
1638
1593
  significandLow = Long.fromNumber(digits[dIdx++]);
1639
1594
  significandHigh = new Long(0, 0);
1640
1595
  for (; dIdx <= lastDigit; dIdx++) {
@@ -1643,7 +1598,7 @@ class Decimal128 extends BSONValue {
1643
1598
  }
1644
1599
  }
1645
1600
  else {
1646
- let dIdx = firstDigit;
1601
+ let dIdx = 0;
1647
1602
  significandHigh = Long.fromNumber(digits[dIdx++]);
1648
1603
  for (; dIdx <= lastDigit - 17; dIdx++) {
1649
1604
  significandHigh = significandHigh.multiply(Long.fromNumber(10));
@@ -1991,20 +1946,11 @@ class ObjectId extends BSONValue {
1991
1946
  this[kId] = ByteUtils.toLocalBufferType(workingId);
1992
1947
  }
1993
1948
  else if (typeof workingId === 'string') {
1994
- if (workingId.length === 12) {
1995
- const bytes = ByteUtils.fromUTF8(workingId);
1996
- if (bytes.byteLength === 12) {
1997
- this[kId] = bytes;
1998
- }
1999
- else {
2000
- throw new BSONError('Argument passed in must be a string of 12 bytes');
2001
- }
2002
- }
2003
- else if (workingId.length === 24 && checkForHexRegExp.test(workingId)) {
1949
+ if (workingId.length === 24 && checkForHexRegExp.test(workingId)) {
2004
1950
  this[kId] = ByteUtils.fromHex(workingId);
2005
1951
  }
2006
1952
  else {
2007
- throw new BSONError('Argument passed in must be a string of 12 bytes or a string of 24 hex characters or an integer');
1953
+ throw new BSONError('input must be a 24 character hex string, 12 byte Uint8Array, or an integer');
2008
1954
  }
2009
1955
  }
2010
1956
  else {
@@ -2066,30 +2012,25 @@ class ObjectId extends BSONValue {
2066
2012
  toJSON() {
2067
2013
  return this.toHexString();
2068
2014
  }
2015
+ static is(variable) {
2016
+ return (variable != null &&
2017
+ typeof variable === 'object' &&
2018
+ '_bsontype' in variable &&
2019
+ variable._bsontype === 'ObjectId');
2020
+ }
2069
2021
  equals(otherId) {
2070
2022
  if (otherId === undefined || otherId === null) {
2071
2023
  return false;
2072
2024
  }
2073
- if (otherId instanceof ObjectId) {
2025
+ if (ObjectId.is(otherId)) {
2074
2026
  return this[kId][11] === otherId[kId][11] && ByteUtils.equals(this[kId], otherId[kId]);
2075
2027
  }
2076
- if (typeof otherId === 'string' &&
2077
- ObjectId.isValid(otherId) &&
2078
- otherId.length === 12 &&
2079
- isUint8Array(this.id)) {
2080
- return ByteUtils.equals(this.id, ByteUtils.fromISO88591(otherId));
2081
- }
2082
- if (typeof otherId === 'string' && ObjectId.isValid(otherId) && otherId.length === 24) {
2028
+ if (typeof otherId === 'string') {
2083
2029
  return otherId.toLowerCase() === this.toHexString();
2084
2030
  }
2085
- if (typeof otherId === 'string' && ObjectId.isValid(otherId) && otherId.length === 12) {
2086
- return ByteUtils.equals(ByteUtils.fromUTF8(otherId), this.id);
2087
- }
2088
- if (typeof otherId === 'object' &&
2089
- 'toHexString' in otherId &&
2090
- typeof otherId.toHexString === 'function') {
2031
+ if (typeof otherId === 'object' && typeof otherId.toHexString === 'function') {
2091
2032
  const otherIdString = otherId.toHexString();
2092
- const thisIdString = this.toHexString().toLowerCase();
2033
+ const thisIdString = this.toHexString();
2093
2034
  return typeof otherIdString === 'string' && otherIdString.toLowerCase() === thisIdString;
2094
2035
  }
2095
2036
  return false;
@@ -2379,7 +2320,7 @@ class BSONSymbol extends BSONValue {
2379
2320
  return this.value;
2380
2321
  }
2381
2322
  inspect() {
2382
- return `new BSONSymbol("${this.value}")`;
2323
+ return `new BSONSymbol(${JSON.stringify(this.value)})`;
2383
2324
  }
2384
2325
  toJSON() {
2385
2326
  return this.value;
@@ -2417,19 +2358,21 @@ class Timestamp extends LongWithoutOverridesClass {
2417
2358
  if (typeof low.i !== 'number' && (typeof low.i !== 'object' || low.i._bsontype !== 'Int32')) {
2418
2359
  throw new BSONError('Timestamp constructed from { t, i } must provide i as a number');
2419
2360
  }
2420
- if (low.t < 0) {
2361
+ const t = Number(low.t);
2362
+ const i = Number(low.i);
2363
+ if (t < 0 || Number.isNaN(t)) {
2421
2364
  throw new BSONError('Timestamp constructed from { t, i } must provide a positive t');
2422
2365
  }
2423
- if (low.i < 0) {
2366
+ if (i < 0 || Number.isNaN(i)) {
2424
2367
  throw new BSONError('Timestamp constructed from { t, i } must provide a positive i');
2425
2368
  }
2426
- if (low.t > 4294967295) {
2369
+ if (t > 4294967295) {
2427
2370
  throw new BSONError('Timestamp constructed from { t, i } must provide t equal or less than uint32 max');
2428
2371
  }
2429
- if (low.i > 4294967295) {
2372
+ if (i > 4294967295) {
2430
2373
  throw new BSONError('Timestamp constructed from { t, i } must provide i equal or less than uint32 max');
2431
2374
  }
2432
- super(low.i.valueOf(), low.t.valueOf(), true);
2375
+ super(i, t, true);
2433
2376
  }
2434
2377
  else {
2435
2378
  throw new BSONError('A Timestamp can only be constructed with: bigint, Long, or { t: number; i: number }');
@@ -2601,7 +2544,7 @@ function deserializeObject(buffer, index, options, isArray = false) {
2601
2544
  }
2602
2545
  if (i >= buffer.byteLength)
2603
2546
  throw new BSONError('Bad BSON Document: illegal CString');
2604
- const name = isArray ? arrayIndex++ : ByteUtils.toUTF8(buffer.subarray(index, i));
2547
+ const name = isArray ? arrayIndex++ : ByteUtils.toUTF8(buffer, index, i);
2605
2548
  let shouldValidateKey = true;
2606
2549
  if (globalUTFValidation || utf8KeysSet.has(name)) {
2607
2550
  shouldValidateKey = validationSetting;
@@ -2816,7 +2759,7 @@ function deserializeObject(buffer, index, options, isArray = false) {
2816
2759
  }
2817
2760
  if (i >= buffer.length)
2818
2761
  throw new BSONError('Bad BSON Document: illegal CString');
2819
- const source = ByteUtils.toUTF8(buffer.subarray(index, i));
2762
+ const source = ByteUtils.toUTF8(buffer, index, i);
2820
2763
  index = i + 1;
2821
2764
  i = index;
2822
2765
  while (buffer[i] !== 0x00 && i < buffer.length) {
@@ -2824,7 +2767,7 @@ function deserializeObject(buffer, index, options, isArray = false) {
2824
2767
  }
2825
2768
  if (i >= buffer.length)
2826
2769
  throw new BSONError('Bad BSON Document: illegal CString');
2827
- const regExpOptions = ByteUtils.toUTF8(buffer.subarray(index, i));
2770
+ const regExpOptions = ByteUtils.toUTF8(buffer, index, i);
2828
2771
  index = i + 1;
2829
2772
  const optionsArray = new Array(regExpOptions.length);
2830
2773
  for (i = 0; i < regExpOptions.length; i++) {
@@ -2849,7 +2792,7 @@ function deserializeObject(buffer, index, options, isArray = false) {
2849
2792
  }
2850
2793
  if (i >= buffer.length)
2851
2794
  throw new BSONError('Bad BSON Document: illegal CString');
2852
- const source = ByteUtils.toUTF8(buffer.subarray(index, i));
2795
+ const source = ByteUtils.toUTF8(buffer, index, i);
2853
2796
  index = i + 1;
2854
2797
  i = index;
2855
2798
  while (buffer[i] !== 0x00 && i < buffer.length) {
@@ -2857,7 +2800,7 @@ function deserializeObject(buffer, index, options, isArray = false) {
2857
2800
  }
2858
2801
  if (i >= buffer.length)
2859
2802
  throw new BSONError('Bad BSON Document: illegal CString');
2860
- const regExpOptions = ByteUtils.toUTF8(buffer.subarray(index, i));
2803
+ const regExpOptions = ByteUtils.toUTF8(buffer, index, i);
2861
2804
  index = i + 1;
2862
2805
  value = new BSONRegExp(source, regExpOptions);
2863
2806
  }
@@ -2954,7 +2897,7 @@ function deserializeObject(buffer, index, options, isArray = false) {
2954
2897
  throw new BSONError('Invalid UTF-8 string in BSON document');
2955
2898
  }
2956
2899
  }
2957
- const namespace = ByteUtils.toUTF8(buffer.subarray(index, index + stringSize - 1));
2900
+ const namespace = ByteUtils.toUTF8(buffer, index, index + stringSize - 1);
2958
2901
  index = index + stringSize;
2959
2902
  const oidBuffer = ByteUtils.allocate(12);
2960
2903
  oidBuffer.set(buffer.subarray(index, index + 12), 0);
@@ -2994,7 +2937,7 @@ function deserializeObject(buffer, index, options, isArray = false) {
2994
2937
  return object;
2995
2938
  }
2996
2939
  function getValidatedString(buffer, start, end, shouldValidateUtf8) {
2997
- const value = ByteUtils.toUTF8(buffer.subarray(start, end));
2940
+ const value = ByteUtils.toUTF8(buffer, start, end);
2998
2941
  if (shouldValidateUtf8) {
2999
2942
  for (let i = 0; i < value.length; i++) {
3000
2943
  if (value.charCodeAt(i) === 0xfffd) {