Skip to main content

Module detect

Module detect 

Source
Expand description

File type detection: signature first, extension as a hint.

Order (see docs/PRD/03-tech-stack.md):

  1. magic bytes — %PDF, {\rtf, PK\x03\x04 (then peek inside the ZIP for mimetype, word/, ppt/, xl/);
  2. extension, which is what decides the text formats (txt/md/csv/…);
  3. a last-resort sniff for HTML in the head bytes.

Detection is a pure function over Sniff, so it is unit-testable without touching the filesystem.

Structs§

Sniff
Everything detection needs about a file: its extension and its head bytes.

Enums§

Format
A document format DeepDoc knows about.

Constants§

SNIFF_LEN
How many bytes of the file head are read for sniffing.

Functions§

detect
Detect a format from already-sniffed bytes. Pure.
detect_path
Detect the format of a file on disk.
detect_signature
Detect a format from magic bytes alone.