ip2location-nodejs
Advanced tools
Comparing version 7.0.1 to 8.0.0
{ | ||
"name": "ip2location-nodejs", | ||
"version": "7.0.1", | ||
"version": "8.0.0", | ||
"description": "IP2Location geolocation component", | ||
@@ -5,0 +5,0 @@ "keywords": ["ip2location", "geolocation"], |
@@ -36,2 +36,2 @@ IP2Location Node.js Module | ||
Copyright (C) 2014 by IP2Location.com, support@ip2location.com | ||
Copyright (C) 2016 by IP2Location.com, support@ip2location.com |
@@ -5,3 +5,3 @@ var net = require("net"); | ||
var version = "7.0.1"; | ||
var version = "8.0.0"; | ||
var binfile = ""; | ||
@@ -14,2 +14,6 @@ var IPv4ColumnSize = 0; | ||
var maxindex = 65536; | ||
var IndexArrayIPv4 = Array(maxindex); | ||
var IndexArrayIPv6 = Array(maxindex); | ||
var country_pos = [0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]; | ||
@@ -85,3 +89,7 @@ var region_pos = [0, 0, 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]; | ||
"_BaseAddrIPv6": 0, | ||
"_OldBIN": 0 | ||
"_OldBIN": 0, | ||
"_Indexed": 0, | ||
"_IndexedIPv6": 0, | ||
"_IndexBaseAddr": 0, | ||
"_IndexBaseAddrIPv6": 0 | ||
}; | ||
@@ -183,4 +191,4 @@ | ||
if (m.length == 2) { | ||
var myarrleft = m[0].split(":"); | ||
var myarrright = m[1].split(":"); | ||
var myarrleft = (m[0] != '') ? m[0].split(":") : []; | ||
var myarrright = (m[1] != '') ? m[1].split(":") : []; | ||
var myarrmid = maxsections - myarrleft.length - myarrright.length; | ||
@@ -220,5 +228,15 @@ | ||
mydb._BaseAddrIPv6 = read32(18); | ||
mydb._IndexBaseAddr = read32(22); | ||
mydb._IndexBaseAddrIPv6 = read32(26); | ||
if (mydb._IndexBaseAddr > 0) { | ||
mydb._Indexed = 1; | ||
} | ||
if (mydb._DBCountIPv6 == 0) { | ||
mydb._OldBIN = 1; | ||
} | ||
else if (mydb._IndexBaseAddrIPv6 > 0) { | ||
mydb._IndexedIPv6 = 1; | ||
} | ||
@@ -270,2 +288,22 @@ IPv4ColumnSize = mydb._DBColumn << 2; // 4 bytes each column | ||
usagetype_enabled = (usagetype_pos[dbt] != 0) ? 1 : 0; | ||
if (mydb._Indexed == 1) { | ||
var pointer = mydb._IndexBaseAddr; | ||
for (var x = 0; x < maxindex; x++) { | ||
IndexArrayIPv4[x] = Array(2); | ||
IndexArrayIPv4[x][0] = read32(pointer); | ||
IndexArrayIPv4[x][1] = read32(pointer + 4); | ||
pointer += 8; | ||
} | ||
if (mydb._IndexedIPv6 == 1) { | ||
for (var x = 0; x < maxindex; x++) { | ||
IndexArrayIPv6[x] = Array(2); | ||
IndexArrayIPv6[x][0] = read32(pointer); | ||
IndexArrayIPv6[x][1] = read32(pointer + 4); | ||
pointer += 8; | ||
} | ||
} | ||
} | ||
} | ||
@@ -277,20 +315,31 @@ } | ||
_DBColumn = mydb._DBColumn; | ||
low = 0; | ||
mid = 0; | ||
high = 0; | ||
if (iptype == 4) { // IPv4 | ||
_DBCount = mydb._DBCount; | ||
high = mydb._DBCount; | ||
_BaseAddr = mydb._BaseAddr; | ||
_ColumnSize = IPv4ColumnSize; | ||
ipnum = dot2num(myIP); | ||
if (mydb._Indexed == 1) { | ||
indexaddr = ipnum >>> 16; | ||
low = IndexArrayIPv4[indexaddr][0]; | ||
high = IndexArrayIPv4[indexaddr][1]; | ||
} | ||
} | ||
else if (iptype == 6) { // IPv6 | ||
_DBCount = mydb._DBCountIPv6; | ||
high = mydb._DBCountIPv6; | ||
_BaseAddr = mydb._BaseAddrIPv6; | ||
_ColumnSize = IPv6ColumnSize; | ||
ipnum = ip2no(myIP); | ||
if (mydb._IndexedIPv6 == 1) { | ||
indexaddr = ipnum.shiftRight(112).toJSNumber(); | ||
low = IndexArrayIPv6[indexaddr][0]; | ||
high = IndexArrayIPv6[indexaddr][1]; | ||
} | ||
} | ||
MSG_NOT_SUPPORTED = "This method is not applicable for current IP2Location binary data file. Please upgrade your subscription package to install new data file."; | ||
low = 0; | ||
mid = 0; | ||
high = _DBCount; | ||
@@ -347,6 +396,6 @@ data.ip = myIP; | ||
if (latitude_enabled) { | ||
data.latitude = readfloat(rowoffset + latitude_pos_offset) | ||
data.latitude = Math.round(readfloat(rowoffset + latitude_pos_offset) * 1000000, 6) / 1000000; | ||
} | ||
if (longitude_enabled) { | ||
data.longitude = readfloat(rowoffset + longitude_pos_offset) | ||
data.longitude = Math.round(readfloat(rowoffset + longitude_pos_offset) * 1000000, 6) / 1000000; | ||
} | ||
@@ -353,0 +402,0 @@ if (timezone_enabled) { |
22250
542