/** * File Validator Utility * * Provides comprehensive file validation including: * - MIME type detection from magic numbers (file signatures) * - MIME type validation against whitelist/blacklist * - File size validation * - Extension validation against MIME type * - Executable file detection for security * - Custom validation support */ import type { FileValidationResult, ValidationRule } from '@plyaz/types/storage'; /** * File Validator Class * Provides static methods for comprehensive file validation */ export declare class FileValidator { /** * Validate a file against provided rules * * @param file - File buffer or stream * @param filename - Original filename * @param mimeType - Provided MIME type (will be verified) * @param rules - Validation rules to apply * @returns Validation result with success/failure and error details */ static validate(file: Buffer, filename: string, mimeType: string, rules?: ValidationRule): Promise; /** * Validate file size against rules */ private static validateSizeRules; /** * Validate MIME type against rules */ private static validateMimeTypeRules; /** * Validate file extension against rules */ private static validateExtensionRules; /** * Run custom validation function */ private static runCustomValidation; /** * Validate MIME type against allowed types (with wildcard support) * * @param mimeType - MIME type to validate * @param allowedTypes - Array of allowed MIME types (supports wildcards like "image/*") * @returns true if MIME type is allowed */ static validateMimeType(mimeType: string, allowedTypes: string[]): boolean; /** * Detect MIME type from file buffer using magic numbers (file signatures) * * @param fileBuffer - File buffer to analyze * @returns Detected MIME type or null if unknown */ static detectMimeType(fileBuffer: Buffer): string | null; /** * Check if buffer is a valid WEBP file */ private static isValidWebp; /** * Validate file size * * @param fileSize - File size in bytes * @param maxSize - Maximum allowed size in bytes * @returns true if size is valid */ static validateFileSize(fileSize: number, maxSize: number): boolean; /** * Validate file extension matches MIME type * * @param filename - Filename with extension * @param mimeType - MIME type * @returns true if extension matches MIME type */ static validateExtension(filename: string, mimeType: string): boolean; /** * Check if file is executable (security check) * * @param filename - Filename with extension * @returns true if file is executable */ static isExecutable(filename: string): boolean; /** * Get file extension from filename * * @param filename - Filename * @returns Extension with dot (e.g., ".jpg") or empty string */ static getExtension(filename: string): string; /** * Get expected file extensions for a MIME type * * @param mimeType - MIME type * @returns Array of valid extensions for this MIME type */ static getExpectedExtensions(mimeType: string): string[]; /** * Match file signature at specified offset * * @param buffer - File buffer * @param signature - Signature bytes to match * @param offset - Byte offset to start matching (default: 0) * @returns true if signature matches */ private static matchesSignature; } /** * Validate file and throw error if invalid * Convenience wrapper around FileValidator.validate that throws on failure * * @param file - File buffer * @param filename - Filename * @param mimeType - MIME type * @param rules - Validation rules * @throws StoragePackageError if validation fails */ export declare function validateFile(file: Buffer, filename: string, mimeType: string, rules?: ValidationRule): Promise;