From 446055603beb813db426cb08b0bcfbb263ab4e6b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Mon, 28 Sep 2020 16:34:41 +0200 Subject: [PATCH] Remove adm-zip dependency (#15) It appears that .gz archives are available for download now, so use these instead of the .zip archives. --- package-lock.json | 14 -------------- package.json | 2 -- src/archive.ts | 23 +++++++++-------------- 3 files changed, 9 insertions(+), 30 deletions(-) diff --git a/package-lock.json b/package-lock.json index acf0cfa..d7a9f0c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -30,15 +30,6 @@ "js-tokens": "^4.0.0" } }, - "@types/adm-zip": { - "version": "0.4.33", - "resolved": "https://registry.npmjs.org/@types/adm-zip/-/adm-zip-0.4.33.tgz", - "integrity": "sha512-WM0DCWFLjXtddl0fu0+iN2ZF+qz8RF9RddG5OSy/S90AQz01Fu8lHn/3oTIZDxvG8gVcnBLAHMHOdBLbV6m6Mw==", - "dev": true, - "requires": { - "@types/node": "*" - } - }, "@types/csv-parse": { "version": "1.2.2", "resolved": "https://registry.npmjs.org/@types/csv-parse/-/csv-parse-1.2.2.tgz", @@ -97,11 +88,6 @@ "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz", "integrity": "sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q==" }, - "adm-zip": { - "version": "0.4.16", - "resolved": "https://registry.npmjs.org/adm-zip/-/adm-zip-0.4.16.tgz", - "integrity": "sha512-TFi4HBKSGfIKsK5YCkKaaFG2m4PEDyViZmEwof3MTIgzimHLto6muaHVpbrljdIvIrFZzEq/p4nafOeLcYegrg==" - }, "ajv": { "version": "6.12.4", "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.4.tgz", diff --git a/package.json b/package.json index 120a772..d662ba6 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,6 @@ "author": "Alexander Ebert", "license": "LGPL-2.1-or-later", "dependencies": { - "adm-zip": "^0.4.16", "csv-parse": "^4.12.0", "minimist": "^1.2.5", "node-fetch": "^2.6.1", @@ -20,7 +19,6 @@ "typedi": "^0.8.0" }, "devDependencies": { - "@types/adm-zip": "^0.4.33", "@types/csv-parse": "^1.2.2", "@types/minimist": "^1.2.0", "@types/node-fetch": "^2.5.7", diff --git a/src/archive.ts b/src/archive.ts index ccce32b..cd29996 100644 --- a/src/archive.ts +++ b/src/archive.ts @@ -1,13 +1,13 @@ -import * as AdmZip from 'adm-zip'; import fetch from 'node-fetch'; +import * as zlib from 'zlib'; export const sources = new Map([ - ['ipv4', 'https://www.stopforumspam.com/downloads/listed_ip_1_all.zip'], - ['ipv6', 'https://www.stopforumspam.com/downloads/listed_ip_1_ipv6_all.zip'], - ['email', 'https://www.stopforumspam.com/downloads/listed_email_1_all.zip'], + ['ipv4', 'https://www.stopforumspam.com/downloads/listed_ip_1_all.gz'], + ['ipv6', 'https://www.stopforumspam.com/downloads/listed_ip_1_ipv6_all.gz'], + ['email', 'https://www.stopforumspam.com/downloads/listed_email_1_all.gz'], [ 'username', - 'https://www.stopforumspam.com/downloads/listed_username_1_all.zip', + 'https://www.stopforumspam.com/downloads/listed_username_1_all.gz', ], ]); @@ -33,16 +33,11 @@ export class Archive { } public async download(): Promise { - const response = await fetch(sources.get(this.type)); + const response = await fetch(sources.get(this.type), { + compress: false, + }); if (response.ok) { - const entries: AdmZip.IZipEntry[] = new AdmZip( - await response.buffer(), - ).getEntries(); - for (let i = 0, length = entries.length; i < length; i++) { - if (/^listed_.+_all\.txt$/.exec(entries[i].name)) { - return entries[i].getData(); - } - } + return zlib.gunzipSync(await response.buffer()); } return undefined; -- 2.20.1