Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

load-ip-set

Package Overview
Dependencies
Maintainers
9
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

load-ip-set - npm Package Compare versions

Comparing version 3.0.0 to 3.0.1

7

CHANGELOG.md

@@ -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": [

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc