File.TypeChecker 4.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package File.TypeChecker --version 4.0.0
NuGet\Install-Package File.TypeChecker -Version 4.0.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="File.TypeChecker" Version="4.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add File.TypeChecker --version 4.0.0
#r "nuget: File.TypeChecker, 4.0.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 File.TypeChecker as a Cake Addin
#addin nuget:?package=File.TypeChecker&version=4.0.0

// Install File.TypeChecker as a Cake Tool
#tool nuget:?package=File.TypeChecker&version=4.0.0

<h1><img src="https://raw.githubusercontent.com/AJMitev/FileTypeChecker/master/tools/FileTypeCheckerLogo-150.png" align="left" alt="FileTypeChecker" width="90">FileTypeChecker - Don't let users to inject you an invalid file</h1>

Build status NuGet Badge License: MIT CodeFactor Discord

Project Description

FileTypeChecker is a easy to use library that provides quality identification of a file type. This will help you to secure your applications and validate all files that are provided by external sources with few lines of code.

Why to use it?

Have you ever had a requirement for users to be able to upload files of a certain type? How do you validate that the file type is allowed? How do you protect your application from uploading a malicious file? It is standard practice to use the FileSystemInfo class provided by Microsoft and its Extension property for this kind of job, but is that enough? The answer is simple - No! This is why this small but effective library comes to help.

How it works?

FileTypeChecker use file's "magic numbers" to identify the type. According to Wikipedia this term ("magic numbers") was used for a specific set of 2-byte identifiers at the beginnings of files, but since any binary sequence can be regarded as a number, any feature of a file format which uniquely distinguishes it can be used for identification. This approach offers better guarantees that the format will be identified correctly, and can often determine more precise information about the file. See more about Magic Numbers

How to install?

You can install this library using NuGet into your project.

Install-Package File.TypeChecker

or by using dotnet CLI

dotnet add package File.TypeChecker

How to use?

using (var fileStream = File.OpenRead("myFileLocation"))
{
    var isRecognizableType = FileTypeValidator.IsTypeRecognizable(fileStream);

    if (!isRecognizableType)
    {
        // Do something ...
    }

    IFileType fileType = FileTypeValidator.GetFileType(fileStream);
    Console.WriteLine("Type Name: {0}", fileType.Name);
    Console.WriteLine("Type Extension: {0}", fileType.Extension);
    Console.WriteLine("Is Image?: {0}", fileStream.IsImage());
    Console.WriteLine("Is Bitmap?: {0}", fileStream.Is<Bitmap>());
}

If you are interested in finding more samples please use our wiki page.

What types of file are supported?

FileTypeChecker is able to identify more than 22 different types but also you are able to register your own types. For more information please visit our wiki page

Credits

Based on mjolka's answer to the Stack Overflow question Guessing a file type based on its content.

This repo is inspired from 0xbrock and the original code can be found in the "original" branch. I re-writed the all project with goal to make it Object oriented, with fluent API and easy to extend.

Support the project

  • If you like this library, ⭐️ the repository and show it to your friends!
  • If you find this library usefull and it helps you please consider to support the project, you can do by buying me a cup of coffee.

<a href="https://www.buymeacoffee.com/ajmitev" target="_blank"><img src="https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png" alt="Buy Me A Coffee" style="height: 41px !important;width: 174px !important;box-shadow: 0px 3px 2px 0px rgba(190, 190, 190, 0.5) !important;-webkit-box-shadow: 0px 3px 2px 0px rgba(190, 190, 190, 0.5) !important;" ></a>

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.

This package has no dependencies.

NuGet packages (7)

Showing the top 5 NuGet packages that depend on File.TypeChecker:

Package Downloads
DeploySoftware.LaunchPad.Core

Shared code for LaunchPad framework.

File.TypeChecker.Web

Don't let users to inject you an invalid file! FileTypeChecker is a easy to use library that allows you to read file and recognize its type. This will help you to validate all files that is provided by external sources.

Deploy.LaunchPad.Core

Shared code for LaunchPad framework.

SAPI

Simple API server written in C#

vergiCommon

Common utilities for personal projects. Mostly input-related, repetitive work that often occures in every prototype/hobby project.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
4.1.0 2,523 4/6/2024
4.0.0 294,080 5/2/2023
3.0.0 455,527 12/16/2021
2.1.0 6,056 11/16/2021
2.0.3 1,372 11/11/2021
1.5.3 19,052 10/29/2021
1.5.2 22,694 8/2/2021
1.5.1 40,640 4/30/2021
1.4.0 58,841 11/24/2020
1.3.3 10,225 10/20/2020
1.3.2 5,393 10/4/2020
1.3.1 89,109 5/15/2020
1.3.0 8,217 5/7/2020
1.2.0 2,154 3/14/2020
1.1.0 1,429 3/7/2020
1.0.4 1,829 10/5/2019
1.0.3 1,604 10/5/2019
1.0.1 1,550 10/5/2019
1.0.0 7,782 10/4/2019