From 4bfd2b72c55c74ad91ff1691d03cd534da4d6d87 Mon Sep 17 00:00:00 2001 From: Roman Burunkov Date: Thu, 6 Jun 2019 11:18:24 +0300 Subject: [PATCH] Add length to Buffer.concat invoke Add length to Buffer.concat invoke. That should increase performance according to the node documenation. If totalLength is not provided, it is calculated from the Buffer instances in list. This however causes an additional loop to be executed in order to calculate the totalLength, so it is faster to provide the length explicitly if it is already known. --- lib/memHandler.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/memHandler.js b/lib/memHandler.js index 29cd2ee..65266b6 100644 --- a/lib/memHandler.js +++ b/lib/memHandler.js @@ -13,7 +13,7 @@ module.exports = (options, fieldname, filename) => { let fileSize = 0; // eslint-disable-line let hash = crypto.createHash('md5'); - const getBuffer = () => Buffer.concat(buffers); + const getBuffer = () => Buffer.concat(buffers, fileSize); const emptyFunc = () => ''; return {