From 75b927b4a33220cdbbf7fc992b90b1e0d9c39919 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Astori?= Date: Thu, 21 Sep 2017 03:20:24 -0400 Subject: [PATCH] Remove event-stream dependency in favor of plain Buffers --- package.json | 1 - src/plugins/irc-events/link.js | 29 ++++++++++++----------------- 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/package.json b/package.json index 999a2d55..6be7e560 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,6 @@ "cheerio": "0.22.0", "colors": "1.1.2", "commander": "2.11.0", - "event-stream": "3.3.4", "express": "4.15.4", "express-handlebars": "3.0.0", "fs-extra": "4.0.2", diff --git a/src/plugins/irc-events/link.js b/src/plugins/irc-events/link.js index 06049b15..5cce11da 100644 --- a/src/plugins/irc-events/link.js +++ b/src/plugins/irc-events/link.js @@ -5,7 +5,6 @@ const request = require("request"); const url = require("url"); const Helper = require("../../helper"); const findLinks = require("../../../client/js/libs/handlebars/ircmessageparser/findLinks"); -const es = require("event-stream"); const storage = require("../storage"); process.setMaxListeners(0); @@ -155,6 +154,7 @@ function fetch(uri, cb) { } catch (e) { return cb(null); } + const buffers = []; var length = 0; var limit = Helper.config.prefetchMaxImageSize * 1024; req @@ -166,18 +166,15 @@ function fetch(uri, cb) { } }) .on("error", function() {}) - .pipe(es.map(function(data, next) { + .on("data", (data) => { length += data.length; - if (length > limit) { - req.response.req.abort(); - } - next(null, data); - })) - .pipe(es.wait(function(err, data) { - if (err) { - return cb(null); - } + buffers.push(data); + if (length > limit) { + req.abort(); + } + }) + .on("end", () => { if (req.response.statusCode < 200 || req.response.statusCode > 299) { return cb(null); } @@ -193,14 +190,12 @@ function fetch(uri, cb) { type = req.response.headers["content-type"].split(/ *; */).shift(); } - data = { - data: data, + cb({ + data: Buffer.concat(buffers, length), type: type, size: size - }; - - cb(data); - })); + }); + }); } // https://github.com/request/request/issues/2120