# h2non/filetype

Fast, dependency-free Go package to infer binary file types based on the magic numbers header signature

Repository: https://github.com/h2non/filetype
Canonical: https://ross.abutalabs.com/products/filetype
Homepage: https://pkg.go.dev/github.com/h2non/filetype?tab=doc
Language: Go
License: MIT
License Family: permissive
Topics: magic-numbers, filetype, mime, mime-types, discovery, lookup, magic-number, extension, validation, binary, golang
Last push: 2026-07-01T21:07:54+00:00

## Health v2 (maintenance only)
Score: 63/100 (v2, computed 2026-09-03T02:20:16.233290+00:00)
- activity 90, release rhythm 8, longevity 100
- inputs: {"age_days": 3996, "days_push": 63, "days_rel": null, "gap_med": null, "n_releases_24m": 0}
- flags: none
- formula: round(0.45*activity + 0.35*rhythm + 0.20*longevity); archived -> min(score, 10)

## Adoption (not part of the score)
Stars 2297, forks 190 (observed 2026-08-28T04:06:35.252841+00:00)

## What it is
A small, dependency-free Go library that infers file and MIME types by checking binary magic number signatures. It supports a wide range of file types, requires only the first 262 bytes of a file, and allows pluggable custom matchers.

## Use cases
- detect the real file type of an uploaded file regardless of its extension
- get the MIME type from a binary file header in Go
- check if a file is an image, video, or audio by its content
- validate that uploaded files match their claimed extension
- identify file types from just the first bytes of a stream

## When to choose
- you need fast, dependency-free file type detection in Go
- you only have access to a file header or byte slice, not the full file
- you want to validate uploads by content rather than trusting extensions or client-supplied MIME types

## When to avoid
- you need to detect text-based formats like SVG (use go-is-svg instead)
- you need deep content inspection beyond the file header
- you are not working in Go

## Facets
- artifact type: library
- maturity: stable
- function: parser, developer-tools
- domain: files, developer-tools
- platform: go, cross-platform
- tags: magic-numbers, mime-type, file-type-detection, file-validation

## Member repositories
- h2non/filetype (main) score 63

## Provenance
- Observed fields: from GitHub, fetched 2026-08-28T04:06:35.252841+00:00.
- Health v2: computed from the inputs above; adoption is never an input.
- Inferred fields (summary, facets, guidance): AI-extracted, prompt v1, taxonomy v1, on 2026-08-30T02:40:18.326096+00:00, confidence not recorded.
  - readme: https://github.com/h2non/filetype (fetched 2026-08-28T04:06:35.252841+00:00, sha c8b06de5cf77)
  - homepage: https://pkg.go.dev/github.com/h2non/filetype?tab=doc (fetched 2026-08-29T10:20:33.965341+00:00, sha 2528be53c308)
  - site_page: https://pkg.go.dev/about (fetched 2026-08-29T10:20:33.974654+00:00, sha 757852027879)
  - site_page: https://go.dev/project (fetched 2026-08-29T10:20:33.976800+00:00, sha d5ca00bb378b)
- Data as of 2026-08-30T08:39:29.467469+00:00.
