Expand description
Crate for determining the file format of a given file or stream.
It provides a variety of functions for identifying a wide range of file formats, including ZIP, Compound File Binary (CFB), Extensible Markup Language (XML) and more.
It checks the signature of the file to determine its format and intelligently employs specific readers when available for accurate identification. If the signature is not recognized, the crate falls back to the default file format, which is Arbitrary Binary Data (BIN).
§Examples
Determines from a file:
use file_format::{FileFormat, Kind};
let fmt = FileFormat::from_file("fixtures/document/sample.pdf")?;
assert_eq!(fmt, FileFormat::PortableDocumentFormat);
assert_eq!(fmt.name(), "Portable Document Format");
assert_eq!(fmt.short_name(), Some("PDF"));
assert_eq!(fmt.media_type(), "application/pdf");
assert_eq!(fmt.extension(), "pdf");
assert_eq!(fmt.kind(), Kind::Document);
Determines from bytes:
use file_format::{FileFormat, Kind};
let fmt = FileFormat::from_bytes(&[0xFF, 0xD8, 0xFF]);
assert_eq!(fmt, FileFormat::JointPhotographicExpertsGroup);
assert_eq!(fmt.name(), "Joint Photographic Experts Group");
assert_eq!(fmt.short_name(), Some("JPEG"));
assert_eq!(fmt.media_type(), "image/jpeg");
assert_eq!(fmt.extension(), "jpg");
assert_eq!(fmt.kind(), Kind::Image);
§Crate features
All features below are disabled by default.
§Reader features
These features enable the detection of file formats that require a specific reader for identification.
reader
- Enables all reader features.reader-asf
- Enables Advanced Systems Format (ASF) based file formats detection.reader-cfb
- Enables Compound File Binary (CFB) based file formats detection.- 3D Studio Max (MAX)
- Autodesk Inventor Assembly (IAM)
- Autodesk Inventor Drawing (IDW)
- Autodesk Inventor Part (IPT)
- Autodesk Inventor Presentation (IPN)
- Corel Presentations 7 (SHW)
- Flash Project (FLA)
- Microsoft Excel Spreadsheet (XLS)
- Microsoft PowerPoint Presentation (PPT)
- Microsoft Project Plan (MPP)
- Microsoft Publisher Document (PUB)
- Microsoft Software Installer (MSI)
- Microsoft Visio Drawing (VSD)
- Microsoft Word Document (DOC)
- Microsoft Works 6 Spreadsheet (XLR)
- Microsoft Works Database (WDB)
- Microsoft Works Word Processor (WPS)
- SolidWorks Assembly (SLDASM)
- SolidWorks Drawing (SLDDRW)
- SolidWorks Part (SLDPRT)
- StarCalc (SDC)
- StarChart (SDS)
- StarDraw (SDA)
- StarImpress (SDD)
- StarMath (SMF)
- StarWriter (SDW)
- WordPerfect Document (WPD)
- WordPerfect Graphics (WPG)
reader-ebml
- Enables Extensible Binary Meta Language (EBML) based file formats detection.reader-exe
- Enables MS-DOS Executable (EXE) based file formats detection.reader-id3v2
- Enables ID3v2 (ID3) based file formats detection.reader-mp4
- Enables MPEG-4 Part 14 (MP4) based file formats detection.reader-pdf
- Enables Portable Document Format (PDF) based file formats detection.reader-rm
- Enables RealMedia (RM) based file formats detection.reader-sqlite3
- Enables SQLite 3 based file formats detection.reader-txt
- Enables Plain Text (TXT) detection when the file format is not recognized by its signature. Please note that this feature only detects files containing ASCII/UTF-8-encoded text.reader-xml
- Enables Extensible Markup Language (XML) based file formats detection. Please note that these file formats may be detected without the feature in certain cases.- AbiWord (ABW)
- AbiWord Template (AWT)
- Additive Manufacturing Format (AMF)
- Advanced Stream Redirector (ASX)
- Atom
- Collaborative Design Activity (COLLADA)
- Extensible 3D (X3D)
- Extensible Stylesheet Language Transformations (XSLT)
- FictionBook (FB2)
- GPS Exchange Format (GPX)
- Geography Markup Language (GML)
- Keyhole Markup Language (KML)
- MPEG-DASH MPD (MPD)
- Mathematical Markup Language (MathML)
- MusicXML
- Really Simple Syndication (RSS)
- Scalable Vector Graphics (SVG)
- Simple Object Access Protocol (SOAP)
- Tiled Map XML (TMX)
- Tiled Tileset XML (TSX)
- Timed Text Markup Language (TTML)
- Training Center XML (TCX)
- Uniform Office Format Presentation (UOP)
- Uniform Office Format Spreadsheet (UOS)
- Uniform Office Format Text (UOT)
- Universal Subtitle Format (USF)
- XML Localization Interchange File Format (XLIFF)
- XML Shareable Playlist Format (XSPF)
- draw.io (DRAWIO)
reader-zip
- Enables ZIP-based file formats detection.- 3D Manufacturing Format (3MF)
- Adobe Integrated Runtime (AIR)
- Android App Bundle (AAB)
- Android Package (APK)
- Autodesk 123D (123DX)
- Circuit Diagram Document (CDDX)
- Design Web Format XPS (DWFX)
- Electronic Publication (EPUB)
- Enterprise Application Archive (EAR)
- FictionBook ZIP (FBZ)
- Flash CS5 Project (FLA)
- Fusion 360 (F3D)
- InDesign Markup Language (IDML)
- Java Archive (JAR)
- Keyhole Markup Language ZIP (KMZ)
- Microsoft Visual Studio Extension (VSIX)
- MusicXML ZIP (MXL)
- Office Open XML Document (DOCX)
- Office Open XML Drawing (VSDX)
- Office Open XML Presentation (PPTX)
- Office Open XML Spreadsheet (XLSX)
- OpenDocument Database (ODB)
- OpenDocument Formula (ODF)
- OpenDocument Formula Template (OTF)
- OpenDocument Graphics (ODG)
- OpenDocument Graphics Template (OTG)
- OpenDocument Presentation (ODP)
- OpenDocument Presentation Template (OTP)
- OpenDocument Spreadsheet (ODS)
- OpenDocument Spreadsheet Template (OTS)
- OpenDocument Text (ODT)
- OpenDocument Text Master (ODM)
- OpenDocument Text Master Template (OTM)
- OpenDocument Text Template (OTT)
- OpenRaster (ORA)
- OpenXPS (OXPS)
- Sketch 43
- SpaceClaim Document (SCDOC)
- Sun XML Calc (SXC)
- Sun XML Calc Template (STC)
- Sun XML Draw (SXD)
- Sun XML Draw Template (STD)
- Sun XML Impress (SXI)
- Sun XML Impress Template (STI)
- Sun XML Math (SXM)
- Sun XML Writer (SXW)
- Sun XML Writer Global (SGW)
- Sun XML Writer Template (STW)
- Universal Scene Description ZIP (USDZ)
- Web Application Archive (WAR)
- Windows App Bundle (APPXBUNDLE)
- Windows App Package (APPX)
- XAP
- XPInstall (XPI)
- iOS App Store Package (IPA)
Enums§
- A file format.
- A kind of file format.