All Projects → hey-red → Mime

hey-red / Mime

Licence: MIT License
.NET wrapper for libmagic

Programming Languages

C#
18002 projects

Projects that are alternatives of or similar to Mime

Fileio.jl
Main Package for IO, loading all different kind of files
Stars: ✭ 133 (+160.78%)
Mutual labels:  file, mime, mime-types
Mime Types
The ultimate javascript content-type utility.
Stars: ✭ 865 (+1596.08%)
Mutual labels:  mime, mime-types
Mime
Shared MIME-info database in D programming language
Stars: ✭ 7 (-86.27%)
Mutual labels:  mime, mime-types
Mime
The Hoa\Mime library.
Stars: ✭ 100 (+96.08%)
Mutual labels:  mime, mime-types
ruby-magic
Simple interface to libmagic for Ruby Programming Language
Stars: ✭ 23 (-54.9%)
Mutual labels:  mime, mime-types
Mime Db
Media Type Database
Stars: ✭ 612 (+1100%)
Mutual labels:  mime, mime-types
Mailmergelib
MailMergeLib is a mail message client library which provides comfortable mail merge capabilities for text, inline images and attachments, as well as good throughput and fault tolerance for sending mail messages.
Stars: ✭ 97 (+90.2%)
Mutual labels:  mime, netstandard
Mimetype
A fast golang library for MIME type and file extension detection, based on magic numbers
Stars: ✭ 452 (+786.27%)
Mutual labels:  mime, mime-types
mimesniff
MIME Sniffing Standard
Stars: ✭ 89 (+74.51%)
Mutual labels:  mime, mime-types
Droply Js
Droply JS, a new responsive and cross browser chunk uploader with DragDrop and File Preview capabilities (HTML5/CSS3)
Stars: ✭ 50 (-1.96%)
Mutual labels:  file, mime
Filetype
Fast, dependency-free, small Go package to infer the binary file type based on the magic numbers signature
Stars: ✭ 1,278 (+2405.88%)
Mutual labels:  mime, mime-types
php-mime-detector
Detect a file's mime type using magic numbers.
Stars: ✭ 20 (-60.78%)
Mutual labels:  file, mime
Swime
🗂 Swift MIME type checking based on magic bytes
Stars: ✭ 119 (+133.33%)
Mutual labels:  mime, mime-types
safe-svg
Enable SVG uploads and sanitize them to stop XML/SVG vulnerabilities in your WordPress website.
Stars: ✭ 129 (+152.94%)
Mutual labels:  file, mime
rust-magic
Rust high level bindings crate for the `libmagic` C library
Stars: ✭ 22 (-56.86%)
Mutual labels:  file, libmagic
replace-in-files
Replace text in one or more files or globs.
Stars: ✭ 21 (-58.82%)
Mutual labels:  file
ShareX-CDN
Basic image, text & file uploader CDN for ShareX
Stars: ✭ 22 (-56.86%)
Mutual labels:  file
FireFiles
Powerful Android File Manager for everything that runs on Android OS (Android TV, Android Watch, Mobile, etc)
Stars: ✭ 37 (-27.45%)
Mutual labels:  file
AspNetCorePdf
Creating PDF documents in ASP.NET Core using PDFSharp
Stars: ✭ 44 (-13.73%)
Mutual labels:  file
EPPlus4PHP
an easy-to-use excel library for php project which is compiled with peachpie. NOT FOR THE COMMON PHP PROJECT!
Stars: ✭ 15 (-70.59%)
Mutual labels:  netstandard

Mime

.NET wrapper for libmagic

NuGet license

Install

via NuGet:

PM> Install-Package Mime

Requirements

Supports only x64 OS(Linux, MacOS and Windows).

Basic usage

using HeyRed.Mime;

// (Optionally) You can set path to magic database file manually.
MimeGuesser.MagicFilePath = "/path/to/magic/file";

// Guess mime type of file(overloaded method takes byte array or stream as arg.)
MimeGuesser.GuessMimeType("path/to/file"); //=> image/jpeg

// Get extension of file(overloaded method takes byte array or stream as arg.)
MimeGuesser.GuessExtension("path/to/file"); //=> jpeg

// Get mime type and extension of file(overloaded method takes byte array or stream as arg.)
MimeGuesser.GuessFileType("path/to/file"); //=> FileType

Advanced

Want more than just the mime type? Use the Magic class:

string calc = @"C:\Windows\System32\calc.exe";
using var magic = new Magic(MagicOpenFlags.MAGIC_NONE);
magic.Read(calc); //=> PE32+ executable (GUI) x86-64, for MS Windows

// Check encoding:
string textFile = @"F:\Temp\file.txt";
using var magic = new Magic(MagicOpenFlags.MAGIC_MIME_ENCODING);
magic.Read(textFile); //=> Output: utf-8

Also, we can combine flags with "|" operator. See all flags for more info.

Remarks

  • The Magic class is not thread safe, but if you use different instances on different threads it seems to work fine.
  • The MimeGuesser is thread safe, since it generates a new instance of Magic class on each use.

Possible problems

Exception Solution
DllNotFoundException Make sure that your bin folder contains runtimes directory. If you publishing platform dependent app, then bin should be contains libmagic-1(.dll, .so or .dylib) and magic.mgc files.
BadImageFormatException Make sure when you target the AnyCPU platform the Prefer 32-bit option is unchecked. Or try to target x64 instead.

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].