Giter VIP home page Giter VIP logo

soranrad / mimetypedetective Goto Github PK

View Code? Open in Web Editor NEW
5.0 2.0 5.0 110 KB

A simple library to find mimetype of a file, stream or buffer array via magic numbers in the header content. It contains over 480 samples that as hardcoded in the library. Detect mimetype of an extension string or mimetype string like “rar”, “exe”,” image/gif” …. It is possible to add more mimetypes in the library to detect files related to them. In fact, this library finds the mimetype via magic numbers.(https://20devs.com/find-mimetype/)

Home Page: https://20devs.com/find-mimetype/

C# 100.00%
magic-numbers mimetypes csharp dotnet dotnet-core

mimetypedetective's Introduction

MimetypeDetective

Build&Test NuGet Badge

A simple library to detect mimetype of a file, stream or buffer array via magic numbers in the header content. It contains over 480 samples that as hardcoded in the library.

Detect mimetype of an extension string or mimetype string like “rar”, “exe”,” image/gif” …. It is possible to add more mimetypes in the library to detect files related to them. In fact, this library finds the mimetype via magic numbers.

Installing Package

Install-Package TwentyDevs.MimeTypeDetective

Or via the .NET Core command line interface:

dotnet add package TwentyDevs.MimeTypeDetective	

to detect a mimetype of a file with the address :

MimeTypeDetection.GetMimeType(filePath, Path.GetExtension(filePath));

In the example, passed the extension to method because some files like fdf, pdf, zip, and office files(xlsx, Docx, … ) have the same magic numbers, then detection must be done by extension. Also, it is possible to Detect the mimetype of streams and buffers (byte array) with the method.

To get the mimetype of an extension :

MimeTypeDetection.GetMimeTypeByExtension("rar");

To get other information about the particular mimetype :

MimeTypeDetection.GetMimeTypeinfoByMimetypeString("image/gif");

Except for mimetypes that are defined in the library you can add other mimetype to the mimetypes collection.

MimeTypes.Add
            (
                fileContent,
                headerOffset,
                headerSize,
                extension,
                mimeType,
                description,
                mustBeDetectByExtention
            );

There is a sample in the source code to add a new mimetype and then use it to detect a file (SVG File).

Using To File Validation

Donate Us

Buy Me A Coffee

mimetypedetective's People

Contributors

egbertn avatar nimamamaghaei avatar soranrad avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.