bson 6.4.0 → 6.4.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.
package/lib/bson.mjs CHANGED
@@ -2123,6 +2123,8 @@ class MinKey extends BSONValue {
2123
2123
 
2124
2124
  const FLOAT = new Float64Array(1);
2125
2125
  const FLOAT_BYTES = new Uint8Array(FLOAT.buffer, 0, 8);
2126
+ FLOAT[0] = -1;
2127
+ const isBigEndian = FLOAT_BYTES[7] === 0;
2126
2128
  const NumberUtils = {
2127
2129
  getInt32LE(source, offset) {
2128
2130
  return (source[offset] |
@@ -2143,21 +2145,39 @@ const NumberUtils = {
2143
2145
  source[offset] * 16777216);
2144
2146
  },
2145
2147
  getBigInt64LE(source, offset) {
2146
- const lo = NumberUtils.getUint32LE(source, offset);
2147
- const hi = NumberUtils.getUint32LE(source, offset + 4);
2148
- return (BigInt(hi) << BigInt(32)) + BigInt(lo);
2149
- },
2150
- getFloat64LE(source, offset) {
2151
- FLOAT_BYTES[0] = source[offset];
2152
- FLOAT_BYTES[1] = source[offset + 1];
2153
- FLOAT_BYTES[2] = source[offset + 2];
2154
- FLOAT_BYTES[3] = source[offset + 3];
2155
- FLOAT_BYTES[4] = source[offset + 4];
2156
- FLOAT_BYTES[5] = source[offset + 5];
2157
- FLOAT_BYTES[6] = source[offset + 6];
2158
- FLOAT_BYTES[7] = source[offset + 7];
2159
- return FLOAT[0];
2148
+ const hi = BigInt(source[offset + 4] +
2149
+ source[offset + 5] * 256 +
2150
+ source[offset + 6] * 65536 +
2151
+ (source[offset + 7] << 24));
2152
+ const lo = BigInt(source[offset] +
2153
+ source[offset + 1] * 256 +
2154
+ source[offset + 2] * 65536 +
2155
+ source[offset + 3] * 16777216);
2156
+ return (hi << BigInt(32)) + lo;
2160
2157
  },
2158
+ getFloat64LE: isBigEndian
2159
+ ? (source, offset) => {
2160
+ FLOAT_BYTES[7] = source[offset];
2161
+ FLOAT_BYTES[6] = source[offset + 1];
2162
+ FLOAT_BYTES[5] = source[offset + 2];
2163
+ FLOAT_BYTES[4] = source[offset + 3];
2164
+ FLOAT_BYTES[3] = source[offset + 4];
2165
+ FLOAT_BYTES[2] = source[offset + 5];
2166
+ FLOAT_BYTES[1] = source[offset + 6];
2167
+ FLOAT_BYTES[0] = source[offset + 7];
2168
+ return FLOAT[0];
2169
+ }
2170
+ : (source, offset) => {
2171
+ FLOAT_BYTES[0] = source[offset];
2172
+ FLOAT_BYTES[1] = source[offset + 1];
2173
+ FLOAT_BYTES[2] = source[offset + 2];
2174
+ FLOAT_BYTES[3] = source[offset + 3];
2175
+ FLOAT_BYTES[4] = source[offset + 4];
2176
+ FLOAT_BYTES[5] = source[offset + 5];
2177
+ FLOAT_BYTES[6] = source[offset + 6];
2178
+ FLOAT_BYTES[7] = source[offset + 7];
2179
+ return FLOAT[0];
2180
+ },
2161
2181
  setInt32BE(destination, offset, value) {
2162
2182
  destination[offset + 3] = value;
2163
2183
  value >>>= 8;
@@ -2198,18 +2218,31 @@ const NumberUtils = {
2198
2218
  destination[offset + 7] = hi;
2199
2219
  return 8;
2200
2220
  },
2201
- setFloat64LE(destination, offset, value) {
2202
- FLOAT[0] = value;
2203
- destination[offset] = FLOAT_BYTES[0];
2204
- destination[offset + 1] = FLOAT_BYTES[1];
2205
- destination[offset + 2] = FLOAT_BYTES[2];
2206
- destination[offset + 3] = FLOAT_BYTES[3];
2207
- destination[offset + 4] = FLOAT_BYTES[4];
2208
- destination[offset + 5] = FLOAT_BYTES[5];
2209
- destination[offset + 6] = FLOAT_BYTES[6];
2210
- destination[offset + 7] = FLOAT_BYTES[7];
2211
- return 8;
2212
- }
2221
+ setFloat64LE: isBigEndian
2222
+ ? (destination, offset, value) => {
2223
+ FLOAT[0] = value;
2224
+ destination[offset] = FLOAT_BYTES[7];
2225
+ destination[offset + 1] = FLOAT_BYTES[6];
2226
+ destination[offset + 2] = FLOAT_BYTES[5];
2227
+ destination[offset + 3] = FLOAT_BYTES[4];
2228
+ destination[offset + 4] = FLOAT_BYTES[3];
2229
+ destination[offset + 5] = FLOAT_BYTES[2];
2230
+ destination[offset + 6] = FLOAT_BYTES[1];
2231
+ destination[offset + 7] = FLOAT_BYTES[0];
2232
+ return 8;
2233
+ }
2234
+ : (destination, offset, value) => {
2235
+ FLOAT[0] = value;
2236
+ destination[offset] = FLOAT_BYTES[0];
2237
+ destination[offset + 1] = FLOAT_BYTES[1];
2238
+ destination[offset + 2] = FLOAT_BYTES[2];
2239
+ destination[offset + 3] = FLOAT_BYTES[3];
2240
+ destination[offset + 4] = FLOAT_BYTES[4];
2241
+ destination[offset + 5] = FLOAT_BYTES[5];
2242
+ destination[offset + 6] = FLOAT_BYTES[6];
2243
+ destination[offset + 7] = FLOAT_BYTES[7];
2244
+ return 8;
2245
+ }
2213
2246
  };
2214
2247
 
2215
2248
  const checkForHexRegExp = new RegExp('^[0-9a-fA-F]{24}$');