New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

geoip-lite

Package Overview
Dependencies
Maintainers
1
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

geoip-lite - npm Package Compare versions

Comparing version 1.3.6 to 1.3.7

test/memory_usage.js

33

lib/geoip.js

@@ -36,3 +36,3 @@ var fs = require('fs');

var cache4 = {
var conf4 = {
firstIP: null,

@@ -47,3 +47,3 @@ lastIP: null,

var cache6 = {
var conf6 = {
firstIP: null,

@@ -56,2 +56,6 @@ lastIP: null,

//copy original configs
var cache4 = JSON.parse(JSON.stringify(conf4));
var cache6 = JSON.parse(JSON.stringify(conf6));
var RECORD_SIZE = 10;

@@ -231,11 +235,3 @@ var RECORD_SIZE6 = 34;

var datSize;
var asyncCache = {
firstIP: null,
lastIP: null,
lastLine: 0,
locationBuffer: null,
locationRecordSize: 64,
mainBuffer: null,
recordSize: 12
};
var asyncCache = JSON.parse(JSON.stringify(conf4));

@@ -319,2 +315,3 @@ //when the preload function receives a callback, do the task asynchronously

asyncCache.lastIP = asyncCache.mainBuffer.readUInt32BE((asyncCache.lastLine * asyncCache.recordSize) + 4);
asyncCache.firstIP = asyncCache.mainBuffer.readUInt32BE(0);
cache4 = asyncCache;

@@ -367,9 +364,3 @@ }

var datSize;
var asyncCache6 = {
firstIP: null,
lastIP: null,
lastLine: 0,
mainBuffer: null,
recordSize: 58
};
var asyncCache6 = JSON.parse(JSON.stringify(conf6));

@@ -521,2 +512,8 @@ //when the preload function receives a callback, do the task asynchronously

},
//clear data
clear: function () {
cache4 = JSON.parse(JSON.stringify(conf4));
cache6 = JSON.parse(JSON.stringify(conf6));
},

@@ -523,0 +520,0 @@ // Reload data synchronously

{
"name" : "geoip-lite",
"version" : "1.3.6",
"version" : "1.3.7",
"description" : "A light weight native JavaScript implementation of GeoIP API from MaxMind",

@@ -22,3 +22,2 @@ "keywords" : ["geo", "geoip", "ip", "ipv4", "ipv6", "geolookup", "maxmind", "geolite"],

"colors": "^1.1.2",
"eslint": "^5.12.1",
"iconv-lite": "^0.4.13",

@@ -34,2 +33,3 @@ "ip-address": "^5.8.9",

"devDependencies": {
"eslint": "^5.12.1",
"nodeunit": "^0.11.2"

@@ -36,0 +36,0 @@ },

@@ -70,3 +70,3 @@ GeoIP-lite

Run `npm run-script updatedb` to update the data files.
Run `cd node_modules/geoip-lite && npm run-script updatedb` to update the data files.

@@ -128,15 +128,37 @@ **NOTE** that this requires a lot of RAM. It is known to fail on on a Digital Ocean or AWS micro instance.

### Start and stop watching for data updates ###
Built-in Updater
----------------
If you have a server running `geoip-lite`, and you want to update its geo data without a restart, you can enable
the data watcher to automatically refresh in-memory geo data when a file changes in the data directory.
This package contains an update script that can pull the files from MaxMind and handle the conversion from CSV.
A npm script alias has been setup to make this process easy. Please keep in mind this requires internet and MaxMind
rate limits that amount of downloads on their servers.
```javascript
geoip.startWatchingDataUpdate();
Package stores checksums of MaxMind data and by default only downloads them if checksums have changed.
### Ways to update data ###
```shell
#update data if new data is available
npm run-script updatedb
#force udpate data even if checkums have not changed
npm run-script updatedb force
```
This tool can be used with `npm run-script updatedb` to periodically update geo data on a running server.
You can also run it by doing:
Additionally, if you schedule upgrades, you can programmatically make geoip reload the data from new database
```bash
node ./node_modules/geoip-lite/scripts/updatedb.js
```
Or, if you really want, run the update once by `require('geoip-lite/scripts/updatedb.js')`.
### Ways to reload data in your app when update finished ###
If you have a server running `geoip-lite`, and you want to reload its geo data, after you finished update, without a restart.
#### Programmatically ####
You can do it programmatically, calling after scheduled data updates
```javascript

@@ -152,22 +174,12 @@ //Synchronously

#### Automatic Start and stop watching for data updates ####
Built-in Updater
----------------
You can enable the data watcher to automatically refresh in-memory geo data when a file changes in the data directory.
This package contains an update script that can pull the files from MaxMind and handle the conversion from CSV.
A npm script alias has been setup to make this process easy. Please keep in mind this requires internet and MaxMind
rate limits that amount of downloads on their servers.
```shell
npm run-script updatedb
```javascript
geoip.startWatchingDataUpdate();
```
You can also run it by doing:
This tool can be used with `npm run-script updatedb` to periodically update geo data on a running server.
```bash
node ./node_modules/geoip-lite/scripts/updatedb.js
```
Or, if you really want, run the update once by `require('geoip-lite/scripts/updatedb.js')`.
Caveats

@@ -185,2 +197,20 @@ -------

### Memory usage ###
Quick test on memory consumption shows that library uses around 100Mb per process
```javascript
var geoip = require('geoip-lite');
console.log(process.memoryUsage());
/**
* Outputs:
* {
* rss: 126365696,
* heapTotal: 10305536,
* heapUsed: 5168944,
* external: 104347120
* }
**/
```
References

@@ -187,0 +217,0 @@ ----------

@@ -8,2 +8,3 @@ // fetches and converts maxmind lite databases

var fs = require('fs');
var http = require('http');
var https = require('https');

@@ -164,3 +165,3 @@ var path = require('path');

if (status !== 200) {
console.log('ERROR'.red + ': HTTP Request Failed [%d %s]', status, https.STATUS_CODES[status]);
console.log('ERROR'.red + ': HTTP Request Failed [%d %s]', status, http.STATUS_CODES[status]);
client.abort();

@@ -226,3 +227,3 @@ process.exit();

if (status !== 200) {
console.log('ERROR'.red + ': HTTP Request Failed [%d %s]', status, https.STATUS_CODES[status]);
console.log('ERROR'.red + ': HTTP Request Failed [%d %s]', status, http.STATUS_CODES[status]);
client.abort();

@@ -229,0 +230,0 @@ process.exit();

@@ -66,3 +66,3 @@ var geoip = require('../lib/geoip');

test.strictEqual(actual.city, 'Amsterdam', "should match city");
test.strictEqual(actual.city, 'Badhoevedorp', "should match city");

@@ -73,3 +73,3 @@ test.ok(actual.ll, 'should contain coordinates');

test.strictEqual(actual.area, 50, "should match area");
test.strictEqual(actual.area, 10, "should match area");

@@ -82,3 +82,3 @@ test.done();

var ip = "95.17.102.184";
var ip = "2.139.175.1";
var expected = "Logroño";

@@ -98,3 +98,3 @@ var actual = geoip.lookup(ip);

test.equal(actual.city, "Perris");//keeps changing with each update from one city to other (close to each other geographically)
test.equal(actual.city, "Nuevo");//keeps changing with each update from one city to other (close to each other geographically)
test.equal(actual.metro, 803);

@@ -114,3 +114,64 @@

test.done();
},
testSyncReload: function (test) {
test.expect(6);
//get original data
var before4 = geoip.lookup("75.82.117.180");
test.notEqual(before4, null);
var before6 = geoip.lookup("::ffff:173.185.182.82");
test.notEqual(before6, null);
//clear data;
geoip.clear();
//make sure data is cleared
var none4 = geoip.lookup("75.82.117.180");
test.equal(none4, null);
var none6 = geoip.lookup("::ffff:173.185.182.82");
test.equal(none6, null);
//reload data synchronized
geoip.reloadDataSync();
//make sure we have value from before
var after4 = geoip.lookup("75.82.117.180");
test.deepEqual(before4, after4);
var after6 = geoip.lookup("::ffff:173.185.182.82");
test.deepEqual(before6, after6);
test.done();
},
testAsyncReload: function (test) {
test.expect(6);
//get original data
var before4 = geoip.lookup("75.82.117.180");
test.notEqual(before4, null);
var before6 = geoip.lookup("::ffff:173.185.182.82");
test.notEqual(before6, null);
//clear data;
geoip.clear();
//make sure data is cleared
var none4 = geoip.lookup("75.82.117.180");
test.equal(none4, null);
var none6 = geoip.lookup("::ffff:173.185.182.82");
test.equal(none6, null);
//reload data asynchronously
geoip.reloadData(function(){
//make sure we have value from before
var after4 = geoip.lookup("75.82.117.180");
test.deepEqual(before4, after4);
var after6 = geoip.lookup("::ffff:173.185.182.82");
test.deepEqual(before6, after6);
test.done();
});
}
};

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc