bson 6.9.0 → 6.10.1

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.
@@ -100,7 +100,7 @@ export const webByteUtils = {
100
100
  return new Uint8Array(potentialUint8array);
101
101
  }
102
102
 
103
- throw new BSONError(`Cannot make a Uint8Array from ${String(potentialUint8array)}`);
103
+ throw new BSONError(`Cannot make a Uint8Array from passed potentialBuffer.`);
104
104
  },
105
105
 
106
106
  allocate(size: number): Uint8Array {
@@ -193,5 +193,24 @@ export const webByteUtils = {
193
193
  return bytes.byteLength;
194
194
  },
195
195
 
196
- randomBytes: webRandomBytes
196
+ randomBytes: webRandomBytes,
197
+
198
+ swap32(buffer: Uint8Array): Uint8Array {
199
+ if (buffer.length % 4 !== 0) {
200
+ throw new RangeError('Buffer size must be a multiple of 32-bits');
201
+ }
202
+
203
+ for (let i = 0; i < buffer.length; i += 4) {
204
+ const byte0 = buffer[i];
205
+ const byte1 = buffer[i + 1];
206
+ const byte2 = buffer[i + 2];
207
+ const byte3 = buffer[i + 3];
208
+ buffer[i] = byte3;
209
+ buffer[i + 1] = byte2;
210
+ buffer[i + 2] = byte1;
211
+ buffer[i + 3] = byte0;
212
+ }
213
+
214
+ return buffer;
215
+ }
197
216
  };