Add custom detectors to FileTypeParser
mainYou can extend file-type detection capabilities by providing custom detectors via the customDetectors option in the FileTypeParser constructor. Detectors provided through the constructor are executed before the default ones. This is useful for supporting uncommon file types or non-binary formats.
Available third-party detectors include:
@file-type/av: Audio and video differentiation.@file-type/cfbf: Compound File Binary Format (e.g., Office 97–2003,.msi).@file-type/pdf: PDF-based types (e.g., Adobe Illustrator).@file-type/xml: Common XML types (e.g., GLM, KML, MusicXML, RSS, SVG, XHTML).
import {FileTypeParser} from 'file-type';
import {detectXml} from '@file-type/xml';
const parser = new FileTypeParser({customDetectors: [detectXml]});
const fileType = await parser.fromFile('sample.kml');
console.log(fileType);