Skip to main content

Module classifier

Module classifier 

Source
Expand description

Drop classifier (seine): entropy + magic-byte heuristics.

Labels each drop’s plaintext with a class so the deepening stage can pick a class-appropriate codec. Pure-functional, stateless, deterministic — same input always yields the same class.

§Classes

  • Text — UTF-8 printable, mostly ASCII
  • Code — executable container (ELF, Mach-O, PE)
  • Compressed — already-compressed bytes (gzip, zstd, xz, bz2)
  • Media — image / audio / video container (JPEG, PNG, GIF, MP3, MP4)
  • Sparse — dominated by zero bytes
  • Binary — fallback when no other class fits
  • Incompressible — high entropy, no magic: random/encrypted; skip codec

§Algorithm

  1. If the first bytes match a known magic, return that class immediately. Magic detection is the highest-confidence signal.
  2. Otherwise, compute Shannon entropy over a sample (first 4 KiB):
    • < 0.5 → Sparse if zero-byte ratio is also high, else Text
    • 0.5–6.5 → Text if mostly printable, else Binary
    • 6.5–7.5 → Incompressible (likely random/encrypted; skip codec)
    • ≥ 7.5 → Incompressible (very high entropy, no magic: same)
  3. Fall back to Binary.

Note: Compressed is only ever returned by the magic-byte path (gzip/zstd/xz streams). High-entropy data without a recognised magic is Incompressible, not Compressed — the previous label was a misnomer that caused the writer to attempt (and fail) compression on random/encrypted input.

Structs§

Classifier
A stateless classifier. Holding it in a struct (rather than a free function) leaves room for future configuration without changing the call sites (OCP).

Enums§

Class
One of the content classes the seine classifier emits. Each chunk gets exactly one class; the writer’s drop-packing layer routes classes to codecs.

Constants§

CLASSIFIER_SAMPLE_SIZE
Number of bytes at the drop’s start used for classification. The full drop can be megabytes; the first 4 KiB is enough signal.