os_mime_type 0.0.2 copy "os_mime_type: ^0.0.2" to clipboard
os_mime_type: ^0.0.2 copied to clipboard

The Flutter package os_mime_type enables the conversion of mime types to file extensions and vice versa, facilitating seamless interaction with file types in application development.

os_mime_type #

os_mime_type is a Dart package that aids in the conversion between MIME types and file extensions. With this package, you can easily determine the MIME type of a file based on its extension or filename, and also derive the file extension from a MIME type.

Functions #

This package provides the following functions:

  • mimeFromExtension({required String extension}): This function takes a file extension and returns the corresponding MIME type. If no matching MIME type is found, it returns "unknown".

  • mimeFromFileName({required String fileName}): This function takes a filename and returns the corresponding MIME type based on its extension.

  • extensionFromMime({required String mime}): This function takes a MIME type and returns the corresponding file extension. If no matching file extension is found, it returns null.

Usage Example #

import 'package:os_mime_type/os_mime_type.dart';

void main() {
  String mime = mimeFromExtension(extension: ".png");
  print(mime);  // Output: "image/png"

  mime = mimeFromFileName(fileName: "image.jpg");
  print(mime);  // Output: "image/jpeg"

  String? ext = extensionFromMime(mime: "application/json");
  print(ext);  // Output: ".json"
}
0
likes
140
points
1.49k
downloads

Publisher

unverified uploader

Weekly Downloads

The Flutter package os_mime_type enables the conversion of mime types to file extensions and vice versa, facilitating seamless interaction with file types in application development.

Homepage

Documentation

API reference

License

MIT (license)

Dependencies

flutter, path

More

Packages that depend on os_mime_type