UNPKG

file-type-checker

Version:

Detect and validate file types by their signatures (✨magic numbers✨)

68 lines (67 loc) 3.34 kB
import { FileInfo } from "../core"; /** * Takes a file content in different types, convert it into array of numbers and returns a chunk of the required size * * @param file - File content represents in Array<number> / ArrayBuffer / Uint8Array * @param fileChunkLength - Required file chunk length * * @returns {Array<number>} File chunk of the required size represents in Array<number> */ export declare function getFileChunk(file: Array<number> | ArrayBuffer | Uint8Array, fileChunkLength?: number): Array<number>; /** * Fetch a property of a object by its name * * @param obj The required object * @param prop The property name * * @returns {FileInfo} A property of the rquired object */ export declare function fetchFromObject(obj: any, prop: string): FileInfo; /** * Identify whether a valid 'mkv'/'web' file is 'mkv' or 'webm'. * By checking for the presence of the "DocType" element in the 'webm' header. * Or by checking the presence of the "Segment" element in the 'mkv' header. * * @param fileChunk - A chunk from the beginning of a file content, represents in array of numbers * * @returns {string | undefined} 'webm' if found webm string A property of the rquired object */ export declare function findMatroskaDocTypeElements(fileChunk: Array<number>): string | undefined; /** * Determine if array of numbers contains the "fytp" string. * M4V files typically have a "ftyp" box in the first few bytes, which can be checked by searching for the string "ftyp" in the buffer. * * @param fileChunk A chunk from the beginning of a file content, represents in array of numbers * * @returns {boolean} True if found the "ftyp" string in the fileChunk, otherwise false */ export declare function isftypStringIncluded(fileChunk: Array<number>): boolean; /** * Determine if array of numbers contains the "FLV" string. * FLV files typically have a "FLV" string in the first few bytes of the file, which can be checked using TextDecoder or similar. * * @param fileChunk A chunk from the beginning of a file content, represents in array of numbers * * @returns {boolean} True if found the "FLV" string in the fileChunk, otherwise false */ export declare function isFlvStringIncluded(fileChunk: Array<number>): boolean; export declare function isFileContaineJfiforExifHeader(file: number[]): boolean; /** * Determine if array of numbers contains the "ftypavif" string. * AVIF files typically have a "ftypavif" string at bytes 5-12 of the file, which can be checked using TextDecoder or similar. * * @param fileChunk A chunk from the beginning of a file content, represents in array of numbers * * @returns {boolean} True if found the "AVIF" string in the fileChunk, otherwise false */ export declare function isAvifStringIncluded(fileChunk: Array<number>): boolean; /** * Determine if a file chunk contains a HEIC file box. * HEIC files typically have an 'ftyp' box with specific major brand signatures * such as 'heic', 'hevc', 'mif1', and 'msf1' which can be checked by searching * for these strings in the file chunk. * * @param fileChunk A chunk from the beginning of a file content, represented as an array of numbers. * @returns {boolean} True if found a HEIC signature in the fileChunk, otherwise false. */ export declare function isHeicSignatureIncluded(fileChunk: Array<number>): boolean;