@agentman/chat-widget
Version:
Agentman Chat Widget for easy integration with web applications
46 lines (45 loc) • 1.52 kB
TypeScript
/**
* FileSignatureValidator - Lightweight file type detection using magic numbers
*
* Validates file types by checking their binary signatures (magic numbers)
* instead of relying on file extensions which can be spoofed.
*
* Size: ~2KB when minified
*/
export declare class FileSignatureValidator {
/**
* File signatures database
* Each signature contains the bytes to match and the corresponding MIME type
*/
private static readonly signatures;
/**
* Detect file type from a File object
* @param file - The file to analyze
* @returns The detected MIME type or null if unknown
*/
static detect(file: File): Promise<string | null>;
/**
* Check if file is probably a text file by analyzing content
* @param filename - The file name
* @param bytes - First bytes of the file
* @returns True if likely a text file
*/
private static isProbablyTextFile;
/**
* Get a human-readable name for a MIME type
* @param mimeType - The MIME type
* @returns A friendly name for the file type
*/
static getFriendlyName(mimeType: string): string;
/**
* Check if a file type is supported
* @param file - The file to check
* @param supportedMimeTypes - Array of supported MIME types
* @returns Object with validation result
*/
static validate(file: File, supportedMimeTypes: string[]): Promise<{
valid: boolean;
detectedType: string | null;
message?: string;
}>;
}