geoip-lite2
Advanced tools
Comparing version 2.1.24 to 2.1.25
declare module 'geoip-lite2' { | ||
export const cmp: number | any | null; | ||
export const cmp: number | null; | ||
@@ -4,0 +4,0 @@ interface GeoIp2Location { |
{ | ||
"name": "geoip-lite2", | ||
"version": "2.1.24", | ||
"version": "2.1.25", | ||
"description": "A light weight native JavaScript implementation of GeoIP API from MaxMind. Improved and faster version by Sefinek.", | ||
@@ -36,15 +36,2 @@ "keywords": [ | ||
"typings": "index.d.ts", | ||
"directories": { | ||
"lib": "lib", | ||
"test": "test" | ||
}, | ||
"files": [ | ||
"data/", | ||
"lib/", | ||
"test/", | ||
"utils/", | ||
"AUTHORS", | ||
"index.d.ts", | ||
"LICENSE" | ||
], | ||
"scripts": { | ||
@@ -54,3 +41,3 @@ "minify-linux": "echo \"Please wait...\n\" && bash _Minify/linux.bash", | ||
"test": "jest test-unminified", | ||
"up": "ncu -u -x chalk && npm install && npm update && npm audit fix", | ||
"up": "ncu -u && npm install && npm update && npm audit fix", | ||
"updatedb": "node utils/updatedb.js", | ||
@@ -64,5 +51,5 @@ "updatedb-debug": "node utils/updatedb.js debug", | ||
"async": "^3.2.5", | ||
"chalk": "4.1.2", | ||
"iconv-lite": "0.6.3", | ||
"ip-address": "^9.0.5", | ||
"kleur": "^4.1.5", | ||
"rimraf": "^5.0.5" | ||
@@ -75,4 +62,4 @@ }, | ||
"engines": { | ||
"node": ">=16.20.2" | ||
"node": ">=10.3.0" | ||
} | ||
} |
@@ -12,4 +12,4 @@ <div align="center"> | ||
<img src="https://img.shields.io/npm/dt/geoip-lite2?maxAge=3600" alt="The number of downloads"> | ||
<img src="https://img.shields.io/github/issues/sefinek24/geoip-lite2" alt="Issues"> | ||
<img src="https://img.shields.io/github/last-commit/sefinek24/geoip-lite2" alt="Last commit"> | ||
<img src="https://img.shields.io/github/issues/sefinek24/geoip-lite2" alt="Issues"> | ||
<img src="https://img.shields.io/github/commit-activity/w/sefinek24/geoip-lite2" alt="Commit activity"> | ||
@@ -16,0 +16,0 @@ <img src="https://img.shields.io/github/languages/code-size/sefinek24/geoip-lite2" alt="Code size"> |
@@ -1,1 +0,1 @@ | ||
'use strict';const{name:e,version:t}=require('../package.json'),n=`Mozilla/5.0 (compatible; ${e}/${t}; +https://sefinek.net)`,r=require('fs'),o=require('http'),s=require('https'),i=require('path'),c=require('zlib'),a=require('readline');r.existsSync=r.existsSync||i.existsSync;const l=require('async'),d=require('chalk'),u=require('iconv-lite'),p=require('rimraf').sync,f=require('adm-zip'),g=require('../lib/utils.js'),{Address6:h,Address4:w}=require('ip-address'),m=process.argv.slice(2);let y=m.find((e=>null!==e.match(/^license_key=[a-zA-Z0-9]+/)));void 0===y&&void 0!==process.env.LICENSE_KEY&&(y=`license_key=${process.env.LICENSE_KEY}`);let I=m.find((e=>null!==e.match(/^geoDataDir=[\w./]+/)));void 0===I&&void 0!==process.env.GEODATADIR&&(I=`geoDataDir=${process.env.GEODATADIR}`);let S=i.resolve(__dirname,'..','data');void 0!==I&&(S=i.resolve(process.cwd(),I.split('=')[1]),r.existsSync(S)||(console.log(d.red('ERROR')+': Directory doesn\'t exist: '+S),process.exit(1)));const v=process.env.GEOTMPDIR?process.env.GEOTMPDIR:i.resolve(__dirname,'..','tmp'),E={},x={NaN:-1},k=[{type:'country',url:`https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-Country-CSV&suffix=zip&${y}`,checksum:`https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-Country-CSV&suffix=zip.sha256&${y}`,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&${y}`,checksum:`https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-City-CSV&suffix=zip.sha256&${y}`,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 D(e){const t=i.dirname(e);r.existsSync(t)||r.mkdirSync(t)}const R=/^\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 B(e){if(!R.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),!R.test(e)))return null;const t=[];return e.replace(C,((e,n,r,o)=>(void 0!==n?t.push(n.replace(/\\'/g,'\'')):void 0!==r?t.push(r.replace(/\\"/g,'"').replace(/\\'/g,'\'')):void 0!==o&&t.push(o),''))),/,\s*$/.test(e)&&t.push(''),t}function _(e){const t=new URL(e),r={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');r.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'),process.exit(-1)}return r}function b(e,t){if(-1!==m.indexOf('force'))return t(null,e);const n=e.checksum;if(void 0===n)return t(null,e);r.readFile(i.join(S,`${e.type}.checksum`),{encoding:'utf8'},((r,i)=>{!r&&i&&i.length&&(e.checkValue=i),console.log('Checking',e.fileName);var c=s.get(_(n),(function(n){const r=n.statusCode;200!==r&&(console.error(d.red('ERROR')+n.data),console.error(d.red('ERROR')+': HTTP Request Failed [%d %s]',r,o.STATUS_CODES[r]),c.end(),process.exit(1));let s='';n.on('data',(e=>{s+=e})),n.on('end',(()=>{s&&s.length?s===e.checkValue?(console.log(d.green('Database "'+e.type+'" is up to date')),e.skip=!0):(console.log(d.green('Database '+e.type+' has new data')),e.checkValue=s):(console.error(d.red('ERROR')+': Could not retrieve checksum for',e.type,d.red('Aborting')),console.error('Run with "force" to update without checksum'),c.end(),process.exit(1)),t(null,e)}))}))}))}function O(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(r.existsSync(u))return t(null,u,a,e);console.log('Fetching',a),D(u);var p=s.get(_(n),(function(n){const s=n.statusCode;let i;200!==s&&(console.error(d.red('ERROR')+': HTTP Request Failed [%d %s]',s,o.STATUS_CODES[s]),p.end(),process.exit(1));const f=r.createWriteStream(u);i=l?n.pipe(c.createGunzip()).pipe(f):n.pipe(f),i.on('close',(()=>{console.log(d.green(' DONE')),t(null,u,a,e)}))}));process.stdout.write(`Retrieving ${a}...`)}function A(e,t,n,o){if(n.skip)return o(null,n);if('.zip'!==i.extname(t))o(null,n);else{process.stdout.write('Extracting '+t+'...');new f(e).getEntries().forEach((e=>{if(e.isDirectory)return;const t=e.entryName.split('/'),n=t[t.length-1],o=i.join(v,n);r.writeFileSync(o,e.getData())})),console.log(d.green(' DONE')),o(null,n)}}function q(e,t){const n=i.join(v,e);process.stdout.write('Processing lookup data (may take a moment)...');const o=a.createInterface({input:r.createReadStream(n).pipe(u.decodeStream('latin1')),output:process.stdout,terminal:!1});let s=0;o.on('line',(e=>{s>0&&function(e){const t=B(e);!t||t.length<6?console.log('Weird line: %s::',e):E[t[0]]=t[4]}(e),s++})),o.on('close',(()=>{console.log(d.green(' DONE')),t()}))}async function G(e,t){let n=0;function o(e){const t=B(e);if(!t||t.length<6)return console.warn('weird line: %s::',e);let r,o,s;n++;const i=E[t[1]];let c,a,d;if(i){if(t[0].match(/:/)){for(a=34,s=new h(t[0]),r=g.aton6(s.startAddress().correctForm()),o=g.aton6(s.endAddress().correctForm()),c=Buffer.alloc(a),d=0;d<r.length;d++)c.writeUInt32BE(r[d],4*d);for(d=0;d<o.length;d++)c.writeUInt32BE(o[d],16+4*d)}else a=10,s=new w(t[0]),r=parseInt(s.startAddress().bigInteger(),10),o=parseInt(s.endAddress().bigInteger(),10),c=Buffer.alloc(a),c.fill(0),c.writeUInt32BE(r,0),c.writeUInt32BE(o,4);return c.write(i,a-2),Date.now()-l>5e3&&(l=Date.now(),process.stdout.write('\nStill working ('+n+')...')),u._writableState.needDrain?new Promise((e=>{u.write(c,e)})):u.write(c)}}const s=i.join(S,t),c=i.join(v,e);p(s),D(s),process.stdout.write('\nProcessing data (may take a moment)...');var l=Date.now(),u=r.createWriteStream(s);const f=a.createInterface({input:r.createReadStream(c),crlfDelay:1/0});let m=0;for await(const e of f)m++,1!==m&&await o(e);u.close(),console.log(d.green(' DONE'))}async function L(e,t){let n=0;async function o(e){if(e.match(/^Copyright/)||!e.match(/\d/))return;const t=B(e);if(!t)return console.warn('Weird line: %s::',e);let r,o,s,i,c,a,u,p,f,m;if(n++,t[0].match(/:/)){let e=0;for(a=48,s=new h(t[0]),r=g.aton6(s.startAddress().correctForm()),o=g.aton6(s.endAddress().correctForm()),i=parseInt(t[1],10),i=x[i],c=Buffer.alloc(a),c.fill(0),m=0;m<r.length;m++)c.writeUInt32BE(r[m],e),e+=4;for(m=0;m<o.length;m++)c.writeUInt32BE(o[m],e),e+=4;c.writeUInt32BE(i>>>0,32),u=Math.round(1e4*parseFloat(t[7])),p=Math.round(1e4*parseFloat(t[8])),f=parseInt(t[9],10),c.writeInt32BE(u,36),c.writeInt32BE(p,40),c.writeInt32BE(f,44)}else a=24,s=new w(t[0]),r=parseInt(s.startAddress().bigInteger(),10),o=parseInt(s.endAddress().bigInteger(),10),i=parseInt(t[1],10),i=x[i],c=Buffer.alloc(a),c.fill(0),c.writeUInt32BE(r>>>0,0),c.writeUInt32BE(o>>>0,4),c.writeUInt32BE(i>>>0,8),u=Math.round(1e4*parseFloat(t[7])),p=Math.round(1e4*parseFloat(t[8])),f=parseInt(t[9],10),c.writeInt32BE(u,12),c.writeInt32BE(p,16),c.writeInt32BE(f,20);return Date.now()-l>5e3&&(l=Date.now(),process.stdout.write('\nStill working ('+n+')...')),d._writableState.needDrain?new Promise((e=>{d.write(c,e)})):d.write(c)}const s=i.join(S,t),c=i.join(v,e);p(s),process.stdout.write('\nProcessing data (may take a moment)...');var l=Date.now(),d=r.createWriteStream(s);const u=a.createInterface({input:r.createReadStream(c),crlfDelay:1/0});let f=0;for await(const e of u)f++,1!==f&&await o(e);d.close()}function F(e,t,n){let o=null,s=0;const c=i.join(S,t),l=i.join(v,e);p(c);var d=r.openSync(c,'w');const f=a.createInterface({input:r.createReadStream(l).pipe(u.decodeStream('utf-8')),output:process.stdout,terminal:!1});let g=0;f.on('line',(e=>{g>0&&function(e){if(e.match(/^Copyright/)||!e.match(/\d/))return;const t=Buffer.alloc(88),n=B(e);if(!n)return void console.warn('Weird line: %s::',e);o=parseInt(n[0]),x[o]=s;const i=n[4],c=n[6],a=n[10],l=parseInt(n[11]),u=n[12],p=n[13];t.fill(0),t.write(i,0),t.write(c,2),l&&t.writeInt32BE(l,5),t.write(p,9),t.write(u,10),t.write(a,42),r.writeSync(d,t,0,t.length,null),s++}(e),g++})),f.on('close',n)}function T(e,t){if(e.skip)return t(null,e);const n=e.type,r=e.src,o=e.dest;'country'===n?Array.isArray(r)?q(r[0],(()=>{G(r[1],o[1]).then((()=>G(r[2],o[2]))).then((()=>{t(null,e)}))})):G(r,o):'city'===n&&F(r[0],o[0],(()=>{L(r[1],o[1]).then((()=>(console.log('\nCity data processed'),L(r[2],o[2])))).then((()=>{console.log(d.green(' DONE')),t(null,e)}))}))}function N(e,t){if(e.skip||!e.checkValue)return t();r.writeFile(i.join(S,e.type+'.checksum'),e.checkValue,'utf8',(n=>{n&&console.log(d.red('Failed to Update checksums!'),'Database:',e.type),t()}))}y||(console.error(d.red('ERROR:'),'Missing license_key'),process.exit(1)),p(v),D(v),l.eachSeries(k,((e,t)=>{l.seq(b,O,A,T,N)(e,t)}),(e=>{e?(console.error(d.red('Failed to update databases from MaxMind'),e),process.exit(1)):(console.log(d.green('Successfully updated databases from MaxMind')),-1!==m.indexOf('debug')?console.debug(d.blue.bold('Notice: temporary files are not deleted for debug purposes')):p(v),process.exit(0))})); | ||
'use strict';const{name:e,version:t}=require('../package.json'),n=`Mozilla/5.0 (compatible; ${e}/${t}; +https://sefinek.net)`,r=require('fs'),o=require('http'),s=require('https'),i=require('path'),c=require('zlib'),a=require('readline');r.existsSync=r.existsSync||i.existsSync;const l=require('async'),d=require('kleur'),u=require('iconv-lite'),p=require('rimraf').sync,f=require('adm-zip'),g=require('../lib/utils.js'),{Address6:h,Address4:w}=require('ip-address'),m=process.argv.slice(2);let y=m.find((e=>null!==e.match(/^license_key=[a-zA-Z0-9]+/)));void 0===y&&void 0!==process.env.LICENSE_KEY&&(y=`license_key=${process.env.LICENSE_KEY}`);let I=m.find((e=>null!==e.match(/^geoDataDir=[\w./]+/)));void 0===I&&void 0!==process.env.GEODATADIR&&(I=`geoDataDir=${process.env.GEODATADIR}`);let S=i.resolve(__dirname,'..','data');void 0!==I&&(S=i.resolve(process.cwd(),I.split('=')[1]),r.existsSync(S)||(console.log(d.red('ERROR')+': Directory doesn\'t exist: '+S),process.exit(1)));const v=process.env.GEOTMPDIR?process.env.GEOTMPDIR:i.resolve(__dirname,'..','tmp'),E={},x={NaN:-1},k=[{type:'country',url:`https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-Country-CSV&suffix=zip&${y}`,checksum:`https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-Country-CSV&suffix=zip.sha256&${y}`,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&${y}`,checksum:`https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-City-CSV&suffix=zip.sha256&${y}`,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 D(e){const t=i.dirname(e);r.existsSync(t)||r.mkdirSync(t)}const R=/^\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 B(e){if(!R.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),!R.test(e)))return null;const t=[];return e.replace(C,((e,n,r,o)=>(void 0!==n?t.push(n.replace(/\\'/g,'\'')):void 0!==r?t.push(r.replace(/\\"/g,'"').replace(/\\'/g,'\'')):void 0!==o&&t.push(o),''))),/,\s*$/.test(e)&&t.push(''),t}function _(e){const t=new URL(e),r={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');r.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'),process.exit(-1)}return r}function b(e,t){if(-1!==m.indexOf('force'))return t(null,e);const n=e.checksum;if(void 0===n)return t(null,e);r.readFile(i.join(S,`${e.type}.checksum`),{encoding:'utf8'},((r,i)=>{!r&&i&&i.length&&(e.checkValue=i),console.log('Checking',e.fileName);var c=s.get(_(n),(function(n){const r=n.statusCode;200!==r&&(console.error(d.red('ERROR')+n.data),console.error(d.red('ERROR')+': HTTP Request Failed [%d %s]',r,o.STATUS_CODES[r]),c.end(),process.exit(1));let s='';n.on('data',(e=>{s+=e})),n.on('end',(()=>{s&&s.length?s===e.checkValue?(console.log(d.green('Database "'+e.type+'" is up to date')),e.skip=!0):(console.log(d.green('Database '+e.type+' has new data')),e.checkValue=s):(console.error(d.red('ERROR')+': Could not retrieve checksum for',e.type,d.red('Aborting')),console.error('Run with "force" to update without checksum'),c.end(),process.exit(1)),t(null,e)}))}))}))}function O(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(r.existsSync(u))return t(null,u,a,e);console.log('Fetching',a),D(u);var p=s.get(_(n),(function(n){const s=n.statusCode;let i;200!==s&&(console.error(d.red('ERROR')+': HTTP Request Failed [%d %s]',s,o.STATUS_CODES[s]),p.end(),process.exit(1));const f=r.createWriteStream(u);i=l?n.pipe(c.createGunzip()).pipe(f):n.pipe(f),i.on('close',(()=>{console.log(d.green(' DONE')),t(null,u,a,e)}))}));process.stdout.write(`Retrieving ${a}...`)}function A(e,t,n,o){if(n.skip)return o(null,n);if('.zip'!==i.extname(t))o(null,n);else{process.stdout.write('Extracting '+t+'...');new f(e).getEntries().forEach((e=>{if(e.isDirectory)return;const t=e.entryName.split('/'),n=t[t.length-1],o=i.join(v,n);r.writeFileSync(o,e.getData())})),console.log(d.green(' DONE')),o(null,n)}}function q(e,t){const n=i.join(v,e);process.stdout.write('Processing lookup data (may take a moment)...');const o=a.createInterface({input:r.createReadStream(n).pipe(u.decodeStream('latin1')),output:process.stdout,terminal:!1});let s=0;o.on('line',(e=>{s>0&&function(e){const t=B(e);!t||t.length<6?console.log('Weird line: %s::',e):E[t[0]]=t[4]}(e),s++})),o.on('close',(()=>{console.log(d.green(' DONE')),t()}))}async function G(e,t){let n=0;function o(e){const t=B(e);if(!t||t.length<6)return console.warn('weird line: %s::',e);let r,o,s;n++;const i=E[t[1]];let c,a,d;if(i){if(t[0].match(/:/)){for(a=34,s=new h(t[0]),r=g.aton6(s.startAddress().correctForm()),o=g.aton6(s.endAddress().correctForm()),c=Buffer.alloc(a),d=0;d<r.length;d++)c.writeUInt32BE(r[d],4*d);for(d=0;d<o.length;d++)c.writeUInt32BE(o[d],16+4*d)}else a=10,s=new w(t[0]),r=parseInt(s.startAddress().bigInteger(),10),o=parseInt(s.endAddress().bigInteger(),10),c=Buffer.alloc(a),c.fill(0),c.writeUInt32BE(r,0),c.writeUInt32BE(o,4);return c.write(i,a-2),Date.now()-l>5e3&&(l=Date.now(),process.stdout.write('\nStill working ('+n+')...')),u._writableState.needDrain?new Promise((e=>{u.write(c,e)})):u.write(c)}}const s=i.join(S,t),c=i.join(v,e);p(s),D(s),process.stdout.write('\nProcessing data (may take a moment)...');var l=Date.now(),u=r.createWriteStream(s);const f=a.createInterface({input:r.createReadStream(c),crlfDelay:1/0});let m=0;for await(const e of f)m++,1!==m&&await o(e);u.close(),console.log(d.green(' DONE'))}async function L(e,t){let n=0;async function o(e){if(e.match(/^Copyright/)||!e.match(/\d/))return;const t=B(e);if(!t)return console.warn('Weird line: %s::',e);let r,o,s,i,c,a,u,p,f,m;if(n++,t[0].match(/:/)){let e=0;for(a=48,s=new h(t[0]),r=g.aton6(s.startAddress().correctForm()),o=g.aton6(s.endAddress().correctForm()),i=parseInt(t[1],10),i=x[i],c=Buffer.alloc(a),c.fill(0),m=0;m<r.length;m++)c.writeUInt32BE(r[m],e),e+=4;for(m=0;m<o.length;m++)c.writeUInt32BE(o[m],e),e+=4;c.writeUInt32BE(i>>>0,32),u=Math.round(1e4*parseFloat(t[7])),p=Math.round(1e4*parseFloat(t[8])),f=parseInt(t[9],10),c.writeInt32BE(u,36),c.writeInt32BE(p,40),c.writeInt32BE(f,44)}else a=24,s=new w(t[0]),r=parseInt(s.startAddress().bigInteger(),10),o=parseInt(s.endAddress().bigInteger(),10),i=parseInt(t[1],10),i=x[i],c=Buffer.alloc(a),c.fill(0),c.writeUInt32BE(r>>>0,0),c.writeUInt32BE(o>>>0,4),c.writeUInt32BE(i>>>0,8),u=Math.round(1e4*parseFloat(t[7])),p=Math.round(1e4*parseFloat(t[8])),f=parseInt(t[9],10),c.writeInt32BE(u,12),c.writeInt32BE(p,16),c.writeInt32BE(f,20);return Date.now()-l>5e3&&(l=Date.now(),process.stdout.write('\nStill working ('+n+')...')),d._writableState.needDrain?new Promise((e=>{d.write(c,e)})):d.write(c)}const s=i.join(S,t),c=i.join(v,e);p(s),process.stdout.write('\nProcessing data (may take a moment)...');var l=Date.now(),d=r.createWriteStream(s);const u=a.createInterface({input:r.createReadStream(c),crlfDelay:1/0});let f=0;for await(const e of u)f++,1!==f&&await o(e);d.close()}function F(e,t,n){let o=null,s=0;const c=i.join(S,t),l=i.join(v,e);p(c);var d=r.openSync(c,'w');const f=a.createInterface({input:r.createReadStream(l).pipe(u.decodeStream('utf-8')),output:process.stdout,terminal:!1});let g=0;f.on('line',(e=>{g>0&&function(e){if(e.match(/^Copyright/)||!e.match(/\d/))return;const t=Buffer.alloc(88),n=B(e);if(!n)return void console.warn('Weird line: %s::',e);o=parseInt(n[0]),x[o]=s;const i=n[4],c=n[6],a=n[10],l=parseInt(n[11]),u=n[12],p=n[13];t.fill(0),t.write(i,0),t.write(c,2),l&&t.writeInt32BE(l,5),t.write(p,9),t.write(u,10),t.write(a,42),r.writeSync(d,t,0,t.length,null),s++}(e),g++})),f.on('close',n)}function T(e,t){if(e.skip)return t(null,e);const n=e.type,r=e.src,o=e.dest;'country'===n?Array.isArray(r)?q(r[0],(()=>{G(r[1],o[1]).then((()=>G(r[2],o[2]))).then((()=>{t(null,e)}))})):G(r,o):'city'===n&&F(r[0],o[0],(()=>{L(r[1],o[1]).then((()=>(console.log('\nCity data processed'),L(r[2],o[2])))).then((()=>{console.log(d.green(' DONE')),t(null,e)}))}))}function N(e,t){if(e.skip||!e.checkValue)return t();r.writeFile(i.join(S,e.type+'.checksum'),e.checkValue,'utf8',(n=>{n&&console.log(d.red('Failed to Update checksums!'),'Database:',e.type),t()}))}y||(console.error(d.red('ERROR:'),'Missing license_key'),process.exit(1)),p(v),D(v),l.eachSeries(k,((e,t)=>{l.seq(b,O,A,T,N)(e,t)}),(e=>{e?(console.error(d.red('Failed to update databases from MaxMind'),e),process.exit(1)):(console.log(d.green('Successfully updated databases from MaxMind')),-1!==m.indexOf('debug')?console.debug(d.blue.bold('Notice: temporary files are not deleted for debug purposes')):p(v),process.exit(0))})); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
168406360
22
537
25
14
+ Addedkleur@^4.1.5
+ Addedkleur@4.1.5(transitive)
- Removedchalk@4.1.2
- Removedchalk@4.1.2(transitive)
- Removedhas-flag@4.0.0(transitive)
- Removedsupports-color@7.2.0(transitive)