Skip to content
pubscout

file_magic_number

2.1.0, released 4 months ago by victorcarreras.dev

Detect file types based on content headers and magic numbers across platforms.

WASM-ready
$ flutter pub add file_magic_number
Source repository

What it does

A Flutter package to detect file types using their magic numbers and file extensions instead of relying solely on MIME types. It reads files cross-platform using cross_file and supports mobile, desktop, and web without native code dependencies.

AI-written summary of version 2.1.0, based on the package's README and metadata. Report an inaccuracy

Use it when

  • You need to reliably identify file types from bytes, paths, or blobs across platforms including the web.
  • You want to avoid relying purely on untrustworthy MIME types or file extensions provided by users.

Skip it when

  • You require deep content inspection or parsing of complex document internals beyond basic file type detection.

Strengths

  • Supports mobile, desktop, and web without native code dependencies.
  • Allows dynamic registration of custom file signatures, extensions, and MIME-to-type mappings.
  • Optimized stream reading prevents high memory usage on large files.

Weaknesses

  • Limited to predefined file type signatures unless custom types are explicitly registered.

Setup

Kind
Flutter widgets
Effort
Low
Code generation
No
Direct dependencies
3
import 'package:file_magic_number/file_magic_number.dart';

void main() {
  final bytes = Uint8List.fromList([0x25, 0x50, 0x44, 0x46]);
  final FileMagicNumberType fileType = FileMagicNumber.detectFileTypeFromBytes(bytes);
  print(fileType);
}

Alternatives

Packages that do the same job and could replace file_magic_number.

Works with

Packages commonly used together with file_magic_number: ones it builds on, ones built on it, and its own family.