YngveHestem.FileTypeInfo 1.0.2

dotnet add package YngveHestem.FileTypeInfo --version 1.0.2                
NuGet\Install-Package YngveHestem.FileTypeInfo -Version 1.0.2                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="YngveHestem.FileTypeInfo" Version="1.0.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add YngveHestem.FileTypeInfo --version 1.0.2                
#r "nuget: YngveHestem.FileTypeInfo, 1.0.2"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install YngveHestem.FileTypeInfo as a Cake Addin
#addin nuget:?package=YngveHestem.FileTypeInfo&version=1.0.2

// Install YngveHestem.FileTypeInfo as a Cake Tool
#tool nuget:?package=YngveHestem.FileTypeInfo&version=1.0.2                

FileTypeInfo

A collection of FileTypes with both file extensions, mime-types and UTType (UTI (Universal Type Identifier)). The FileType-structure makes it also easy to create other types not defined yet also.

##How to use this package

The easiest way to use the package is to download it from nuget: https://www.nuget.org/packages/YngveHestem.FileTypeInfo/

Why this was made

This small project was made because I needed a way to easily get both extensions, mime-types and UTType (also called UTI (Universal Type Identifier)) of a given type/extension in a MAUI-application. I tried to find a library that could do this, but could only find extension and mime-type-mappings, and not anything with UTType/UTI, which is needed for Apple-systems.

Features

  • Has a list of FileTypes already defined. This contains most of the file-types defined in https://developer.apple.com/library/archive/documentation/Miscellaneous/Reference/UTIRef/Articles/System-DeclaredUniformTypeIdentifiers.html, plus some more.
  • Has some extension-methods to get FileTypes based on extensions, mime-types and UTTypes for an IEnumerable of FileType.
  • Has a predefined Dictionary of UTTypes childs.
  • Some extension-methods to, by a given UTType, get it's children. This can then for example be used to again get a collection of file types (like getting all file types defined as children to the "public.image" UTI).
  • Use the Filetype-class to create your own types. Either in conjunction with some or all of the alredy defined types, or alone.

Some things to watch out for

  • Mark that while the most mime-types is properly defined, a few of the mime-types defined can be very broad, or not defined on some rare types. This is because either no mime type was found for the type, or only a broad one was found. If you know a better mime-type, I will be glad if you want to contribute.
  • Mark that while some of the UTType-parents maybe only contains the expected types, many, like "public.image", also contains some rare or maybe not expected types. Therefore, I will reccommend that if you use UTType-parents to get a collection of FileType's, you don't use it directly on the whole defined list of FileType's, but only use it on a subset of the list, so you know what you are getting.

Contribute

If you want to contribute, either it is fixing some bugs, adding one or more types to the list, or new features, you are welcome to both create a PR or create an issue.

How to add a new type to the list

You need first to find the file extension(s), mime-type(s) and at least one UTType/UTI (and hopefully also the parent(s) (what Apple calls "conforms to"), so it can be added to its parent(s) (but not it grandparents). See below for how you can find these. If you don't have the possibillity to find the UTType/UTI (like don't have a MAC), but want to contribute, create an issue with all the other information. A properly created example-file would also be appriciated in such a case.

Find the mime-type

There are multiple ways to do this. Online it is databases with many extensions and their types. Sadly, theese don't have all, as I found out when creating this list. It also exists some online file-checkers.

If you have a file and are on a linux-computer (at least ubuntu), you can use what it says here (not tested): https://askubuntu.com/questions/3395/how-to-get-the-mime-type-of-a-file-from-the-command-line

If you have a file and are on mac, you can use the method described here: https://stackoverflow.com/questions/46217787/where-is-the-location-of-the-mime-plugin-files-in-mac-and-linux

Find the UTType/UTI

The UTType/UTI is something Apple has defined themself (see more info about it here https://en.wikipedia.org/wiki/Uniform_Type_Identifier, and maybe also some here https://developer.apple.com/documentation/uniformtypeidentifiers).

To find the type, you can see https://superuser.com/questions/209145/how-to-get-a-files-uti-from-the-command-line-in-mac-os-x. If you call mdls "FILENAME", where FILENAME is the path to the file, you will also get many other entries. One of them is "kMDItemContentTypeTree", which will help find which parents it has. The first entry is usually it's own UTI, and then parents and grandparents come in a single list.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on YngveHestem.FileTypeInfo:

Package Downloads
YngveHestem.GenericParameterCollection.Maui

This provides controls for using GenericParameterCollection in .NET MAUI.

YngveHestem.BytesPreview.Maui.Core

This package provides an interface to create different "preview"-functionality for byte-arrays.

YngveHestem.GenericParameterCollection.Avalonia

This provides controls for using GenericParameterCollection in an AvaloniaUI-application.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.2 681 7/2/2023
1.0.1 231 6/1/2023
1.0.0 132 5/17/2023

Version 1.0.2:
       - Now the methods check that inputted lists are null instead of creating Null-exceptions.

       Version 1.0.1:
       - Added some methods to get all extensions, mime-types and uttypes as a one dimensional string-list respectively. Theese methods also support removing duplicates from the list.

       Version 1.0.0:
       - Initial release