Skip to main content

Module classify

Module classify 

Source
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, and ext_bucket, which labels its None as NO_EXTENSION. Any final dotted component counts if that extension is valid Unicode, with no character or length restriction; a .tar before it is kept. An invalid native extension has no bucketable string and maps to None. 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_ext and NameClassification::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_ext and NameClassification::canonical_extension, from TypeRegistry::classify_name. This is the declared extension the logical one matched, whole or by its final component. It is None when nothing declared matches, or when an exact filename wins first.

Where the levels part, with the compiled registry (none is None):

NameRawBucketLogicalCanonical
archive.tar.gz.tar.gz.tar.gz.tar.gz.tar.gz
release.v2.zip.zip.zip.v2.zip.zip
file.c++.c++.c++nonenone
.gitignorenone(none)nonenone
notes.none(none)nonenone

A unit test reads this table and checks every cell against the functions.

Structs§

Classification
Result of the cheapest-first file-type cascade.
ClassificationFlags
Orthogonal attributes discovered from bounded path and prefix checks.
FileTypeId
Stable identifier for a known or preserved unknown file type.
NameClassification
Registry-derived portable identity for one basename.
TypeFamily
One ordered display family from a File Rollup registry.
TypeGroup
One ordered browsing group from a File Rollup registry.
TypeRegistry
A set of file-type rules, indexed for the classification cascade.

Enums§

ContentFamily
Broad analysis family for a recognized file type.
DetectionConfidence
Coarse confidence attached to a classification decision.
DetectionSource
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.