maxminddb 0.1.18 → 0.1.19
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/maxminddb.rb +2 -1
- data/lib/maxminddb/reader.rb +30 -0
- data/lib/maxminddb/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: baa15e403f8935e07c5f2c2286fc14267534a4ef
|
4
|
+
data.tar.gz: 1cf297075926ddac4893041e858a96733a024b32
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3d92adbd9707dda2dc77e702a77680fa7c7b41541be96391c0630e053c106bbe2f4a9eaf562770ca0df492f9a0c71f7cda52ece0d47b4b1e8c35abc4ef9b3b2d
|
7
|
+
data.tar.gz: 2bb2d4f9477331bb72a60beb61ac9289cceff933af353933b184a2cbe3f966cb1d53b2ffba51c507c21b41090a59cb1750ff9705f841319e636b8891ce5a7a89
|
data/CHANGELOG.md
CHANGED
data/lib/maxminddb.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
require "maxminddb/version"
|
2
2
|
require 'maxminddb/result'
|
3
|
+
require 'maxminddb/reader'
|
3
4
|
require 'ipaddr'
|
4
5
|
|
5
6
|
module MaxMindDB
|
6
7
|
|
7
|
-
DEFAULT_FILE_READER = proc { |path|
|
8
|
+
DEFAULT_FILE_READER = proc { |path| MaxMindDB::Reader.new(path) }
|
8
9
|
|
9
10
|
def self.new(path, file_reader=DEFAULT_FILE_READER)
|
10
11
|
Client.new(path, file_reader)
|
@@ -0,0 +1,30 @@
|
|
1
|
+
|
2
|
+
module MaxMindDB
|
3
|
+
class Reader
|
4
|
+
METADATA_MAX_SIZE = 128 * 1024
|
5
|
+
|
6
|
+
def initialize(path)
|
7
|
+
@mutex = Mutex.new
|
8
|
+
@file = File.open(path, 'rb')
|
9
|
+
end
|
10
|
+
|
11
|
+
def [](pos, length=1)
|
12
|
+
atomic_read(length, pos)
|
13
|
+
end
|
14
|
+
|
15
|
+
def rindex(search)
|
16
|
+
base = [0, @file.size - METADATA_MAX_SIZE].max
|
17
|
+
tail = atomic_read(METADATA_MAX_SIZE, base)
|
18
|
+
pos = tail.rindex(search)
|
19
|
+
return nil if pos.nil?
|
20
|
+
base + pos
|
21
|
+
end
|
22
|
+
|
23
|
+
def atomic_read(length, pos)
|
24
|
+
@mutex.synchronize do
|
25
|
+
@file.seek(pos)
|
26
|
+
@file.read(length)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/maxminddb/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: maxminddb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.19
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- yhirose
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-06-
|
11
|
+
date: 2018-06-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -82,6 +82,7 @@ files:
|
|
82
82
|
- README.md
|
83
83
|
- Rakefile
|
84
84
|
- lib/maxminddb.rb
|
85
|
+
- lib/maxminddb/reader.rb
|
85
86
|
- lib/maxminddb/result.rb
|
86
87
|
- lib/maxminddb/result/location.rb
|
87
88
|
- lib/maxminddb/result/named_location.rb
|