Skip to content

Commit 90267a3

Browse files
Merge pull request #22 from targos/improve-perf
improve performance for large files
2 parents ac309ee + e23f337 commit 90267a3

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

lib/index.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ function processMultipart(options, req, res, next) {
6767

6868
// Build req.files fields
6969
busboy.on('file', function(fieldname, file, filename, encoding, mime) {
70-
let buf = new Buffer(0);
70+
const buffers = [];
7171
let safeFileNameRegex = /[^\w-]/g;
7272

7373
file.on('data', function(data) {
74-
buf = Buffer.concat([buf, data]);
74+
buffers.push(data);
7575

7676
if (options.debug)
7777
return console.log('Uploading %s -> %s', fieldname, filename);
@@ -81,6 +81,7 @@ function processMultipart(options, req, res, next) {
8181
if (!req.files)
8282
req.files = {};
8383

84+
const buf = Buffer.concat(buffers);
8485
// see: https://github.com/richardgirges/express-fileupload/issues/14
8586
// firefox uploads empty file in case of cache miss when f5ing page.
8687
// resulting in unexpected behavior. if there is no file data, the file is invalid.

0 commit comments

Comments
 (0)