Merge pull request #1554 from thelounge/astorije/rm-event-stream

Remove event-stream dependency in favor of plain Buffers
This commit is contained in:
Pavel Djundik 2017-09-26 11:00:35 +03:00 committed by GitHub
commit 7cfd8d90c1
2 changed files with 12 additions and 18 deletions

View File

@ -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",

View File

@ -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
@ -173,18 +173,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);
}
@ -200,14 +197,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