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