geoip-lite2 2.2.4 → 2.2.6

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.
@@ -1 +1 @@
1
- dacef45e8358b2004b5a70e94ac74d2f7c5ed5e238dc4c5b9ff27d340ff6bea4 GeoLite2-City-CSV_20250304.zip
1
+ 7014a41dc60b27ef593d260eca0d4b396d38c924c0eee9859662f4ecae56b092 GeoLite2-City-CSV_20250620.zip
@@ -1 +1 @@
1
- 103ac5bbb6cae42abf033a1623bb4f51342fbdbffdf4218c568d043ada815e22 GeoLite2-Country-CSV_20250304.zip
1
+ 6c3d34a9eaa8d2bdafe85701f906c36c5f0eecde4f6c91a00499eaa612bfa26f GeoLite2-Country-CSV_20250620.zip
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -1 +1 @@
1
- const{access:t,constants:e,watch:n}=require('fs'),{join:o}=require('path'),l={},u=t=>l[t].close();module.exports={makeFsWatchFilter:(c,r,s,i,a)=>{let f=null;function h(){f=null,a()}'function'==typeof i&&(a=i,i=s,s=null),l[c]&&u(c),l[c]=n(r,(function(n,l){if(!l)return;const u=o(r,l);s&&s!==l||t(u,e.F_OK,(t=>{if(t)return console.error(t);null!==f&&(clearTimeout(f),f=null),f=setTimeout(h,i)}))}))},stopWatching:u};
1
+ const{access:t,constants:e,watch:n}=require('fs'),{join:o}=require('path'),l={},u=t=>l[t].close();module.exports={makeFsWatchFilter:(c,r,s,i,a)=>{let f=null;function h(){f=null,a()}'function'==typeof i&&(a=i,i=s,s=null),l[c]&&u(c),l[c]=n(r,function(n,l){if(!l)return;const u=o(r,l);s&&s!==l||t(u,e.F_OK,t=>{if(t)return console.error(t);null!==f&&(clearTimeout(f),f=null),f=setTimeout(h,i)})})},stopWatching:u};
@@ -1 +1 @@
1
- const{open:e,fstat:r,read:t,close:n,openSync:i,fstatSync:a,readSync:o,closeSync:l}=require('fs'),{join:u,resolve:c}=require('path'),{isIP:f}=require('net'),s=require('async'),{aton4:d,aton6:y,cmp6:B,ntoa4:p,ntoa6:S,cmp:g}=require('./utils.js'),I=require('./fsWatcher.js'),{version:E}=require('../package.json'),m='dataWatcher',z=c(__dirname,global.geoDataDir||process.env.GEODATADIR||'../geoip-data/'),N={city:u(z,'geoip-city.dat'),city6:u(z,'geoip-city6.dat'),cityNames:u(z,'geoip-city-names.dat'),country:u(z,'geoip-country.dat'),country6:u(z,'geoip-country6.dat')},P=[[d('10.0.0.0'),d('10.255.255.255')],[d('172.16.0.0'),d('172.31.255.255')],[d('192.168.0.0'),d('192.168.255.255')]],h={firstIP:null,lastIP:null,lastLine:0,locationBuffer:null,locationRecordSize:88,mainBuffer:null,recordSize:24},F={firstIP:null,lastIP:null,lastLine:0,mainBuffer:null,recordSize:48};let O=JSON.parse(JSON.stringify(h)),L=JSON.parse(JSON.stringify(F));const U=e=>{let r,t,n=0,i=O.lastLine,a=O.lastIP,o=O.firstIP;const l=O.mainBuffer,u=O.locationBuffer,c=P,f=O.recordSize,s=O.locationRecordSize,d={range:[null,null],country:'',region:'',eu:'',timezone:'',city:'',ll:[null,null],metro:null,area:null};if(e>O.lastIP||e<O.firstIP)return null;for(let r=0;r<c.length;r++)if(e>=c[r][0]&&e<=c[r][1])return null;for(;;){if(r=Math.round((i-n)/2)+n,a=l.readUInt32BE(r*f),o=l.readUInt32BE(r*f+4),a<=e&&o>=e)return d.range=[a,o],10===f?d.country=l.toString('utf8',r*f+8,r*f+10):(t=l.readUInt32BE(r*f+8),-1>>>0>t&&(d.country=u.toString('utf8',t*s,t*s+2).replace(/\u0000.*/,''),d.region=u.toString('utf8',t*s+2,t*s+5).replace(/\u0000.*/,''),d.metro=u.readInt32BE(t*s+5),d.ll[0]=l.readInt32BE(r*f+12)/1e4,d.ll[1]=l.readInt32BE(r*f+16)/1e4,d.area=l.readUInt32BE(r*f+20),d.eu=u.toString('utf8',t*s+9,t*s+10).replace(/\u0000.*/,''),d.timezone=u.toString('utf8',t*s+10,t*s+42).replace(/\u0000.*/,''),d.city=u.toString('utf8',t*s+42,t*s+s).replace(/\u0000.*/,''))),d;if(n===i)return null;n===i-1?r===n?n=i:i=n:a>e?i=r:o<e&&(n=r)}},D=['0:0:0:0:0:FFFF:','::FFFF:'];function J(u){let c,f;const d=JSON.parse(JSON.stringify(h));if('function'==typeof arguments[0])s.series([i=>{s.series([r=>{e(N.cityNames,'r',((e,t)=>{c=t,r(e)}))},e=>{r(c,((r,t)=>{f=t.size,d.locationBuffer=Buffer.alloc(f),e(r)}))},e=>{t(c,d.locationBuffer,0,f,0,e)},e=>{n(c,e)},r=>{e(N.city,'r',((e,t)=>{c=t,r(e)}))},e=>{r(c,((r,t)=>{f=t.size,e(r)}))}],(t=>{if(t){if('ENOENT'!==t.code&&'EBADF'!==t.code)throw t;e(N.country,'r',((e,t)=>{e?i(e):(c=t,r(c,((e,r)=>{f=r.size,d.recordSize=10,i()})))}))}else i()}))},()=>{d.mainBuffer=Buffer.alloc(f),s.series([e=>{t(c,d.mainBuffer,0,f,0,e)},e=>{n(c,e)}],(e=>{e||(d.lastLine=f/d.recordSize-1,d.lastIP=d.mainBuffer.readUInt32BE(d.lastLine*d.recordSize+4),d.firstIP=d.mainBuffer.readUInt32BE(0),O=d),u(e)}))}]);else{try{if(c=i(N.cityNames,'r'),f=a(c).size,0===f)throw{code:'EMPTY_FILE'};O.locationBuffer=Buffer.alloc(f),o(c,O.locationBuffer,0,f,0),l(c),c=i(N.city,'r'),f=a(c).size}catch(e){if('ENOENT'!==e.code&&'EBADF'!==e.code&&'EMPTY_FILE'!==e.code)throw e;c=i(N.country,'r'),f=a(c).size,O.recordSize=10}O.mainBuffer=Buffer.alloc(f),o(c,O.mainBuffer,0,f,0),l(c),O.lastLine=f/O.recordSize-1,O.lastIP=O.mainBuffer.readUInt32BE(O.lastLine*O.recordSize+4),O.firstIP=O.mainBuffer.readUInt32BE(0)}}function T(u){let c,f;const d=JSON.parse(JSON.stringify(F));if('function'==typeof arguments[0])s.series([t=>{s.series([r=>{e(N.city6,'r',((e,t)=>{c=t,r(e)}))},e=>{r(c,((r,t)=>{f=t.size,e(r)}))}],(n=>{if(n){if('ENOENT'!==n.code&&'EBADF'!==n.code)throw n;e(N.country6,'r',((e,n)=>{e?t(e):(c=n,r(c,((e,r)=>{f=r.size,d.recordSize=34,t()})))}))}else t()}))},()=>{d.mainBuffer=Buffer.alloc(f),s.series([e=>{t(c,d.mainBuffer,0,f,0,e)},e=>{n(c,e)}],(e=>{e||(d.lastLine=f/d.recordSize-1,L=d),u(e)}))}]);else{try{if(c=i(N.city6,'r'),f=a(c).size,0===f)throw{code:'EMPTY_FILE'}}catch(e){if('ENOENT'!==e.code&&'EBADF'!==e.code&&'EMPTY_FILE'!==e.code)throw e;c=i(N.country6,'r'),f=a(c).size,L.recordSize=34}L.mainBuffer=Buffer.alloc(f),o(c,L.mainBuffer,0,f,0),l(c),L.lastLine=f/L.recordSize-1}}module.exports={cmp:g,lookup:e=>{if(!e)return null;if('number'==typeof e)return U(e);if(4===f(e))return U(d(e));if(6===f(e)){const r=(e=>{const r=e.toUpperCase();for(let e=0;e<D.length;e++){const t=D[e];if(0===r.indexOf(t))return r.substring(t.length)}return null})(e);return r?U(d(r)):(e=>{const r=L.mainBuffer,t=L.recordSize,n=O.locationBuffer,i=O.locationRecordSize,a={range:[null,null],country:'',region:'',city:'',ll:[0,0],metro:null,area:null,eu:'',timezone:''},o=(e,n)=>{const i=[];for(let a=0;a<2;a++)i.push(r.readUInt32BE(e*t+16*n+4*a));return i};L.lastIP=o(L.lastLine,1),L.firstIP=o(0,0);let l,u,c=0,f=L.lastLine,s=L.lastIP,d=L.firstIP;if(B(e,L.lastIP)>0||B(e,L.firstIP)<0)return null;for(;;){if(l=Math.round((f-c)/2)+c,s=o(l,0),d=o(l,1),B(s,e)<=0&&B(d,e)>=0)return 34===t?a.country=r.toString('utf8',l*t+32,l*t+34).replace(/\u0000.*/,''):(u=r.readUInt32BE(l*t+32),-1>>>0>u&&(a.country=n.toString('utf8',u*i,u*i+2).replace(/\u0000.*/,''),a.region=n.toString('utf8',u*i+2,u*i+5).replace(/\u0000.*/,''),a.metro=n.readInt32BE(u*i+5),a.ll[0]=r.readInt32BE(l*t+36)/1e4,a.ll[1]=r.readInt32BE(l*t+40)/1e4,a.area=r.readUInt32BE(l*t+44),a.eu=n.toString('utf8',u*i+9,u*i+10).replace(/\u0000.*/,''),a.timezone=n.toString('utf8',u*i+10,u*i+42).replace(/\u0000.*/,''),a.city=n.toString('utf8',u*i+42,u*i+i).replace(/\u0000.*/,''))),a;if(c===f)return null;c===f-1?l===c?c=f:f=c:B(s,e)>0?f=l:B(d,e)<0&&(c=l)}})(y(e))}return null},pretty:e=>'string'==typeof e?e:'number'==typeof e?p(e):Array.isArray(e)?S(e):e,startWatchingDataUpdate:e=>{I.makeFsWatchFilter(m,z,6e4,(async()=>{await s.series([e=>{J(e)},e=>{T(e)}],e)}))},stopWatchingDataUpdate:()=>I.stopWatching(m),clear:()=>{O=JSON.parse(JSON.stringify(h)),L=JSON.parse(JSON.stringify(F))},reloadDataSync:()=>{J(),T()},reloadData:async e=>{await s.series([e=>{J(e)},e=>{T(e)}],e)},version:E},J(),T();
1
+ const{open:e,fstat:r,read:t,close:n,openSync:i,fstatSync:a,readSync:o,closeSync:l}=require('fs'),{join:u,resolve:c}=require('path'),{isIP:f}=require('net'),s=require('async'),{aton4:d,aton6:y,cmp6:B,ntoa4:p,ntoa6:S,cmp:g}=require('./utils.js'),I=require('./fsWatcher.js'),{version:E}=require('../package.json'),m='dataWatcher',z=c(__dirname,global.geoDataDir||process.env.GEODATADIR||'../geoip-data/'),N={city:u(z,'geoip-city.dat'),city6:u(z,'geoip-city6.dat'),cityNames:u(z,'geoip-city-names.dat'),country:u(z,'geoip-country.dat'),country6:u(z,'geoip-country6.dat')},P=[[d('10.0.0.0'),d('10.255.255.255')],[d('172.16.0.0'),d('172.31.255.255')],[d('192.168.0.0'),d('192.168.255.255')]],h={firstIP:null,lastIP:null,lastLine:0,locationBuffer:null,locationRecordSize:88,mainBuffer:null,recordSize:24},F={firstIP:null,lastIP:null,lastLine:0,mainBuffer:null,recordSize:48};let O=JSON.parse(JSON.stringify(h)),L=JSON.parse(JSON.stringify(F));const U=e=>{let r,t,n=0,i=O.lastLine,a=O.lastIP,o=O.firstIP;const l=O.mainBuffer,u=O.locationBuffer,c=P,f=O.recordSize,s=O.locationRecordSize,d={range:[null,null],country:'',region:'',eu:'',timezone:'',city:'',ll:[null,null],metro:null,area:null};if(e>O.lastIP||e<O.firstIP)return null;for(let r=0;r<c.length;r++)if(e>=c[r][0]&&e<=c[r][1])return null;for(;;){if(r=Math.round((i-n)/2)+n,a=l.readUInt32BE(r*f),o=l.readUInt32BE(r*f+4),a<=e&&o>=e)return d.range=[a,o],10===f?d.country=l.toString('utf8',r*f+8,r*f+10):(t=l.readUInt32BE(r*f+8),-1>>>0>t&&(d.country=u.toString('utf8',t*s,t*s+2).replace(/\u0000.*/,''),d.region=u.toString('utf8',t*s+2,t*s+5).replace(/\u0000.*/,''),d.metro=u.readInt32BE(t*s+5),d.ll[0]=l.readInt32BE(r*f+12)/1e4,d.ll[1]=l.readInt32BE(r*f+16)/1e4,d.area=l.readUInt32BE(r*f+20),d.eu=u.toString('utf8',t*s+9,t*s+10).replace(/\u0000.*/,''),d.timezone=u.toString('utf8',t*s+10,t*s+42).replace(/\u0000.*/,''),d.city=u.toString('utf8',t*s+42,t*s+s).replace(/\u0000.*/,''))),d;if(n===i)return null;n===i-1?r===n?n=i:i=n:a>e?i=r:o<e&&(n=r)}},D=['0:0:0:0:0:FFFF:','::FFFF:'];function J(u){let c,f;const d=JSON.parse(JSON.stringify(h));if('function'==typeof arguments[0])s.series([i=>{s.series([r=>{e(N.cityNames,'r',(e,t)=>{c=t,r(e)})},e=>{r(c,(r,t)=>{f=t.size,d.locationBuffer=Buffer.alloc(f),e(r)})},e=>{t(c,d.locationBuffer,0,f,0,e)},e=>{n(c,e)},r=>{e(N.city,'r',(e,t)=>{c=t,r(e)})},e=>{r(c,(r,t)=>{f=t.size,e(r)})}],t=>{if(t){if('ENOENT'!==t.code&&'EBADF'!==t.code)throw t;e(N.country,'r',(e,t)=>{e?i(e):(c=t,r(c,(e,r)=>{f=r.size,d.recordSize=10,i()}))})}else i()})},()=>{d.mainBuffer=Buffer.alloc(f),s.series([e=>{t(c,d.mainBuffer,0,f,0,e)},e=>{n(c,e)}],e=>{e||(d.lastLine=f/d.recordSize-1,d.lastIP=d.mainBuffer.readUInt32BE(d.lastLine*d.recordSize+4),d.firstIP=d.mainBuffer.readUInt32BE(0),O=d),u(e)})}]);else{try{if(c=i(N.cityNames,'r'),f=a(c).size,0===f)throw{code:'EMPTY_FILE'};O.locationBuffer=Buffer.alloc(f),o(c,O.locationBuffer,0,f,0),l(c),c=i(N.city,'r'),f=a(c).size}catch(e){if('ENOENT'!==e.code&&'EBADF'!==e.code&&'EMPTY_FILE'!==e.code)throw e;c=i(N.country,'r'),f=a(c).size,O.recordSize=10}O.mainBuffer=Buffer.alloc(f),o(c,O.mainBuffer,0,f,0),l(c),O.lastLine=f/O.recordSize-1,O.lastIP=O.mainBuffer.readUInt32BE(O.lastLine*O.recordSize+4),O.firstIP=O.mainBuffer.readUInt32BE(0)}}function T(u){let c,f;const d=JSON.parse(JSON.stringify(F));if('function'==typeof arguments[0])s.series([t=>{s.series([r=>{e(N.city6,'r',(e,t)=>{c=t,r(e)})},e=>{r(c,(r,t)=>{f=t.size,e(r)})}],n=>{if(n){if('ENOENT'!==n.code&&'EBADF'!==n.code)throw n;e(N.country6,'r',(e,n)=>{e?t(e):(c=n,r(c,(e,r)=>{f=r.size,d.recordSize=34,t()}))})}else t()})},()=>{d.mainBuffer=Buffer.alloc(f),s.series([e=>{t(c,d.mainBuffer,0,f,0,e)},e=>{n(c,e)}],e=>{e||(d.lastLine=f/d.recordSize-1,L=d),u(e)})}]);else{try{if(c=i(N.city6,'r'),f=a(c).size,0===f)throw{code:'EMPTY_FILE'}}catch(e){if('ENOENT'!==e.code&&'EBADF'!==e.code&&'EMPTY_FILE'!==e.code)throw e;c=i(N.country6,'r'),f=a(c).size,L.recordSize=34}L.mainBuffer=Buffer.alloc(f),o(c,L.mainBuffer,0,f,0),l(c),L.lastLine=f/L.recordSize-1}}module.exports={cmp:g,lookup:e=>{if(!e)return null;if('number'==typeof e)return U(e);if(4===f(e))return U(d(e));if(6===f(e)){const r=(e=>{const r=e.toUpperCase();for(let e=0;e<D.length;e++){const t=D[e];if(0===r.indexOf(t))return r.substring(t.length)}return null})(e);return r?U(d(r)):(e=>{const r=L.mainBuffer,t=L.recordSize,n=O.locationBuffer,i=O.locationRecordSize,a={range:[null,null],country:'',region:'',city:'',ll:[0,0],metro:null,area:null,eu:'',timezone:''},o=(e,n)=>{const i=[];for(let a=0;a<2;a++)i.push(r.readUInt32BE(e*t+16*n+4*a));return i};L.lastIP=o(L.lastLine,1),L.firstIP=o(0,0);let l,u,c=0,f=L.lastLine,s=L.lastIP,d=L.firstIP;if(B(e,L.lastIP)>0||B(e,L.firstIP)<0)return null;for(;;){if(l=Math.round((f-c)/2)+c,s=o(l,0),d=o(l,1),B(s,e)<=0&&B(d,e)>=0)return 34===t?a.country=r.toString('utf8',l*t+32,l*t+34).replace(/\u0000.*/,''):(u=r.readUInt32BE(l*t+32),-1>>>0>u&&(a.country=n.toString('utf8',u*i,u*i+2).replace(/\u0000.*/,''),a.region=n.toString('utf8',u*i+2,u*i+5).replace(/\u0000.*/,''),a.metro=n.readInt32BE(u*i+5),a.ll[0]=r.readInt32BE(l*t+36)/1e4,a.ll[1]=r.readInt32BE(l*t+40)/1e4,a.area=r.readUInt32BE(l*t+44),a.eu=n.toString('utf8',u*i+9,u*i+10).replace(/\u0000.*/,''),a.timezone=n.toString('utf8',u*i+10,u*i+42).replace(/\u0000.*/,''),a.city=n.toString('utf8',u*i+42,u*i+i).replace(/\u0000.*/,''))),a;if(c===f)return null;c===f-1?l===c?c=f:f=c:B(s,e)>0?f=l:B(d,e)<0&&(c=l)}})(y(e))}return null},pretty:e=>'string'==typeof e?e:'number'==typeof e?p(e):Array.isArray(e)?S(e):e,startWatchingDataUpdate:e=>{I.makeFsWatchFilter(m,z,6e4,async()=>{await s.series([e=>{J(e)},e=>{T(e)}],e)})},stopWatchingDataUpdate:()=>I.stopWatching(m),clear:()=>{O=JSON.parse(JSON.stringify(h)),L=JSON.parse(JSON.stringify(F))},reloadDataSync:()=>{J(),T()},reloadData:async e=>{await s.series([e=>{J(e)},e=>{T(e)}],e)},version:E},J(),T();
package/package.json CHANGED
@@ -1,44 +1,42 @@
1
1
  {
2
2
  "name": "geoip-lite2",
3
- "version": "2.2.4",
3
+ "version": "2.2.6",
4
4
  "description": "A light weight native JavaScript implementation of GeoIP API from MaxMind. Improved and faster version by Sefinek.",
5
5
  "keywords": [
6
6
  "city",
7
7
  "country",
8
- "fast geoip",
9
- "fast geolocation",
10
- "geo ip",
11
- "geo location api",
12
- "geo",
8
+ "fast-geoip",
9
+ "fast-geolocation",
13
10
  "geo-ip",
14
- "geoip api",
15
- "geoip data",
16
- "geoip database",
17
- "geoip",
11
+ "geo-location-api",
12
+ "geo",
18
13
  "geoip-api",
19
- "geoip2 lite",
20
- "geoip2 lite2",
14
+ "geoip-data",
15
+ "geoip-database",
16
+ "geoip",
17
+ "geoip2-lite",
18
+ "geoip2-lite2",
21
19
  "geoip2",
22
20
  "geolite",
23
21
  "geolite2",
24
22
  "geolocation",
25
23
  "geolookup",
26
- "global ip data",
27
- "ip analytics",
28
- "ip geo",
29
- "ip geolocation",
30
- "ip georesolution",
31
- "ip location",
32
- "ip lookup",
33
- "ip mapping",
34
- "ip resolver",
35
- "ip tracking",
24
+ "global-ip-data",
25
+ "ip-analytics",
26
+ "ip-geo",
27
+ "ip-geolocation",
28
+ "ip-georesolution",
29
+ "ip-location",
30
+ "ip-lookup",
31
+ "ip-mapping",
32
+ "ip-resolver",
33
+ "ip-tracking",
36
34
  "ip",
37
35
  "ipv4",
38
36
  "ipv6",
39
37
  "location",
40
- "maxmind integration",
41
- "maxmind lite",
38
+ "maxmind-integration",
39
+ "maxmind-lite",
42
40
  "maxmind",
43
41
  "region",
44
42
  "state"
@@ -53,12 +51,17 @@
53
51
  },
54
52
  "license": "Apache-2.0",
55
53
  "author": "Philip Tellis <philip@bluesmoon.info> (https://bluesmoon.info)",
54
+ "type": "commonjs",
56
55
  "main": "lib-minified/main.js",
57
56
  "types": "index.d.ts",
57
+ "directories": {
58
+ "lib": "lib",
59
+ "test": "test"
60
+ },
58
61
  "scripts": {
59
- "up": "ncu -u && npm install && npm update && npm audit fix",
60
62
  "minify": "node minify.js",
61
63
  "test": "jest test",
64
+ "up": "ncu -u && npm install && npm update && npm audit fix",
62
65
  "updatedb": "node utils-minified/updatedb.js",
63
66
  "updatedb-debug": "node utils-minified/updatedb.js debug",
64
67
  "updatedb-force": "node utils-minified/updatedb.js force"
@@ -71,10 +74,10 @@
71
74
  "rimraf": "^6.0.1"
72
75
  },
73
76
  "devDependencies": {
74
- "@eslint/js": "^9.21.0",
75
- "globals": "^16.0.0",
76
- "jest": "^29.7.0",
77
- "terser": "^5.39.0"
77
+ "@eslint/js": "^9.29.0",
78
+ "globals": "^16.2.0",
79
+ "jest": "^30.0.2",
80
+ "terser": "^5.43.1"
78
81
  },
79
82
  "engines": {
80
83
  "node": ">=10.3.0"
@@ -44,7 +44,7 @@ describe('GeoIP2', () => {
44
44
  expect(actual.country).toBe('JP');
45
45
  expect(actual.eu).toBe('0');
46
46
  expect(actual.timezone).toBe('Asia/Tokyo');
47
- expect(actual.city).toBe('Roppongi');
47
+ expect(actual.city).toBe('');
48
48
  expect(actual.ll).toBeTruthy();
49
49
  expect(actual.metro).toBe(0);
50
50
  expect(actual.area).toBe(500);
@@ -56,10 +56,10 @@ describe('GeoIP2', () => {
56
56
  expect(actual.region).toBe('IVA');
57
57
  expect(actual.eu).toBe('0');
58
58
  expect(actual.timezone).toBe('Europe/Moscow');
59
- expect(actual.city).toBe('Shuya');
59
+ expect(actual.city).toBe('Kineshma');
60
60
  expect(actual.ll).toBeTruthy();
61
61
  expect(actual.metro).toBe(0);
62
- expect(actual.area).toBe(50);
62
+ expect(actual.area).toBe(100);
63
63
  });
64
64
  });
65
65
 
@@ -70,10 +70,10 @@ describe('GeoIP2', () => {
70
70
  expect(actual.region).toBe('06');
71
71
  expect(actual.eu).toBe('1');
72
72
  expect(actual.timezone).toBe('Europe/Warsaw');
73
- expect(actual.city).toBe('Cyców');
73
+ expect(actual.city).toBe('Lublin');
74
74
  expect(actual.ll).toBeTruthy();
75
75
  expect(actual.metro).toBe(0);
76
- expect(actual.area).toBe(200);
76
+ expect(actual.area).toBe(100);
77
77
  });
78
78
 
79
79
  it('should match data for IPv6 - NL ', () => {
@@ -105,7 +105,7 @@ describe('GeoIP2', () => {
105
105
  it('should return UTF8 city name', () => {
106
106
  const actual = geoIp2.lookup('2.139.175.1');
107
107
  expect(actual.country).toBe('ES');
108
- expect(actual.city).toBe('Madrid');
108
+ expect(actual.city).toBe('Barcelona');
109
109
  expect(actual.timezone).toBe('Europe/Madrid');
110
110
  });
111
111
 
@@ -1 +1 @@
1
- const{name:e,version:t}=require('../package.json'),n=`Mozilla/5.0 (compatible; ${e}/${t}; +https://github.com/sefinek/geoip-lite2)`,o=require('fs'),r=require('http'),s=require('https'),i=require('path'),c=require('zlib'),a=require('readline'),l=require('async'),{decodeStream:u}=require('iconv-lite'),d=require('rimraf').sync,p=require('adm-zip'),f=require('../lib/utils.js'),{Address6:h,Address4:g}=require('ip-address'),w=process.argv.slice(2);let m=w.find((e=>null!==e.match(/^license_key=[a-zA-Z0-9]+/)));void 0===m&&void 0!==process.env.LICENSE_KEY&&(m=`license_key=${process.env.LICENSE_KEY}`);let y=w.find((e=>null!==e.match(/^geoDataDir=[\w./]+/)));void 0===y&&void 0!==process.env.GEODATADIR&&(y=`geoDataDir=${process.env.GEODATADIR}`);let I=i.resolve(__dirname,'..','geoip-data');void 0!==y&&(I=i.resolve(process.cwd(),y.split('=')[1]),o.existsSync(I)||(console.log('ERROR: Directory doesn\'t exist: '+I),process.exit(1)));const v=process.env.GEOTMPDIR||i.resolve(__dirname,'..','tmp'),S={},E={NaN:-1},x=[{type:'country',url:`https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-Country-CSV&suffix=zip&${m}`,checksum:`https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-Country-CSV&suffix=zip.sha256&${m}`,fileName:'GeoLite2-Country-CSV.zip',src:['GeoLite2-Country-Locations-en.csv','GeoLite2-Country-Blocks-IPv4.csv','GeoLite2-Country-Blocks-IPv6.csv'],dest:['','geoip-country.dat','geoip-country6.dat']},{type:'city',url:`https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-City-CSV&suffix=zip&${m}`,checksum:`https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-City-CSV&suffix=zip.sha256&${m}`,fileName:'GeoLite2-City-CSV.zip',src:['GeoLite2-City-Locations-en.csv','GeoLite2-City-Blocks-IPv4.csv','GeoLite2-City-Blocks-IPv6.csv'],dest:['geoip-city-names.dat','geoip-city.dat','geoip-city6.dat']}];function k(e){const t=i.dirname(e);o.existsSync(t)||o.mkdirSync(t)}const D=/^\s*(?:'[^'\\]*(?:\\[\S\s][^'\\]*)*'|"[^"\\]*(?:\\[\S\s][^"\\]*)*"|[^,'"\s\\]*(?:\s+[^,'"\s\\]+)*)\s*(?:,\s*(?:'[^'\\]*(?:\\[\S\s][^'\\]*)*'|"[^"\\]*(?:\\[\S\s][^"\\]*)*"|[^,'"\s\\]*(?:\s+[^,'"\s\\]+)*)\s*)*$/,C=/(?!\s*$)\s*(?:'([^'\\]*(?:\\[\S\s][^'\\]*)*)'|"([^"\\]*(?:\\[\S\s][^"\\]*)*)"|([^,'"\s\\]*(?:\s+[^,'"\s\\]+)*))\s*(?:,|$)/g;function R(e){if(!D.test(e)&&(e=function(e){let t=0,n=-1;for(e=e.replace(/""/,'\\"').replace(/'/g,'\\\'');t<e.length&&n<e.length;)t=n,n=e.indexOf(',',t+1),n<0&&(n=e.length),e.indexOf('\'',t||0)>-1&&e.indexOf('\'',t)<n&&'"'!=e[t+1]&&'"'!=e[n-1]&&(n=(e=e.substr(0,t+1)+'"'+e.substr(t+1,n-t-1)+'"'+e.substr(n,e.length-n)).indexOf(',',n+1),n<0&&(n=e.length));return e}(e),!D.test(e)))return null;const t=[];return e.replace(C,((e,n,o,r)=>(void 0!==n?t.push(n.replace(/\\'/g,'\'')):void 0!==o?t.push(o.replace(/\\"/g,'"').replace(/\\'/g,'\'')):void 0!==r&&t.push(r),''))),/,\s*$/.test(e)&&t.push(''),t}function B(e){const t=new URL(e),o={protocol:t.protocol,host:t.host,path:t.pathname+t.search,headers:{'User-Agent':n}};if(process.env.http_proxy||process.env.https_proxy)try{const e=require('https-proxy-agent');o.agent=new e(process.env.http_proxy||process.env.https_proxy)}catch(e){console.error(`Install https-proxy-agent to use an HTTP/HTTPS proxy. ${e.message}`),process.exit(-1)}return o}function _(e,t){if(-1!==w.indexOf('force'))return t(null,e);const n=e.checksum;if(void 0===n)return t(null,e);o.readFile(i.join(I,`${e.type}.checksum`),{encoding:'utf8'},((o,i)=>{!o&&i&&i.length&&(e.checkValue=i),console.log('Checking',e.fileName);var c=s.get(B(n),(function n(o){const i=o.statusCode;if([301,302,303,307,308].includes(i))return s.get(B(o.headers.location),n);200!==i&&(console.error(o.data),console.error('ERROR: HTTP Request Failed [%d %s]',i,r.STATUS_CODES[i]),c.end(),process.exit(1));let a='';o.on('data',(e=>{a+=e})),o.on('end',(()=>{a&&a.length?a===e.checkValue?(console.log(`Database "${e.type}" is up to date`),e.skip=!0):(console.log(`Database "${e.type}" has new data`),e.checkValue=a):(console.error(`ERROR: Could not retrieve checksum for ${e.type}. Aborting.`),console.error('Run with "force" to update without checksum'),c.end(),process.exit(1)),t(null,e)}))}))}))}function A(e,t){if(e.skip)return t(null,null,null,e);const n=e.url;let a=e.fileName;const l='.gz'===i.extname(a);l&&(a=a.replace('.gz',''));const u=i.join(v,a);if(o.existsSync(u))return t(null,u,a,e);console.log('Fetching',a),k(u);var d=s.get(B(n),(function n(i){const p=i.statusCode;if([301,302,303,307,308].includes(p))return s.get(B(i.headers.location),n);let f;200!==p&&(console.error('ERROR: HTTP Request Failed [%d %s]',p,r.STATUS_CODES[p]),d.end(),process.exit(1));const h=o.createWriteStream(u);f=l?i.pipe(c.createGunzip()).pipe(h):i.pipe(h),f.on('close',(()=>{console.log(' DONE'),t(null,u,a,e)}))}));process.stdout.write(`Retrieving ${a}...`)}function O(e,t,n,r){if(n.skip)return r(null,n);'.zip'!==i.extname(t)||(process.stdout.write('Extracting '+t+'...'),new p(e).getEntries().forEach((e=>{if(e.isDirectory)return;const t=e.entryName.split('/'),n=t[t.length-1],r=i.join(v,n);o.writeFileSync(r,e.getData())})),console.log(' DONE')),r(null,n)}async function b(e,t){var n,r;let s=0;function c(e){const t=R(e);if(!t||t.length<6)return console.warn('weird line: %s::',e);let o,i,c;s++;const a=S[t[1]];let l,u,d;if(a){if(t[0].match(/:/)){for(u=34,c=new h(t[0]),o=f.aton6(c.startAddress().correctForm()),i=f.aton6(c.endAddress().correctForm()),l=Buffer.alloc(u),d=0;d<o.length;d++)l.writeUInt32BE(o[d],4*d);for(d=0;d<i.length;d++)l.writeUInt32BE(i[d],16+4*d)}else u=10,c=new g(t[0]),o=parseInt(c.startAddress().bigInt(),10),i=parseInt(c.endAddress().bigInt(),10),l=Buffer.alloc(u),l.fill(0),l.writeUInt32BE(o,0),l.writeUInt32BE(i,4);return l.write(a,u-2),Date.now()-n>5e3&&(n=Date.now(),process.stdout.write(`\nStill working (${s})...`)),r._writableState.needDrain?new Promise((e=>{r.write(l,e)})):r.write(l)}}const l=i.join(I,t),u=i.join(v,e);d(l),k(l),process.stdout.write('\nProcessing data (may take a moment)...'),n=Date.now(),r=o.createWriteStream(l);const p=a.createInterface({input:o.createReadStream(u),crlfDelay:1/0});let w=0;for await(const e of p)w++,1!==w&&await c(e);r.close(),console.log(' DONE')}async function $(e,t){var n,r;let s=0;async function c(e){if(e.match(/^Copyright/)||!e.match(/\d/))return;const t=R(e);if(!t)return console.warn('Weird line: %s::',e);let o,i,c,a,l,u,d,p,w,m;if(s++,t[0].match(/:/)){let e=0;for(u=48,c=new h(t[0]),o=f.aton6(c.startAddress().correctForm()),i=f.aton6(c.endAddress().correctForm()),a=parseInt(t[1],10),a=E[a],l=Buffer.alloc(u),l.fill(0),m=0;m<o.length;m++)l.writeUInt32BE(o[m],e),e+=4;for(m=0;m<i.length;m++)l.writeUInt32BE(i[m],e),e+=4;l.writeUInt32BE(a>>>0,32),d=Math.round(1e4*parseFloat(t[7])),p=Math.round(1e4*parseFloat(t[8])),w=parseInt(t[9],10),l.writeInt32BE(d,36),l.writeInt32BE(p,40),l.writeInt32BE(w,44)}else u=24,c=new g(t[0]),o=parseInt(c.startAddress().bigInt(),10),i=parseInt(c.endAddress().bigInt(),10),a=parseInt(t[1],10),a=E[a],l=Buffer.alloc(u),l.fill(0),l.writeUInt32BE(o>>>0,0),l.writeUInt32BE(i>>>0,4),l.writeUInt32BE(a>>>0,8),d=Math.round(1e4*parseFloat(t[7])),p=Math.round(1e4*parseFloat(t[8])),w=parseInt(t[9],10),l.writeInt32BE(d,12),l.writeInt32BE(p,16),l.writeInt32BE(w,20);return Date.now()-n>5e3&&(n=Date.now(),process.stdout.write('\nStill working ('+s+')...')),r._writableState.needDrain?new Promise((e=>{r.write(l,e)})):r.write(l)}const l=i.join(I,t),u=i.join(v,e);d(l),process.stdout.write('\nProcessing data (may take a moment)...'),n=Date.now(),r=o.createWriteStream(l);const p=a.createInterface({input:o.createReadStream(u),crlfDelay:1/0});let w=0;for await(const e of p)w++,1!==w&&await c(e);r.close()}function q(e,t){if(e.skip)return t(null,e);const n=e.type,r=e.src,s=e.dest;'country'===n?Array.isArray(r)?function(e,t){const n=i.join(v,e);process.stdout.write('Processing lookup data (may take a moment)...');const r=a.createInterface({input:o.createReadStream(n).pipe(u('latin1')),output:process.stdout,terminal:!1});let s=0;r.on('line',(e=>{s>0&&function(e){const t=R(e);!t||t.length<6?console.log('Weird line: %s::',e):S[t[0]]=t[4]}(e),s++})),r.on('close',(()=>{console.log(' DONE'),t()}))}(r[0],(()=>{b(r[1],s[1]).then((()=>b(r[2],s[2]))).then((()=>{t(null,e)}))})):b(r,s):'city'===n&&function(e,t,n){let r=null,s=0;const c=i.join(I,t),l=i.join(v,e);d(c);var p=o.openSync(c,'w');const f=a.createInterface({input:o.createReadStream(l).pipe(u('utf-8')),output:process.stdout,terminal:!1});let h=0;f.on('line',(e=>{h>0&&function(e){if(e.match(/^Copyright/)||!e.match(/\d/))return;const t=Buffer.alloc(88),n=R(e);if(!n)return void console.warn('Weird line: %s::',e);r=parseInt(n[0]),E[r]=s;const i=n[4],c=n[6],a=n[10],l=parseInt(n[11]),u=n[12],d=n[13];t.fill(0),t.write(i,0),t.write(c,2),l&&t.writeInt32BE(l,5),t.write(d,9),t.write(u,10),t.write(a,42),o.writeSync(p,t,0,t.length,null),s++}(e),h++})),f.on('close',n)}(r[0],s[0],(()=>{$(r[1],s[1]).then((()=>(console.log('\nCity data processed'),$(r[2],s[2])))).then((()=>{console.log(' DONE'),t(null,e)}))}))}function L(e,t){if(e.skip||!e.checkValue)return t();o.writeFile(i.join(I,e.type+'.checksum'),e.checkValue,'utf8',(n=>{n&&console.log('Failed to Update checksums! Database:',e.type),t()}))}m||(console.error('ERROR: Missing license_key'),process.exit(1)),d(v),k(v),l.eachSeries(x,((e,t)=>{l.seq(_,A,O,q,L)(e,t)}),(e=>{e?(console.error('Failed to update databases from MaxMind!',e),process.exit(1)):(console.log('Successfully updated databases from MaxMind'),-1!==w.indexOf('debug')||d(v),process.exit(0))}));
1
+ const{name:e,version:t}=require('../package.json'),n=`Mozilla/5.0 (compatible; ${e}/${t}; +https://github.com/sefinek/geoip-lite2)`,o=require('fs'),r=require('http'),s=require('https'),i=require('path'),c=require('zlib'),a=require('readline'),l=require('async'),{decodeStream:u}=require('iconv-lite'),d=require('rimraf').sync,p=require('adm-zip'),f=require('../lib/utils.js'),{Address6:h,Address4:g}=require('ip-address'),w=process.argv.slice(2);let m=w.find(e=>null!==e.match(/^license_key=[a-zA-Z0-9]+/));void 0===m&&void 0!==process.env.LICENSE_KEY&&(m=`license_key=${process.env.LICENSE_KEY}`);let y=w.find(e=>null!==e.match(/^geoDataDir=[\w./]+/));void 0===y&&void 0!==process.env.GEODATADIR&&(y=`geoDataDir=${process.env.GEODATADIR}`);let I=i.resolve(__dirname,'..','geoip-data');void 0!==y&&(I=i.resolve(process.cwd(),y.split('=')[1]),o.existsSync(I)||(console.log('ERROR: Directory doesn\'t exist: '+I),process.exit(1)));const v=process.env.GEOTMPDIR||i.resolve(__dirname,'..','tmp'),S={},E={NaN:-1},x=[{type:'country',url:`https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-Country-CSV&suffix=zip&${m}`,checksum:`https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-Country-CSV&suffix=zip.sha256&${m}`,fileName:'GeoLite2-Country-CSV.zip',src:['GeoLite2-Country-Locations-en.csv','GeoLite2-Country-Blocks-IPv4.csv','GeoLite2-Country-Blocks-IPv6.csv'],dest:['','geoip-country.dat','geoip-country6.dat']},{type:'city',url:`https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-City-CSV&suffix=zip&${m}`,checksum:`https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-City-CSV&suffix=zip.sha256&${m}`,fileName:'GeoLite2-City-CSV.zip',src:['GeoLite2-City-Locations-en.csv','GeoLite2-City-Blocks-IPv4.csv','GeoLite2-City-Blocks-IPv6.csv'],dest:['geoip-city-names.dat','geoip-city.dat','geoip-city6.dat']}];function k(e){const t=i.dirname(e);o.existsSync(t)||o.mkdirSync(t)}const D=/^\s*(?:'[^'\\]*(?:\\[\S\s][^'\\]*)*'|"[^"\\]*(?:\\[\S\s][^"\\]*)*"|[^,'"\s\\]*(?:\s+[^,'"\s\\]+)*)\s*(?:,\s*(?:'[^'\\]*(?:\\[\S\s][^'\\]*)*'|"[^"\\]*(?:\\[\S\s][^"\\]*)*"|[^,'"\s\\]*(?:\s+[^,'"\s\\]+)*)\s*)*$/,C=/(?!\s*$)\s*(?:'([^'\\]*(?:\\[\S\s][^'\\]*)*)'|"([^"\\]*(?:\\[\S\s][^"\\]*)*)"|([^,'"\s\\]*(?:\s+[^,'"\s\\]+)*))\s*(?:,|$)/g;function R(e){if(!D.test(e)&&(e=function(e){let t=0,n=-1;for(e=e.replace(/""/,'\\"').replace(/'/g,'\\\'');t<e.length&&n<e.length;)t=n,n=e.indexOf(',',t+1),n<0&&(n=e.length),e.indexOf('\'',t||0)>-1&&e.indexOf('\'',t)<n&&'"'!=e[t+1]&&'"'!=e[n-1]&&(n=(e=e.substr(0,t+1)+'"'+e.substr(t+1,n-t-1)+'"'+e.substr(n,e.length-n)).indexOf(',',n+1),n<0&&(n=e.length));return e}(e),!D.test(e)))return null;const t=[];return e.replace(C,(e,n,o,r)=>(void 0!==n?t.push(n.replace(/\\'/g,'\'')):void 0!==o?t.push(o.replace(/\\"/g,'"').replace(/\\'/g,'\'')):void 0!==r&&t.push(r),'')),/,\s*$/.test(e)&&t.push(''),t}function B(e){const t=new URL(e),o={protocol:t.protocol,host:t.host,path:t.pathname+t.search,headers:{'User-Agent':n}};if(process.env.http_proxy||process.env.https_proxy)try{const e=require('https-proxy-agent');o.agent=new e(process.env.http_proxy||process.env.https_proxy)}catch(e){console.error(`Install https-proxy-agent to use an HTTP/HTTPS proxy. ${e.message}`),process.exit(-1)}return o}function _(e,t){if(-1!==w.indexOf('force'))return t(null,e);const n=e.checksum;if(void 0===n)return t(null,e);o.readFile(i.join(I,`${e.type}.checksum`),{encoding:'utf8'},(o,i)=>{!o&&i&&i.length&&(e.checkValue=i),console.log('Checking',e.fileName);var c=s.get(B(n),function n(o){const i=o.statusCode;if([301,302,303,307,308].includes(i))return s.get(B(o.headers.location),n);200!==i&&(console.error(o.data),console.error('ERROR: HTTP Request Failed [%d %s]',i,r.STATUS_CODES[i]),c.end(),process.exit(1));let a='';o.on('data',e=>{a+=e}),o.on('end',()=>{a&&a.length?a===e.checkValue?(console.log(`Database "${e.type}" is up to date`),e.skip=!0):(console.log(`Database "${e.type}" has new data`),e.checkValue=a):(console.error(`ERROR: Could not retrieve checksum for ${e.type}. Aborting.`),console.error('Run with "force" to update without checksum'),c.end(),process.exit(1)),t(null,e)})})})}function A(e,t){if(e.skip)return t(null,null,null,e);const n=e.url;let a=e.fileName;const l='.gz'===i.extname(a);l&&(a=a.replace('.gz',''));const u=i.join(v,a);if(o.existsSync(u))return t(null,u,a,e);console.log('Fetching',a),k(u);var d=s.get(B(n),function n(i){const p=i.statusCode;if([301,302,303,307,308].includes(p))return s.get(B(i.headers.location),n);let f;200!==p&&(console.error('ERROR: HTTP Request Failed [%d %s]',p,r.STATUS_CODES[p]),d.end(),process.exit(1));const h=o.createWriteStream(u);f=l?i.pipe(c.createGunzip()).pipe(h):i.pipe(h),f.on('close',()=>{console.log(' DONE'),t(null,u,a,e)})});process.stdout.write(`Retrieving ${a}...`)}function O(e,t,n,r){if(n.skip)return r(null,n);'.zip'!==i.extname(t)||(process.stdout.write('Extracting '+t+'...'),new p(e).getEntries().forEach(e=>{if(e.isDirectory)return;const t=e.entryName.split('/'),n=t[t.length-1],r=i.join(v,n);o.writeFileSync(r,e.getData())}),console.log(' DONE')),r(null,n)}async function b(e,t){var n,r;let s=0;function c(e){const t=R(e);if(!t||t.length<6)return console.warn('weird line: %s::',e);let o,i,c;s++;const a=S[t[1]];let l,u,d;if(a){if(t[0].match(/:/)){for(u=34,c=new h(t[0]),o=f.aton6(c.startAddress().correctForm()),i=f.aton6(c.endAddress().correctForm()),l=Buffer.alloc(u),d=0;d<o.length;d++)l.writeUInt32BE(o[d],4*d);for(d=0;d<i.length;d++)l.writeUInt32BE(i[d],16+4*d)}else u=10,c=new g(t[0]),o=parseInt(c.startAddress().bigInt(),10),i=parseInt(c.endAddress().bigInt(),10),l=Buffer.alloc(u),l.fill(0),l.writeUInt32BE(o,0),l.writeUInt32BE(i,4);return l.write(a,u-2),Date.now()-n>5e3&&(n=Date.now(),process.stdout.write(`\nStill working (${s})...`)),r._writableState.needDrain?new Promise(e=>{r.write(l,e)}):r.write(l)}}const l=i.join(I,t),u=i.join(v,e);d(l),k(l),process.stdout.write('\nProcessing data (may take a moment)...'),n=Date.now(),r=o.createWriteStream(l);const p=a.createInterface({input:o.createReadStream(u),crlfDelay:1/0});let w=0;for await(const e of p)w++,1!==w&&await c(e);r.close(),console.log(' DONE')}async function $(e,t){var n,r;let s=0;async function c(e){if(e.match(/^Copyright/)||!e.match(/\d/))return;const t=R(e);if(!t)return console.warn('Weird line: %s::',e);let o,i,c,a,l,u,d,p,w,m;if(s++,t[0].match(/:/)){let e=0;for(u=48,c=new h(t[0]),o=f.aton6(c.startAddress().correctForm()),i=f.aton6(c.endAddress().correctForm()),a=parseInt(t[1],10),a=E[a],l=Buffer.alloc(u),l.fill(0),m=0;m<o.length;m++)l.writeUInt32BE(o[m],e),e+=4;for(m=0;m<i.length;m++)l.writeUInt32BE(i[m],e),e+=4;l.writeUInt32BE(a>>>0,32),d=Math.round(1e4*parseFloat(t[7])),p=Math.round(1e4*parseFloat(t[8])),w=parseInt(t[9],10),l.writeInt32BE(d,36),l.writeInt32BE(p,40),l.writeInt32BE(w,44)}else u=24,c=new g(t[0]),o=parseInt(c.startAddress().bigInt(),10),i=parseInt(c.endAddress().bigInt(),10),a=parseInt(t[1],10),a=E[a],l=Buffer.alloc(u),l.fill(0),l.writeUInt32BE(o>>>0,0),l.writeUInt32BE(i>>>0,4),l.writeUInt32BE(a>>>0,8),d=Math.round(1e4*parseFloat(t[7])),p=Math.round(1e4*parseFloat(t[8])),w=parseInt(t[9],10),l.writeInt32BE(d,12),l.writeInt32BE(p,16),l.writeInt32BE(w,20);return Date.now()-n>5e3&&(n=Date.now(),process.stdout.write('\nStill working ('+s+')...')),r._writableState.needDrain?new Promise(e=>{r.write(l,e)}):r.write(l)}const l=i.join(I,t),u=i.join(v,e);d(l),process.stdout.write('\nProcessing data (may take a moment)...'),n=Date.now(),r=o.createWriteStream(l);const p=a.createInterface({input:o.createReadStream(u),crlfDelay:1/0});let w=0;for await(const e of p)w++,1!==w&&await c(e);r.close()}function q(e,t){if(e.skip)return t(null,e);const n=e.type,r=e.src,s=e.dest;'country'===n?Array.isArray(r)?function(e,t){const n=i.join(v,e);process.stdout.write('Processing lookup data (may take a moment)...');const r=a.createInterface({input:o.createReadStream(n).pipe(u('latin1')),output:process.stdout,terminal:!1});let s=0;r.on('line',e=>{s>0&&function(e){const t=R(e);!t||t.length<6?console.log('Weird line: %s::',e):S[t[0]]=t[4]}(e),s++}),r.on('close',()=>{console.log(' DONE'),t()})}(r[0],()=>{b(r[1],s[1]).then(()=>b(r[2],s[2])).then(()=>{t(null,e)})}):b(r,s):'city'===n&&function(e,t,n){let r=null,s=0;const c=i.join(I,t),l=i.join(v,e);d(c);var p=o.openSync(c,'w');const f=a.createInterface({input:o.createReadStream(l).pipe(u('utf-8')),output:process.stdout,terminal:!1});let h=0;f.on('line',e=>{h>0&&function(e){if(e.match(/^Copyright/)||!e.match(/\d/))return;const t=Buffer.alloc(88),n=R(e);if(!n)return void console.warn('Weird line: %s::',e);r=parseInt(n[0]),E[r]=s;const i=n[4],c=n[6],a=n[10],l=parseInt(n[11]),u=n[12],d=n[13];t.fill(0),t.write(i,0),t.write(c,2),l&&t.writeInt32BE(l,5),t.write(d,9),t.write(u,10),t.write(a,42),o.writeSync(p,t,0,t.length,null),s++}(e),h++}),f.on('close',n)}(r[0],s[0],()=>{$(r[1],s[1]).then(()=>(console.log('\nCity data processed'),$(r[2],s[2]))).then(()=>{console.log(' DONE'),t(null,e)})})}function L(e,t){if(e.skip||!e.checkValue)return t();o.writeFile(i.join(I,e.type+'.checksum'),e.checkValue,'utf8',n=>{n&&console.log('Failed to Update checksums! Database:',e.type),t()})}m||(console.error('ERROR: Missing license_key'),process.exit(1)),d(v),k(v),l.eachSeries(x,(e,t)=>{l.seq(_,A,O,q,L)(e,t)},e=>{e?(console.error('Failed to update databases from MaxMind!',e),process.exit(1)):(console.log('Successfully updated databases from MaxMind'),-1!==w.indexOf('debug')||d(v),process.exit(0))});