UNPKG

@adonisjs/bodyparser

Version:

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

40 lines (39 loc) 1.11 kB
import { type MultipartFile } from '../file.ts'; /** * Size validator validates the file size against configured limits */ export declare class SizeValidator { #private; /** * Whether the file has been validated */ validated: boolean; /** * Defining the maximum bytes the file can have */ get maxLimit(): number | string | undefined; set maxLimit(limit: number | string | undefined); /** * Creates a new SizeValidator instance * * @param file - The multipart file to validate */ constructor(file: MultipartFile); /** * Validates the file size against configured limits. Can be called multiple * times during streaming; validation is marked complete only when the file * exceeds the limit or after the stream is consumed. * * @example * ```ts * const validator = new SizeValidator(file) * validator.maxLimit = '2mb' * validator.validate() * * if (!file.isValid) { * console.log(file.errors) // Size validation errors * } * ``` */ validate(): void; }