Class: IParty::MaxMind::EagerReader
- Inherits:
-
Object
- Object
- IParty::MaxMind::EagerReader
- Defined in:
- lib/iparty/max_mind/eager_reader.rb
Overview
A fast read-access reader for MaxMindDB (mmdb) files. Reads the database into memory. This creates a higher memory overhead and slower init phase but faster lookup times.
Instance Method Summary collapse
- #[](pos, length = 1) ⇒ Object
- #close ⇒ Object
- #closed? ⇒ Boolean
-
#initialize(path) ⇒ EagerReader
constructor
A new instance of EagerReader.
- #rindex(search) ⇒ Object
Constructor Details
#initialize(path) ⇒ EagerReader
Returns a new instance of EagerReader.
8 9 10 |
# File 'lib/iparty/max_mind/eager_reader.rb', line 8 def initialize path @data = File.binread(path) end |
Instance Method Details
#[](pos, length = 1) ⇒ Object
12 13 14 15 16 |
# File 'lib/iparty/max_mind/eager_reader.rb', line 12 def [] pos, length = 1 raise IOError, "closed stream" unless @data @data.slice(pos, length) end |
#close ⇒ Object
24 25 26 |
# File 'lib/iparty/max_mind/eager_reader.rb', line 24 def close @data = nil end |
#closed? ⇒ Boolean
28 29 30 |
# File 'lib/iparty/max_mind/eager_reader.rb', line 28 def closed? @data.nil? end |
#rindex(search) ⇒ Object
18 19 20 21 22 |
# File 'lib/iparty/max_mind/eager_reader.rb', line 18 def rindex search raise IOError, "closed stream" unless @data @data.rindex(search) end |