Add missing APIs into ByteUtils and export it top-level from BSON

XMLWordPrintableJSON

    • Type: Sub-task
    • Resolution: Fixed
    • Priority: Unknown
    • bson-7.1.0
    • Affects Version/s: None
    • Component/s: None
    • 0
    • Not Needed
    • None
    • Not Needed
    • None
    • None
    • None
    • None
    • None
    • None

      The following is a full list of Buffer APIs used by the driver:

      • .isBuffer
        • Does not exist; but we'll either want to remove usages of this from the driver (we'll need to evaluate on a case-by-case basis) or use `isUint8Array`, which exists in BSON.  Maybe it makes sense to export isUint8Array from BSON too.
      • .concat
        • We'll need to add this to ByteUtils.
      • .from
        • The driver uses Buffer.from to convert the following to buffers:
          • utf8 strings
          • number arrays
          • buffers
          • base64 strings
        • Byte utils supports converting base64 strings and number arrays to Uint8Arrays already.  converting buffers to buffers can be done using `isUint8Array` and conditionally converting the string argument to a buffer if needed.  We will need to add conversion of utf8 strings -> buffers to byte utils.
      • .equals
        • exists in ByteUtils.
      • .compare
        • We will need to implement .compare() for Uint8Arrays.  Alternatively, this is only used for ObjectIds in the driver - we could hard-code this logic into a new method, ObjectId.compare().
      • .toBase64
        • exists in ByteUtils
      • .allocUnsafe
        • exists in ByteUtils
      • .alloc
        • exists in ByteUtils
      • .readInt32LE
        • exists in NumberUtils

       

      Acceptance Criteria:

      • Implement any missing APIs from the list above in BSON.
      • Export BSON ByteUtils from the library.

      Follow-up:

      • Highlight those changes in the release section

            Assignee:
            Sergey Zelenov
            Reporter:
            Sergey Zelenov
            Bailey Pearson
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: