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
407 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
63 /100 Good
Development Activity 44
Maintenance 60
Community 68
Maturity 60
Momentum 20

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
75 /100 Good
Architecture 74
Code Quality 78
Innovation 60
Learning Curve 88

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 8 apps in this directory

Rust
65%
Other

GitButler

AI Development · Developer Tools · Devops

21,726

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
66
Dependency
Built with
Rust 65%
TypeScript 22%
Svelte 10%
Updated 1 weeks ago
TypeScript
67%
MIT

Hoppscotch

Developer Tools

80,529

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
65
Dependency
Built with
TypeScript 67%
Vue 25%
Updated 1 weeks ago
Rust
52%
Other

Jan

AI Assistants

44,680

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
65
Dependency
Built with
Rust 52%
TypeScript 44%
Updated 1 weeks ago
Rust
78%
AGPL 3.0

Lemmy

Community · Social Media

14,614

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

View details
89
Repo Health
74
Technical
62
Dependency
Built with
Rust 78%
PLpgSQL 14%
Updated 2 weeks ago
Rust
48%
MIT

Meetily

AI Assistants · Productivity

31,171

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

View details
85
Repo Health
72
Technical
67
Dependency
Built with
Rust 48%
TypeScript 29%
Updated 3 weeks ago
Rust
68%
MIT

Readur

Bookmarks Archiving · File Storage · Knowledge Management

797

A self-hosted document management system that OCRs, indexes, and makes every PDF, scan, and Office file instantly searchable.

View details
81
Repo Health
78
Technical
67
Dependency
Built with
Rust 68%
TypeScript 30%
Updated 1 weeks ago
Rust
98%

Stalwart

Collaboration

14,848

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
65
Dependency
Built with
Rust 98%
Updated 1 weeks ago
TypeScript
67%
Apache 2.0

tabularis

Databases · Developer Tools

5,076

Open-source desktop SQL workspace with built-in PostgreSQL, MySQL, and SQLite drivers, SQL notebooks, a visual query builder, and a built-in MCP server for AI agents like Claude and Cursor.

View details
83
Repo Health
89
Technical
70
Dependency
Built with
TypeScript 67%
Rust 32%
Updated 1 weeks ago

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