Skip to content

Commit

Permalink
Added async functions
Browse files Browse the repository at this point in the history
  • Loading branch information
ip2location committed Aug 29, 2023
1 parent 7711e7a commit c1c28b6
Show file tree
Hide file tree
Showing 5 changed files with 1,082 additions and 44 deletions.
13 changes: 13 additions & 0 deletions docs/source/code.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,26 @@ Load the IP2Location BIN database for lookup.
:param str binPath: (Required) The file path links to IP2Location BIN databases.
```

```{py:function} openAsync(binPath)
Load the IP2Location BIN database for lookup asynchronously.
:param str binPath: (Required) The file path links to IP2Location BIN databases.
```

```{py:function} getAll(ipAddress)
Retrieve geolocation information for an IP address.
:param str ipAddress: (Required) The IP address (IPv4 or IPv6).
:return: Returns the geolocation information in array. Refer below table for the fields avaliable in the array
:rtype: array
{py:function} getAllAsync(ipAddress)
Retrieve geolocation information for an IP address asynchronously.
:param str ipAddress: (Required) The IP address (IPv4 or IPv6).
:return: Returns the geolocation information in a Promise of an array. Refer below table for the fields avaliable in the array
:rtype: Promise of an array
**RETURN FIELDS**
| Field Name | Description |
Expand Down
24 changes: 24 additions & 0 deletions docs/source/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,30 @@ for (var x = 0; x < testip.length; x++) {
ip2location.close();
```

### Query geolocation information from BIN database asynchronously

You can asynchronously query the geolocation information from the IP2Location BIN database as below:

```javascript

const {IP2Location} = require("ip2location-nodejs");

let ip2location = new IP2Location();

testip = ['8.8.8.8', '2404:6800:4001:c01::67'];

ip2location.openAsync("./DB26.BIN").then(() => {
for (var x = 0; x < testip.length; x++) {
ip2location.getAllAsync(testip[x]).then(result => {
for (var key in result) {
console.log(key + ": " + result[key]);
}
console.log("--------------------------------------------------------------");
});
}
});
```

### Processing IP address using IP Tools class

You can manupulate IP address, IP number and CIDR as below:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ip2location-nodejs",
"version": "9.5.0",
"version": "9.6.0",
"description": "IP2Location geolocation component",
"keywords": [
"ip2location",
Expand Down
Loading

0 comments on commit c1c28b6

Please sign in to comment.