Skip to content

How to use?

Aleksander J. Mitev edited this page Mar 10, 2020 · 1 revision

In this page you will find how easy is to recognize type of a file with FileTypeChecker.

Identify if the file can be identified

using var fileStream = File.OpenRead(filePath);
var isRecognizableType = FileTypeValidator.IsTypeRecognizable(fileStream);

Identify the exact file type

using var fileStream = File.OpenRead(filePath);
var isRecognizableType = FileTypeValidator.IsTypeRecognizable(fileStream);

if (!isRecognizableType)
{
    throw new InvalidDataException("Invalid file type!");                
}

IFileType fileType = FileTypeValidator.GetFileType(fileStream);

Identify if the file is from a specific type

using FileTypeChecker.Types;

bool isBitmap = FileTypeValidator.Is<Bitmap>(fileStream);

Or

using FileTypeChecker.Types;
using FileTypeChecker.Extensions;

bool isBitmap = fileStream.Is<Bitmap>();

General types

With FileTypeChecker you can easily check if the file is a general type. We create some extension methods that will give you this flexibility

using FileTypeChecker.Extensions;

bool isImage = fileStream.IsImage();
bool isArchive = fileStream.IsArchive();

Or

bool isImage = FileTypeValidator.IsImage(fileStream);
bool isArchive = FileTypeValidator.IsArchive(fileStream);