diff --git a/lib/src/utils/mime_type_utils.dart b/lib/src/utils/mime_type_utils.dart index 2f06052..bda321d 100644 --- a/lib/src/utils/mime_type_utils.dart +++ b/lib/src/utils/mime_type_utils.dart @@ -17,9 +17,11 @@ String? lookupMimeType(String path, {List? headerBytes}) { return mime.lookupMimeType(path, headerBytes: headerBytes); } -String lookupMimeTypeWithDefaultType(String path, {List? headerBytes}) => - lookupMimeType(path, headerBytes: headerBytes) ?? - 'application/octet-stream'; +String lookupMimeTypeWithDefaultType(String path, {List? headerBytes}) { + path = path.toLowerCase(); + + return lookupMimeType(path, headerBytes: headerBytes) ?? octetStream; +} /// This implementation is specific for `file_saver` package. MimeType getMimeTypeFromString(String mimeType) { @@ -76,3 +78,5 @@ MimeType getMimeTypeFromString(String mimeType) { return MimeType.OTHER; } } + +const String octetStream = 'application/octet-stream'; diff --git a/pubspec.yaml b/pubspec.yaml index 2f09c47..81b5c2a 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: ardrive_io description: A new Flutter package project. -version: 1.4.4 +version: 1.4.5 homepage: publish_to: none diff --git a/test/src/utils/mime_type_utils_test.dart b/test/src/utils/mime_type_utils_test.dart index 01a7e0c..c7e3d45 100644 --- a/test/src/utils/mime_type_utils_test.dart +++ b/test/src/utils/mime_type_utils_test.dart @@ -35,8 +35,21 @@ void main() { 'path/to/my/non tar/file.iso': 'application/x-iso9660-image', 'ardrive.png': 'image/png', '.tar.gz': 'application/gzip', - 'my.non.tar.gz.file': 'application/octet-stream', - 'where\'s waldo.tar.gz.': 'application/octet-stream', + 'my.non.tar.gz.file': octetStream, + 'where\'s waldo.tar.gz.': octetStream, + }; + + const pathToMimeMappingUpperCase = { + '.my.file.TAR.GZ': 'application/gzip', + 'abcdefghijklmnñopqrstuvwxyz.tar.GZ': 'application/gzip', + 'path/to/my/file.TAR.GZ': 'application/gzip', + 'path/to/my/file.GZ': 'application/gzip', + 'path/to/my/file.tGZ': 'application/gzip', + 'path/to/my/non tar/file.ISO': 'application/x-iso9660-image', + 'ardrive.PNG': 'image/png', + '.tar.GZ': 'application/gzip', + 'my.non.tar.GZ.file': octetStream, + 'where\'s waldo.TAR.gz.': octetStream, }; test('returns the expected mime type', () { @@ -47,12 +60,20 @@ void main() { } }); + test('returns the expected mime type when written in uppercase', () { + for (final path in pathToMimeMappingUpperCase.keys) { + final expectedMime = pathToMimeMappingUpperCase[path]; + final mime = lookupMimeTypeWithDefaultType(path); + expect(mime, expectedMime); + } + }); + test( 'returns the application/octet-stream type when not provided a mime type', () { final mime = lookupMimeTypeWithDefaultType('path/some_file_without_extension'); - expect(mime, 'application/octet-stream'); + expect(mime, octetStream); }); }); } diff --git a/test/src/utils/path_utils_test.dart b/test/src/utils/path_utils_test.dart index 06613f1..78d97b7 100644 --- a/test/src/utils/path_utils_test.dart +++ b/test/src/utils/path_utils_test.dart @@ -1,5 +1,4 @@ -import 'package:ardrive_io/src/io_exception.dart'; -import 'package:ardrive_io/src/utils/path_utils.dart'; +import 'package:ardrive_io/ardrive_io.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { @@ -76,7 +75,7 @@ void main() { test('should return the extension from mimetype name without .', () { final ext = getFileExtension( name: 'file', - contentType: 'application/octet-stream', + contentType: octetStream, withExtensionDot: false, );