File Type Plus

Github action Code Coverage Pub Package Pub Points
MIT License


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: ^0.1.2

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

// Detect from category name (useful for deserialization)
final type = FileType.fromName('video');
print(type.value); // video

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:

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

Libraries

file_type_plus
A Flutter library that provides comprehensive state management solutions and utility functions for building scalable mobile applications.