Skip to content

Commit

Permalink
Update Library
Browse files Browse the repository at this point in the history
  • Loading branch information
Nitesh Sharma committed Jul 2, 2022
1 parent 8ed357b commit cf4d1cb
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 109 deletions.
35 changes: 0 additions & 35 deletions .github/scripts/pub_login.sh

This file was deleted.

32 changes: 0 additions & 32 deletions .github/workflows/publish.yaml

This file was deleted.

20 changes: 10 additions & 10 deletions example/mime_dart_example.dart
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import 'package:mime_dart/mime_dart.dart';

void main() {
print(Mime.getExtensionFromType('application/pdf'));
// returns `pdf`
print(Mime.getExtensionsFromType('application/xml'));
// returns `[xml, xsl, xsd, rng]`

print(Mime.getTypeFromExtension('pdf'));
// returns `application/pdf`
print(Mime.getTypesFromExtension('xml'));
// returns `[application/xml, text/xml]`

print(Mime.getMime('application/pdf'));
print(Mime.getMimeData('application/xml'));
// returns MimeData(
// charset: null,
// source: iana,
// compressible: false,
// extensions: [pdf]
// )
// charset: null,
// source: iana,
// compressible: true,
// extensions: [xml, xsl, xsd, rng],
// );
}
63 changes: 32 additions & 31 deletions lib/src/mime_dart_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,58 +2,59 @@ import 'package:mime_dart/src/db.dart';
import 'package:mime_dart/src/mime_data/mime_data.dart';

/// Mime Base Class
///
///
/// It contains three methods for getting different mime types
///
/// - [getExtensionFromType]
///
/// - [getTypeFromExtension]
///
/// - [getMime]
///
/// - [getExtensionsFromType]
///
/// - [getTypesFromExtension]
///
/// - [getMimeData]
class Mime {
/// This method helps in getting extension from type
///
/// This method helps in getting extensions from type
///
/// [type] takes a [String] input. For Example: `application/pdf`
///
/// Returns `pdf`
static String? getExtensionFromType(String type) {
if (!database.containsKey(type)) {
return null;
}

MimeData mime = MimeData.fromJson(database[type] as Map<String, Object?>);

if (mime.extensions != null && mime.extensions!.isNotEmpty) {
return mime.extensions?.first;
///
/// Returns `[pdf]`
static List<String>? getExtensionsFromType(String type) {
if (type.isEmpty) return null;

if (database.containsKey(type)) {
MimeData mime = MimeData.fromJson(database[type] as Map<String, Object?>);
return mime.extensions;
}

return null;
}

/// This method helps in getting type from extension
///
/// This method helps in getting types from extension
///
/// [extension] takes [String] as input. For Example: `pdf`
///
/// Returns `application/pdf`
static String? getTypeFromExtension(String extension) {
///
/// Returns `[application/pdf]`
static List<String>? getTypesFromExtension(String extension) {
if (extension.isEmpty) return null;

List<String> types = [];

for (final entry in database.entries) {
final mime = MimeData.fromJson(entry.value as Map<String, Object?>);

if (mime.extensions != null && mime.extensions!.contains(extension)) {
return entry.key;
types.add(entry.key);
}
}

return null;
return types.isNotEmpty ? types : null;
}

/// This method helps in getting MimeData from type
///
///
/// [type] takes [String] as input. For Example: `application/pdf`
///
///
/// returns [MimeData] object with relevant fields
static MimeData? getMime(String type) {
if (!database.containsKey(type)) {
static MimeData? getMimeData(String type) {
if (type.isEmpty || !database.containsKey(type)) {
return null;
}

Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: mime_dart
description: Mime Types for Dart and Flutter.
version: 1.0.1
version: 2.0.0
homepage: https://github.com/niteshsh4rma/mime_dart

environment:
Expand Down

0 comments on commit cf4d1cb

Please sign in to comment.