ip2location_ruby 8.4.0 → 8.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c6b5f833dfd8e52321b11114f24103b44ff2cc9279360a71a0948ecb6742d2d1
4
- data.tar.gz: 9f2b62167a00f19ac4f342d222291c108a3204b4c99324e9c21770339a73444d
3
+ metadata.gz: f7f7cc867aa07b3595ae89b5f5fa55fab2b210236b106fa8ad10ccb5b9dd15b1
4
+ data.tar.gz: 36b720b84b89cfaad323c1d695e1b5408eca69476197cdb7911cdb614856c5e9
5
5
  SHA512:
6
- metadata.gz: 59be638fbbba78173c4fc3ba9bc708d4a43b21024cf5e675135533bbc10093c6a6707a15e108646e0d546b130e59a63e355c9d2c2ace995b0bd59c51484c454d
7
- data.tar.gz: 283ac65d80c92f7bd054eb82399217901b08da84b965fa6764002baa5773073f130689b0646217b98ff62ebacf672e6990787a5d287075750eb05b9518f3892f
6
+ metadata.gz: 7a84781d5ab63cee79729be08a0ebdc1f3866630b8f00e4aea983e654c2cf55fd66370d8006666c76880621231fd91d9ddf3f19c2efdd0d7b7fde9428f630935
7
+ data.tar.gz: d6e40740c7fa84c5410239e93f54502e197a19dcc8c00b8a1d30bec76660a35bb9dfe78bced75ae7b4b3c15e29ad9f7e339a1b817e4b28cc4aff99caaf58f624
data/VERSION CHANGED
@@ -1 +1 @@
1
- 8.4.0
1
+ 8.5.0
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "ip2location_ruby"
3
- s.version = "8.4.0"
3
+ s.version = "8.5.0"
4
4
 
5
5
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
6
6
  s.require_paths = ["lib"]
@@ -13,7 +13,7 @@ require 'ip2location_ruby/ip2location_record'
13
13
  class Ip2location
14
14
  attr_accessor :record_class4, :record_class6, :v4, :file, :db_index, :count, :base_addr, :ipno, :count, :record, :database, :columns, :ip_version, :ipv4databasecount, :ipv4databaseaddr, :ipv4indexbaseaddr, :ipv6databasecount, :ipv6databaseaddr, :ipv6indexbaseaddr, :databaseyear, :databasemonth, :databaseday, :last_err_msg
15
15
 
16
- VERSION = '8.4.0'
16
+ VERSION = '8.5.0'
17
17
  FIELD_NOT_SUPPORTED = 'NOT SUPPORTED'
18
18
  INVALID_IP_ADDRESS = 'INVALID IP ADDRESS'
19
19
  INVALID_BIN_DATABASE = 'Incorrect IP2Location BIN file format. Please make sure that you are using the latest IP2Location BIN file.'
@@ -88,7 +88,7 @@ class Ip2location
88
88
  if ip_version == 6 && self.ipv6databasecount == 0
89
89
  return IPV6_ADDRESS_IN_IPV4_BIN
90
90
  end
91
- col_length = columns * 4
91
+ col_length = self.columns * 4
92
92
  if ipv4indexbaseaddr > 0 || ipv6indexbaseaddr > 0
93
93
  indexpos = 0
94
94
  case ip_version
@@ -107,8 +107,7 @@ class Ip2location
107
107
  ipnum = realipno - 1
108
108
  end
109
109
  end
110
- low = read32(indexpos)
111
- high = read32(indexpos + 4)
110
+ low, high = read32x2(indexpos)
112
111
  return self.record = bsearch(low, high, ipnum, self.base_addr, col_length)
113
112
  else
114
113
  return self.record = bsearch(0, self.count, ipnum, self.base_addr, col_length)
@@ -618,7 +617,7 @@ class Ip2location
618
617
  mid = (low + high) >> 1
619
618
  ip_from, ip_to = get_from_to(mid, base_addr, col_length)
620
619
  if ipnum >= ip_from && ipnum < ip_to
621
- from_base = ( base_addr + mid * (col_length + (self.v4 ? 0 : 12)))
620
+ from_base = (base_addr + mid * (col_length + (self.v4 ? 0 : 12)))
622
621
  file.seek(from_base)
623
622
  if v4
624
623
  return self.record_class4.read(file)
@@ -636,11 +635,12 @@ class Ip2location
636
635
  end
637
636
 
638
637
  def get_from_to(mid, base_addr, col_length)
639
- from_base = ( base_addr + mid * (col_length + (v4 ? 0 : 12)))
638
+ from_base = (base_addr + mid * (col_length + (v4 ? 0 : 12)))
639
+ data_length = col_length + (v4 ? 4 : (12 + 16))
640
640
  file.seek(from_base)
641
- ip_from = v4 ? file.read(4).unpack('V').first : readipv6(file)
642
- file.seek(from_base + col_length + (v4 ? 0 : 12))
643
- ip_to = v4 ? file.read(4).unpack('V').first : readipv6(file)
641
+ data_read = file.read(data_length)
642
+ ip_from = v4 ? data_read[0..3].unpack('V').first : readipv6(data_read[0..15].unpack('V*'))
643
+ ip_to = v4 ? data_read[(data_length - 4)..(data_length - 1)].unpack('V').first : readipv6(data_read[(data_length - 16)..(data_length - 1)].unpack('V*'))
644
644
  [ip_from, ip_to]
645
645
  end
646
646
 
@@ -676,17 +676,19 @@ class Ip2location
676
676
  [ipv, ipnum]
677
677
  end
678
678
 
679
- def read32(indexp)
679
+ def read32x2(indexp)
680
680
  file.seek(indexp - 1)
681
- return file.read(4).unpack('V').first
681
+ data_read = file.read(8)
682
+ data1 = data_read[0..3].unpack('V').first
683
+ data2 = data_read[4..7].unpack('V').first
684
+ return [data1, data2]
682
685
  end
683
686
 
684
- def readipv6(filer)
685
- parts = filer.read(16).unpack('V*')
687
+ def readipv6(parts)
686
688
  return parts[0] + parts[1] * 4294967296 + parts[2] * 4294967296**2 + parts[3] * 4294967296**3
687
689
  end
688
690
 
689
- private :get_record, :bsearch, :get_from_to, :read32, :readipv6
691
+ private :get_record, :bsearch, :get_from_to, :read32x2, :readipv6
690
692
  end
691
693
 
692
694
  class Ip2locationWebService
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ip2location_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 8.4.0
4
+ version: 8.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ip2location
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-05-05 00:00:00.000000000 Z
11
+ date: 2022-06-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bindata