infer

A small Rust crate that infers a file's true type from its magic-number byte signature, not its extension

Library
Cargo
v0.22.0
397stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
66/100Good
Development Activity56
Maintenance60
Community68
Maturity60
Momentum20

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
75/100Good
Architecture74
Code Quality78
Innovation60
Learning Curve88

infer determines a file’s real type by inspecting the first bytes of its content against a built-in table of magic-number signatures, covering images, video, audio, archives, documents, fonts, and executables. Because it reads the byte signature rather than trusting a filename extension or user-supplied MIME type, it is commonly used to validate uploaded files server-side where an attacker could otherwise rename a malicious file to look like an innocuous one.

The crate supports both a std mode (reading from a File or byte slice, including container formats like CFB via the cfb dependency) and a no_std/alloc mode for embedded or constrained environments, and exposes a small, extensible Matcher type so applications can register custom signatures for formats infer doesn’t recognize out of the box.

What You Get

  • Magic-number-based type detection covering images, video, audio, archives, documents, fonts, and executables
  • get() / get_from_path() functions returning a Type with extension and MIME type
  • is_*() convenience predicates (is_image, is_video, is_archive, etc.) for common category checks
  • Custom Matcher registration for detecting formats not covered by the built-in signature table
  • no_std + alloc compatibility for use in embedded or WASM contexts

Common Use Cases

  • Validating uploaded file content server-side so an attacker can’t bypass extension-based checks by renaming a malicious file
  • Sniffing the real type of a file whose extension is missing, wrong, or untrusted
  • Routing files to type-specific processing pipelines (image resizing, video transcoding, document parsing) based on detected type rather than extension
  • Adding detection for a proprietary or uncommon binary format via a custom Matcher

Under The Hood

Architecture - The crate centers on a Type enum returned by get()/get_from_path(), backed by a matchers/ directory splitting signature-matching logic by category (image, video, audio, archive, doc, font, app, text, odf, book), each exposing small matcher functions checked in priority order against the byte buffer; map.rs wires these matchers to their corresponding extension/MIME-type metadata.

Tech Stack - Pure Rust, no_std-compatible by default with std/alloc as opt-in Cargo features; the only optional dependency is cfb (Compound File Binary format support, e.g. for legacy MS Office formats), pulled in only under the std feature so the no_std build stays dependency-free.

Code Quality - The tests/ and testdata/ directories contain real sample files per supported format used to assert correct detection, and the matcher functions are small, single-purpose, and easy to audit individually; the crate has maintained a steady, if modest, contribution and release cadence.

API Design - The primary entry points (infer::get(buf), infer::get_from_path(path), and category predicates like infer::is_image(buf)) require no configuration and return a simple Option<Type> or bool, making the common case a one-line call; extending detection with a custom Matcher is a small amount of additional code, keeping the API approachable for both the simple and the extensible use case.

Used by 6 apps in this directory

Rust
69%
Other

GitButler

Developer Tools · Devops · AI Development

21,531

Git, but better — a modern version control client with stacked branches, parallel workflows, unlimited undo, and first-class support for AI-powered development.

View details
89
Repo Health
84
Technical
68
Dependency
Built with
Rust69%
TypeScript18%
Svelte12%
Updated today
TypeScript
67%
MIT

Hoppscotch

Developer Tools

80,055

A lightweight, offline-capable API development ecosystem for testing HTTP, GraphQL, WebSocket, MQTT, and SSE endpoints across web, desktop, and CLI.

View details
91
Repo Health
83
Technical
66
Dependency
Built with
TypeScript67%
Vue23%
Updated 3 days ago
TypeScript
75%
Other

Jan

AI Assistants

44,052

Run LLMs 100% locally with full privacy, or connect to cloud AI — your machine, your data, your control.

View details
90
Repo Health
81
Technical
66
Dependency
Built with
TypeScript75%
Rust21%
Updated today
Rust
78%
AGPL 3.0

Lemmy

Community · Social Media

14,555

Federated, self-hosted Reddit alternative with full community ownership and no corporate control.

View details
90
Repo Health
74
Technical
63
Dependency
Built with
Rust78%
PLpgSQL14%
Updated yesterday
Rust
46%
MIT

Meetily

Productivity · AI Assistants

29,484

Privacy-first AI meeting assistant that transcribes and summarizes your meetings entirely on your local machine — no cloud, no data leakage.

View details
70
Repo Health
72
Technical
71
Dependency
Built with
Rust46%
TypeScript30%
Updated 2 months ago
Rust
98%

Stalwart

Collaboration

14,255

All-in-one secure mail and collaboration server covering IMAP, JMAP, SMTP, CalDAV, CardDAV, and WebDAV in a single memory-safe Rust binary.

View details
89
Repo Health
81
Technical
68
Dependency
Built with
Rust98%
Updated yesterday

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search