diff --git a/src/Formidable.js b/src/Formidable.js index ce492c1c..0120f732 100644 --- a/src/Formidable.js +++ b/src/Formidable.js @@ -6,9 +6,15 @@ import dezalgo from 'dezalgo'; import { EventEmitter } from 'node:events'; import fsPromises from 'node:fs/promises'; import os from 'node:os'; -import stream from 'node:stream'; 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'; @@ -262,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 = 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)