-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
34 lines (25 loc) · 1.02 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
'use strict';
var path = require("path");
var mmdbreader = require('maxmind-db-reader');
var geoDataFile = path.join(__dirname, '/data/GeoLite2-City.mmdb');
function MaxmindDBReader (){
this.reader = null;
};
MaxmindDBReader.prototype.initSync =
MaxmindDBReader.prototype.init = function(cb){
this.reader = mmdbreader.openSync(geoDataFile);
if (!!cb && typeof cb === 'function') cb(null, null);
}
MaxmindDBReader.prototype.getGeoData = function getGeoData(ipAddress,callback) {
if (!this.reader) throw Error("must init the mudule first");
this.reader.getGeoData(ipAddress,callback);
};
MaxmindDBReader.prototype.getGeoDataSync = function getGeoDataSync(ipAddress) {
if (!this.reader) throw Error("must init the mudule first");
return this.reader.getGeoDataSync(ipAddress);
};
MaxmindDBReader.prototype.getDatabaseMetadata = function getDatabaseMetadata() {
if (!this.reader) throw Error("must init the mudule first");
return this.reader.getDatabaseMetadata();
};
exports = module.exports = new MaxmindDBReader();