UNPKG

1.68 kBTypeScriptView Raw
1/// <reference types="node" resolution-mode="require"/>
2import { MultipartFile } from './file.js';
3import type { MultipartStream, FileValidationOptions } from '../types.js';
4/**
5 * Part handler handles the progress of a stream and also internally validates
6 * it's size and extension.
7 *
8 * This class offloads the task of validating a file stream, regardless of how
9 * the stream is consumed. For example:
10 *
11 * In classic scanerio, we will process the file stream and write files to the
12 * tmp directory and in more advanced cases, the end user can handle the
13 * stream by themselves and report each chunk to this class.
14 */
15export declare class PartHandler {
16 #private;
17 /**
18 * Creating a new file object for each part inside the multipart
19 * form data
20 */
21 file: MultipartFile;
22 constructor(part: MultipartStream, options: Partial<FileValidationOptions & {
23 deferValidations: boolean;
24 }>);
25 /**
26 * Start the process the updating the file state
27 * to streaming mode.
28 */
29 begin(): void;
30 /**
31 * Handles the file upload progress by validating the file size and
32 * extension.
33 */
34 reportProgress(line: Buffer, bufferLength: number): Promise<void>;
35 /**
36 * Report errors encountered while processing the stream. These can be errors
37 * apart from the one reported by this class. For example: The `s3` failure
38 * due to some bad credentails.
39 */
40 reportError(error: any): Promise<void>;
41 /**
42 * Report success data about the file.
43 */
44 reportSuccess(data?: {
45 filePath?: string;
46 tmpPath?: string;
47 } & {
48 [key: string]: any;
49 }): Promise<void>;
50}