UNPKG

@adonisjs/bodyparser

Version:

BodyParser middleware for AdonisJS http server to read and parse request body

63 lines (62 loc) 2.14 kB
import { MultipartFile } from './file.ts'; import type { MultipartStream, FileValidationOptions } from '../types.ts'; /** * Part handler handles the progress of a stream and also internally validates * its size and extension. * * This class offloads the task of validating a file stream, regardless of how * the stream is consumed. For example: * * In classic scenario, we will process the file stream and write files to the * tmp directory and in more advanced cases, the end user can handle the * stream by themselves and report each chunk to this class. */ export declare class PartHandler { #private; /** * Creating a new file object for each part inside the multipart * form data */ file: MultipartFile; /** * Creates a new part handler instance for processing multipart stream parts * * @param part - The multipart stream to handle * @param options - Validation options and configuration */ constructor(part: MultipartStream, options: Partial<FileValidationOptions & { deferValidations: boolean; }>); /** * Marks the file as being in streaming mode. Should be called before * processing the stream. */ begin(): void; /** * Handles the file upload progress by validating the file size and * extension. * * @param line - Buffer chunk from the stream * @param bufferLength - Length of the buffer chunk in bytes */ reportProgress(line: Buffer, bufferLength: number): Promise<void>; /** * Report errors encountered while processing the stream. These can be errors * apart from the one reported by this class. For example: The `s3` failure * due to some bad credentials. * * @param error - The error encountered during stream processing */ reportError(error: any): Promise<void>; /** * Report success data about the file. * * @param data - Success data containing file paths and metadata */ reportSuccess(data?: { filePath?: string; tmpPath?: string; } & { [key: string]: any; }): Promise<void>; }