file-type

Detect the file type of a buffer, stream, or file by reading its magic number.

Library
npm
v22.0.2
4,320stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
70/100Good
Development Activity60
Maintenance56
Community64
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
89/100Excellent
Architecture88
Code Quality92
Innovation90
Learning Curve82

file-type is a JavaScript library that determines the true type of binary data by inspecting its magic number (the signature bytes at the start of a file) rather than trusting a filename extension or a client-supplied MIME type. It returns the canonical extension and MIME type for hundreds of formats spanning images, audio, video, archives, documents, and fonts.

Built on a streaming tokenizer, it works across Node.js and the browser and can read from files, Uint8Array/ArrayBuffer buffers, Blobs, and web ReadableStreams. Because it only needs the leading bytes of a file, it can identify large or remote files without downloading them in full, making it a common building block for secure upload validation and content pipelines.

What You Get

  • Detection from files, buffers, Blobs, web ReadableStreams, and custom tokenizers via a small set of fileTypeFrom* functions.
  • Support for hundreds of binary formats across images, audio, video, archives, documents, and fonts, each mapped to its canonical extension and MIME type.
  • Streaming detection that only reads the leading bytes, so large or remote files can be identified without loading them entirely.
  • First-class TypeScript definitions plus exported supportedExtensions and supportedMimeTypes sets.
  • A customDetectors hook and reusable FileTypeParser class for extending detection to formats not built in.

Common Use Cases

  • Validating file uploads on a server by verifying the real type instead of trusting the extension or client MIME header.
  • Routing or transcoding media by detecting whether incoming bytes are an image, audio, video, or archive.
  • Inspecting remote files over HTTP range requests or S3 without downloading the whole object.
  • Enforcing allow-lists of accepted formats in content pipelines and asset-processing jobs.

Under The Hood

Architecture Detection is organized around a streaming tokenizer abstraction. The fileTypeFrom* entry points in source/index.js normalize their input (file path, Uint8Array/ArrayBuffer, Blob, or web ReadableStream) into an strtok3 tokenizer, then hand it to a FileTypeParser whose parse method walks an ordered ladder of magic-number checks, reading only as many leading bytes as each signature requires. More involved container formats (PNG, ZIP, EBML/Matroska, ASF) live in dedicated modules under source/detectors/, keeping the main dispatch readable, and source/supported.js centralizes the extension and MIME tables exported as supportedExtensions and supportedMimeTypes.

Tech Stack The package is authored as pure ESM ("type": "module") targeting Node.js >= 22, with no build step for consumers beyond its TypeScript definitions. It depends on a small, focused tokenizer stack — strtok3, token-types, @tokenizer/inflate, and uint8array-extras — rather than pulling in heavy runtime dependencies. Development uses ava for tests, xo for linting, tsd for type-definition testing, and esbuild.

Code Quality Quality is a clear strength. The repository ships an exceptionally large test.js (roughly 280KB) exercised against a fixture/ directory of real sample files, so detection is validated against genuine binaries rather than hand-crafted byte stubs. Linting is enforced with xo and the public type surface is checked with tsd via source/index.test-d.ts. Naming is consistent and descriptive (fileTypeFromBuffer, fileTypeFromStream), and functions return undefined on no match rather than throwing, giving predictable control flow.

API Design The public API is small, orthogonal, and ergonomic: a family of fileTypeFrom{Buffer,File,Stream,Blob,Tokenizer} functions that each resolve to {ext, mime} or undefined, plus a fileTypeStream helper and a FileTypeParser class for advanced reuse. Extensibility is handled cleanly through a customDetectors option, and full TypeScript types plus a thorough README with copy-paste examples mean most users are productive after a single import.

Used by 40 apps in this directory

TypeScript
88%
Other

AFFiNE

Productivity · Project Management · Note Taking

71,668

Write, draw, and plan in one infinite canvas — the open-source alternative to Notion and Miro that keeps your data yours.

View details
91
Repo Health
87
Technical
68
Dependency
Built with
TypeScript88%
Updated today
TypeScript
89%
Other

anytype-ts

Knowledge Management · Note Taking · Collaboration

8,665

A local-first, end-to-end encrypted knowledge OS that lets you build notes, tasks, wikis, and entire apps — with your data stored offline and synced peer-to-peer.

View details
88
Repo Health
78
Technical
67
Dependency
Built with
TypeScript89%
Updated yesterday
TypeScript
97%
AGPL 3.0

Bigcapital

Invoicing Finance

3,846

Self-hostable double-entry accounting platform with invoicing, inventory, multi-currency, and real-time financial reporting for small and medium businesses.

View details
91
Repo Health
77
Technical
64
Dependency
Built with
TypeScript97%
Updated yesterday
TypeScript
92%
GPL 3.0

Blinko

Knowledge Management · Note Taking

10,880

A self-hosted, AI-powered card note-taking tool that lets you capture fleeting thoughts instantly and retrieve them with natural language search.

View details
83
Repo Health
69
Technical
65
Dependency
Built with
TypeScript92%
Updated 2 weeks ago
TypeScript
90%
Other

browserless

Developer Tools · Automation

13,605

Run headless Chrome, Firefox, and WebKit as a managed Docker service — drop-in Puppeteer and Playwright support with no infrastructure overhead.

View details
84
Repo Health
82
Technical
75
Dependency
Built with
TypeScript90%
Updated yesterday
TypeScript
99%
AGPL 3.0

Cherry Studio

AI Assistants

50,753

All-in-one AI desktop client with 300+ assistants and multi-model support

View details
88
Repo Health
84
Technical
71
Dependency
Built with
TypeScript99%
Updated today
TypeScript
99%
Apache 2.0

Colanode

Knowledge Management · Team Chat · Collaboration

5,018

Local-first, self-hosted workspace that combines real-time chat, Notion-style pages, and structured databases — all synced via CRDTs so you work offline without losing a keystroke.

View details
47
Repo Health
73
Technical
73
Dependency
Built with
TypeScript99%
Updated 4 months ago
TypeScript
100%
Other

Dub

Marketing · Analytics

24,521

The open-source link attribution platform for short links, conversion tracking, and affiliate programs — powering 100M+ clicks monthly.

View details
81
Repo Health
78
Technical
65
Dependency
Built with
TypeScript100%
Updated today
TypeScript
89%
Other

FastGPT

AI Agents · AI Development

29,387

Build, debug, and deploy knowledge-based AI agents with a visual workflow editor, RAG retrieval, and support for any OpenAI-compatible LLM.

View details
93
Repo Health
84
Technical
70
Dependency
Built with
TypeScript89%
Updated today

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