Comparing version
const fs = require('fs') | ||
const net = require('net') | ||
const isBuffer = obj => { | ||
return obj !== null && obj.constructor !== null && | ||
typeof obj.constructor.isBuffer === 'function' && obj.constructor.isBuffer(obj) | ||
} | ||
class Parse { | ||
constructor(filename, options = {}) { | ||
const data = fs.readFileSync(filename) | ||
const data = isBuffer(filename) ? filename : fs.readFileSync(filename) | ||
const metaLen = data.readInt32BE(0) | ||
@@ -9,0 +13,0 @@ const meta = data.slice(4, 4 + metaLen) |
{ | ||
"name": "ipdb", | ||
"version": "0.2.2", | ||
"version": "0.3.0", | ||
"description": "IP lookup using IPIP.net database", | ||
@@ -24,3 +24,3 @@ "license": "MIT", | ||
"@ipdb/database": "^2019.1.9", | ||
"ava": "^1.3.1", | ||
"ava": "^2.1.0", | ||
"xo": "^0.24.0" | ||
@@ -27,0 +27,0 @@ }, |
@@ -35,4 +35,49 @@ # ipdb [](https://travis-ci.com/metowolf/ipdb) | ||
## Related | ||
## API | ||
### ipdb = new IPDB(file, [options]) | ||
#### file | ||
Type: `string | Buffer` | ||
The ipdb database pathname (string) or contents (buffer). | ||
#### options | ||
Type: `object` | ||
##### patches | ||
Type: `array` | ||
Default: `[]` | ||
See [Patches](#patches) | ||
### ipdb.find(ip, [options]) | ||
Return a result `object` | ||
#### ip | ||
Type: `string` | ||
#### options | ||
Type: `object` | ||
##### language | ||
Type: `string` | ||
Default: `CN` | ||
##### patches | ||
Type: `array` | ||
Default: `[]` | ||
See [Patches](#patches) | ||
## Patches | ||
- [@ipdb/iso3166](https://github.com/metowolf/ipdb-iso3166) - IPIP.net database patches (ISO-3166) | ||
@@ -42,5 +87,10 @@ - [@ipdb/cac](https://github.com/metowolf/ipdb-cac) - IPIP.net database patches (中国行政区划代码) | ||
## Related | ||
- [@ipdb/database](https://www.npmjs.com/package/@ipdb/database) - IPIP.net free database | ||
- [qqwry.ipdb](https://www.npmjs.com/package/qqwry.ipdb) - 纯真数据库 IPIP.net 格式版 | ||
## License | ||
MIT © [metowolf](https://i-meto.com/) |
7062
13.9%123
3.36%95
111.11%