mirror of
https://github.com/metowolf/iplist.git
synced 2025-12-19 00:04:36 +08:00
replace cidr-tools with fast-cidr-tools for improved CIDR merging functionality
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
const cidrTools = require('cidr-tools')
|
||||
const { merge } = require('fast-cidr-tools')
|
||||
|
||||
const plugin = (through2, file, cb) => {
|
||||
|
||||
@@ -28,7 +28,7 @@ const plugin = (through2, file, cb) => {
|
||||
223.120.0.0/13
|
||||
`
|
||||
white = white.trim().split('\n')
|
||||
data = cidrTools.merge([...data, ...white])
|
||||
data = merge([...data, ...white], true)
|
||||
|
||||
file.contents = Buffer.from(data.join('\n'))
|
||||
file.path = file.path.replace('CN.txt', 'china.txt')
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
const cidrTools = require('cidr-tools')
|
||||
const ProgressBar = require('progress')
|
||||
const { merge } = require('fast-cidr-tools')
|
||||
|
||||
const plugin = (file, _, cb) => {
|
||||
let cidrs = file.contents.toString().split('\n')
|
||||
@@ -7,19 +6,7 @@ const plugin = (file, _, cb) => {
|
||||
console.log(file.path)
|
||||
|
||||
if (cidrs.length) {
|
||||
let result = [cidrs[0]]
|
||||
let bar = new ProgressBar(':bar :current/:total', { total: cidrs.length })
|
||||
for (let i = 1; i < cidrs.length; i += 1) {
|
||||
let t = cidrTools.merge([result[result.length - 1], cidrs[i]])
|
||||
if (t.length === 1) {
|
||||
result[result.length - 1] = t[0]
|
||||
} else {
|
||||
result.push(cidrs[i])
|
||||
}
|
||||
bar.tick()
|
||||
}
|
||||
cidrs = result
|
||||
console.log()
|
||||
cidrs = merge(cidrs, true)
|
||||
}
|
||||
|
||||
file.contents = Buffer.from(cidrs.join('\n'))
|
||||
|
||||
Reference in New Issue
Block a user