file_type_plus 0.1.1
file_type_plus: ^0.1.1 copied to clipboard
Utilities for handling media (MIME) types, including determining a type from a file extension and file contents.
example/README.md
Examples #
This directory contains comprehensive examples demonstrating various features of the file_type_plus package.
Quick Start #
New to the package? Start here:
dart run example/quick_start.dart
This shows the most common use cases in a simple format.
Running Examples #
To run any example:
dart run example/quick_start.dart # π Start here!
dart run example/basic_usage.dart
dart run example/path_detection.dart
dart run example/bytes_detection.dart
dart run example/filtering_files.dart
dart run example/html_filtering.dart
dart run example/advanced_usage.dart
dart run example/file_manager_demo.dart
Example Files #
0. quick_start.dart π Start Here! #
Quick introduction showing the most common use cases.
Topics covered:
- Basic detection from extension
- Basic detection from MIME type
- Detection from path
- Simple file filtering
- Multiple type filtering
- List of all available types
Run:
dart run example/quick_start.dart
1. basic_usage.dart #
Basic file type detection using extensions and MIME types.
Topics covered:
- Detecting file types from extensions
- Detecting from MIME types
- Case-insensitive detection
- Extension vs MIME type priority
- Handling unknown types
- Listing all available types
Run:
dart run example/basic_usage.dart
2. path_detection.dart #
Detecting file types from file paths and URLs.
Topics covered:
- Simple file paths
- HTTP/HTTPS URLs
- Special case: ISM streaming detection
- Using explicit MIME types
- Complex paths with query parameters
- Windows paths
- File filtering by path
- Real-world media gallery example
Run:
dart run example/path_detection.dart
3. bytes_detection.dart #
Detecting file types from byte data (magic numbers).
Topics covered:
- JPEG magic bytes detection
- PNG magic bytes detection
- PDF magic bytes detection
- MIME type override
- Unknown byte patterns
- Reading real files
- File upload validation
- Extension vs content validation
Run:
dart run example/bytes_detection.dart
4. filtering_files.dart #
Filtering and categorizing files by type.
Topics covered:
- Filter by single type
- Filter by multiple types using
isAny() - Grouping files by type
- File statistics
- Media gallery example
- Advanced filtering
- Excluding certain types
Run:
dart run example/filtering_files.dart
5. html_filtering.dart #
Detecting and filtering HTML files.
Topics covered:
- HTML file extension detection
- MIME type detection
- Filtering HTML files from mixed content
- Web-related file filtering
- HTML extensions list
- Web project file processing
- Building site maps
Run:
dart run example/html_filtering.dart
6. advanced_usage.dart #
Advanced use cases and patterns.
Topics covered:
- Extension map exploration
- Type comparison
- Using
isAnyType() - Streaming video detection (ISM, HLS)
- Building a file manager
- Content-Type headers
- Bulk file validation
- Custom icons by file type
Run:
dart run example/advanced_usage.dart
7. file_manager_demo.dart #
Complete file manager application demonstration.
Topics covered:
- Building a complete file manager
- File organization by type
- File organization by folder
- Search functionality
- Storage analysis
- File statistics
- Export options
- Real-world application structure
Run:
dart run example/file_manager_demo.dart
Quick Reference #
Basic Detection #
// From extension
final type = FileType.fromExtensionOrMime(extension: 'jpg');
print(type.value); // image
// From MIME type
final type = FileType.fromExtensionOrMime(mimeType: 'image/jpeg');
print(type.value); // image
// From file path
final type = FileType.fromPath('photo.jpg', null);
print(type.value); // image
// From bytes
final bytes = Uint8List.fromList([0xFF, 0xD8, 0xFF]);
final type = FileType.fromBytes(bytes, null);
print(type.value); // image
Filtering #
// Single type
final images = files.where((f) =>
FileType.fromPath(f, null) == FileType.image
).toList();
// Multiple types
final media = files.where((f) {
final type = FileType.fromPath(f, null);
return type.isAny([FileType.image, FileType.audio, FileType.video]);
}).toList();
Available 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
See Also #
- Package Documentation
- API Reference
- Test Files - Additional usage examples in tests