diff --git a/manual-test.ts b/manual-test.ts new file mode 100644 index 0000000..cfef6f3 --- /dev/null +++ b/manual-test.ts @@ -0,0 +1,47 @@ +import { createServer } from "http"; +import { parseFormData } from "."; +import { DefaultField } from "./types"; + +createServer( + async (req, res) => { + try { + const { fields, files } = await parseFormData( + req, + { + "file1": { + maxFileByteLength: 0.05 * 1024 * 1024, + maxFileCount: 3 + }, + "file2": { + maxFileByteLength: 2 * 1024 * 1024, + maxFileCount: 0 + }, + [DefaultField]: { + maxFileByteLength: 0.01 * 1024 * 1024, + maxFileCount: 1 + } + }, + undefined, + { limits: { fields: 2, files: 4 } } + ); + + console.log(fields); + + for await (const { byteLength, stream, ...restFile } of files) { + stream.resume(); + + console.log({ + ...restFile, + byteLength: await byteLength + }); + } + } catch (error) { + console.error(error); + } + + res.end(''); + } +) +.listen(3000); + +console.log("Started"); \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index cf81fb6..c50d4ef 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -6,6 +6,6 @@ "module": "CommonJS", "sourceMap": true }, - "include": ["index.ts", "server.ts"], + "include": ["index.ts", "manual-test.ts"], "exclude": ["node_modules"] } \ No newline at end of file