const crypto = require('crypto');
const {debugLog} = require('./utilities');

/**
 * memHandler - In memory upload handler
 * @param {Object} options
 * @param {String} fieldname
 * @param {String} filename
 * @returns {Object}
 */
module.exports = (options, fieldname, filename) => {
  let buffers = [];
  let fileSize = 0; // eslint-disable-line
  let hash = crypto.createHash('md5');

  const getBuffer = () => Buffer.concat(buffers);
  const emptyFunc = () => '';

  return {
    dataHandler: (data) => {
      buffers.push(data);
      hash.update(data);
      fileSize += data.length;
      debugLog(options, `Uploading ${fieldname} -> ${filename}, bytes: ${fileSize}`);
    },
    getBuffer: getBuffer,
    getFilePath: emptyFunc,
    getFileSize: () => fileSize,
    getHash: () => hash.digest('hex'),
    complete: getBuffer,
    cleanup: emptyFunc
  };
};

const crypto = require('crypto');
const {debugLog} = require('./utilities');

/**
 * memHandler - In memory upload handler
 * @param {Object} options
 * @param {String} fieldname
 * @param {String} filename
 * @returns {Object}
 */
module.exports = (options, fieldname, filename) => {
  let buffers = [];
  let fileSize = 0; // eslint-disable-line
  let hash = crypto.createHash('md5');

  const getBuffer = () => Buffer.concat(buffers, fileSize);
  const emptyFunc = () => '';

  return {
    dataHandler: (data) => {
      buffers.push(data);
      hash.update(data);
      fileSize += data.length;
      debugLog(options, `Uploading ${fieldname} -> ${filename}, bytes: ${fileSize}`);
    },
    getBuffer: getBuffer,
    getFilePath: emptyFunc,
    getFileSize: () => fileSize,
    getHash: () => hash.digest('hex'),
    complete: getBuffer,
    cleanup: emptyFunc
  };
};

Add length to Buffer.concat invoke
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.