ts-ip2region2 1.2.1 → 1.3.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.
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md CHANGED
@@ -1,7 +1,15 @@
1
1
  # ts-ip2region2
2
2
 
3
+ [![npm version](https://badge.fury.io/js/ts-ip2region2.svg)](https://badge.fury.io/js/ts-ip2region2)
4
+ [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
5
+ [![Node.js CI](https://github.com/Steven-Qiang/ts-ip2region2/workflows/Release/badge.svg)](https://github.com/Steven-Qiang/ts-ip2region2/actions)
6
+
7
+ [English](README.md) | [中文](README_CN.md)
8
+
3
9
  High-performance Node.js native addon for ip2region xdb query with IPv4/IPv6 support. Written in TypeScript with full type definitions.
4
10
 
11
+ > **Note**: This project is based on the official [ip2region C client](https://github.com/lionsoul2014/ip2region/tree/master/binding/c) with enhanced TypeScript support.
12
+
5
13
  ## Features
6
14
 
7
15
  - 🚀 **High Performance** - Native C++ implementation with microsecond-level response
@@ -10,15 +18,19 @@ High-performance Node.js native addon for ip2region xdb query with IPv4/IPv6 sup
10
18
  - 🔒 **Memory Safe** - Automatic resource management prevents memory leaks
11
19
  - 📝 **TypeScript** - Complete TypeScript type definitions included
12
20
  - 🔧 **Cross Platform** - Works on Windows, Linux, and macOS
13
- - 📦 **Bundled Data** - Includes compressed database files
21
+ - 📦 **Auto-Updated Data** - Database files are automatically synced daily
14
22
 
15
23
  ## Installation
16
24
 
17
25
  ```bash
18
26
  npm install ts-ip2region2
27
+ # or
28
+ pnpm add ts-ip2region2
29
+ # or
30
+ yarn add ts-ip2region2
19
31
  ```
20
32
 
21
- The database files are automatically included and extracted during installation.
33
+ > **Database Included**: Database files are now bundled and automatically extracted during installation.
22
34
 
23
35
  ## Quick Start
24
36
 
@@ -69,6 +81,29 @@ new Ip2Region(dbPath: string, options?: Ip2RegionOptions)
69
81
  - `Ip2Region.verify(dbPath: string): boolean` - Verify xdb file
70
82
  - `Ip2Region.verifyDetailed(dbPath: string): VerifyResult` - Verify with detailed info
71
83
 
84
+ ### Type Definitions
85
+
86
+ ```typescript
87
+ interface SearchResult {
88
+ region: string; // Geographic location
89
+ ioCount: number; // Number of IO operations
90
+ took: number; // Query time in microseconds
91
+ }
92
+
93
+ interface Ip2RegionOptions {
94
+ cachePolicy?: 'file' | 'vectorIndex' | 'content';
95
+ ipVersion?: 'v4' | 'v6';
96
+ }
97
+ ```
98
+
99
+ ## Cache Strategies
100
+
101
+ | Strategy | Performance | Use Case |
102
+ |----------|-------------|----------|
103
+ | `file` | Good | Memory-constrained environments |
104
+ | `vectorIndex` | Better | General use (recommended) |
105
+ | `content` | Best | High-concurrency scenarios |
106
+
72
107
  ## Performance Benchmark
73
108
 
74
109
  Benchmark results on Windows x64 with Node.js v22.14.0 (10,000 iterations):
@@ -98,6 +133,55 @@ Run benchmark yourself:
98
133
  npm run benchmark
99
134
  ```
100
135
 
136
+ ## Examples
137
+
138
+ ```bash
139
+ # Build and run example
140
+ npm run example
141
+
142
+ # Build and run tests
143
+ npm test
144
+
145
+ # Build native addon
146
+ npm run build
147
+
148
+ # Compile TypeScript
149
+ npm run compile
150
+ ```
151
+
152
+ ## Project Structure
153
+
154
+ ```
155
+ ts-ip2region2/
156
+ ├── src/ # TypeScript source code
157
+ │ └── index.ts # Main TypeScript API
158
+ ├── dist/ # Compiled JavaScript output
159
+ │ ├── index.js
160
+ │ ├── index.d.ts
161
+ │ └── ...
162
+ ├── data/ # Bundled xdb database files
163
+ │ ├── checksums.json
164
+ │ └── ip2region.7z
165
+ ├── extracted/ # Extracted database files
166
+ │ ├── ip2region_v4.xdb
167
+ │ └── ip2region_v6.xdb
168
+ ├── ip2region/ # Original ip2region C source
169
+ │ ├── xdb_api.h
170
+ │ ├── xdb_util.c
171
+ │ └── xdb_searcher.c
172
+ ├── scripts/ # Build and utility scripts
173
+ ├── addon.cpp # Node.js addon implementation
174
+ ├── binding.gyp # Build configuration
175
+ ├── example.js # JavaScript example
176
+ ├── tsconfig.json # TypeScript configuration
177
+ ├── package.json
178
+ └── README.md
179
+ ```
180
+
181
+ ## Contributing
182
+
183
+ Contributions are welcome! Please feel free to submit a Pull Request.
184
+
101
185
  ## License
102
186
 
103
187
  Apache-2.0
@@ -0,0 +1,4 @@
1
+ {
2
+ "v4": "5555fd1aab63e06096d9ee2a4187e93b8451e650b77ce4138a26eb9cf4d81469",
3
+ "v6": "2c0ec39095bc224a506657d20dfbb460707dd94a9cfc2242fd5fe2b2e36cbf1c"
4
+ }
Binary file
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,YAAY;IACzB,6CAA6C;IAC7C,MAAM,EAAE,MAAM,CAAC;IACf,8BAA8B;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,iCAAiC;IACjC,IAAI,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,gBAAgB;IAC7B,yDAAyD;IACzD,WAAW,CAAC,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS,CAAC;IACjD,8BAA8B;IAC9B,SAAS,CAAC,EAAE,IAAI,GAAG,IAAI,CAAC;CAC3B;AAED,MAAM,WAAW,YAAY;IACzB,0BAA0B;IAC1B,KAAK,EAAE,OAAO,CAAC;IACf,iBAAiB;IACjB,SAAS,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,CAAC,OAAO,OAAO,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAM;IACtB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA6B;IAErD;;;;OAIG;gBACS,eAAe,CAAC,EAAE,MAAM,GAAG,gBAAgB,EAAE,OAAO,CAAC,EAAE,gBAAgB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AOhC;;OAEG;IACH,KAAK,IAAI,IAAI;IAIb;;;;OAIG;IACH,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;IAQtC;;;;OAIG;IACH,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY;IAOnD;;;OAGG;IACH,UAAU,IAAI,QAAQ,CAAC,gBAAgB,CAAC;IAIxC;;;OAGG;IACH,SAAS,IAAI,MAAM;CAGtB;AAED,OAAO,EAAE,SAAS,EAAE,CAAA"}
package/dist/index.js CHANGED
@@ -1,8 +1,53 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
2
35
  Object.defineProperty(exports, "__esModule", { value: true });
3
36
  exports.Ip2Region = void 0;
4
37
  const addon = require('../build/Release/ip2region.node');
5
- const ts_ip2region2_data_1 = require("ts-ip2region2-data");
38
+ const path = __importStar(require("path"));
39
+ const fs = __importStar(require("fs"));
40
+ function getDataPaths() {
41
+ const dataDir = path.join(__dirname, '..', 'extracted');
42
+ return {
43
+ v4: path.join(dataDir, 'ip2region_v4.xdb'),
44
+ v6: path.join(dataDir, 'ip2region_v6.xdb')
45
+ };
46
+ }
47
+ function isDataExtracted() {
48
+ const paths = getDataPaths();
49
+ return fs.existsSync(paths.v4) && fs.existsSync(paths.v6);
50
+ }
6
51
  class Ip2Region {
7
52
  /**
8
53
  * Create ip2region searcher instance
@@ -26,10 +71,10 @@ class Ip2Region {
26
71
  ipVersion: finalOptions.ipVersion || 'v4',
27
72
  };
28
73
  if (!dbPath) {
29
- if (!(0, ts_ip2region2_data_1.isDataExtracted)()) {
30
- throw new Error('Bundled data not found. Please ensure ts-ip2region2-data is properly installed.');
74
+ if (!isDataExtracted()) {
75
+ throw new Error('Database files not found. Run "npm run postinstall" or "node scripts/extract.js" to extract bundled data.');
31
76
  }
32
- const dataPaths = (0, ts_ip2region2_data_1.getDataPaths)();
77
+ const dataPaths = getDataPaths();
33
78
  this.dbPath = this.options.ipVersion === 'v6' ? dataPaths.v6 : dataPaths.v4;
34
79
  }
35
80
  else {
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,MAAM,KAAK,GAAG,OAAO,CAAC,iCAAiC,CAAC,CAAC;AACzD,2DAAmE;AAyBnE,MAAqB,SAAS;IAK1B;;;;OAIG;IACH,YAAY,eAA2C,EAAE,OAA0B;QAC/E,IAAI,MAA0B,CAAC;QAC/B,IAAI,YAA8B,CAAC;QAEnC,2DAA2D;QAC3D,IAAI,OAAO,eAAe,KAAK,QAAQ,IAAI,eAAe,KAAK,IAAI,EAAE,CAAC;YAClE,MA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AAS"}
package/package.json CHANGED
@@ -1,19 +1,25 @@
1
1
  {
2
2
  "name": "ts-ip2region2",
3
- "version": "1.2.1",
3
+ "version": "1.3.0",
4
4
  "description": "TypeScript-first ip2region implementation with native Node.js addon. Ultra-fast IPv4/IPv6 geolocation queries.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
+ "packageManager": "pnpm@10.29.2",
7
8
  "scripts": {
8
9
  "build": "node-gyp rebuild",
9
10
  "compile": "tsc",
10
- "build:all": "npm run build && npm run compile",
11
+ "build:all": "pnpm run build && pnpm run compile",
11
12
  "rebuild": "node-gyp rebuild",
12
13
  "clean": "node-gyp clean",
13
- "test": "npm run build:all && node test.js",
14
- "benchmark": "node benchmark.js",
15
- "example": "npm run build:all && node example.js",
16
- "prepublishOnly": "npm run build:all"
14
+ "test": "pnpm run build:all && node scripts/test.js",
15
+ "benchmark": "node scripts/benchmark.js",
16
+ "example": "pnpm run build:all && node example.js",
17
+ "sync": "node scripts/sync-data.js --no-exit-code",
18
+ "sync-check": "node scripts/sync-data.js",
19
+ "postinstall": "node scripts/extract.js",
20
+ "semantic-release": "semantic-release",
21
+ "semantic-release:dry": "semantic-release --dry-run",
22
+ "prepublishOnly": "pnpm run build:all"
17
23
  },
18
24
  "keywords": [
19
25
  "typescript",
@@ -30,8 +36,7 @@
30
36
  "license": "Apache-2.0",
31
37
  "repository": {
32
38
  "type": "git",
33
- "url": "https://github.com/Steven-Qiang/ts-ip2region2.git",
34
- "directory": "packages/ts-ip2region2"
39
+ "url": "git+https://github.com/Steven-Qiang/ts-ip2region2.git"
35
40
  },
36
41
  "bugs": {
37
42
  "url": "https://github.com/Steven-Qiang/ts-ip2region2/issues"
@@ -39,11 +44,21 @@
39
44
  "homepage": "https://github.com/Steven-Qiang/ts-ip2region2#readme",
40
45
  "dependencies": {
41
46
  "node-addon-api": "^8.5.0",
42
- "ts-ip2region2-data": "*"
47
+ "7zip-bin": "^5.2.0",
48
+ "node-7z": "^3.0.0"
43
49
  },
44
50
  "devDependencies": {
45
- "@types/node": "^24.8.1",
46
- "node-gyp": "^11.5.0",
51
+ "@semantic-release/changelog": "^6.0.3",
52
+ "@semantic-release/commit-analyzer": "^13.0.1",
53
+ "@semantic-release/git": "^10.0.1",
54
+ "@semantic-release/github": "^12.0.5",
55
+ "@semantic-release/npm": "^13.1.4",
56
+ "@semantic-release/release-notes-generator": "^14.1.0",
57
+ "@types/node": "^25.2.2",
58
+ "@types/node-7z": "^2.1.11",
59
+ "node-gyp": "^12.2.0",
60
+ "progress": "^2.0.3",
61
+ "semantic-release": "^25.0.3",
47
62
  "typescript": "^5.9.3"
48
63
  },
49
64
  "engines": {
@@ -63,11 +78,15 @@
63
78
  "addon.cpp",
64
79
  "ip2region/**/*",
65
80
  "binding.gyp",
81
+ "data/checksums.json",
82
+ "data/ip2region.7z",
83
+ "scripts/extract.js",
66
84
  "README.md"
67
85
  ],
68
86
  "gypfile": true,
69
87
  "publishConfig": {
70
88
  "access": "public",
89
+ "registry": "https://registry.npmjs.org/",
71
90
  "provenance": true
72
91
  }
73
92
  }
@@ -0,0 +1,58 @@
1
+ const path = require('path');
2
+ const fs = require('fs');
3
+ const { extractFull } = require('node-7z');
4
+ const sevenBin = require('7zip-bin');
5
+
6
+ async function extractData() {
7
+ const packageDir = path.dirname(__dirname);
8
+ const archivePath = path.join(packageDir, 'data', 'ip2region.7z');
9
+ const extractDir = path.join(packageDir, 'extracted');
10
+
11
+ if (!fs.existsSync(archivePath)) {
12
+ console.error('Archive file not found:', archivePath);
13
+ process.exit(1);
14
+ }
15
+
16
+ if (fs.existsSync(extractDir)) {
17
+ console.log('Data already extracted');
18
+ return;
19
+ }
20
+
21
+ console.log('Extracting ip2region database files...');
22
+
23
+ try {
24
+ fs.mkdirSync(extractDir, { recursive: true });
25
+
26
+ if (process.platform !== 'win32') {
27
+ try {
28
+ fs.chmodSync(sevenBin.path7za, 0o755);
29
+ } catch (chmodError) {
30
+ console.warn('Could not set executable permissions on 7zip binary:', chmodError);
31
+ }
32
+ }
33
+
34
+ const stream = extractFull(archivePath, extractDir, {
35
+ $bin: sevenBin.path7za,
36
+ recursive: true
37
+ });
38
+
39
+ await new Promise((resolve, reject) => {
40
+ stream.on('end', () => {
41
+ console.log('Extraction completed successfully');
42
+ resolve();
43
+ });
44
+
45
+ stream.on('error', (err) => {
46
+ console.error('Extraction failed:', err);
47
+ reject(err);
48
+ });
49
+ });
50
+ } catch (error) {
51
+ console.error('Failed to extract data:', error);
52
+ process.exit(1);
53
+ }
54
+ }
55
+
56
+ if (require.main === module) {
57
+ extractData().catch(console.error);
58
+ }