load-ip-set
Advanced tools
Comparing version 3.0.0 to 3.0.1
@@ -0,1 +1,8 @@ | ||
## [3.0.1](https://github.com/webtorrent/load-ip-set/compare/v3.0.0...v3.0.1) (2023-01-25) | ||
### Performance Improvements | ||
* drop simple-get ([cff6579](https://github.com/webtorrent/load-ip-set/commit/cff6579f0b4518bb21cf092a326cbd14db1b819e)) | ||
# [3.0.0](https://github.com/webtorrent/load-ip-set/compare/v2.2.1...v3.0.0) (2022-11-24) | ||
@@ -2,0 +9,0 @@ |
47
index.js
/*! load-ip-set. MIT License. WebTorrent LLC <https://webtorrent.io/opensource> */ | ||
import fs from 'fs' | ||
import get from 'simple-get' | ||
import fetch from 'cross-fetch-ponyfill' | ||
import IPSet from 'ip-set' | ||
@@ -9,2 +9,3 @@ import { Netmask } from 'netmask' | ||
import zlib from 'zlib' | ||
import queueMicrotask from 'queue-microtask' | ||
@@ -17,3 +18,3 @@ // Match single IPs and IP ranges (IPv4 and IPv6), with or without a description | ||
function loadIPSet (input, opts, cb) { | ||
async function loadIPSet (input, opts, cb) { | ||
if (typeof opts === 'function') return loadIPSet(input, {}, opts) | ||
@@ -23,11 +24,18 @@ cb = once(cb) | ||
if (Array.isArray(input) || !input) { | ||
process.nextTick(() => { | ||
queueMicrotask(() => { | ||
cb(null, new IPSet(input)) | ||
}) | ||
} else if (/^https?:\/\//.test(input)) { | ||
opts.url = input | ||
get(opts, (err, res) => { | ||
if (err) return cb(err) | ||
onStream(res) | ||
}) | ||
let res = null | ||
try { | ||
res = await fetch(input, opts) | ||
} catch (err) { | ||
return cb(err) | ||
} | ||
const text = await res.text() | ||
const blocklist = [] | ||
for (const line of text.split('\n')) { | ||
handleLine(line, blocklist) | ||
} | ||
cb(null, new IPSet(blocklist)) | ||
} else { | ||
@@ -38,2 +46,14 @@ let f = fs.createReadStream(input).on('error', cb) | ||
} | ||
function handleLine (line, blocklist) { | ||
let match = ipSetRegex.exec(line) | ||
if (match) { | ||
blocklist.push({ start: match[1], end: match[2] }) | ||
} else { | ||
match = cidrRegex.exec(line) | ||
if (match) { | ||
const range = new Netmask(`${match[1]}/${match[2]}`) | ||
blocklist.push({ start: range.first, end: range.broadcast || range.last }) | ||
} | ||
} | ||
} | ||
@@ -46,12 +66,3 @@ function onStream (stream) { | ||
.on('data', line => { | ||
let match = ipSetRegex.exec(line) | ||
if (match) { | ||
blocklist.push({ start: match[1], end: match[2] }) | ||
} else { | ||
match = cidrRegex.exec(line) | ||
if (match) { | ||
const range = new Netmask(`${match[1]}/${match[2]}`) | ||
blocklist.push({ start: range.first, end: range.broadcast || range.last }) | ||
} | ||
} | ||
handleLine(line, blocklist) | ||
}) | ||
@@ -58,0 +69,0 @@ .on('end', () => { |
{ | ||
"name": "load-ip-set", | ||
"description": "download and parse ip-set (blocklist) files", | ||
"version": "3.0.0", | ||
"version": "3.0.1", | ||
"author": { | ||
@@ -18,6 +18,7 @@ "name": "WebTorrent LLC", | ||
"dependencies": { | ||
"cross-fetch-ponyfill": "^1.0.1", | ||
"ip-set": "^2.1.0", | ||
"netmask": "^2.0.1", | ||
"once": "^1.4.0", | ||
"simple-get": "^4.0.0", | ||
"queue-microtask": "^1.2.3", | ||
"split": "^1.0.1" | ||
@@ -27,5 +28,5 @@ }, | ||
"@webtorrent/semantic-release-config": "1.0.8", | ||
"semantic-release": "19.0.5", | ||
"semantic-release": "20.0.4", | ||
"standard": "*", | ||
"tape": "5.6.1" | ||
"tape": "5.6.3" | ||
}, | ||
@@ -32,0 +33,0 @@ "keywords": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
7420
64
6
+ Addedcross-fetch-ponyfill@^1.0.1
+ Addedqueue-microtask@^1.2.3
+ Addedabort-controller@3.0.0(transitive)
+ Addedcross-fetch-ponyfill@1.0.3(transitive)
+ Addeddata-uri-to-buffer@4.0.1(transitive)
+ Addedevent-target-shim@5.0.1(transitive)
+ Addedfetch-blob@3.2.0(transitive)
+ Addedformdata-polyfill@4.0.10(transitive)
+ Addednode-domexception@1.0.0(transitive)
+ Addednode-fetch@3.3.2(transitive)
+ Addedqueue-microtask@1.2.3(transitive)
+ Addedweb-streams-polyfill@3.3.3(transitive)
- Removedsimple-get@^4.0.0
- Removeddecompress-response@6.0.0(transitive)
- Removedmimic-response@3.1.0(transitive)
- Removedsimple-concat@1.0.1(transitive)
- Removedsimple-get@4.0.1(transitive)