mime
2.1.0, released 3 months ago by tools.dart.dev
Utilities to resolve MIME types from file names, magic bytes, and to parse multipart streams.
What it does
Provides functions to look up a MIME type based on a filename or header bytes and to get a file extension from a MIME type. Includes a stream transformer that splits multipart/form-data into separate parts.
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 determine MIME types for files without external libraries
- You need to parse multipart/form-data streams in a server or client
- You want a lightweight, pure‑Dart solution for MIME handling
Skip it when
- You require a full‑featured HTTP client that already handles multipart parsing
- You need advanced MIME type detection beyond extensions and basic magic numbers
Strengths
- Zero dependencies, pure Dart
- Supports both extension and magic‑byte lookup
- Provides a ready‑to‑use multipart stream transformer
Weaknesses
- Limited to the built‑in MIME table; not exhaustive for obscure types
- No async API for large file scanning beyond header bytes
Setup
- Kind
- Pure Dart
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 0
import 'package:mime/mime.dart';
void main() {
print(lookupMimeType('test.html')); // text/html
print(lookupMimeType('test', headerBytes: [0xFF, 0xD8])); // image/jpeg
}
Alternatives
Packages that do the same job and could replace mime.
- extension_discovery
Convention and utilities for discovering package extensions via config.yaml files.
86Compare - black_hole_flutter
Flutter utility functions, extension methods, and custom widgets.
83Compare - gtk
GTK utilities for Flutter Linux applications, providing settings and application lifecycle helpers.
76Compare - flutter_flavorizr
A utility to easily create and configure application flavors in Flutter.
86Compare
Works with
Packages commonly used together with mime: ones it builds on, ones built on it, and its own family.
- shelf_staticBuilt on mimeServe static files over HTTP with the shelf package
- ddsBuilt on mimeLibrary to spawn and communicate with the Dart Developer Service (DDS) via HTTP, WebSocket, or SSE.
- build_runnerBuilt on mimeA build system for Dart code generation and modular compilation.
- image_picker_for_webBuilt on mimeWeb implementation of image_picker that lets users select images or videos via the browser file picker.
- dioBuilt on mimeA powerful HTTP networking package for Dart and Flutter with interceptors and request cancellation.
- share_plusBuilt on mimeShare text, files, or URIs via native share dialogs on mobile, web, and desktop.
- storage_clientBuilt on mimeDart client library to interact with Supabase Storage.
- firebase_storageBuilt on mimeFlutter plugin to read and write files in Firebase Cloud Storage.