diff --git a/src/Formidable.js b/src/Formidable.js index 5ea964e0..b4a8f483 100644 --- a/src/Formidable.js +++ b/src/Formidable.js @@ -8,6 +8,13 @@ import fsPromises from 'node:fs/promises'; import os from 'node:os'; import path from 'node:path'; import { StringDecoder } from 'node:string_decoder'; +import { Transform } from 'node:stream'; +import { + createGunzip, + createInflate, + createBrotliDecompress, + createUnzip, +} from 'node:zlib'; import once from 'once'; import FormidableError, * as errors from './FormidableError.js'; import PersistentFile from './PersistentFile.js'; @@ -261,25 +268,24 @@ class IncomingForm extends EventEmitter { switch (this.headers['content-encoding']) { case "gzip": - pipe = require("zlib").createGunzip(); + pipe = createGunzip(); break; case "deflate": - pipe = require("zlib").createInflate(); + pipe = createInflate(); break; case "br": - pipe = require("zlib").createBrotliDecompress(); + pipe = createBrotliDecompress(); break; case "compress": - pipe = require("zlib").createUnzip(); + pipe = createUnzip(); break; - default: - pipe = node_stream.Transform({ - transform: function (chunk, encoding, callback) { + default: + pipe = new Transform({ + transform(chunk, encoding, callback) { callback(null, chunk); - } - - }) + }, + }); } pipe.on("data", datafn).on('end', endfn); req.pipe(pipe)