SharpMagic 1.0.2

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

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

NCV Sharpmagic

Tiny C# P-invoking client class built on top off libmagic (see e.g.) LibMagic. Should work on all platforms that have Libmagic as part of the OS package (including macOS). The idea behind mime-type recognition is using magic numbers and some other features.

Description

Wraps basic LibMagic calls in order to get mimetype and file type properties (if possible) using the well known library which is mostly standard on Linux

Key Features

  • Highly optimized for low resource usage.
  • Enables using the libmagic library to retrieve mime types or file info (as properties)
  • e.g.
detected mimetype = ISO Media,MP4 Base Media v1 [IS0 14496-12:2003]
detected mimetype = JPEG image data,JFIF standard 1.01,aspect ratio,density 1x1,segment length 16,baseline,precision 8,1200x826,
components 3
  • Only supporting linux or OS-es that have libmagic as part of the OS.

How To Use

To clone and run this application, you'll need Git From your command line:

# Clone this repository
$ git clone https://github.com/egbertn/SharpMagic


Credits

This software uses the following open source packages:

  • [Libmagic]
  • Hey-Red (inspired this code)

Usage

Register SharpMagic as singleton e.g.

// somewhere in program.cs / startup.cs
  services.AddSingleTon<SharpMagic>();
  //or directly:
  SharpMagic sharpMagic = new();

// somewhere in your code
  using var mp4 = File.OpenRead("tesje.mp4");
  var (mp4MimeType, _) = sharpMagic.GuessMimeType(mp4, 2048, true);
  Console.WriteLine($"detected mimetype = {mp4MimeType}");

  using var jpg = File.OpenRead("gun.jpg");
  var (mimeType, _) = sharpMagic.GuessMimeType(jpg, mimeOnly: true);

  Console.WriteLine($"detected properties = {string.Join(',', dll.GuessMimeType(Path.GetFullPath("gun.jpg")).Properties)}");
output:
detected mimetype = video/mp4
detected mimetype = image/jpeg
detected properties = JPEG image data,JFIF standard 1.01,aspect ratio,density 1x1,segment length 16,baseline,precision 8,1200x826,components 3
detected properties = ISO Media,MP4 v2 [ISO 14496-14]

See also other great components

###ISP Session Enables Session and Application State using redis, while in an easy fashion using minimal resources. NCV ISPSession (And Application State)

###CCTV Camera Streaming and Management and Notification management. Enables you to organizate your camerastreams to a NVidia Jetson (nano e.g.) the default features plus training your own models Does not need to use the cloud, so privacy is covered for most of it. CCure Image Stream

Support

Not really. If I have time. Drop a message.

You may also like...

License

MIT

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.2 84 5/3/2024

* remove confusing seemingly arch-linux-only support.