Expand description
Format detection by content sniffing.
The file extension is a hint and is never consulted here. A .jpg that is really a
PDF must be handled as a PDF or refused outright; handing it to the JPEG handler would
produce a confident success message about a file that was never touched
(docs/ARCHITECTURE.md §1, docs/THREAT_MODEL.md §5.4). Detection therefore takes bytes
and nothing else — there is deliberately no way to pass it a path.
Detection is itself a hostile-input parser: it is the one piece of code that sees every
byte of every file the user feeds in, including files no handler will ever accept. It
reads through [crate::bytes::Reader] for the same reason the handlers do.
§Why this is hand-written rather than a dependency
file-format and infer were both evaluated (docs/ARCHITECTURE.md §4). Phase 1 needs
to discriminate exactly four supported formats plus a short list of formats worth naming
in a refusal, which is under a hundred lines of magic-number matching. Taking a crate with
broad magic tables for that would add supply-chain surface (ADR-0008) to save very little.
Revisit in Phase 2, when the supported-format count grows and the container types get
genuinely ambiguous.
Enums§
- Format
- A format strypt has a handler for.
Functions§
- detect
- Identify
databy content.