File.TypeChecker
1.4.0
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.
Install-Package File.TypeChecker -Version 1.4.0
dotnet add package File.TypeChecker --version 1.4.0
<PackageReference Include="File.TypeChecker" Version="1.4.0" />
paket add File.TypeChecker --version 1.4.0
FileTypeChecker - Don't let users to inject you an invalid file
FileTypeChecker is a easy to use library that allows you to identify type of file. This will help you to validate all files that are provided by external sources.
Changelog
- Adding recognition for xml files with BOM header.
See what is new in this version in our github release page
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 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?
Currently FileTypeChecker is able to identify 22 different types but also you are able to register your own types. For more information please visit our wiki page
FileTypeChecker - Don't let users to inject you an invalid file
FileTypeChecker is a easy to use library that allows you to identify type of file. This will help you to validate all files that are provided by external sources.
Changelog
- Adding recognition for xml files with BOM header.
See what is new in this version in our github release page
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 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?
Currently FileTypeChecker is able to identify 22 different types but also you are able to register your own types. For more information please visit our wiki page
Dependencies
This package has no dependencies.
Used By
NuGet packages (1)
Showing the top 1 NuGet packages that depend on File.TypeChecker:
Package | Downloads |
---|---|
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.
|
GitHub repositories
This package is not used by any popular GitHub repositories.