Skip to main content

Module detect

Module detect 

Source
Expand description

Format detection. Magic bytes first, extension as tiebreak.

Detection resolves every file against the versioned format table in rules/formats.toml. Magic bytes win when they map to a table entry. When magic bytes are inconclusive, or point at a format the table does not name, the file extension decides. Both views are recorded, with a mismatch flag when they disagree.

Structs§

Detection
The detection outcome for one file.
FormatDef
One entry in the format table.
FormatTable
The parsed format table from rules/formats.toml.

Constants§

UNKNOWN_FORMAT
The detected id for a file neither magic bytes nor the extension can place.

Functions§

declared_format
The format id a file’s extension declares, when the table knows it.
detect_bytes_with_warnings
Detects the format of in-memory bytes against the table, using a path hint only for the declared extension or basename.
detect_file
Detects the format of one file against the table.
detect_file_with_warnings
Detects the format of one file and collects detection warnings.