Skip to content

Commit c1c28b6

Browse files
committed
Added async functions
1 parent 7711e7a commit c1c28b6

File tree

5 files changed

+1082
-44
lines changed

5 files changed

+1082
-44
lines changed

docs/source/code.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,26 @@ Load the IP2Location BIN database for lookup.
1212
:param str binPath: (Required) The file path links to IP2Location BIN databases.
1313
```
1414

15+
```{py:function} openAsync(binPath)
16+
Load the IP2Location BIN database for lookup asynchronously.
17+
18+
:param str binPath: (Required) The file path links to IP2Location BIN databases.
19+
```
20+
1521
```{py:function} getAll(ipAddress)
1622
Retrieve geolocation information for an IP address.
1723
1824
:param str ipAddress: (Required) The IP address (IPv4 or IPv6).
1925
:return: Returns the geolocation information in array. Refer below table for the fields avaliable in the array
2026
:rtype: array
2127
28+
{py:function} getAllAsync(ipAddress)
29+
Retrieve geolocation information for an IP address asynchronously.
30+
31+
:param str ipAddress: (Required) The IP address (IPv4 or IPv6).
32+
:return: Returns the geolocation information in a Promise of an array. Refer below table for the fields avaliable in the array
33+
:rtype: Promise of an array
34+
2235
**RETURN FIELDS**
2336
2437
| Field Name | Description |

docs/source/quickstart.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,30 @@ for (var x = 0; x < testip.length; x++) {
5252
ip2location.close();
5353
```
5454

55+
### Query geolocation information from BIN database asynchronously
56+
57+
You can asynchronously query the geolocation information from the IP2Location BIN database as below:
58+
59+
```javascript
60+
61+
const {IP2Location} = require("ip2location-nodejs");
62+
63+
let ip2location = new IP2Location();
64+
65+
testip = ['8.8.8.8', '2404:6800:4001:c01::67'];
66+
67+
ip2location.openAsync("./DB26.BIN").then(() => {
68+
for (var x = 0; x < testip.length; x++) {
69+
ip2location.getAllAsync(testip[x]).then(result => {
70+
for (var key in result) {
71+
console.log(key + ": " + result[key]);
72+
}
73+
console.log("--------------------------------------------------------------");
74+
});
75+
}
76+
});
77+
```
78+
5579
### Processing IP address using IP Tools class
5680

5781
You can manupulate IP address, IP number and CIDR as below:

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ip2location-nodejs",
3-
"version": "9.5.0",
3+
"version": "9.6.0",
44
"description": "IP2Location geolocation component",
55
"keywords": [
66
"ip2location",

0 commit comments

Comments
 (0)