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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6c383d38332c6e85095da4c02cc421c839baba0a
4
- data.tar.gz: fea281059ff4437763f6c936d29df745d9c2f7c1
3
+ metadata.gz: baa15e403f8935e07c5f2c2286fc14267534a4ef
4
+ data.tar.gz: 1cf297075926ddac4893041e858a96733a024b32
5
5
  SHA512:
6
- metadata.gz: 3250775dae6e0f623594df43f68421e58b491a277a4272f9c00debfcee8ba0406d3508b6d83c66d40c2a7522aa70057e99a8c2ccf3eaf341884cc6d4ef0e54b9
7
- data.tar.gz: 7684e0416fd72ef3a492aab344e4eea6e89d139286e340bd586c212299cb49d818ab72b21c96784fe1583225b782ad9b5b71f4c46c98679ab4bade72e01432cd
6
+ metadata.gz: 3d92adbd9707dda2dc77e702a77680fa7c7b41541be96391c0630e053c106bbe2f4a9eaf562770ca0df492f9a0c71f7cda52ece0d47b4b1e8c35abc4ef9b3b2d
7
+ data.tar.gz: 2bb2d4f9477331bb72a60beb61ac9289cceff933af353933b184a2cbe3f966cb1d53b2ffba51c507c21b41090a59cb1750ff9705f841319e636b8891ce5a7a89
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ### 0.1.19 (June 22, 2018)
4
+
5
+ - Implement a faster default reader
6
+
3
7
  ### 0.1.18 (June 18, 2018)
4
8
 
5
9
  - Backward Compatible Client Initialize
@@ -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| File.binread(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
@@ -1,3 +1,3 @@
1
1
  module MaxMindDB
2
- VERSION = "0.1.18"
2
+ VERSION = "0.1.19"
3
3
  end
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.18
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-18 00:00:00.000000000 Z
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