file_type_plus 1.0.0
file_type_plus: ^1.0.0 copied to clipboard
Utilities for handling media (MIME) types, including determining a type from a file extension and file contents.
File Type Plus
File Type Plus is a powerful and lightweight Dart package that intelligently detects and categorizes file types with multiple detection methods. Whether you're working with file paths, URLs, MIME types, or raw byte data, this package provides accurate file type classification for images, audio, video, documents, HTML files, archives, and more.
Perfect for file upload validation, content management systems, file browsers, media galleries, and any application that needs reliable file type detection. Built with 100% test coverage and full null safety support.
β¨ Features #
- π― Multiple Detection Methods - Detect from file extensions, MIME types, file paths, URLs, or raw bytes
- π Magic Number Support - Identify files by analyzing their byte signatures (magic numbers)
- π 7 File Categories - Organized classification: image, audio, video, document, HTML, archive, and other
- π¬ Streaming Video Support - Special handling for ISM, HLS (.m3u8), and DASH formats
- β‘ Fast & Lightweight - Minimal dependencies with efficient detection algorithms
- π‘οΈ Type Safe - Full null safety and strong typing support
- β 100% Test Coverage - Thoroughly tested with 81+ unit tests
- π¦ Easy Integration - Simple API with comprehensive examples
- π URL & Path Support - Works with local paths, network URLs, and various path formats
Installation #
Add this to your package's pubspec.yaml file:
dependencies:
file_type_plus: ^1.0.0
Then run:
dart pub get
Usage #
Basic Usage #
import 'package:file_type_plus/file_type_plus.dart';
// Detect from file extension
final type = FileType.fromExtensionOrMime(extension: 'jpg');
print(type.value); // image
// Detect from MIME type
final type = FileType.fromExtensionOrMime(mimeType: 'image/jpeg');
print(type.value); // image
// Detect from file path
final type = FileType.fromPath('photo.jpg', null);
print(type.value); // image
// Detect from bytes
final bytes = Uint8List.fromList([0xFF, 0xD8, 0xFF]);
final type = FileType.fromBytes(bytes, null);
print(type.value); // image
Filtering Files #
final files = ['photo.jpg', 'song.mp3', 'video.mp4'];
// Filter by single type
final images = files.where((f) =>
FileType.fromPath(f, null) == FileType.image
).toList();
// Filter by multiple types
final media = files.where((f) {
final type = FileType.fromPath(f, null);
return type.isAny([FileType.image, FileType.audio, FileType.video]);
}).toList();
Examples #
Check out the example directory for comprehensive examples:
- basic_usage.dart - Basic file type detection
- path_detection.dart - Detecting from file paths and URLs
- bytes_detection.dart - Detecting from byte data
- filtering_files.dart - Filtering and categorizing files
- html_filtering.dart - HTML file detection
- advanced_usage.dart - Advanced use cases
Run any example:
dart run example/basic_usage.dart
Available File Types #
FileType.image- Image files (jpg, png, gif, etc.)FileType.audio- Audio files (mp3, wav, flac, etc.)FileType.video- Video files (mp4, avi, mov, etc.)FileType.document- Document files (pdf, doc, txt, etc.)FileType.html- HTML files (html, htm, xhtml, etc.)FileType.archive- Archive files (zip, rar, tar, etc.)FileType.other- Unknown or unclassified files
Development #
Running Tests #
dart test
Running Tests with Coverage #
# Quick way
dart test --coverage=coverage