From 4720b7ec4e719980032aba86d3604446ac419b92 Mon Sep 17 00:00:00 2001 From: Coding4ever123 <148124024+Coding4ever123@users.noreply.github.com> Date: Wed, 4 Jun 2025 20:21:19 +0200 Subject: [PATCH 1/3] Added Support for Compression For: Gzip, Deflate, Brotli and Compress --- src/Formidable.js | 43 +++++++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/src/Formidable.js b/src/Formidable.js index 916b5396..b468b7d2 100644 --- a/src/Formidable.js +++ b/src/Formidable.js @@ -240,22 +240,33 @@ class IncomingForm extends EventEmitter { .on('aborted', () => { this.emit('aborted'); this._error(new FormidableError('Request aborted', errors.aborted)); - }) - .on('data', (buffer) => { - try { - this.write(buffer); - } catch (err) { - this._error(err); - } - }) - .on('end', () => { - if (this.error) { - return; - } - if (this._parser) { - this._parser.end(); - } - }); + }) + + switch (this.headers['content-encoding']) { + case "gzip": + pipe = require("zlib").createGunzip(); + break; + case "deflate": + pipe = require("zlib").createInflate(); + break; + case "br": + pipe = require("zlib").createBrotliDecompress(); + break; + case "compress": + pipe = require("zlib").createUnzip(); + break; + + default: + pipe = node_stream.Transform({ + transform: function (chunk, encoding, callback) { + callback(null, chunk); + } + + }) + } + pipe.on("data", datafn).on('end', endfn); + req.pipe(pipe) + if (promise) { return promise; } From 28bb55edaecb0d7366db25d43ed1189005d5bc4e Mon Sep 17 00:00:00 2001 From: Coding4ever123 <148124024+Coding4ever123@users.noreply.github.com> Date: Wed, 4 Jun 2025 20:33:09 +0200 Subject: [PATCH 2/3] Update Formidable.js --- src/Formidable.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/Formidable.js b/src/Formidable.js index b468b7d2..260224c8 100644 --- a/src/Formidable.js +++ b/src/Formidable.js @@ -232,6 +232,25 @@ class IncomingForm extends EventEmitter { // Parse headers and setup the parser, ready to start listening for data. await this.writeHeaders(req.headers); + let datafn = (buffer) => { + console.log("recieved Data!") + try { + this.write(buffer); + } catch (err) { + this._error(err); + } + } + let endfn = () => { + console.log("endfn called") + if (this.error) { + return; + } + if (this._parser) { + this._parser.end(); + } + } + let pipe = null; + // Start listening for data. req .on('error', (err) => { From 730181760a35ace63952e5475bf7f8fa5953e4c9 Mon Sep 17 00:00:00 2001 From: Coding4ever123 <148124024+Coding4ever123@users.noreply.github.com> Date: Wed, 4 Jun 2025 21:55:02 +0200 Subject: [PATCH 3/3] Removed Temporary Console.log statements --- src/Formidable.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Formidable.js b/src/Formidable.js index 260224c8..34d7a207 100644 --- a/src/Formidable.js +++ b/src/Formidable.js @@ -233,7 +233,6 @@ class IncomingForm extends EventEmitter { await this.writeHeaders(req.headers); let datafn = (buffer) => { - console.log("recieved Data!") try { this.write(buffer); } catch (err) { @@ -241,7 +240,6 @@ class IncomingForm extends EventEmitter { } } let endfn = () => { - console.log("endfn called") if (this.error) { return; }