Skip to main content

Module document_format

Module document_format 

Source
Expand description

Byte-based document-format detection for the universal observation API (Phase 12.7, ADR-0031, plan §DEC-5).

The format of a field is decided from its source bytes, never from a file name or extension. Detection is deliberately conservative: an ambiguous or malformed input falls back to DocumentFormat::Opaque rather than guessing, and a format whose adapter is not compiled in cannot be detected (the input is then Opaque), so the reported capability set always matches what the build can actually serve.

  • PDF — the byte-authoritative physical scanner admits a validated PDF (crate::adapter::pdf::detect).
  • DOCX — a valid ZIP that also carries the OPC content-types part ([Content_Types].xml) and a package officeDocument relationship.
  • EPUB — a valid ZIP that is an OCF container: the mandatory stored mimetype member equals application/epub+zip, or META-INF/container.xml names the OCF namespace and an OPF (application/oebps-package+xml) rootfile.
  • ODT — a valid ZIP that is an OpenDocument (ODF) package: the mandatory stored mimetype member is an OpenDocument text media type, or META-INF/manifest.xml declares one.
  • Opaque — everything else, including a ZIP that matches none of the above (or more than one — an ambiguous ZIP fails safe).

The detected format is recorded in the field manifest’s provenance (a machine-readable format=<name>; prefix, see DocumentFormat::from_provenance), so observe/find/explain can dispatch common selectors without reading the whole source again.

Enums§

DocumentFormat
A detected document format (the class of the field’s source bytes).

Constants§

CONTAINER_MEMBER
The mandatory OCF container descriptor member.
CONTAINER_NS
The OCF container-descriptor namespace.
EPUB_MIMETYPE
The mandatory OCF mimetype payload.
OPF_MEDIA_TYPE
The default (and only normative) package-document media type.

Functions§

detect_document_format
Detect the document format of source from its bytes alone.