1 |
|
2 |
|
3 |
|
4 |
|
5 | import { IncomingMessage } from "http";
|
6 | import { EventEmitter } from "stream";
|
7 | import { DefaultOptions, EmitData, EventData, Fields, File, Files, Options, Part, PluginFunction } from "./";
|
8 |
|
9 | declare class IncomingForm extends EventEmitter {
|
10 | static readonly DEFAULT_OPTIONS: DefaultOptions;
|
11 | constructor(options?: Partial<Options>);
|
12 |
|
13 | /**
|
14 | * Parses an incoming Node.js request containing form data. If callback is provided, all fields
|
15 | * and files are collected and passed to the callback.
|
16 | *
|
17 | * @link https://github.com/node-formidable/formidable#parserequest-callback
|
18 | */
|
19 | parse<FieldKey extends string, FileKey extends string>(
|
20 | request: IncomingMessage,
|
21 | ): Promise<[Fields<FieldKey>, Files<FileKey>]>;
|
22 | parse<FieldKey extends string, FileKey extends string>(
|
23 | request: IncomingMessage,
|
24 | callback?: (err: any, fields: Fields<FieldKey>, files: Files<FileKey>) => void,
|
25 | ): void;
|
26 |
|
27 | once(eventName: "end", listener: () => void): this;
|
28 | once(eventName: "error", listener: (err: any) => void): this;
|
29 |
|
30 | on(eventName: "data", listener: (data: EventData) => void): this;
|
31 | on(eventName: "error", listener: (err: any) => void): this;
|
32 | on(eventName: "field", listener: (name: string, value: string) => void): this;
|
33 | on(eventName: "fileBegin" | "file", listener: (formName: string, file: File) => void): this;
|
34 | on(eventName: "progress", listener: (bytesReceived: number, bytesExpected: number) => void): this;
|
35 | on(eventName: string, listener: () => void): this;
|
36 |
|
37 | emit(eventName: "data", data: EmitData): boolean;
|
38 |
|
39 | /**
|
40 | * A method that allows you to extend the Formidable library. By default we include 4 plugins,
|
41 | * which essentially are adapters to plug the different built-in parsers.
|
42 | *
|
43 | * @link https://github.com/node-formidable/formidable#useplugin-plugin
|
44 | */
|
45 | use(plugin: PluginFunction): void;
|
46 |
|
47 | /**
|
48 | * If you want to use Formidable to only handle certain parts for you, you can do something
|
49 | * similar. Or see #387 for inspiration, you can for example validate the mime-type.
|
50 | *
|
51 | * @link https://github.com/node-formidable/formidable#formonpart
|
52 | */
|
53 | onPart(part: Part): void;
|
54 |
|
55 | _handlePart(part: Part): void;
|
56 | }
|
57 |
|
58 | export = IncomingForm;
|