mmdb-lib 2.2.1 → 3.0.0

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/decoder.js CHANGED
@@ -99,9 +99,9 @@ class Decoder {
99
99
  case DataType.Int32:
100
100
  return cursor(this.decodeInt32(offset, size), newOffset);
101
101
  case DataType.Uint64:
102
- return cursor(this.decodeUint(offset, size), newOffset);
102
+ return cursor(this.decodeBigUint(offset, size), newOffset);
103
103
  case DataType.Uint128:
104
- return cursor(this.decodeUint(offset, size), newOffset);
104
+ return cursor(this.decodeBigUint(offset, size), newOffset);
105
105
  }
106
106
  throw new Error('Unknown type ' + type + ' at offset ' + offset);
107
107
  }
@@ -222,27 +222,24 @@ class Decoder {
222
222
  if (size === 0) {
223
223
  return 0;
224
224
  }
225
- if (size <= 6) {
225
+ if (size <= 4) {
226
226
  return this.db.readUIntBE(offset, size);
227
227
  }
228
- if (size == 8) {
229
- return this.db.readBigUInt64BE(offset).toString();
230
- }
231
- if (size > 16) {
232
- return 0;
233
- }
234
- return this.decodeBigUint(offset, size);
228
+ throw new Error(`Invalid size for unsigned integer: ${size}`);
235
229
  }
236
230
  decodeString(offset, size) {
237
231
  return this.db.toString('utf8', offset, offset + size);
238
232
  }
239
233
  decodeBigUint(offset, size) {
234
+ if (size > 16) {
235
+ throw new Error(`Invalid size for big unsigned integer: ${size}`);
236
+ }
240
237
  let integer = 0n;
241
238
  for (let i = 0; i < size; i++) {
242
239
  integer <<= 8n;
243
240
  integer |= BigInt(this.db.readUInt8(offset + i));
244
241
  }
245
- return integer.toString();
242
+ return integer;
246
243
  }
247
244
  }
248
245
  exports.default = Decoder;
package/lib/metadata.js CHANGED
@@ -20,7 +20,7 @@ const parseMetadata = (db) => {
20
20
  return {
21
21
  binaryFormatMajorVersion: metadata.binary_format_major_version,
22
22
  binaryFormatMinorVersion: metadata.binary_format_minor_version,
23
- buildEpoch: new Date(metadata.build_epoch * 1000),
23
+ buildEpoch: new Date(Number(metadata.build_epoch) * 1000),
24
24
  databaseType: metadata.database_type,
25
25
  description: metadata.description,
26
26
  ipVersion: metadata.ip_version,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mmdb-lib",
3
- "version": "2.2.1",
3
+ "version": "3.0.0",
4
4
  "homepage": "https://github.com/runk/mmdb-lib",
5
5
  "description": "Maxmind DB (MMDB) Library",
6
6
  "keywords": [