IP2Location-Elixir v0.1.1 IP2Location
Interface for accessing IP2Location Binary Format databases. This is unstable software, and not officially vetted by IP2Location or anybody else. You have been warned.
Implementation details
This is mostly a port of the official Erlang library, with three main differences:
- It uses binary strings instead of charlists (as is common with Elixir libraries)
- It returns structs instead of records (again, as usual)
- It accepts the raw binary rather than directly using file IO, giving a very small speed bonus at a massive memory cost. This library is therefore almost useless except for regional datasets. Due to how large binaries are stored in the BEAM VM heap (using refcounting), once you load a binary database it should be safe to send it across processes without memory copying
Summary
Functions
Returns supported API version for binary file
Shortcut for loading and parsing a database file
Attempts to find a valid entry for a given IP address. If no entry is found in the database, it still returns a unitialized struct
Parses a database header and returns an struct with all needed settings for querying it later
Functions
Shortcut for loading and parsing a database file.
Raises if given a invalid raw binary or if there is an error reading the file into memory
Examples
iex> db = IP2Location.open_database!("path/to/database.bin")
%IP2Location.Database{...}
Attempts to find a valid entry for a given IP address. If no entry is found in the database, it still returns a unitialized struct.
Returns {:error, error_message}
if the given IP address is mal-formed.
Examples
iex> %IP2Location.Record{city: city} = IP2Location.query(db, "12.166.16.221"); city
"Indianapolis"
iex> IP2Location.query(db, "not a IP")
{:error, "Invalid IP address."}