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.
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.
- file_selector_macos
macOS implementation of the file_selector plugin
82Compare - flutter_downloader
Plugin to create and manage background download tasks on Android and iOS.
80Compare - path_provider_android
Android implementation of the path_provider plugin for finding commonly used locations.
79Compare - path_provider_foundation
iOS/macOS implementation of path_provider using direct FFI calls
78Compare
Works with
Packages commonly used together with file_magic_number: ones it builds on, ones built on it, and its own family.
- mimefile_magic_number depends on itUtilities to resolve MIME types from file names, magic bytes, and to parse multipart streams.
- webfile_magic_number depends on itLightweight bindings for browser APIs via JS interop
- cross_filefile_magic_number depends on itAn abstraction to allow working with files across multiple platforms.
- file_pickerSame familyUse the native file explorer to pick single or multiple files, directories, and save files.
- file_picker_webSame familyWeb implementation of file_picker for selecting, streaming, and saving files in browsers.
- file_picker_platform_interfaceSame familyCommon platform interface for the file_picker federated plugin.
- pdf_combinerBuilt on file_magic_numberMerge multiple PDF documents and images into a single file or extract images from PDFs.