Expand description
File-type recognition.
Exact filenames and extensions are resolved from a TypeRegistry; the repository
default is compiled at build time, and callers may parse a replacement once at setup.
Classification may also use a caller-supplied bounded prefix for binary signatures,
shebangs, modelines, ambiguous headers, and origin flags. Classification never parses
rules or opens a file; the caller owns the optional read.
§Extension levels
A file name has up to three extensions, one per question, and each has its own functions:
- Raw:
derive_ext, andext_bucket, which labels itsNoneasNO_EXTENSION. Any final dotted component counts if that extension is valid Unicode, with no character or length restriction; a.tarbefore it is kept. An invalid native extension has no bucketable string and maps toNone. The extension view, per-directory extension tallies, and an unrecognized type’s label use this level. It is the answer fdu gave before registries existed. - Logical:
logical_extandNameClassification::logical_extension. This is File Rollup Format’s name-owned extension: up to two trailing components, each ASCII alphanumeric and at most twelve bytes. A portable entry row reports it. - Canonical:
TypeRegistry::canonical_extandNameClassification::canonical_extension, fromTypeRegistry::classify_name. This is the declared extension the logical one matched, whole or by its final component. It isNonewhen nothing declared matches, or when an exact filename wins first.
Where the levels part, with the compiled registry (none is None):
| Name | Raw | Bucket | Logical | Canonical |
|---|---|---|---|---|
archive.tar.gz | .tar.gz | .tar.gz | .tar.gz | .tar.gz |
release.v2.zip | .zip | .zip | .v2.zip | .zip |
file.c++ | .c++ | .c++ | none | none |
.gitignore | none | (none) | none | none |
notes. | none | (none) | none | none |
A unit test reads this table and checks every cell against the functions.
Structs§
- Classification
- Result of the cheapest-first file-type cascade.
- Classification
Flags - Orthogonal attributes discovered from bounded path and prefix checks.
- File
Type Id - Stable identifier for a known or preserved unknown file type.
- Name
Classification - Registry-derived portable identity for one basename.
- Type
Family - One ordered display family from a File Rollup registry.
- Type
Group - One ordered browsing group from a File Rollup registry.
- Type
Registry - A set of file-type rules, indexed for the classification cascade.
Enums§
- Content
Family - Broad analysis family for a recognized file type.
- Detection
Confidence - Coarse confidence attached to a classification decision.
- Detection
Source - Which bounded step established a classification.
Constants§
- NO_
EXTENSION - Extension-view label for files whose name carries no extension.
Functions§
- classify_
path - Classify from path metadata only, against the compiled default rules.
- classify_
path_ with_ prefix - Classify with an optional bounded content prefix, against the compiled default rules.
- classify_
with - Classify against a specific registry, with an optional bounded content prefix.
- derive_
ext - Extract the compound-tail extension from a file name, lowercased and including the leading dot.
- ext_
bucket - Label of the extension bucket a file belongs to, including the one for no extension.
- logical_
ext - Return the logical extension of a file name, lowercased and including its leading dot.
- type_
rule_ fingerprint - Fingerprint of the repository-owned rule manifest compiled into this build.