Myrmec 1.2.0

dotnet add package Myrmec --version 1.2.0                
NuGet\Install-Package Myrmec -Version 1.2.0                
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="Myrmec" Version="1.2.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Myrmec --version 1.2.0                
#r "nuget: Myrmec, 1.2.0"                
#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 Myrmec as a Cake Addin
#addin nuget:?package=Myrmec&version=1.2.0

// Install Myrmec as a Cake Tool
#tool nuget:?package=Myrmec&version=1.2.0                

Version 1.1 released!

  1. Support discontinuous binary, such as 0x11,0x22,??,??,0x33,0x66
  2. Support offset, such as 0x11,0x22,0x33 but has offset 10
  3. Obsolete FileTypes.CommonFileTypes and instead with FileTypes.Common By the way: now fully support jpeg.

What is Myrmec

Myrmec is a library that used to identifie real file format type by detecting the file binary head with out file extention like xxxxx.png.

How to use

That was very easy.

Install from nuget

Install-Package Myrmec

Or DotNet cli

dotnet add package Myrmec

Write code

// create a sniffer instance.
Sniffer sniffer = new Sniffer();

// populate with mata data.
// FileTypes.Common contains file types that we usually see.
sniffer.Populate(FileTypes.Common);

// get file head byte, may be 20 bytes enough.
byte[] fileHead = ReadFileHead();

// start match.
List<string> results = sniffer.Match(fileHead);

Many times the results has more than one value, because some file format has multiple extentions, such as jpeg,jpg. or some extentions that point to same file format like apk,zip,pptx they are all zip archive.

Find one result vs multiple result

// this will match one result that sniffer first matched.
// default is false
List<string> results = sniffer.Match(fileHead,false);

// this will match all result that sniffer matched.
List<string> results = sniffer.Match(fileHead,true);

Add your own file format head into metadata

May be you make some file format,or the FileTypes.CommonFileTypes not contains the file format that you need, then you can add it in :

var data = new byte[]
{
    0x11,
    0x22,
    0x33
};
sniffer.Add(data, new[] { "what", "file", "type" });

The variable data is file hex head that you want to add, new[] { "what", "file", "type" } mean that this file type has three extention that named what,file,type. When you match this head will return three result at least*(may be some other file type has same hex head or it's head contains above head(but only on match multiple))*.

Get the MIME type

Suprise! this library also offer the function is get Mime type:

List<string> result = sniffer.Match(head);
string mimeType = MimeTypes.GetMimeType(result.First());

But, some thing that you need to know is this function relay on file extention name, you can write like this:

string mimeType = MimeTypes.GetMimeType("png");

The result is

image/png

Api ducument

github pages

Matedate source

the metadata information from wiki pedia List of file signatures.

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 netcoreapp1.0 was computed.  netcoreapp1.1 was computed.  netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard1.3 is compatible.  netstandard1.4 was computed.  netstandard1.5 was computed.  netstandard1.6 was computed.  netstandard2.0 was computed.  netstandard2.1 was computed. 
.NET Framework net45 is compatible.  net451 was computed.  net452 was computed.  net46 was computed.  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 tizen30 was computed.  tizen40 was computed.  tizen60 was computed. 
Universal Windows Platform uap was computed.  uap10.0 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.

NuGet packages (6)

Showing the top 5 NuGet packages that depend on Myrmec:

Package Downloads
Logibricks.Utility

Package Description

LDFCore.Common

Package Description

LDFCore.Net5.Common

Package Description

AspNetCore.DynaX

DynaX For AspNetCore

14All

Package Description

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on Myrmec:

Repository Stars
anuraj/AspNetCoreSamples
This repository is set of ASP.NET Core projects and scripts.
Version Downloads Last updated
1.2.0 602,498 6/12/2018
1.1.0 2,378 3/12/2018
1.0.0 1,008 2/10/2018

Myrmec is a library that used to identifie real file format type by detecting the file binary head with out file extention.