# mime_type 1.0.1

MIME type library for Dart HTTP server applications.




## Installing
```
export PUB_HOSTED_URL=https://pub.mirror.p-hatan.com
flutter pub add mime_type
```
Published: 2024-08-27T22:00:29.636526Z
Expected archive SHA-256: d652b613e84dac1af28030a9fba82c0999be05b98163f9e18a0849c6e63838bb

Available in cache; verification: upstream_checksum
## Direct dependencies

## Package README (untrusted upstream documentation)
MIME type
==

Library to get MIME type from a file name or a file path and get the file extension from a MIME type.
When a HTTP server sends a file to the client, MIME type of the file must be set to the Content-Type header of the response.

Only three methods are available:

+   String `mime(String FileName)` //
    gets the MIME type from a file name (such as 'Hello.dart') or a file path (such as '..\Hello.dart').
 
+   String `mimeFromExtension(String extension)` //
    gets the MIME type from an extension (such as 'dart')
    
+   String `extensionFromMime(String mime)` //
    gets extension from MIME type (returns null if there is no such mime type)

All methods return null if they cannot find a match.

## Example


```dart
import 'package:mime_type/mime_type.dart';

sendFile(HttpRequest request, String fileName) {
  HttpResponse response = request.response;
  File file = new File(fileName);
  if (file.existsSync()) {
    String mimeType = mime(fileName);
    if (mimeType == null) mimeType = 'text/plain; charset=UTF-8';
      // you can change the default content type
      // or, you can choose to send error message
    response.headers.set('Content-Type', mimeType);
    RandomAccessFile openedFile = file.openSync();
    response.contentLength = openedFile.lengthSync();
    openedFile.closeSync();
    file.openRead().pipe(response);
  } else {
    // send 404 (Not Found) status to the client
  }
}
```

## License
This library is licensed under [MIT License](http://www.opensource.org/licenses/mit-license.php).

## Changelog
# Changelog

## 1.0.1
- Add `mjs` as `application/javascript`

## 1.0.0
- Null safety version of version 0.3.2

## 0.3.2
- Hashmap speedup and updated types.

## 0.3.1
- Check null or empty filename to avoid crash.

## 0.3.0
- Added `extensionFromMime` function to get an extension given a mime type.

## 0.2.7
- Support for High Efficiency Video Coding

## 0.2.6
- Support for High Efficiency Image File Format

## 0.2.5
- avoid to give false result for JPG files

## 0.2.4
- prepare for Uint8List SDK breaking change

## 0.2.3
- forward compatible change in test/apache-types_includer.dart for upcoming SDK change

## 0.2.2
- add dart environment information
 
## 0.2.1
- Type woff2 added.

## 0.2.0

- Included [Apache-types](https://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types).
- Changed MIME type for extension 'dart' from 'application/dart' to 'application/vnd.dart'.

## 0.1.1 to 0.1.7

- Several types added.

## 0.1.0

- First publishing.







 
