Skip to content

Commit 4720b7e

Browse files
Added Support for Compression
For: Gzip, Deflate, Brotli and Compress
1 parent d0fbec1 commit 4720b7e

File tree

1 file changed

+27
-16
lines changed

1 file changed

+27
-16
lines changed

src/Formidable.js

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -240,22 +240,33 @@ class IncomingForm extends EventEmitter {
240240
.on('aborted', () => {
241241
this.emit('aborted');
242242
this._error(new FormidableError('Request aborted', errors.aborted));
243-
})
244-
.on('data', (buffer) => {
245-
try {
246-
this.write(buffer);
247-
} catch (err) {
248-
this._error(err);
249-
}
250-
})
251-
.on('end', () => {
252-
if (this.error) {
253-
return;
254-
}
255-
if (this._parser) {
256-
this._parser.end();
257-
}
258-
});
243+
})
244+
245+
switch (this.headers['content-encoding']) {
246+
case "gzip":
247+
pipe = require("zlib").createGunzip();
248+
break;
249+
case "deflate":
250+
pipe = require("zlib").createInflate();
251+
break;
252+
case "br":
253+
pipe = require("zlib").createBrotliDecompress();
254+
break;
255+
case "compress":
256+
pipe = require("zlib").createUnzip();
257+
break;
258+
259+
default:
260+
pipe = node_stream.Transform({
261+
transform: function (chunk, encoding, callback) {
262+
callback(null, chunk);
263+
}
264+
265+
})
266+
}
267+
pipe.on("data", datafn).on('end', endfn);
268+
req.pipe(pipe)
269+
259270
if (promise) {
260271
return promise;
261272
}

0 commit comments

Comments
 (0)