CtrlK
BlogDocsLog inGet started
Tessl Logo

mime-detection-routing

MIME type detection and extractor routing in core/mime.rs and core/extractor/bytes.rs — the extension→EXT_TO_MIME→validate→registry→extractor flow, key detection functions, the 118+ case-insensitive extension map, priority-based registry selection, wildcard MIME families, and how to add a new MIME type. Load when adding a format, wiring an extractor to a MIME type, or debugging why a file routes to the wrong (or no) extractor.

75

Quality

92%

Does it follow best practices?

Run evals on this skill

Adds up to 20 points to the overall score

View guide

SecuritybySnyk

Passed

No findings from the security scan

SKILL.md
Quality
Evals
Security

MIME Detection & Routing

Detection Flow

Extension -> EXT_TO_MIME map -> validate -> Registry lookup -> Extractor

Key Functions

FunctionLocationPurpose
detect_mime_type(path, inspect)core/mime.rsExtension + optional content inspection
detect_mime_type_from_bytes(bytes)core/mime.rsMagic number detection (infer crate)
validate_mime_type(mime)core/mime.rsCheck if any extractor supports it

Extension Mapping

118+ extensions mapped in EXT_TO_MIME (core/mime.rs). Case-insensitive.

Key mappings: .pdf -> application/pdf, .docx -> application/vnd.openxmlformats-officedocument.wordprocessingml.document, .xlsx -> spreadsheet variant, .png/.jpg -> image/*

Registry Selection

// In core/extractor/bytes.rs
fn select_extractor_for_mime(mime_type: &str) -> Result<Arc<dyn DocumentExtractor>> {
    let registry = get_document_extractor_registry();
    let registry_guard = registry.read()?;
    registry_guard.get_for_mime_type(mime_type)
        .ok_or_else(|| XbergError::UnsupportedFormat(mime_type.into()))
}

Selects highest-priority extractor registered for that MIME type.

Adding New MIME Types

  1. Add extension mapping: m.insert("ext", "application/x-new"); in core/mime.rs
  2. Implement DocumentExtractor with supported_mime_types() returning the MIME
  3. Register in register_default_extractors()

Wildcard Support

Extractors can register for MIME type families: "image/*" matches image/png, image/jpeg, etc.

Critical Rules

  1. Always validate_mime_type() before extraction
  2. Extension mapping is case-insensitive
  3. Content inspection (infer crate) is fallback for extension-less files
  4. Registry validation is final authority on supported types
Repository
xberg-io/xberg
Last updated
First committed

Is this your skill?

If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.